OBP60v/pages/anchor.py

175 lines
4.9 KiB
Python

"""
Ankerinfo / -alarm
Daten
- Position des Ankers
- Wassertiefe beim Ankern
- Gesteckte Kettenlänge
- aktuelle Position des Schiffs
- aktuelle Wassertiefe an Schiffsposition
- aktuelle Schiffsausrichtung bearing/heading
- aktuelle Windrichtung (wahr)
- aktuelle Windstärke (wahr)
- Alarm aktiv J/N
- Alarmradius
- GPS Abweichung/ Fehler in der Horizontalen
Darstellung:
- Modi:
- Anker oben / unten
- Nord ist oben
Es gibt verschiedene Unterseiten
- Normalansicht
- Konfigurationsseite
"""
import os
import cairo
import math
from .page import Page
class Anchor(Page):
def __init__(self, pageno, cfg, boatdata):
super().__init__(pageno, cfg, boatdata)
self.sym_anchor = cairo.ImageSurface.create_from_png(os.path.join(cfg['imgpath'], "anchor.png"))
self.buttonlabel[1] = 'MODE'
self.buttonlabel[2] = 'DROP'
self.buttonlabel[5] = '' # ALARM erst möglich wenn der Anker unten ist
self.mode = 'N' # (N)ormal, (C)onfiguration
self._bd = boatdata
# Der sinnvolle Abstand ist abhängig von der Länge der gesteckten Kette
# Die initial eingegebene Position des Ankers sollte nactträglich justiert
# werden können
self.chain_length = 60 # maximale Länge die ausgesteckt werden kann
self.chain = 35 # aktuell gesteckte Länge
self.anchor_set = False
self.anchor_lat = 0
self.anchor_lon = 0
self.anchor_depth = -1
self.lat = 0
self.lon = 0
self.heading = -1
self.depth = -1
self.alarm_range = 20
self.alarm_enabled = False
self.alarm = False # Alarm ist ausgelöst und aktiv
self.wind_angle = -1
def handle_key(self, buttonid):
if buttonid == 1:
if self.mode == 'N':
self.mode = 'C'
else:
self.mode = 'N'
return True
if buttonid == 2:
if not self.anchor_set:
self.anchor_lat = self._bd.lat
self.anchor_lon = self._bd.lon
self.anchor_set = True
self.buttonlabel[2] = 'RISE'
self.buttonlabel[5] = 'ALARM'
else:
self.anchor_set = False
self.alarm = False
self.alarm_enabled = False
self.buttonlabel[2] = 'SET'
self.buttonlabel[5] = ''
if buttonid == 5:
# Bei aktivem Alarm kann mit dieser Taste der Alarm zurückgesetzt
# werden. Die Tastenbeschriftung wechselt zwischen ALARM und OFF.
if self.alarm:
self.alarm = False
self.buttonlabel[5] = 'ALARM'
if self.alarm_enabled:
self.alarm_enabled = False
self.buttonlabel[5] = 'ALARM'
else:
self.alarm_enabled = True
self.buttonlabel[5] = 'OFF'
return False
def draw(self, ctx):
"""
value1 = LAT
value2 = LON
value3 = HDOP
value4 = DBS
value5 = TWD
value6 = TWS
"""
# self.anchor_lat =
# Name
ctx.select_font_face("Ubuntu", cairo.FontSlant.NORMAL, cairo.FontWeight.BOLD)
ctx.set_font_size(20)
ctx.move_to(2, 50)
ctx.show_text("Anchor")
ctx.move_to(2, 200)
ctx.show_text("Depth")
ctx.move_to(320, 50)
ctx.show_text("Chain")
ctx.set_font_size(16)
ctx.move_to(2, 70)
ctx.show_text("Alarm: ")
if self.alarm_enabled:
ctx.show_text("On")
else:
ctx.show_text("Off")
ctx.move_to(320, 70)
ctx.show_text(f"{self.chain} m")
ctx.move_to(10, 220)
if self._bd.dbs.valid:
ctx.show_text(self._bd.dbs.format())
ctx.stroke()
# Spezialseite
cx = 200
cy = 150
r = 125
ctx.set_line_width(1.5)
ctx.arc(cx, cy, r, 0, 2*math.pi)
ctx.stroke()
# Ankersymbol falls Anker fallen gelassen wurde, ansonsten nur Kreis-
# mittelpunkt kennzeichnen
if self.anchor_set:
ctx.save()
ctx.set_source_surface(self.sym_anchor, cx-8, cy-8)
ctx.paint()
ctx.restore()
else:
ctx.move_to(cx-6, cy-6)
ctx.line_to(cx+6, cy+6)
ctx.move_to(cx+6, cy-6)
ctx.line_to(cx-6, cy+6)
ctx.stroke()
# Boot zeichnen
# Heading beachten
# Windpfeil zeichnen
if self._bd.awa.value:
p = ((cx, cy - r + 25), (cx - 12, cy - r - 4), (cx, cy - r + 6), (cx + 12, cy - r - 4), (cx, cy - r + 25))
wind = self.rotate((cx, cy), p, self._bd.awa.value)
ctx.move_to(*wind[0])
for point in wind[1:]:
ctx.line_to(*point)
ctx.fill()