]> defiant.homedns.org Git - pyshared.git/commitdiff
i2c: reuse code from i2c_write_reg() for read
authorErik Andresen <erik@vontaene.de>
Tue, 3 Jan 2017 19:03:59 +0000 (20:03 +0100)
committerErik Andresen <erik@vontaene.de>
Tue, 3 Jan 2017 19:03:59 +0000 (20:03 +0100)
i2c.py

diff --git a/i2c.py b/i2c.py
index 60d825dd2a7ad31a5d3e744a55227e05a0128254..bffa9fe0c61e3b556ae534e43412dc7f07b83b16 100755 (executable)
--- a/i2c.py
+++ b/i2c.py
@@ -57,11 +57,8 @@ class i2c:
                        self.dev = None
                        i2c.__single = None
 
-       def __del__(self):
-               self.close()
 
-
-def i2c_write_reg(addr, reg, buf):
+def i2c_write_reg(addr, reg, buf=""):
        dev = i2c(addr)
        s = struct.pack(">B", reg) + buf
        dev.write(s)
@@ -69,9 +66,9 @@ def i2c_write_reg(addr, reg, buf):
 
 
 def i2c_read_reg(addr, reg, num=1):
+       i2c_write_reg(addr, reg)
+
        dev = i2c(addr)
-       s = struct.pack(">B", reg)
-       dev.write(s)
        s = dev.read(num)
        dev.close()
        return s