From c0beb2624233bf2737219cd8a222bece7a37dda7 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Tue, 3 Jan 2017 20:03:59 +0100 Subject: [PATCH] i2c: reuse code from i2c_write_reg() for read --- i2c.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) 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 -- 2.39.5