Skip to content

Commit dee8833

Browse files
committed
Add support for HW sub-revisions on rev. B/flagship
1 parent db49396 commit dee8833

File tree

2 files changed

+53
-22
lines changed

2 files changed

+53
-22
lines changed

library/lcd_comm_rev_a.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def WriteData(self, byteBuffer: bytearray):
6060
self.lcd_serial.write(bytes(byteBuffer))
6161
except serial.serialutil.SerialTimeoutException:
6262
# We timed-out trying to write to our device, slow things down.
63-
logger.warn("(Write data) Too fast! Slow down!")
63+
logger.warning("(Write data) Too fast! Slow down!")
6464

6565
def SendLine(self, line: bytes):
6666
config.update_queue.put((self.WriteLine, [line]))
@@ -70,7 +70,7 @@ def WriteLine(self, line: bytes):
7070
self.lcd_serial.write(line)
7171
except serial.serialutil.SerialTimeoutException:
7272
# We timed-out trying to write to our device, slow things down.
73-
logger.warn("(Write line) Too fast! Slow down!")
73+
logger.warning("(Write line) Too fast! Slow down!")
7474

7575
def InitializeComm(self):
7676
# HW revision A does not need init commands

library/lcd_comm_rev_b.py

+51-20
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ class OrientationValueRevB(IntEnum):
1919
ORIENTATION_LANDSCAPE = 0x1
2020

2121

22+
# HW revision B offers 4 sub-revisions to identify the HW capabilities
23+
class SubRevision(IntEnum):
24+
A01 = 0xA01 # HW revision B - brightness 0/1
25+
A02 = 0xA02 # HW revision "flagship" - brightness 0/1
26+
A11 = 0xA11 # HW revision B - brightness 0-255
27+
A12 = 0xA12 # HW revision "flagship" - brightness 0-255
28+
29+
2230
def get_rev_b_orientation(orientation: Orientation) -> OrientationValueRevB:
2331
if orientation == Orientation.PORTRAIT or orientation == Orientation.REVERSE_PORTRAIT:
2432
return OrientationValueRevB.ORIENTATION_PORTRAIT
@@ -29,13 +37,20 @@ def get_rev_b_orientation(orientation: Orientation) -> OrientationValueRevB:
2937
class LcdCommRevB(LcdComm):
3038
def __init__(self):
3139
self.openSerial()
40+
self.sub_revision = SubRevision.A01 # Will be detected later by Hello
3241

3342
def __del__(self):
3443
try:
3544
self.lcd_serial.close()
3645
except:
3746
pass
3847

48+
def is_flagship(self):
49+
return self.sub_revision == SubRevision.A02 or self.sub_revision == SubRevision.A12
50+
51+
def is_brightness_range(self):
52+
return self.sub_revision == SubRevision.A11 or self.sub_revision == SubRevision.A12
53+
3954
@staticmethod
4055
def auto_detect_com_port():
4156
com_ports = serial.tools.list_ports.comports()
@@ -78,7 +93,7 @@ def WriteData(self, byteBuffer: bytearray):
7893
self.lcd_serial.write(bytes(byteBuffer))
7994
except serial.serialutil.SerialTimeoutException:
8095
# We timed-out trying to write to our device, slow things down.
81-
logger.warn("(Write data) Too fast! Slow down!")
96+
logger.warning("(Write data) Too fast! Slow down!")
8297

8398
def SendLine(self, line: bytes):
8499
config.update_queue.put((self.WriteLine, [line]))
@@ -88,7 +103,7 @@ def WriteLine(self, line: bytes):
88103
self.lcd_serial.write(line)
89104
except serial.serialutil.SerialTimeoutException:
90105
# We timed-out trying to write to our device, slow things down.
91-
logger.warn("(Write line) Too fast! Slow down!")
106+
logger.warning("(Write line) Too fast! Slow down!")
92107

93108
def Hello(self):
94109
hello = [ord('H'), ord('E'), ord('L'), ord('L'), ord('O')]
@@ -98,18 +113,27 @@ def Hello(self):
98113
response = self.lcd_serial.read(10)
99114

100115
if len(response) != 10:
101-
logger.warn("Device not recognised (short response to HELLO)")
116+
logger.warning("Device not recognised (short response to HELLO)")
102117
if response[0] != Command.HELLO or response[-1] != Command.HELLO:
103-
logger.warn("Device not recognised (bad framing)")
118+
logger.warning("Device not recognised (bad framing)")
104119
if [x for x in response[1:6]] != hello:
105-
logger.warn("Device not recognised (No HELLO; got %r)" % (response[1:6],))
106-
# The HELLO response here is followed by:
107-
# 0x0A, 0x12, 0x00
108-
# It is not clear what these might be.
109-
# It would be handy if these were a version number, or a set of capability
110-
# flags. The 0x0A=10 being version 10 or 0.10, and the 0x12 being the size or the
111-
# indication that a backlight is present, would be nice. But that's guessing
112-
# based on how I'd do it.
120+
logger.warning("Device not recognised (No HELLO; got %r)" % (response[1:6],))
121+
# The HELLO response here is followed by 2 bytes
122+
# This is the screen version (not like the revision which is B/flagship)
123+
# The version is used to determine what capabilities the screen offers (see SubRevision class above)
124+
if response[6] == 0xA:
125+
if response[7] == 0x01:
126+
self.sub_revision = SubRevision.A01
127+
elif response[7] == 0x02:
128+
self.sub_revision = SubRevision.A02
129+
elif response[7] == 0x11:
130+
self.sub_revision = SubRevision.A11
131+
elif response[7] == 0x12:
132+
self.sub_revision = SubRevision.A12
133+
else:
134+
logger.warning("Display returned unknown sub-revision on Hello answer")
135+
136+
logger.debug("HW sub-revision: %s" % (hex(self.sub_revision)))
113137

114138
def InitializeComm(self):
115139
self.Hello()
@@ -131,18 +155,25 @@ def ScreenOn(self):
131155
# HW revision B does not implement a "ScreenOn" native command: using SetBrightness() instead
132156
self.SetBrightness()
133157

134-
def SetBrightness(self, level: int = CONFIG_DATA["display"]["BRIGHTNESS"]):
135-
assert 0 <= level <= 100, 'Brightness level must be [0-100]'
158+
def SetBrightness(self, level_user: int = CONFIG_DATA["display"]["BRIGHTNESS"]):
159+
assert 0 <= level_user <= 100, 'Brightness level must be [0-100]'
136160

137-
# Display scales from 0 to 255, with 255 being the brightest and 0 being the darkest.
138-
# Convert our brightness % to an absolute value.
139-
level_absolute = int((level / 100) * 255)
161+
if self.is_brightness_range():
162+
# Brightness scales from 0 to 255, with 255 being the brightest and 0 being the darkest.
163+
# Convert our brightness % to an absolute value.
164+
level = int((level_user / 100) * 255)
165+
else:
166+
# Brightness is 1 (off) or 0 (full brightness)
167+
logger.info("Your display does not support custom brightness level")
168+
level = 1 if level_user == 0 else 0
140169

141-
# Level : 0 (darkest) - 255 (brightest)
142-
self.SendCommand(Command.SET_BRIGHTNESS, payload=[level_absolute])
170+
self.SendCommand(Command.SET_BRIGHTNESS, payload=[level])
143171

144172
def SetBackplateLedColor(self, led_color: tuple[int, int, int] = THEME_DATA['display']["DISPLAY_RGB_LED"]):
145-
self.SendCommand(Command.SET_LIGHTING, payload=led_color)
173+
if self.is_flagship():
174+
self.SendCommand(Command.SET_LIGHTING, payload=led_color)
175+
else:
176+
logger.info("Only HW revision 'flagship' supports backplate LED color setting")
146177

147178
def SetOrientation(self, orientation: Orientation = get_theme_orientation()):
148179
self.SendCommand(Command.SET_ORIENTATION, payload=[get_rev_b_orientation(orientation)])

0 commit comments

Comments
 (0)