@@ -19,6 +19,14 @@ class OrientationValueRevB(IntEnum):
19
19
ORIENTATION_LANDSCAPE = 0x1
20
20
21
21
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
+
22
30
def get_rev_b_orientation (orientation : Orientation ) -> OrientationValueRevB :
23
31
if orientation == Orientation .PORTRAIT or orientation == Orientation .REVERSE_PORTRAIT :
24
32
return OrientationValueRevB .ORIENTATION_PORTRAIT
@@ -29,13 +37,20 @@ def get_rev_b_orientation(orientation: Orientation) -> OrientationValueRevB:
29
37
class LcdCommRevB (LcdComm ):
30
38
def __init__ (self ):
31
39
self .openSerial ()
40
+ self .sub_revision = SubRevision .A01 # Will be detected later by Hello
32
41
33
42
def __del__ (self ):
34
43
try :
35
44
self .lcd_serial .close ()
36
45
except :
37
46
pass
38
47
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
+
39
54
@staticmethod
40
55
def auto_detect_com_port ():
41
56
com_ports = serial .tools .list_ports .comports ()
@@ -78,7 +93,7 @@ def WriteData(self, byteBuffer: bytearray):
78
93
self .lcd_serial .write (bytes (byteBuffer ))
79
94
except serial .serialutil .SerialTimeoutException :
80
95
# 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!" )
82
97
83
98
def SendLine (self , line : bytes ):
84
99
config .update_queue .put ((self .WriteLine , [line ]))
@@ -88,7 +103,7 @@ def WriteLine(self, line: bytes):
88
103
self .lcd_serial .write (line )
89
104
except serial .serialutil .SerialTimeoutException :
90
105
# 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!" )
92
107
93
108
def Hello (self ):
94
109
hello = [ord ('H' ), ord ('E' ), ord ('L' ), ord ('L' ), ord ('O' )]
@@ -98,18 +113,27 @@ def Hello(self):
98
113
response = self .lcd_serial .read (10 )
99
114
100
115
if len (response ) != 10 :
101
- logger .warn ("Device not recognised (short response to HELLO)" )
116
+ logger .warning ("Device not recognised (short response to HELLO)" )
102
117
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)" )
104
119
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 )))
113
137
114
138
def InitializeComm (self ):
115
139
self .Hello ()
@@ -131,18 +155,25 @@ def ScreenOn(self):
131
155
# HW revision B does not implement a "ScreenOn" native command: using SetBrightness() instead
132
156
self .SetBrightness ()
133
157
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]'
136
160
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
140
169
141
- # Level : 0 (darkest) - 255 (brightest)
142
- self .SendCommand (Command .SET_BRIGHTNESS , payload = [level_absolute ])
170
+ self .SendCommand (Command .SET_BRIGHTNESS , payload = [level ])
143
171
144
172
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" )
146
177
147
178
def SetOrientation (self , orientation : Orientation = get_theme_orientation ()):
148
179
self .SendCommand (Command .SET_ORIENTATION , payload = [get_rev_b_orientation (orientation )])
0 commit comments