Reorganised repo

This commit is contained in:
Conr86
2019-07-09 13:36:59 +10:00
parent de2e70136a
commit 411f02dcff
4 changed files with 19 additions and 18 deletions

View File

@@ -18,6 +18,6 @@ class CRC8:
s.crc = crc & 0xFF s.crc = crc & 0xFF
return s.crc return s.crc
#print(CRC8().hash([1,144])) # print(CRC8().hash([1,144]))
#print(hex(CRC8().hash([0xBE, 0xEF]))) #print(hex(CRC8().hash([0xBE, 0xEF])))
#[1, 144, 76, 0, 6, 39] #[1, 144, 76, 0, 6, 39]

View File

@@ -15,7 +15,7 @@ setup(
long_description=readme, long_description=readme,
author='Connor Kneebone', author='Connor Kneebone',
author_email='connor@sfxrescue.com', author_email='connor@sfxrescue.com',
url='https://github.com/zinob/RPI_SGP30', url='https://github.com/Conr86/PySGP30',
license='MIT', license='MIT',
packages=find_packages(exclude=('tests')), packages=find_packages(exclude=('tests')),
install_requires=['smbus2'], install_requires=['smbus2'],

View File

@@ -8,6 +8,7 @@ from .crc import CRC8
DEVICE_BUS = 1 DEVICE_BUS = 1
class _cmds(): class _cmds():
"""container class for mapping between human readable names and the command values used by the sgp""" """container class for mapping between human readable names and the command values used by the sgp"""
SGP30Cmd = namedtuple("SGP30Cmd", ["commands", "replylen", "waittime"]) SGP30Cmd = namedtuple("SGP30Cmd", ["commands", "replylen", "waittime"])
@@ -57,20 +58,20 @@ class SGP30():
return self.SGP30Packet(answer, r, crc_ok) return self.SGP30Packet(answer, r, crc_ok)
def dump_baseline(self): def dump_baseline(self):
baseline = self.read_write(_cmds.GET_BASELINE) baseline = self.read_write(_cmds.GET_BASELINE)
if baseline.crc_ok == True: if baseline.crc_ok == True:
print(baseline) print(baseline)
else: else:
print("Ignoring baseline due to invalid CRC") print("Ignoring baseline due to invalid CRC")
def set_baseline(self): def set_baseline(self):
crc, _ = self._raw_validate_crc(self._baseline) crc, _ = self._raw_validate_crc(self._baseline)
if len(self._baseline) == 6 and crc == True: if len(self._baseline) == 6 and crc == True:
self.read_write(_cmds.new_set_baseline(self._baseline)) self.read_write(_cmds.new_set_baseline(self._baseline))
return True return True
else: else:
#print("Failed to load baseline, invalid data") #print("Failed to load baseline, invalid data")
return False return False
def read_measurements(self): def read_measurements(self):
return self.read_write(_cmds.IAQ_MEASURE) return self.read_write(_cmds.IAQ_MEASURE)
@@ -110,9 +111,9 @@ def main():
print(sgp.read_serial()) print(sgp.read_serial())
sgp.init_sgp() sgp.init_sgp()
for i in range(300): for i in range(300):
print(sgp.read_measurements()) print(sgp.read_measurements())
time.sleep(0.1) time.sleep(0.1)
sgp.store_baseline() sgp.store_baseline()
bus.close() bus.close()