Compare commits

...

3 Commits

Author SHA1 Message Date
Markus Koch fa50e271a6 sw: Implement livetime for screens
Also, implement volume screen.
2020-08-08 18:18:22 +02:00
Markus Koch 69ae7e5d42 sw: Implement text centering and fix short text 2020-08-08 18:17:10 +02:00
Markus Koch 91af51f51b sw: Move bar_redraw variable where it belongs 2020-08-08 18:16:47 +02:00
1 changed files with 27 additions and 4 deletions

View File

@ -18,7 +18,6 @@ class display(object):
self.font_info = ImageFont.truetype('/usr/share/fonts/TTF/DejaVuSans.ttf', 10)
self.img = Image.new('1', (self.width, self.height), color = not self.fg)
self.d = ImageDraw.Draw(self.img)
self.bar_redraw = True
def render(self):
print("render NYI")
@ -39,10 +38,12 @@ class display_playback(display):
self.info = ""
self.syms = [];
self.title_img = Image.new('1', (0, 0), color = not self.fg)
self.bar_redraw = True
def update_text(self, title):
def update_text(self, title, center=False):
self.title = title
font_shift = 5
w,h = self.d.textsize(self.title, font=self.font_title)
if (w > self.width): # Check the text is short enough to be static
self.title += "."
@ -53,11 +54,17 @@ class display_playback(display):
# Prerender
fw = w + self.width
self.title_img = Image.new('1', (fw, h), color = not self.fg)
font_shift = 5
ImageDraw.Draw(self.title_img).text((0,-font_shift), self.title, font=self.font_title, fill=self.fg)
self.title_img.paste(self.title_img, (w,0))
self.title_img = self.title_img.crop((0,0,fw,h-font_shift))
else:
if (center):
x_shift = (self.width - w) / 2
else:
x_shift = 0;
w = self.width
self.title_img = Image.new('1', (w, h), color = not self.fg)
ImageDraw.Draw(self.title_img).text((x_shift,-font_shift), self.title, font=self.font_title, fill=self.fg)
self.title_scroll = 0
self.title_scroll_max = -1
@ -105,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):
@ -126,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:
@ -160,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)
@ -243,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)