Skip to content

Commit fcfd21d

Browse files
committed
display working :)
1 parent d275f45 commit fcfd21d

File tree

3 files changed

+60
-48
lines changed

3 files changed

+60
-48
lines changed

SipNPyuff/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.pylintrc
2+
__pycache__/*

SipNPyuff/code.py

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,36 @@
11
import time
22
import board
3-
import busio
43
import adafruit_lps35hw
4+
5+
import displayio
6+
import terminalio
7+
from adafruit_display_text import label
8+
import adafruit_displayio_ssd1306
59
from puff_detector import PuffDetector
610

7-
i2c = busio.I2C(board.SCL, board.SDA)
11+
displayio.release_displays()
12+
oled_reset = board.D9
13+
14+
DISPLAY_WIDTH = 128
15+
# DISPLAY_HEIGHT = 32
16+
DISPLAY_HEIGHT = 64 # Change to 64 if needed
17+
BORDER = 1
18+
Y_OFFSET = 3
19+
TEXT_HEIGHT = 8
20+
BOTTOM_ROW = DISPLAY_HEIGHT - TEXT_HEIGHT - Y_OFFSET
21+
22+
23+
i2c = board.I2C()
24+
# 128x32
25+
# display_bus = displayio.I2CDisplay(i2c, device_address=0x3C, reset=oled_reset)
26+
# 128x64
27+
display_bus = displayio.I2CDisplay(i2c, device_address=0x3D, reset=oled_reset)
28+
29+
display = adafruit_displayio_ssd1306.SSD1306(
30+
display_bus, width=DISPLAY_WIDTH, height=DISPLAY_HEIGHT
31+
)
32+
33+
834
# i2c = DebugI2C(i2c)
935
lps = adafruit_lps35hw.LPS35HW(i2c, 0x5C)
1036
CONSOLE = True
@@ -37,6 +63,35 @@
3763

3864

3965
while True:
66+
######################################
67+
splash = displayio.Group(max_size=10)
68+
# Set text, font, and color
69+
font = terminalio.FONT
70+
color = 0xFFFFFF
71+
72+
# Create the tet label
73+
text_area = label.Label(font, text="SIP-N-PYUFF", color=color)
74+
text_area2 = label.Label(font, text="STRING TWO", color=color)
75+
text_area3 = label.Label(font, text=str(time.monotonic()), color=color)
76+
77+
# Set the location
78+
text_area.x = 0
79+
text_area.y = 0 + Y_OFFSET
80+
# Set the location
81+
82+
text_area2.x = 20
83+
text_area2.y = 10 + Y_OFFSET
84+
x, y, w, h = text_area3.bounding_box
85+
text_area3.x = DISPLAY_WIDTH - w
86+
text_area3.y = BOTTOM_ROW + Y_OFFSET
87+
88+
splash.append(text_area)
89+
splash.append(text_area2)
90+
splash.append(text_area3)
91+
# Show it
92+
display.show(splash)
93+
94+
######################################
4095
current_pressure = lps.pressure
4196
if not CONSOLE:
4297
print((current_pressure,))

SipNPyuff/puff_detector.py

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ def pressure_string(pressure_type):
6161
return pressure_str
6262

6363
def check_for_puff(self, current_pressure):
64+
"""Updates the internal state to detect if a sip/puff has been started or stopped"""
6465
puff_polarity = None
6566
puff_peak_level = None
6667
puff_duration = None
67-
#######################
6868
polarity, level = self.catagorize_pressure(current_pressure)
6969

7070
# if (polarity != 0) or (level != 0):
@@ -94,48 +94,3 @@ def check_for_puff(self, current_pressure):
9494
self.duration = 0
9595
self.counter += 1
9696
return (puff_polarity, puff_peak_level, puff_duration)
97-
##############################################
98-
99-
100-
# pylint:disable=pointless-string-statement
101-
"""
102-
pressure_list = []
103-
prev_pressure_type = tuple()
104-
prev_polarity = None
105-
current_level = 0
106-
prev_level = 0
107-
108-
def old_detect(self):
109-
if pressure_type != prev_pressure_type:
110-
puff_end = time.monotonic()
111-
puff_duration = puff_end - puff_start
112-
puff_start = puff_end
113-
if DEBUG and CONSOLE: print("\tpressure type:", pressure_type)
114-
if DEBUG and CONSOLE: print("duration:", puff_duration)
115-
if CONSOLE: print("polarity:", polarity, "level:", level)
116-
117-
# hack to handle triggering twice on the way up or down
118-
if (polarity == 1) and (prev_level > level):
119-
if CONSOLE: print("Down")
120-
puff_duration += prev_duration
121-
level = prev_level
122-
if (polarity == -1) and (prev_level < level):
123-
if CONSOLE: print("Up")
124-
puff_duration += prev_duration
125-
level = prev_level
126-
127-
if DEBUG and CONSOLE: print("polarity:", polarity, "level:", level)
128-
if puff_duration > 0.2:
129-
if CONSOLE: print("polarity:", polarity, "level:", level)
130-
131-
if CONSOLE: print("\tduration:", puff_duration)
132-
if DEBUG and CONSOLE: print(current_pressure)
133-
label = detector.pressure_string((polarity, level))
134-
label = detector.pressure_string(pressure_type)
135-
if CONSOLE: print("\t\t\t\t", label)
136-
if CONSOLE: print("____________________")
137-
prev_pressure_type = pressure_type
138-
prev_duration = puff_duration
139-
prev_level = level
140-
prev_level = level
141-
"""

0 commit comments

Comments
 (0)