Skip to content

Instantly share code, notes, and snippets.

@albertskog
Created November 13, 2024 11:44
Show Gist options
  • Select an option

  • Save albertskog/aaac416906a3be7c1c73f6f66307ddfe to your computer and use it in GitHub Desktop.

Select an option

Save albertskog/aaac416906a3be7c1c73f6f66307ddfe to your computer and use it in GitHub Desktop.
Diff to print DDC commands to terminal instead of SMBus
diff --git a/ddcci.py b/ddcci.py
index 4c98a91..bbfb4b9 100644
--- a/ddcci.py
+++ b/ddcci.py
@@ -1,4 +1,4 @@
-import smbus
+# import smbus
import time
from functools import wraps
@@ -48,10 +48,10 @@ class ReadException(Exception):
class DDCCIDevice(object):
def __init__(self, bus, address=DEFAULT_DDCCI_ADDR):
- if isinstance(bus, smbus.SMBus):
- self.bus = bus
- else:
- self.bus = smbus.SMBus(bus)
+ # if isinstance(bus, smbus.SMBus):
+ # self.bus = bus
+ # else:
+ # self.bus = smbus.SMBus(bus)
self.address = address
@@ -73,12 +73,12 @@ class DDCCIDevice(object):
time.sleep(READ_DELAY)
- if self.bus.read_byte(self.address) != self.address << 1:
- raise ReadException("ACK invalid")
+ # if self.bus.read_byte(self.address) != self.address << 1:
+ # raise ReadException("ACK invalid")
- data_length = self.bus.read_byte(self.address) & ~PROTOCOL_FLAG
- data = [self.bus.read_byte(self.address) for n in xrange(data_length)]
- checksum = self.bus.read_byte(self.address)
+ # data_length = self.bus.read_byte(self.address) & ~PROTOCOL_FLAG
+ # data = [self.bus.read_byte(self.address) for n in xrange(data_length)]
+ # checksum = self.bus.read_byte(self.address)
xor = (self.address << 1 | 1) ^ HOST_SLAVE_ADDRESS ^ (PROTOCOL_FLAG | len(data))
@@ -112,7 +112,8 @@ class DDCCIDevice(object):
@throttle
def write_payload(self, payload):
- self.bus.write_i2c_block_data(self.address, payload[0], payload[1:])
+ print(list(map(hex, payload)))
+ # self.bus.write_i2c_block_data(self.address, payload[0], payload[1:])
def prepare_payload(self, addr, data):
payload = [HOST_SLAVE_ADDRESS, PROTOCOL_FLAG | len(data)]
diff --git a/ddccli.py b/ddccli.py
index 784ce04..6cf9448 100644
--- a/ddccli.py
+++ b/ddccli.py
@@ -59,9 +59,9 @@ def main(argv):
if v[0] is Actions.GET:
if args.raw:
- print device.read(control_id)
+ print(device.read(control_id))
else:
- print '%s=%d' % (p, device.read(control_id))
+ print('%s=%d' % (p, device.read(control_id)))
elif v[0] is Actions.SET:
device.write(control_id, v[1])
elif v[0] is Actions.SET_RELATIVE:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment