From ece40868e55a982d753f7e8b05ae2a8b145a3dd6 Mon Sep 17 00:00:00 2001 From: Stefan Bethke Date: Sun, 1 Jun 2025 19:03:00 +0200 Subject: [PATCH] Add two animations --- buba/BubaAnimator.py | 56 ++++++++++++++++++++++++++++++++++++------ buba/__main__.py | 4 ++- buba/static/display.js | 4 --- 3 files changed, 51 insertions(+), 13 deletions(-) diff --git a/buba/BubaAnimator.py b/buba/BubaAnimator.py index 7606038..a71d342 100644 --- a/buba/BubaAnimator.py +++ b/buba/BubaAnimator.py @@ -6,19 +6,59 @@ from time import sleep from buba.BubaCmd import BubaCmd +class BubaAnimation: + def __init__(self, buba: BubaCmd): + self.buba = buba + pass + + def run(self): + pass + + +class BubaTime(BubaAnimation): + def __init__(self, buba: BubaCmd): + super().__init__(buba) + + def run(self): + self.buba.simple_text(page=0, row=1, col=1, text="Buba") + self.buba.simple_text(page=0, row=2, col=1, text="CCC Hansestadt Hamburg") + self.buba.simple_text(page=0, row=3, col=1, text="") + self.buba.simple_text(page=0, row=4, col=1, text="Hello, world!") + self.buba.set_page(0) + + for i in range(15): + self.buba.simple_text(page=0, row=1, col=94, text=datetime.now().strftime("%H:%M:%S")) + sleep(1) + + +class BubaCharset(BubaAnimation): + def __init__(self, buba: BubaCmd): + super().__init__(buba) + + def run(self): + self.buba.simple_text(page=0, row=1, col=1, text=" !\"#$%&'()*+,-./0123456789:;<=>?") + self.buba.simple_text(page=0, row=2, col=1, text="@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_") + self.buba.simple_text(page=0, row=3, col=1, text="`abcdefghijklmnopqrstuvwxyz{|}~\u2302") + self.buba.simple_text(page=0, row=4, col=1, text="That's all, folks!") + sleep(10) + + class BubaAnimator: - def __init__(self, buba:BubaCmd): + def __init__(self, buba: BubaCmd): self.log = logging.getLogger(__name__) self.buba = buba + self.animations = [] Thread(target=self.run, daemon=True).start() def run(self): while True: - self.buba.simple_text(page=0, row=2, col=1, text="") - self.buba.simple_text(page=0, row=3, col=1, text="") - self.buba.simple_text(page=0, row=4, col=1, text="") + if len(self.animations) == 0: + a = BubaTime(self.buba) + a.run() + else: + for a in self.animations: + self.log.debug(f"Starting animation: {a}") + a.run() - self.buba.simple_text(page=0, row=1, col=1, text="CCCHH Buba") - self.buba.simple_text(page=0, row=1, col=94, text=datetime.now().strftime("%H:%M:%S")) - self.buba.set_page(0) - sleep(1) \ No newline at end of file + def add(self, animation): + self.animations.append(animation(self.buba)) \ No newline at end of file diff --git a/buba/__main__.py b/buba/__main__.py index 05de4ac..6d928c3 100644 --- a/buba/__main__.py +++ b/buba/__main__.py @@ -6,7 +6,7 @@ from bottle_websocket import websocket, GeventWebSocketServer from geventwebsocket.websocket import WebSocket from buba.AppConfig import AppConfig -from buba.BubaAnimator import BubaAnimator +from buba.BubaAnimator import BubaAnimator, BubaTime, BubaCharset from buba.BubaCmd import BubaCmd from buba.websocketcomm import WebSocketClients @@ -24,6 +24,8 @@ TEMPLATE_PATH.insert(0, config.templatepath) websocket_clients = WebSocketClients() buba = BubaCmd(config.serial, websocket_clients.send) animator = BubaAnimator(buba) +animator.add(BubaTime) +animator.add(BubaCharset) # bottle_helpers = BottleHelpers(auth, group=config.requires_group, allowed=config.allowed) # update_poller = UpdatePoller(websocket_clients, ccujack, 1 if config.debug else 0.1) diff --git a/buba/static/display.js b/buba/static/display.js index 7038a63..dc95ce9 100644 --- a/buba/static/display.js +++ b/buba/static/display.js @@ -64,10 +64,6 @@ export default class { } } } - let c = 1 - this.applyText(1, 1, " !\"#$%&'()*+,-./0123456789:;<=>?"); - this.applyText(2, 1, "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"); - this.applyText(3, 1, "`abcdefghijklmnopqrstuvwxyz{|}~\u2302"); } eraseCol(row, col) {