@@ -38,7 +38,7 @@ class LinuxVCP(VCP):
38
38
39
39
# addresses
40
40
DDCCI_ADDR = 0x37 # DDC-CI command address on the I2C bus
41
- HOST_ADDRESS = 0x50 # virtual I2C slave address of the host
41
+ HOST_ADDRESS = 0x51 # virtual I2C slave address of the host
42
42
I2C_SLAVE = 0x0703 # I2C bus slave address
43
43
44
44
GET_VCP_RESULT_CODES = {
@@ -110,9 +110,12 @@ def set_vcp_feature(self, code: int, value: int):
110
110
# add headers and footers
111
111
data .insert (0 , (len (data ) | self .PROTOCOL_FLAG ))
112
112
data .insert (0 , self .HOST_ADDRESS )
113
- data .append (self .get_checksum (data ))
113
+ data .append (
114
+ self .get_checksum (bytearray ([self .DDCCI_ADDR << 1 ]) + data )
115
+ )
114
116
115
117
# write data
118
+ self .logger .debug ("data=" + " " .join ([f"{ x :02X} " for x in data ]))
116
119
self .write_bytes (data )
117
120
118
121
# store time of last set VCP
@@ -141,24 +144,26 @@ def get_vcp_feature(self, code: int) -> Tuple[int, int]:
141
144
# add headers and footers
142
145
data .insert (0 , (len (data ) | self .PROTOCOL_FLAG ))
143
146
data .insert (0 , self .HOST_ADDRESS )
144
- data .append (self .get_checksum (data ))
145
- self .logger .debug (f"data={ data } " )
147
+ data .append (
148
+ self .get_checksum (bytearray ([self .DDCCI_ADDR << 1 ]) + data )
149
+ )
146
150
147
151
# write data
152
+ self .logger .debug ("data=" + " " .join ([f"{ x :02X} " for x in data ]))
148
153
self .write_bytes (data )
149
154
150
155
time .sleep (self .GET_VCP_TIMEOUT )
151
156
152
157
# read the data
153
158
header = self .read_bytes (self .GET_VCP_HEADER_LENGTH )
154
- self .logger .debug (f "header={ header } " )
155
- source , length = struct .unpack ("BB" , header )
159
+ self .logger .debug ("header=" + " " . join ([ f" { x :02X } " for x in header ]) )
160
+ source , length = struct .unpack ("= BB" , header )
156
161
length &= ~ self .PROTOCOL_FLAG # clear protocol flag
157
162
payload = self .read_bytes (length + 1 )
158
- self .logger .debug (f "payload={ payload } " )
163
+ self .logger .debug ("payload=" + " " . join ([ f" { x :02X } " for x in payload ]) )
159
164
160
165
# check checksum
161
- payload , checksum = struct .unpack (f"{ length } sB" , payload )
166
+ payload , checksum = struct .unpack (f"= { length } sB" , payload )
162
167
calculated_checksum = self .get_checksum (header + payload )
163
168
checksum_xor = checksum ^ calculated_checksum
164
169
if checksum_xor :
@@ -245,11 +250,15 @@ def get_vcp_capabilities(self):
245
250
246
251
# read the data
247
252
header = self .read_bytes (self .GET_VCP_HEADER_LENGTH )
248
- self .logger .debug (f"response header={ header } " )
253
+ self .logger .debug (
254
+ "header=" + " " .join ([f"{ x :02X} " for x in header ])
255
+ )
249
256
source , length = struct .unpack ("BB" , header )
250
257
length &= ~ self .PROTOCOL_FLAG # clear protocol flag
251
258
payload = self .read_bytes (length + 1 )
252
- self .logger .debug (f"payload={ payload } " )
259
+ self .logger .debug (
260
+ "payload=" + " " .join ([f"{ x :02X} " for x in payload ])
261
+ )
253
262
254
263
# check if length is valid
255
264
if length < 3 or length > 35 :
@@ -298,19 +307,19 @@ def get_vcp_capabilities(self):
298
307
299
308
return caps_str
300
309
301
- def get_checksum (self , data : List , prime : bool = False ) -> int :
310
+ @staticmethod
311
+ def get_checksum (data : bytearray ) -> int :
302
312
"""
303
313
Computes the checksum for a set of data, with the option to
304
314
use the virtual host address (per the DDC-CI specification).
305
315
306
316
Args:
307
- data: data array to transmit
308
- prime: compute checksum using the 0x50 virtual host address
317
+ data: Data array to transmit.
309
318
310
319
Returns:
311
- checksum for the data
320
+ Checksum for the data.
312
321
"""
313
- checksum = self . HOST_ADDRESS
322
+ checksum = 0x00
314
323
for data_byte in data :
315
324
checksum ^= data_byte
316
325
return checksum
0 commit comments