now only displays when the pressure type changes
@@ -3,10 +3,34 @@ import board
import busio
import adafruit_lps35hw
from puff_detector import PuffDetector
+from adafruit_debug_i2c import DebugI2C
-i2c = busio.I2C(board.SCL, board.SDA)
+#pylint:disable:invalid-name
+def pressure_str(pressure):
+ pressure_type = ""
+ pressure_level = 0
+
+ if abs(pressure) > 10:
+ pressure_level = 1
+ if abs(pressure) > high_pressure:
+ pressure_level = 2
+ if pressure > 0:
+ if pressure_level == 1:
+ pressure_type = "Soft Puff"
+ if pressure_level == 2:
+ pressure_type = "Hard Puff"
+ else:
+
+ if pressure_level == 1:
+ pressure_type = "Soft Sip"
+ if pressure_level == 2:
+ pressure_type = "Hard Sip"
+ return pressure_type
-lps = adafruit_lps35hw.LPS35HW(i2c)
+
+i2c = busio.I2C(board.SCL, board.SDA)
+# i2c = DebugI2C(i2c)
+lps = adafruit_lps35hw.LPS35HW(i2c, 0x5c)
lps.zero_pressure()
lps.data_rate = adafruit_lps35hw.DataRate.RATE_75_HZ
@@ -17,30 +41,27 @@ high_pressure = 20
# sip/puff is "over" on keyup/pressure direction reversal
# averaging code
+
+
# find reasonable band estimatesV
+print("Filter enabled:", lps.low_pass_enabled)
+lps.filter_enabled = True
+print("Filter enabled:", lps.low_pass_enabled)
+
+print("Filter Config:", lps.low_pass_config)
+lps.filter_config = True
+print("Filter Config:", lps.low_pass_config)
prev_direction = None
pressure_list = []
+pressure_type = ""
+prev_pressure_type = ""
while True:
- pressure_level = 0
pressure = lps.pressure
- if abs(pressure) > 10:
- pressure_level = 1
- if abs(pressure) > high_pressure:
- pressure_level = 2
- if pressure > 0:
- if pressure_level == 1:
- print("SOFT PUFF", end="\n\n")
- if pressure_level == 2:
- print("HARD PUFF", end="\n\n")
-
- else:
- # if pressure < max_negative:
- # max_negative = pressure
- # #print ("new max negative pressure: %0.2f"%pressure)
- if pressure_level == 1:
- print("SOFT SIP", end="\n\n")
- if pressure_level == 2:
- print("HARD SIP", end="\n\n")
+ # print((pressure,))
+ pressure_type = pressure_str(pressure)
+ if pressure_type != prev_pressure_type:
+ print(pressure_type)
+ prev_pressure_type = pressure_type
time.sleep(0.01)
\ No newline at end of file
