This commit is contained in:
Aadi Desai 2022-03-01 17:19:44 +00:00
parent 4db2a4d34d
commit d6e996bad8
No known key found for this signature in database
GPG key ID: CFFFE425830EF4D9
3 changed files with 9 additions and 8 deletions

View file

@ -82,7 +82,7 @@ class LIS3DH:
int1_src_loc = smbus2.i2c_msg.write(self.addr, [0x31])
read_int1_src = smbus2.i2c_msg.read(self.addr, 1)
self.i2c.i2c_rdwr(int1_src_loc,read_int1_src)
if read_int1_src.bug[0] != None:
if read_int1_src.buf[0] != None:
return True
else:
return False
@ -92,7 +92,7 @@ class LIS3DH:
int2_src_loc = smbus2.i2c_msg.write(self.addr, [0x35])
read_int2_src = smbus2.i2c_msg.read(self.addr, 1)
self.i2c.i2c_rdwr(int2_src_loc,read_int2_src)
if read_int2_src.bug[0] != None:
if read_int2_src.buf[0] != None:
return True
else:
return False

10
main.py
View file

@ -1,6 +1,6 @@
import os, sys
from time import sleep
from strictyaml import load, Map, Str, YAMLError
import yaml
import paho.mqtt.client as mqtt
import json, smbus2, si7201, tmp006, lis3dh, hci, gpiozero
@ -29,15 +29,15 @@ irtemp.active = 1 # turn on TMP006
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
fall.when_activated = lambda: 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
step.when_activated = lambda: incrementStepCount(step, accel) # increment step count when Step Counter Interrupt (INT2) is triggered
with open(".secrets.yml", "r") as secrets:
try:
secrets = load(secrets, schema = Map({"key": Str()}))
secrets = yaml.load(secrets, Loader = yaml.SafeLoader)
key = secrets["key"] # Get Base64 encoded device public key from secrets file
except YAMLError as exc:
except ImportError as exc:
print(exc)
sleep(60) # 60s delay before restarting
os.execl(sys.executable, os.path.abspath(__file__), *sys.argv) # Restart propgram

View file

@ -2,6 +2,7 @@ colorzero==2.0
gpiozero==1.6.2
paho-mqtt==1.6.1
python-dateutil==2.8.2
PyYAML==6.0
RPi.GPIO==0.7.1
six==1.16.0
smbus2==0.4.1
strictyaml==1.6.1