diff --git a/setup.py b/setup.py index 8275fb0..1bf173b 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ with open('LICENSE') as f: setup( name='sgp30', - description='Library for reading data from the sensiron SGP30', + description='Library for reading data from the Sensirion SGP30', version='0.1.5', long_description=readme, author='Simon Albinsson', diff --git a/sgp30/crc.py b/sgp30/crc.py index 2252483..e69785e 100644 --- a/sgp30/crc.py +++ b/sgp30/crc.py @@ -1,4 +1,4 @@ -class Crc8: +class CRC8: def __init__(s): s.crc = 255 @@ -18,6 +18,6 @@ class Crc8: s.crc = crc & 0xFF return s.crc -# print(Crc8().hash([1,144])) -#print(hex(Crc8().hash([0xBE, 0xEF]))) +#print(CRC8().hash([1,144])) +#print(hex(CRC8().hash([0xBE, 0xEF]))) #[1, 144, 76, 0, 6, 39] diff --git a/sgp30/sgp30.py b/sgp30/sgp30.py index 7f9cd6c..469dbcc 100644 --- a/sgp30/sgp30.py +++ b/sgp30/sgp30.py @@ -3,10 +3,8 @@ from smbus2 import SMBusWrapper, SMBus, i2c_msg from collections import namedtuple from functools import partial from time import sleep, asctime, time -import json from copy import copy -import os.path -from .crc import Crc8 +from .crc import CRC8 DEVICE_BUS = 1 @@ -37,11 +35,11 @@ class SGP30(): self._last_save_time = time() self._baseline = baseline - SGP30Answer = namedtuple("SGP30Answer", ["data", "raw", "crc_ok"]) + SGP30Packet = namedtuple("SGP30Packet", ["data", "raw", "crc_ok"]) def _raw_validate_crc(s, r): a = list(zip(r[0::3], r[1::3])) - crc = r[2::3] == [Crc8().hash(i) for i in a] + crc = r[2::3] == [CRC8().hash(i) for i in a] return(crc, a) def read_write(self, cmd): @@ -56,7 +54,7 @@ class SGP30(): r = list(read) crc_ok, a = self._raw_validate_crc(r) answer = [i << 8 | j for i, j in a] - return self.SGP30Answer(answer, r, crc_ok) + return self.SGP30Packet(answer, r, crc_ok) def dump_baseline(self): baseline = self.read_write(_cmds.GET_BASELINE) @@ -111,7 +109,10 @@ def main(): print(sgp.read_features()) print(sgp.read_serial()) sgp.init_sgp() - print(sgp.read_measurements()) + for i in range(300): + print(sgp.read_measurements()) + time.sleep(0.1) + sgp.store_baseline() bus.close() diff --git a/test.py b/test.py deleted file mode 100644 index 2c0c6f5..0000000 --- a/test.py +++ /dev/null @@ -1,14 +0,0 @@ -from smbus2 import SMBusWrapper -from sgp30 import SGP30 -import time -with SMBusWrapper(1) as bus: - sgp = SGP30(bus) - print("resetting all i2c devices") - sgp.i2c_general_call() - print(sgp.read_features()) - print(sgp.read_serial()) - sgp.init_sgp() - for i in range(300): - print(sgp.read_measurements()) - time.sleep(0.1) - sgp.store_baseline()