From: Erik Andresen Date: Tue, 3 Jan 2017 19:03:59 +0000 (+0100) Subject: i2c: reuse code from i2c_write_reg() for read X-Git-Url: https://defiant.homedns.org/gitweb/?a=commitdiff_plain;h=c0beb2624233bf2737219cd8a222bece7a37dda7;p=pyshared.git i2c: reuse code from i2c_write_reg() for read --- diff --git a/i2c.py b/i2c.py index 60d825d..bffa9fe 100755 --- 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