Skip to content

Commit 2e9ea5d

Browse files
committed
displaying initial data
1 parent fcfd21d commit 2e9ea5d

File tree

1 file changed

+53
-36
lines changed

1 file changed

+53
-36
lines changed

SipNPyuff/code.py

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
TEXT_HEIGHT = 8
2020
BOTTOM_ROW = DISPLAY_HEIGHT - TEXT_HEIGHT - Y_OFFSET
2121

22-
2322
i2c = board.I2C()
2423
# 128x32
2524
# display_bus = displayio.I2CDisplay(i2c, device_address=0x3C, reset=oled_reset)
@@ -49,7 +48,7 @@
4948

5049
lps.filter_config = True
5150
# if CONSOLE: print("Filter Config:", lps.low_pass_config)
52-
detector = PuffDetector(min_pressure=8, high_pressure=20)
51+
detector = PuffDetector(min_pressure=8, high_pressure=40)
5352
time.sleep(1)
5453

5554

@@ -61,62 +60,80 @@
6160
if DEBUG and CONSOLE:
6261
print("Debug CONSOLE")
6362

63+
color = 0xFAFAFA
64+
65+
font = terminalio.FONT
6466

67+
banner_string = "PUFF-O-TRON-9000"
68+
state_string = " "
69+
pressure_string = " "
70+
input_type_string = " "
71+
72+
state_display_timeout = 1.0
73+
state_display_start = 0
6574
while True:
6675
######################################
6776
splash = displayio.Group(max_size=10)
6877
# 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)
9378

9479
######################################
9580
current_pressure = lps.pressure
81+
pressure_string = "Pressure: %0.3f" % current_pressure
9682
if not CONSOLE:
9783
print((current_pressure,))
9884
puff_polarity, puff_peak_level, puff_duration = detector.check_for_puff(
9985
current_pressure
10086
)
10187

10288
if CONSOLE and puff_duration is None and puff_polarity:
103-
print("START", end=" ")
10489
if puff_polarity == 1:
105-
print("PUFF")
90+
state_string = "PUFF"
10691
if puff_polarity == -1:
107-
print("SIP")
92+
state_string = "SIP"
93+
state_string += " START"
94+
10895
if CONSOLE and puff_duration:
10996

110-
print("END", end=" ")
97+
state_string = "DETECTED:"
98+
print(state_string)
11199
if puff_peak_level == 1:
112-
print("SOFT", end=" ")
100+
input_type_string = "SOFT"
113101
if puff_peak_level == 2:
114-
print("HARD", end=" ")
102+
input_type_string = "HARD"
115103

116104
if puff_polarity == 1:
117-
print("PUFF")
105+
input_type_string += " PUFF"
118106
if puff_polarity == -1:
119-
print("SIP")
120-
121-
print("Duration:", puff_duration)
107+
input_type_string += " SIP"
108+
print("END", end=" ")
109+
print(input_type_string)
110+
duration_string = "Duration: %0.2f" % puff_duration
111+
print(duration_string)
112+
# Create the tet label
113+
if puff_polarity == 0:
114+
state_string = "Waiting for Input"
115+
banner = label.Label(font, text=banner_string, color=color)
116+
state = label.Label(font, text=state_string, color=color)
117+
detector_result = label.Label(font, text=input_type_string, color=color)
118+
text_area4 = label.Label(font, text=state_string, color=color)
119+
pressure_label = label.Label(font, text=pressure_string, color=color)
120+
121+
banner.x = 0
122+
banner.y = 0 + Y_OFFSET
123+
124+
state.x = 20
125+
state.y = 10 + Y_OFFSET
126+
detector_result.x = 20
127+
detector_result.y = 20 + Y_OFFSET
128+
129+
x, y, w, h = pressure_label.bounding_box
130+
pressure_label.x = DISPLAY_WIDTH - w
131+
pressure_label.y = BOTTOM_ROW + Y_OFFSET
132+
133+
splash.append(banner)
134+
splash.append(state)
135+
splash.append(detector_result)
136+
splash.append(pressure_label)
137+
# Show it
138+
display.show(splash)
122139
time.sleep(0.01)

0 commit comments

Comments
 (0)