X-Git-Url: https://defiant.homedns.org/gitweb/?p=ros_wild_thumper.git;a=blobdiff_plain;f=scripts%2Fi2c.py;fp=scripts%2Fi2c.py;h=4522c5ff52e0c5b8a999f9213f5bd48c76c53c62;hp=2e9a109e0fe2891175726af4e6d739958e032208;hb=ece97d94709b5e779ec2a48cf47319163a122bc5;hpb=eef02300bd4b99a11e6a1756f7b8d4e25c6c0908 diff --git a/scripts/i2c.py b/scripts/i2c.py index 2e9a109..4522c5f 100755 --- a/scripts/i2c.py +++ b/scripts/i2c.py @@ -5,6 +5,7 @@ import threading import inspect import os import logging +import struct from ctypes import * from time import sleep @@ -62,6 +63,23 @@ class i2c: def __del__(self): self.close() + +def i2c_write_reg(addr, reg, buf): + dev = i2c(addr) + s = struct.pack("B", reg) + buf + dev.write(s) + dev.close() + + +def i2c_read_reg(addr, reg, num=1): + dev = i2c(addr) + s = struct.pack("B", reg) + dev.write(s) + s = dev.read(num) + dev.close() + return s + + if __name__ == "__main__": import struct import sys