155 lines
4.6 KiB
Python
155 lines
4.6 KiB
Python
"""
|
|
Tracker mit MQTT client
|
|
|
|
Es gibt zwei Modi: Track und Race
|
|
A) Track: Es wird nur der Track gesended / aufgezeichnet
|
|
B) Race: Es werden zusätzlich Regattadaten angezeigt, das beinhaltet
|
|
die Auswahl einer Regatta, das Teilnehmen, das Aufgeben und die
|
|
Signalisierung vor und während einer Wettfahrt.
|
|
|
|
Das Tracking kann über eine Taste ein- und ausgeschaltet werden.
|
|
Um versehentliches Umschalten zu vermeiden ist eine Nachfrage
|
|
integriert.
|
|
|
|
- currentry only Ragatta hero supported
|
|
|
|
Behandlung von Verbindungsabbrüchen:
|
|
- on_disconnect
|
|
|
|
|
|
"""
|
|
|
|
import os
|
|
import cairo
|
|
from .page import Page
|
|
|
|
class Tracker(Page):
|
|
|
|
def __init__(self, pageno, cfg, appdata, boatdata):
|
|
super().__init__(pageno, cfg, appdata, boatdata)
|
|
self._appdata = appdata
|
|
self.bv_lat = boatdata.getRef("LAT")
|
|
self.bv_lon = boatdata.getRef("LON")
|
|
self.bv_sog = boatdata.getRef("SOG")
|
|
self.buttonlabel[1] = 'MODE'
|
|
self.buttonlabel[2] = 'ON'
|
|
self.mode = 'N' # (N)ormal, (C)onfiguration
|
|
|
|
# Flaggengröße: 96 x 64 Pixel
|
|
self.flagpos = ((208, 140), (308, 140), (208, 210), (308, 210))
|
|
|
|
# Flaggen laden
|
|
flag = ('alpha', 'answer', 'black', 'blue', 'charlie', 'class',
|
|
'finish', 'hotel', 'india', 'november', 'orange',
|
|
'papa', 'repeat_one', 'sierra', 'start', 'uniform',
|
|
'xray', 'yankee', 'zulu')
|
|
self.sym_flag = {}
|
|
for f in flag:
|
|
flagfile = os.path.join(cfg['imgpath'], 'flags', f + '.png')
|
|
self.sym_flag[f] = cairo.ImageSurface.create_from_png(flagfile)
|
|
print(self.sym_flag)
|
|
|
|
def handle_key(self, buttonid):
|
|
if buttonid == 1:
|
|
# Modus umschalten
|
|
if self.mode == 'N':
|
|
self.mode = 'C'
|
|
else:
|
|
self.mode = 'N'
|
|
elif buttonid == 2:
|
|
# Tracking ein/-ausschalten
|
|
if self._appdata.track.is_active():
|
|
self._appdata.track.set_active(False)
|
|
self.buttonlabel[2] = 'ON'
|
|
else:
|
|
self._appdata.track.set_active(True)
|
|
self.buttonlabel[2] = 'OFF'
|
|
elif buttonid == 5:
|
|
self._appdata.frontend.flashled.setColor('yellow')
|
|
#self._appdata.frontend.flashled.switchOn(4)
|
|
self._appdata.frontend.flashled.doFlash(2)
|
|
|
|
def draw_normal(self, ctx):
|
|
# Name
|
|
#ctx.select_font_face("Ubuntu", cairo.FontSlant.NORMAL, cairo.FontWeight.BOLD)
|
|
#ctx.set_font_size(32)
|
|
#ctx.move_to(20, 80)
|
|
#ctx.show_text("Tracker")
|
|
|
|
ctx.select_font_face("DSEG7 Classic")
|
|
ctx.set_font_size(80)
|
|
|
|
if self._appdata.track.is_active():
|
|
ctx.move_to(20, 120)
|
|
ctx.show_text("-00:00")
|
|
else:
|
|
ctx.move_to(100, 120)
|
|
ctx.show_text("off")
|
|
|
|
x0 = 8
|
|
x1 = 104
|
|
y0 = 150
|
|
ctx.select_font_face("Ubuntu", cairo.FontSlant.NORMAL, cairo.FontWeight.BOLD)
|
|
ctx.set_font_size(16)
|
|
ctx.move_to(x0, y0)
|
|
ctx.show_text("Type: ")
|
|
ctx.move_to(x1, y0)
|
|
ctx.show_text(self._appdata.track.ttype)
|
|
|
|
ctx.move_to(x0, y0 + 16)
|
|
ctx.show_text("Regatta")
|
|
ctx.move_to(x1, y0 + 16)
|
|
ctx.show_text('')
|
|
|
|
ctx.move_to(x0, y0 + 32)
|
|
ctx.show_text("Lat=")
|
|
ctx.move_to(x1, y0 + 32)
|
|
ctx.show_text(self.bv_lat.format())
|
|
|
|
ctx.move_to(x0, y0 + 48)
|
|
ctx.show_text("Lon=")
|
|
ctx.move_to(x1, y0 + 48)
|
|
ctx.show_text(self.bv_lon.format())
|
|
|
|
ctx.move_to(x0, y0 + 64)
|
|
ctx.show_text("Sog=")
|
|
ctx.move_to(x1, y0 + 64)
|
|
ctx.show_text(self.bv_sog.format())
|
|
|
|
def draw_config(self, ctx):
|
|
|
|
ctx.select_font_face("Ubuntu", cairo.FontSlant.NORMAL, cairo.FontWeight.BOLD)
|
|
ctx.set_font_size(32)
|
|
ctx.move_to(20, 80)
|
|
ctx.show_text("Tracker configuration")
|
|
# Daten aus Konfiguration anzeigen
|
|
# - boot
|
|
# - tracker
|
|
|
|
ctx.set_font_size(16)
|
|
|
|
# Mögliche Regatten
|
|
# -> auf Konfigurationsmodus verschieben
|
|
x = 250
|
|
y = 100
|
|
ctx.move_to(x, y - 24)
|
|
ctx.show_text("Regattas")
|
|
for r in self._appdata.track.hero_get_races():
|
|
ctx.move_to(x, y)
|
|
ctx.show_text(r)
|
|
y += 20
|
|
if y == 160:
|
|
ctx.move_to(x, y)
|
|
ctx.show_text("keine")
|
|
|
|
|
|
ctx.move_to(20, 120)
|
|
ctx.show_text("Type: ")
|
|
ctx.show_text(self._appdata.track.ttype)
|
|
|
|
def draw(self, ctx):
|
|
if self.mode == 'N':
|
|
self.draw_normal(ctx)
|
|
else:
|
|
self.draw_config(ctx)
|