From fa50e271a6dce562bd8c22a65b7eb09f53581b85 Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Sat, 8 Aug 2020 18:18:22 +0200 Subject: [PATCH] sw: Implement livetime for screens Also, implement volume screen. --- software/webradio.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/software/webradio.py b/software/webradio.py index 6aa15bb..5a5d435 100644 --- a/software/webradio.py +++ b/software/webradio.py @@ -112,8 +112,14 @@ class display_manager(object): self.tick = 0 self.current_display = None - def set_display(self, disp): + def set_display(self, disp, live=-1): self.current_display = disp + self.current_display.live = live + + def display_is_dead(self): + if (self.current_display): + return (self.current_display.live == 0) + return 0 def render(self): if (self.current_display): @@ -133,6 +139,8 @@ class display_manager(object): self.current_display.ltick = old_tick self.current_display.animate(self.tick - self.current_display.ltick) self.current_display.ltick = self.tick + if (self.current_display.live > 0): + self.current_display.live -= ticks # TODO: Consider also animating inactive screens... Might resolve some glitches when updating text while a screen is in the background (or pass `tick` to update funcs) class radioserv: @@ -167,11 +175,16 @@ class radioserv: nvol = 0; elif (nvol > 100): nvol = 100 + self.disp_info.update_text("{}%".format(nvol), True) + self.disp_info.update_info("Volume") + self.disp_mgr.set_display(self.disp_info, 40) self.mpd.setvol(nvol) #print("Battery: {}".format(rdata[2])) async def io_main(self): while True: + if self.disp_mgr.display_is_dead(): + self.disp_mgr.set_display(self.disp_playback) self.disp_mgr.animate(1) self.disp_mgr.render() rdata = self.spi.xfer([100, 101, 102], 50000, 1000) @@ -250,6 +263,9 @@ class radioserv: self.disp_playback = display_playback() self.disp_playback.update_text("Loading...") + self.disp_info = display_playback() + self.disp_info.update_text("---"); + self.disp_mgr = display_manager() self.disp_mgr.set_display(self.disp_playback)