Enable text scrolling (banner-style) on media title

This commit is contained in:
2024-05-17 00:48:41 +01:00
parent 1a96ed6ed5
commit a0e524a8b1
2 changed files with 28 additions and 10 deletions

6
app.py
View File

@@ -17,6 +17,7 @@ class App:
else: self.scr_n = 0 else: self.scr_n = 0
self.lcd = LCD() self.lcd = LCD()
self.last_cng = 0 self.last_cng = 0
self.must_draw = False
def __connect(self) -> int: def __connect(self) -> int:
wlan = WLAN(STA_IF) wlan = WLAN(STA_IF)
@@ -161,13 +162,16 @@ class App:
self.s = MediaScreen(SCREENS[self.scr_n]["name"], SCREENS[self.scr_n]["entity"]) self.s = MediaScreen(SCREENS[self.scr_n]["name"], SCREENS[self.scr_n]["entity"])
else: else:
self.s = UnknownScreen("Unknown") self.s = UnknownScreen("Unknown")
self.s.display(self.lcd) self.must_draw = self.s.display(self.lcd)
# otherwise minimise the number of pixels being changed # otherwise minimise the number of pixels being changed
else: else:
b = self.handleButtons() b = self.handleButtons()
if (b): if (b):
self.last_cng = time() self.last_cng = time()
continue continue
if (self.must_draw):
self.s.display(self.lcd)
else:
self.s.update(self.lcd) self.s.update(self.lcd)
else: else:
if (self.handleButtons(False)): if (self.handleButtons(False)):

View File

@@ -1,4 +1,4 @@
from font import cntr_st, rght_st from font import cntr_st, rght_st, sz_to_w
from utils import colour from utils import colour
from bmp_file_reader import BMPFileReader from bmp_file_reader import BMPFileReader
from api import getMediaPlayerData, getLightData, playPause, nextTrack, prevTrack, changeVolume, setVolume, toggleLight, setBrightness from api import getMediaPlayerData, getLightData, playPause, nextTrack, prevTrack, changeVolume, setVolume, toggleLight, setBrightness
@@ -9,9 +9,10 @@ class Screen():
self.d = {} self.d = {}
self.prev = {} self.prev = {}
def display(self, lcd) -> None: def display(self, lcd) -> bool:
lcd.fill(0x0000) lcd.fill(0x0000)
cntr_st(lcd, lcd.width, self.name, 20, 2, 255, 255, 255) cntr_st(lcd, lcd.width, self.name, 20, 2, 255, 255, 255)
return False
def update(self, lcd) -> None: def update(self, lcd) -> None:
pass pass
@@ -32,12 +33,13 @@ class MediaScreen(Screen):
super().__init__(n) super().__init__(n)
self.e = e self.e = e
self.valid = e != None and e != "" self.valid = e != None and e != ""
self.m_t = -1
def display(self, lcd) -> None: def display(self, lcd) -> bool:
super().display(lcd) super().display(lcd)
if (not self.valid): if (not self.valid):
self._invalidConfig(lcd) self._invalidConfig(lcd)
return return False
if (self.d == {}): if (self.d == {}):
self.d = self._updateData() self.d = self._updateData()
y_offset = 62 y_offset = 62
@@ -64,9 +66,20 @@ class MediaScreen(Screen):
mins = self.d["media_duration"] // 60 mins = self.d["media_duration"] // 60
secs = self.d["media_duration"] % 60 secs = self.d["media_duration"] % 60
rght_st(lcd, f"{mins}:{secs}", lcd.width, lcd.height - 16, 1, 180, 180, 180) rght_st(lcd, f"{mins}:{secs}", lcd.width, lcd.height - 16, 1, 180, 180, 180)
cs = lcd.width//sz_to_w(3)
l = len(self.d["media_title"]) > cs
if (l):
if (self.m_t + cs > len(self.d["media_title"])):
self.m_t = 0
else:
self.m_t += 1
cntr_st(lcd, lcd.width, self.d["media_title"][self.m_t:self.m_t + cs], lcd.height - 72, 3, 255, 255, 255)
else:
self.m_t = -1
cntr_st(lcd, lcd.width, self.d["media_title"], lcd.height - 72, 3, 255, 255, 255) cntr_st(lcd, lcd.width, self.d["media_title"], lcd.height - 72, 3, 255, 255, 255)
cntr_st(lcd, lcd.width, self.d["media_artist"], lcd.height - 98, 2, 255, 255, 255) cntr_st(lcd, lcd.width, self.d["media_artist"], lcd.height - 98, 2, 255, 255, 255)
lcd.show() lcd.show()
return l
def __updateMediaPositionBar(self, lcd, p: int, d: int): def __updateMediaPositionBar(self, lcd, p: int, d: int):
if (d > 0): if (d > 0):
@@ -124,11 +137,11 @@ class LightsScreen(Screen):
self.es = es self.es = es
self.valid = es != None and len(es) != 0 self.valid = es != None and len(es) != 0
def display(self, lcd) -> None: def display(self, lcd) -> bool:
super().display(lcd) super().display(lcd)
if (not self.valid): if (not self.valid):
self._invalidConfig(lcd) self._invalidConfig(lcd)
return return False
if (self.d == {}): if (self.d == {}):
self._updateData() self._updateData()
# display up to four lights as defined in env.py # display up to four lights as defined in env.py
@@ -137,6 +150,7 @@ class LightsScreen(Screen):
h = lcd.height - 30 h = lcd.height - 30
self.__displayLightEntity(lcd, i, lcd.width//2, h//2, lcd.width//2 * (i % 2), h//2 * (i//2) + 30, self.es[i]["name"], self.d[i]) self.__displayLightEntity(lcd, i, lcd.width//2, h//2, lcd.width//2 * (i % 2), h//2 * (i//2) + 30, self.es[i]["name"], self.d[i])
lcd.show() lcd.show()
return False
def __displayLightEntity(self, lcd, i: int, w: int, h: int, xo: int, yo: int, n: str, d) -> None: def __displayLightEntity(self, lcd, i: int, w: int, h: int, xo: int, yo: int, n: str, d) -> None:
# if the light is turned on, display the filled-in lightbulb icon in the colour of the light, centrally in the light's grid square # if the light is turned on, display the filled-in lightbulb icon in the colour of the light, centrally in the light's grid square