[FIX] Enable text scrolling if required when song changes

This commit is contained in:
2024-05-17 01:12:50 +01:00
parent 7d27767915
commit 97d18a67c8
2 changed files with 15 additions and 15 deletions

7
app.py
View File

@@ -131,10 +131,7 @@ class App:
active = True active = True
self.last_cng = time() self.last_cng = time()
while (True): while (True):
print("Mem free before and after collecting:")
print(mem_free())
collect() collect()
print(mem_free())
if (localtime()[3] == 0): if (localtime()[3] == 0):
try: try:
settime() settime()
@@ -170,9 +167,9 @@ class App:
self.last_cng = time() self.last_cng = time()
continue continue
if (self.must_draw): if (self.must_draw):
self.s.display(self.lcd) self.must_draw = self.s.display(self.lcd)
else: else:
self.s.update(self.lcd) self.must_draw = self.s.update(self.lcd)
else: else:
if (self.handleButtons(False)): if (self.handleButtons(False)):
LCD.setDuty() LCD.setDuty()

View File

@@ -14,8 +14,8 @@ class Screen():
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 return False
def update(self, lcd) -> None: def update(self, lcd) -> bool:
pass return False
def handleButtons(self, up: bool, down: bool, left: bool, right: bool, keyA: bool, keyB: bool, keyX: bool, keyY: bool, ctrl: bool) -> bool: def handleButtons(self, up: bool, down: bool, left: bool, right: bool, keyA: bool, keyB: bool, keyX: bool, keyY: bool, ctrl: bool) -> bool:
return False return False
@@ -101,19 +101,20 @@ class MediaScreen(Screen):
lcd.pixel(x, lcd.height - 1, 0xffff) lcd.pixel(x, lcd.height - 1, 0xffff)
lcd.pixel(x, lcd.height, 0xffff) lcd.pixel(x, lcd.height, 0xffff)
def update(self, lcd): def update(self, lcd) -> bool:
if (not self.valid): if (not self.valid):
super().display(lcd) super().display(lcd)
self._invalidConfig(lcd) self._invalidConfig(lcd)
return return False
self._updateData() self._updateData()
# if same media is playing (same title and duration), just update the position bar # if same media is playing (same title and duration), just update the position bar
if (self.d["media_title"] == self.prev["media_title"] and self.d["media_duration"] == self.prev["media_duration"] and self.d["playing"] == self.prev["playing"]): if (self.d["media_title"] == self.prev["media_title"] and self.d["media_duration"] == self.prev["media_duration"] and self.d["playing"] == self.prev["playing"]):
self.__updateMediaPositionBar(lcd, self.d["media_position"], self.d["media_duration"]) self.__updateMediaPositionBar(lcd, self.d["media_position"], self.d["media_duration"])
lcd.show() lcd.show()
return False
# otherwise redraw the whole screen # otherwise redraw the whole screen
else: else:
self.display(lcd) return self.display(lcd)
def _updateData(self) -> dict: def _updateData(self) -> dict:
super()._updateData() super()._updateData()
@@ -197,11 +198,11 @@ class LightsScreen(Screen):
# display the name of the light 8px below the lightbulb icon # display the name of the light 8px below the lightbulb icon
cntr_st(lcd, w, n, y_offset + img_height + 8, 2, 220, 220, 220, xo) cntr_st(lcd, w, n, y_offset + img_height + 8, 2, 220, 220, 220, xo)
def update(self, lcd): def update(self, lcd) -> bool:
if (not self.valid): if (not self.valid):
super().display(lcd) super().display(lcd)
self._invalidConfig(lcd) self._invalidConfig(lcd)
return return False
self._updateData() self._updateData()
# for each light to be displayed # for each light to be displayed
for i in range(0, len(self.d)): for i in range(0, len(self.d)):
@@ -210,6 +211,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 _updateData(self) -> dict: def _updateData(self) -> dict:
super()._updateData() super()._updateData()
@@ -244,12 +246,13 @@ class UnknownScreen(Screen):
def __init__(self, n: str) -> None: def __init__(self, n: str) -> None:
super().__init__(n) super().__init__(n)
def display(self, lcd) -> None: def display(self, lcd) -> bool:
super().display(lcd) super().display(lcd)
self._invalidConfig(lcd) self._invalidConfig(lcd)
return False
def update(self, lcd) -> None: def update(self, lcd) -> bool:
pass return False
def _updateData(self) -> dict: def _updateData(self) -> dict:
return {} return {}