Compare commits

..

No commits in common. "fa50e271a6dce562bd8c22a65b7eb09f53581b85" and "8fec7fbc8b64817abe63b23a44e51485050ad805" have entirely different histories.

View File

@ -18,6 +18,7 @@ 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")
@ -38,12 +39,10 @@ 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, center=False):
def update_text(self, title):
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 += "."
@ -54,17 +53,11 @@ 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
@ -112,14 +105,8 @@ class display_manager(object):
self.tick = 0
self.current_display = None
def set_display(self, disp, live=-1):
def set_display(self, disp):
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):
@ -139,8 +126,6 @@ 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:
@ -175,16 +160,11 @@ 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)
@ -263,9 +243,6 @@ 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)