@@ -38,7 +38,7 @@ class LinuxVCP(VCP):
3838
3939 # addresses
4040 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
4242 I2C_SLAVE = 0x0703 # I2C bus slave address
4343
4444 GET_VCP_RESULT_CODES = {
@@ -110,9 +110,12 @@ def set_vcp_feature(self, code: int, value: int):
110110 # add headers and footers
111111 data .insert (0 , (len (data ) | self .PROTOCOL_FLAG ))
112112 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+ )
114116
115117 # write data
118+ self .logger .debug ("data=" + " " .join ([f"{ x :02X} " for x in data ]))
116119 self .write_bytes (data )
117120
118121 # store time of last set VCP
@@ -141,24 +144,26 @@ def get_vcp_feature(self, code: int) -> Tuple[int, int]:
141144 # add headers and footers
142145 data .insert (0 , (len (data ) | self .PROTOCOL_FLAG ))
143146 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+ )
146150
147151 # write data
152+ self .logger .debug ("data=" + " " .join ([f"{ x :02X} " for x in data ]))
148153 self .write_bytes (data )
149154
150155 time .sleep (self .GET_VCP_TIMEOUT )
151156
152157 # read the data
153158 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 )
156161 length &= ~ self .PROTOCOL_FLAG # clear protocol flag
157162 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 ]) )
159164
160165 # check checksum
161- payload , checksum = struct .unpack (f"{ length } sB" , payload )
166+ payload , checksum = struct .unpack (f"= { length } sB" , payload )
162167 calculated_checksum = self .get_checksum (header + payload )
163168 checksum_xor = checksum ^ calculated_checksum
164169 if checksum_xor :
@@ -245,11 +250,15 @@ def get_vcp_capabilities(self):
245250
246251 # read the data
247252 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+ )
249256 source , length = struct .unpack ("BB" , header )
250257 length &= ~ self .PROTOCOL_FLAG # clear protocol flag
251258 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+ )
253262
254263 # check if length is valid
255264 if length < 3 or length > 35 :
@@ -298,19 +307,19 @@ def get_vcp_capabilities(self):
298307
299308 return caps_str
300309
301- def get_checksum (self , data : List , prime : bool = False ) -> int :
310+ @staticmethod
311+ def get_checksum (data : bytearray ) -> int :
302312 """
303313 Computes the checksum for a set of data, with the option to
304314 use the virtual host address (per the DDC-CI specification).
305315
306316 Args:
307- data: data array to transmit
308- prime: compute checksum using the 0x50 virtual host address
317+ data: Data array to transmit.
309318
310319 Returns:
311- checksum for the data
320+ Checksum for the data.
312321 """
313- checksum = self . HOST_ADDRESS
322+ checksum = 0x00
314323 for data_byte in data :
315324 checksum ^= data_byte
316325 return checksum
0 commit comments