From e7e0fde3fcdd98c5561edf1ca5e8e8fb230123a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Agsj=C3=B6?= Date: Sun, 22 Jan 2017 00:43:54 +0100 Subject: [PATCH] Moved to ReadWordData for TSL2561, fixed weird problem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Erik Agsjö --- drivers/i2c/tsl2561_driver.go | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/drivers/i2c/tsl2561_driver.go b/drivers/i2c/tsl2561_driver.go index af0468fc..3e895194 100644 --- a/drivers/i2c/tsl2561_driver.go +++ b/drivers/i2c/tsl2561_driver.go @@ -431,24 +431,7 @@ func (d *TSL2561Driver) writeByteRegisters(regValPairs [][2]uint8) (err error) { return err } -func (d *TSL2561Driver) read16bitInteger(reg uint8) (val uint16, err error) { - err = d.connection.WriteByte(reg) - if err != nil { - return 0, err - } - low, err := d.connection.ReadByte() - if err != nil { - return 0, err - } - high, err := d.connection.ReadByte() - if err != nil { - return 0, err - } - return (uint16(high) << 8) | uint16(low), nil -} - func (d *TSL2561Driver) enable() (err error) { - err = d.connection.WriteByteData(uint8(tsl2561CommandBit|tsl2561RegisterControl), tsl2561ControlPowerOn) return err } @@ -474,13 +457,13 @@ func (d *TSL2561Driver) getData() (broadband uint16, ir uint16, err error) { } // Reads a two byte value from channel 0 (visible + infrared) - broadband, err = d.read16bitInteger(tsl2561CommandBit | tsl2561WordBit | tsl2561RegisterChan0Low) + broadband, err = d.connection.ReadWordData(tsl2561CommandBit | tsl2561WordBit | tsl2561RegisterChan0Low) if err != nil { return } // Reads a two byte value from channel 1 (infrared) - ir, err = d.read16bitInteger(tsl2561CommandBit | tsl2561WordBit | tsl2561RegisterChan1Low) + ir, err = d.connection.ReadWordData(tsl2561CommandBit | tsl2561WordBit | tsl2561RegisterChan1Low) if err != nil { return }