Updated naming conventions, remerged test into source file
This commit is contained in:
2
setup.py
2
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',
|
||||
|
@@ -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]
|
||||
|
@@ -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()
|
||||
|
||||
|
||||
|
14
test.py
14
test.py
@@ -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()
|
Reference in New Issue
Block a user