mirror of
https://github.com/supleed2/ELEC60013-ES-CW1.git
synced 2024-12-23 05:55:49 +00:00
Fix errors in TMP006 Lib
Byte values in int form need to be converted to bytes before concatenation Active flag buffer needs to be converted to int before comparison with int literal
This commit is contained in:
parent
be0aa0fb87
commit
540c3e44ef
10
tmp006.py
10
tmp006.py
|
@ -26,8 +26,8 @@ class TMP006:
|
||||||
self.samplerate = samplerate
|
self.samplerate = samplerate
|
||||||
i2cBus.pec = True # enable smbus2 Packet Error Checking
|
i2cBus.pec = True # enable smbus2 Packet Error Checking
|
||||||
self.config = bytes([0x00, 0x00])
|
self.config = bytes([0x00, 0x00])
|
||||||
self.config = (
|
self.config = bytes(
|
||||||
self.config[0] | samplerate[0] | _MODE_ON[0] | _DRDY_EN[0] + self.config[1]
|
[self.config[0] | samplerate[0] | _MODE_ON[0] | _DRDY_EN[0], self.config[1]]
|
||||||
)
|
)
|
||||||
ptrConfig = smbus2.i2c_msg.write(self.addr, _REG_CNFG)
|
ptrConfig = smbus2.i2c_msg.write(self.addr, _REG_CNFG)
|
||||||
writeConfig = smbus2.i2c_msg.write(self.addr, self.config)
|
writeConfig = smbus2.i2c_msg.write(self.addr, self.config)
|
||||||
|
@ -63,7 +63,7 @@ class TMP006:
|
||||||
ptrPower = smbus2.i2c_msg.write(self.addr, _REG_CNFG)
|
ptrPower = smbus2.i2c_msg.write(self.addr, _REG_CNFG)
|
||||||
power = smbus2.i2c_msg.read(self.addr, 2)
|
power = smbus2.i2c_msg.read(self.addr, 2)
|
||||||
self.i2c.i2c_rdwr(ptrPower, power)
|
self.i2c.i2c_rdwr(ptrPower, power)
|
||||||
return power.buf[0] & _MODE_ON[0] != 0
|
return power.buf[0][0] & _MODE_ON[0] != 0
|
||||||
|
|
||||||
@active.setter
|
@active.setter
|
||||||
def active(self, value: bool):
|
def active(self, value: bool):
|
||||||
|
@ -72,14 +72,14 @@ class TMP006:
|
||||||
ptrPower = smbus2.i2c_msg.write(self.addr, _REG_CNFG)
|
ptrPower = smbus2.i2c_msg.write(self.addr, _REG_CNFG)
|
||||||
power = smbus2.i2c_msg.read(self.addr, 2)
|
power = smbus2.i2c_msg.read(self.addr, 2)
|
||||||
self.i2c.i2c_rdwr(ptrPower, power)
|
self.i2c.i2c_rdwr(ptrPower, power)
|
||||||
newPower = power.buf[0] | _MODE_ON[0] + power.buf[1]
|
newPower = bytes([power.buf[0][0] | _MODE_ON[0], power.buf[1][0]])
|
||||||
updatePower = smbus2.i2c_msg.write(self.addr, newPower)
|
updatePower = smbus2.i2c_msg.write(self.addr, newPower)
|
||||||
self.i2c.i2c_rdwr(ptrPower, updatePower)
|
self.i2c.i2c_rdwr(ptrPower, updatePower)
|
||||||
else:
|
else:
|
||||||
ptrPower = smbus2.i2c_msg.write(self.addr, _REG_CNFG)
|
ptrPower = smbus2.i2c_msg.write(self.addr, _REG_CNFG)
|
||||||
power = smbus2.i2c_msg.read(self.addr, 2)
|
power = smbus2.i2c_msg.read(self.addr, 2)
|
||||||
self.i2c.i2c_rdwr(ptrPower, power)
|
self.i2c.i2c_rdwr(ptrPower, power)
|
||||||
newPower = power.buf[0] & ~_MODE_ON[0] + power.buf[1]
|
newPower = bytes([power.buf[0][0] & ~_MODE_ON[0], power.buf[1][0]])
|
||||||
updatePower = smbus2.i2c_msg.write(self.addr, newPower)
|
updatePower = smbus2.i2c_msg.write(self.addr, newPower)
|
||||||
self.i2c.i2c_rdwr(ptrPower, updatePower)
|
self.i2c.i2c_rdwr(ptrPower, updatePower)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue