diff --git a/lis3dh.py b/lis3dh.py index c96813d..38f8f97 100644 --- a/lis3dh.py +++ b/lis3dh.py @@ -43,7 +43,7 @@ INT1_DURATION_V = bytes([0x03]) INT1_CFG_V = bytes([0x95]) EMPTY = bytes([0x00]) -class lis3dh: +class LIS3DH: def __init__(self, i2cBus, samplerate=10, i2cAddress=0x18): sleep(0.005) self.i2c = i2cBus diff --git a/main.py b/main.py index 82cbad4..03c8bf1 100644 --- a/main.py +++ b/main.py @@ -2,19 +2,21 @@ import os, sys from time import sleep from strictyaml import load, Map, Str, YAMLError import paho.mqtt.client as mqtt -import json, smbus2, si7201, tmp006, hci, gpiozero +import json, smbus2, si7201, tmp006, lis3dh, hci, gpiozero # Global Sensor Data Variables dailysteps = 0 fallen = False -def incrementStepCount() -> None: +def incrementStepCount(interrupt, sensor) -> None: global dailysteps dailysteps += 1 + sensor.resetint2() -def setFallen() -> None: +def setFallen(interrupt, sensor) -> None: global fallen fallen = True + sensor.resetint1() # Setup bus = smbus2.SMBus(1) # set up I2C bus 1 @@ -25,12 +27,11 @@ temphum.reset() # reset Si7201 irtemp = tmp006.TMP006(bus, 0x41, tmp006.SAMPLERATE_4HZ) # set up TMP006 sensor irtemp.active = 1 # turn on TMP006 -# accel = lis3dh.LIS3DH(bus, 0x18, otherconfigflags) # set up LIS3DH sensor -# TODO: other LIS3DH Setup -step = gpiozero.Button(18, pull_up = False) # GPIO18: Step Counter Interrupt (INT1) -step.when_activated = incrementStepCount # increment step count when Step Counter Interrupt (INT1) is triggered -fall = gpiozero.Button(17, pull_up = False) # GPIO17: Freefall Interrupt (INT2) -fall.when_activated = setFallen # set fallen to True when Freefall Interrupt (INT2) is triggered +accel = lis3dh.LIS3DH(bus, 10, 0x18) # set up LIS3DH sensor +fall = gpiozero.Button(18, pull_up = False) # GPIO17: Freefall Interrupt (INT1) +fall.when_activated = setFallen(fall, accel) # set fallen to True when Freefall Interrupt (INT1) is triggered +step = gpiozero.Button(17, pull_up = False) # GPIO18: Step Counter Interrupt (INT2) +step.when_activated = incrementStepCount(step, accel) # increment step count when Step Counter Interrupt (INT2) is triggered with open(".secrets.yml", "r") as secrets: try: