From fa6e90cbe0ae47621a5b958ebe26dfa4c07a119d Mon Sep 17 00:00:00 2001 From: Stefan Rupp Date: Sat, 21 Apr 2018 01:51:01 +0200 Subject: [PATCH] done. --- SI1145.py | 12 ++++++------ boot.py | 12 ++++++++++-- translate_layer.py | 19 +++++++++++++++++++ 3 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 translate_layer.py diff --git a/SI1145.py b/SI1145.py index af0953a..a5c3c64 100644 --- a/SI1145.py +++ b/SI1145.py @@ -22,10 +22,12 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -import logging +#import logging import time +from translate_layer import I2C_Device + +#import Adafruit_GPIO.I2C as I2C -import Adafruit_GPIO.I2C as I2C # COMMANDS SI1145_PARAM_QUERY = 0x80 @@ -152,12 +154,10 @@ SI1145_REG_CHIPSTAT = 0x30 SI1145_ADDR = 0x60 class SI1145(object): - def __init__(self, address=SI1145_ADDR, busnum=I2C.get_default_bus()): - - self._logger = logging.getLogger('SI1145') + def __init__(self, i2cbus, address=SI1145_ADDR): # Create I2C device. - self._device = I2C.Device(address, busnum) + self._device = I2C_Device(i2cbus, address) #reset device self._reset() diff --git a/boot.py b/boot.py index 699e126..bb3d119 100644 --- a/boot.py +++ b/boot.py @@ -1,8 +1,16 @@ import machine -import SI1145.py +import time +import SI1145 i2c = machine.I2C(scl=machine.Pin(27), sda=machine.Pin(26)) -i2c_addr = 0x60 # default ADDR for SI1145 +s = SI1145.SI1145(i2c) + +s.readIR() +s.readUV() +s.readVisible() + +while True: + time.sleep(10) diff --git a/translate_layer.py b/translate_layer.py new file mode 100644 index 0000000..96b5372 --- /dev/null +++ b/translate_layer.py @@ -0,0 +1,19 @@ + + +class I2C_Device: + def __init__(self, i2c_dev, i2c_addr): + self._device = i2c_dev + self._addr = i2c_addr + + def write8(self, register, data): + b = data.to_bytes(1, 'little') + self._device.writeto_mem(self._addr, register, b) + + def readU8(self, register): + result = self._device.readfrom_mem(self._addr, register, 1) + return result[0] + + def readU16LE(self, register): + result = self._device.readfrom_mem(self._addr, register, 2) + r = int.from_bytes(result, 'little') + return r