Still dosnt work but now it compiles
This commit is contained in:
@@ -38,15 +38,16 @@ class Sgp30():
|
|||||||
|
|
||||||
Sgp30Answer = namedtuple("Sgp30Answer",["data","raw"])
|
Sgp30Answer = namedtuple("Sgp30Answer",["data","raw"])
|
||||||
|
|
||||||
def read_write(cmd,bus,addr=DEVICE_ADDR):
|
def read_write(self,cmd):
|
||||||
write = i2c_msg.write(addr,cmd.commands)
|
write = i2c_msg.write(self._device_addr,cmd.commands)
|
||||||
if cmd.replylen <= 0 :
|
if cmd.replylen <= 0 :
|
||||||
bus.i2c_rdwr(write)
|
self._bus.i2c_rdwr(write)
|
||||||
else:
|
else:
|
||||||
read = i2c_msg.read(addr,cmd.replylen)
|
read = i2c_msg.read(self._device_addr,cmd.replylen)
|
||||||
bus.i2c_rdwr(write)
|
bus.i2c_rdwr(write)
|
||||||
sleep(waittime/1000.0)
|
self._bus.i2c_rdwr(write)
|
||||||
bus.i2c_rdwr(read)
|
bus.i2c_rdwr(read)
|
||||||
|
self._bus.i2c_rdwr(read)
|
||||||
r = list(read)
|
r = list(read)
|
||||||
answer = [i<<8 | j for i,j in zip(r[0::3],r[1::3])]
|
answer = [i<<8 | j for i,j in zip(r[0::3],r[1::3])]
|
||||||
return Sgp30Answer(answer,r)
|
return Sgp30Answer(answer,r)
|
||||||
@@ -62,17 +63,16 @@ class Sgp30():
|
|||||||
else:
|
else:
|
||||||
if len(baseline) == 6:
|
if len(baseline) == 6:
|
||||||
print("Loading baseline data into sensor")
|
print("Loading baseline data into sensor")
|
||||||
rw(baseline_cmd)
|
self.rw(baseline_cmd)
|
||||||
|
|
||||||
def init_sgp(bus):
|
def init_sgp(self):
|
||||||
print("Initializing SGP30")
|
print("Initializing SGP30")
|
||||||
rw(IAQ_INIT)
|
self.rw(IAQ_INIT)
|
||||||
print("Waiting for sensor warmup")
|
self.try_set_baseline()
|
||||||
try_set_baseline()
|
|
||||||
#print(rw(SET_BASELINE))
|
#print(rw(SET_BASELINE))
|
||||||
sleep(15)
|
print("Waiting for sensor warmup")
|
||||||
|
|
||||||
def i2c_geral_call(bus):
|
def i2c_geral_call(self):
|
||||||
"""This attempts to reset _ALL_ devices on the i2c buss
|
"""This attempts to reset _ALL_ devices on the i2c buss
|
||||||
|
|
||||||
This command issues the i2c-general call RW command that should result
|
This command issues the i2c-general call RW command that should result
|
||||||
@@ -82,7 +82,7 @@ class Sgp30():
|
|||||||
This will usually un-stick the SGP30, but might reset or otherwise
|
This will usually un-stick the SGP30, but might reset or otherwise
|
||||||
affect any device on the bus.
|
affect any device on the bus.
|
||||||
"""
|
"""
|
||||||
bus.write_byte(0,0x06)
|
self._bus.write_byte(0,0x06)
|
||||||
sleep(.1)
|
sleep(.1)
|
||||||
|
|
||||||
def store_baseline(n):
|
def store_baseline(n):
|
||||||
@@ -91,9 +91,7 @@ def store_baseline(n):
|
|||||||
baseline= rw(GET_BASELINE)
|
baseline= rw(GET_BASELINE)
|
||||||
json.dump(baseline.raw,conf)
|
json.dump(baseline.raw,conf)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def main():
|
||||||
main()
|
|
||||||
main():
|
|
||||||
with SMBusWrapper(1) as bus:
|
with SMBusWrapper(1) as bus:
|
||||||
rw=partial(read_write,bus=bus)
|
rw=partial(read_write,bus=bus)
|
||||||
i2c_geral_call(bus)
|
i2c_geral_call(bus)
|
||||||
@@ -119,3 +117,6 @@ main():
|
|||||||
sleep(1 - elapsed )
|
sleep(1 - elapsed )
|
||||||
|
|
||||||
bus.close()
|
bus.close()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
Reference in New Issue
Block a user