From cd04a5560d89adca42dd59b4beb953db99cde611 Mon Sep 17 00:00:00 2001 From: Thomas Hooge Date: Sun, 26 Oct 2025 09:38:50 +0100 Subject: [PATCH] =?UTF-8?q?Konfigurationsmodus=20f=C3=BCr=20Tide=20begonne?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/navtex.py | 2 ++ pages/tide.py | 85 +++++++++++++++++++++++++++++++++++++++++++++++-- web.py | 8 +++++ 3 files changed, 93 insertions(+), 2 deletions(-) diff --git a/pages/navtex.py b/pages/navtex.py index e6c9fd3..95149af 100644 --- a/pages/navtex.py +++ b/pages/navtex.py @@ -13,6 +13,8 @@ class Navtex(Page): def __init__(self, pageno, cfg, appdata, boatdata): super().__init__(pageno, cfg, appdata, boatdata) self.disabled = self.app.navtex is None + if self.disabled: + return self.ids = self.app.navtex.get_ids() if len(self.ids) > 0: self.current = 1 diff --git a/pages/tide.py b/pages/tide.py index 29977c8..7d5a458 100644 --- a/pages/tide.py +++ b/pages/tide.py @@ -13,11 +13,86 @@ class Tide(Page): def __init__(self, pageno, cfg, appdata, boatdata): super().__init__(pageno, cfg, appdata, boatdata) + self.buttonlabel[1] = 'MODE' + self.mode = 'N' # (N)ormal, (C)onfiguration + self.station = "f3c6ee73-5561-4068-96ec-364016e7d9ef" # Schulau - self.app.web.set_pegel('List, Sylt') + self.pegel = 'List, Sylt' + self.app.web.set_pegel(self.pegel) self.app.web.refresh() - def draw(self, ctx): + # Steuerung der Stationsliste + self.list_max = 10 + self.list_top = 0 + self.list_ix = 0 + self.list_pegel = self.pegel + self.list_count = len(self.app.web.pegeldata) + + def handle_key(self, buttonid): + if buttonid == 1: + if self.mode == 'N': + self.mode = 'C' + self.buttonlabel[3] = '#UP' + self.buttonlabel[4] = '#DOWN' + self.buttonlabel[5] = 'SET' + else: + self.mode = 'N' + self.buttonlabel[3] = '#PREV' + self.buttonlabel[4] = '#NEXT' + self.buttonlabel[5] = '' + return True + if self.mode == 'C': + if buttonid == 3: + # Up + self.list_ix -= 1 + if self.list_ix < self.list_top: + self.list_top -= 1 + elif buttonid == 4: + # Down + self.list_ix += 1 + if self.list_ix > self.list_top + self.list_max: + self.list_top += 1 + elif buttonid == 5: + # Set + print(self.list_pegel) + self.pegel = self.list_pegel + self.app.web.set_pegel(self.list_pegel) + self.app.web.refresh() + return True + return False + + def draw_config(self, ctx): + # Auswahl + # - Station + # - Zeitraum + # + ctx.select_font_face("Ubuntu", cairo.FontSlant.NORMAL, cairo.FontWeight.BOLD) + ctx.set_font_size(20) + + ctx.move_to(2, 50) + ctx.show_text("Tide configuration") + + y = 80 + dy = 20 + ctx.set_font_size(20) + i = 0 + ix = -1 + for pd in self.app.web.pegeldata: + ix += 1 + if ix < self.list_top: + continue + ctx.move_to(20, y + dy * i) + ctx.show_text(pd) + self.list_pegel = pd + if self.list_ix == ix: + ctx.show_text(' X') + i += 1 + if self.pegel == pd: + ctx.show_text(' *') + if ix > self.list_top + self.list_max - 1: + break + + def draw_normal(self, ctx): # Title ctx.select_font_face("Ubuntu", cairo.FontSlant.NORMAL, cairo.FontWeight.BOLD) ctx.set_font_size(24) @@ -124,3 +199,9 @@ class Tide(Page): else: prev_valid = False x += dx + + def draw(self, ctx): + if self.mode == 'N': + self.draw_normal(ctx) + else: + self.draw_config(ctx) diff --git a/web.py b/web.py index f7053d3..287dcfd 100644 --- a/web.py +++ b/web.py @@ -74,6 +74,14 @@ class WebInterface(): ) self.cur.execute(sql) self.log.info(f"Created tide database: {dbpath}") + else: + # TODO Alte Daten aus vorhandener Datenbank bereinigen + ts = datetime.now().replace(minute=0, second=0, microsecond=0) - timedelta(days=2) + sql = "DELETE FROM data WHERE timestamp < ?" + self.cur.execute(sql, (ts,)) + self.conn.commit() + if self.cur.rowcount > 0: + print("Tide: {} old data ponts have been deleted".format(self.cur.rowcount)) self.pegelid = 'Schulau' self.bshid = self.pegeldata[self.pegelid]