Skip to content

Commit c9b3e21

Browse files
rev C: honor a STARTMODE config option for power-on display
The revision C protocol already defines STARTMODE_DEFAULT/IMAGE/VIDEO (byte 0 of the OPTIONS payload), but SetOrientation always sent DEFAULT, which blanks the panel at power-on until the host connects. The panel keeps this setting across power cycles. Read an optional display.STARTMODE config value (DEFAULT/IMAGE/VIDEO) so a display fitted with an SD card can instead replay the last image or video it was sent. Defaults to DEFAULT, so behavior is unchanged unless the option is set; unknown values warn and fall back to DEFAULT. config.yaml is intentionally not modified (guarded by CI); maintainers can add the documented 'STARTMODE: DEFAULT' key to the shipped template.
1 parent 4df61d9 commit c9b3e21

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

library/lcd/lcd_comm_rev_c.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from PIL import Image
3232
from serial.tools.list_ports import comports
3333

34+
import library.config as config
3435
from library.lcd.lcd_comm import Orientation, LcdComm
3536
from library.lcd.serialize import image_to_BGRA, image_to_BGR, chunked
3637
from library.log import logger
@@ -311,12 +312,32 @@ def SetOrientation(self, orientation: Orientation = Orientation.PORTRAIT):
311312
# logger.info(f"Call SetOrientation to: {self.orientation.name}")
312313

313314
# if self.orientation == Orientation.REVERSE_LANDSCAPE or self.orientation == Orientation.REVERSE_PORTRAIT:
314-
# b = Command.STARTMODE_DEFAULT.value + Padding.NULL.value + Command.FLIP_180.value + SleepInterval.OFF.value
315+
# b = self._start_mode() + Padding.NULL.value + Command.FLIP_180.value + SleepInterval.OFF.value
315316
# self._send_command(Command.OPTIONS, payload=b)
316317
# else:
317-
b = Command.STARTMODE_DEFAULT.value + Padding.NULL.value + Command.NO_FLIP.value + SleepInterval.OFF.value
318+
b = self._start_mode() + Padding.NULL.value + Command.NO_FLIP.value + SleepInterval.OFF.value
318319
self._send_command(Command.OPTIONS, payload=b)
319320

321+
@staticmethod
322+
def _start_mode() -> bytearray:
323+
# Byte 0 of the OPTIONS payload selects what the panel shows at power-on,
324+
# a choice the firmware keeps across power cycles until it is changed
325+
# again. This driver always sent DEFAULT, which blanks the panel until
326+
# the host connects; the STARTMODE config option lets the panel instead
327+
# replay the last image or video it was sent (useful with an SD card).
328+
modes = {
329+
"DEFAULT": Command.STARTMODE_DEFAULT, # show nothing until the host connects
330+
"IMAGE": Command.STARTMODE_IMAGE, # replay the last image sent to the panel
331+
"VIDEO": Command.STARTMODE_VIDEO, # replay the last video sent to the panel
332+
}
333+
name = str(config.CONFIG_DATA["display"].get("STARTMODE", "DEFAULT")).upper()
334+
if name not in modes:
335+
logger.warning("Unknown STARTMODE '%s' in config.yaml, using DEFAULT" % name)
336+
name = "DEFAULT"
337+
if name != "DEFAULT":
338+
logger.debug("Display start mode at power-on: %s" % name)
339+
return modes[name].value
340+
320341
def DisplayPILImage(
321342
self,
322343
image: Image.Image,

0 commit comments

Comments
 (0)