|
17 | 17 | BORDER = 1
|
18 | 18 | Y_OFFSET = 3
|
19 | 19 | TEXT_HEIGHT = 8
|
20 |
| -BOTTOM_ROW = DISPLAY_HEIGHT - TEXT_HEIGHT - Y_OFFSET |
| 20 | +BOTTOM_ROW = DISPLAY_HEIGHT - TEXT_HEIGHT |
| 21 | + |
| 22 | +# Get wifi details and more from a secrets.py file |
| 23 | + |
21 | 24 |
|
22 | 25 | # States:
|
23 | 26 | WAITING = 0
|
|
36 | 39 |
|
37 | 40 | # i2c = DebugI2C(i2c)
|
38 | 41 | lps = adafruit_lps35hw.LPS35HW(i2c, 0x5C)
|
39 |
| -CONSOLE = True |
| 42 | +CONSOLE = False |
40 | 43 | DEBUG = True
|
41 | 44 |
|
42 | 45 | lps.zero_pressure()
|
|
55 | 58 | detector = PuffDetector()
|
56 | 59 | time.sleep(1)
|
57 | 60 |
|
58 |
| -if CONSOLE: |
59 |
| - print("CONSOLE?") |
60 |
| -if DEBUG and CONSOLE: |
61 |
| - print("Debug CONSOLE") |
| 61 | +print("det timeout:", detector.display_timeout) |
62 | 62 |
|
63 | 63 | color = 0xFFFFFF
|
64 |
| - |
65 | 64 | font = terminalio.FONT
|
66 | 65 |
|
67 | 66 | banner_string = "PUFF-O-TRON-9000"
|
|
74 | 73 | state_display_start = 0
|
75 | 74 | while True:
|
76 | 75 | curr_time = time.monotonic()
|
77 |
| - ###################################### |
78 |
| - splash = displayio.Group(max_size=10) |
79 | 76 | # Set text, font, and color
|
80 | 77 |
|
81 |
| - ###################################### |
82 | 78 | current_pressure = lps.pressure
|
83 |
| - pressure_string = "Pressure: %0.3f" % current_pressure |
| 79 | + pressure_string = "Press: %0.3f" % current_pressure |
84 | 80 | if CONSOLE:
|
85 | 81 | print(pressure_string)
|
86 | 82 | else:
|
87 |
| - print((current_pressure,)) |
| 83 | + # print((current_pressure,)) |
| 84 | + pass |
88 | 85 |
|
89 | 86 | puff_polarity, puff_peak_level, puff_duration = detector.check_for_puff(
|
90 | 87 | current_pressure
|
|
104 | 101 | "Duration: %0.2f" % puff_duration
|
105 | 102 | ) # puff duration can be none? after detect?
|
106 | 103 | state_string = "DETECTED:"
|
107 |
| - print(state_string) |
108 | 104 | if puff_peak_level == 1:
|
109 | 105 | input_type_string = "SOFT"
|
110 | 106 | if puff_peak_level == 2:
|
|
116 | 112 | input_type_string += " SIP"
|
117 | 113 | state_display_start = curr_time
|
118 | 114 |
|
119 |
| - if CONSOLE: |
120 |
| - print("END", end=" ") |
121 |
| - if CONSOLE: |
122 |
| - print(input_type_string) |
123 |
| - if CONSOLE: |
124 |
| - print(duration_string) |
125 |
| - |
126 | 115 | elif detector.state == STARTED:
|
127 | 116 | # elif puff_duration is None and puff_polarity:
|
128 | 117 | dir_string = ""
|
|
131 | 120 | if puff_polarity == -1:
|
132 | 121 | dir_string = "SIP"
|
133 | 122 | state_string = "%s START" % dir_string
|
134 |
| - if CONSOLE: |
135 |
| - print(state_string) |
136 | 123 | else:
|
137 | 124 | state = WAITING
|
138 |
| - if (curr_time - state_display_start) > state_display_timeout: |
| 125 | + if (curr_time - state_display_start) > detector.display_timeout: |
139 | 126 | state_string = "Waiting for Input"
|
140 | 127 | input_type_string = " "
|
141 | 128 | duration_string = " "
|
142 | 129 |
|
143 |
| - # Create the tet label |
144 |
| - print((curr_time - state_display_start)) |
145 |
| - |
146 | 130 | # if it's been >timeout since we started displaying puff result
|
147 | 131 |
|
| 132 | + min_press_str = "min: %d" % detector.min_pressure |
| 133 | + high_press_str = "hi: %d" % detector.high_pressure |
| 134 | + |
148 | 135 | banner = label.Label(font, text=banner_string, color=color)
|
149 | 136 | state = label.Label(font, text=state_string, color=color)
|
150 | 137 | detector_result = label.Label(font, text=input_type_string, color=color)
|
151 | 138 | duration = label.Label(font, text=duration_string, color=color)
|
| 139 | + min_pressure_label = label.Label(font, text=min_press_str, color=color) |
| 140 | + high_pressure_label = label.Label(font, text=high_press_str, color=color) |
152 | 141 | pressure_label = label.Label(font, text=pressure_string, color=color)
|
153 | 142 | if CONSOLE:
|
154 | 143 | print(banner.text)
|
155 | 144 | print(state.text)
|
156 | 145 | print(detector_result.text)
|
157 | 146 | print(duration.text)
|
| 147 | + print(min_pressure_label.text) |
| 148 | + print(high_pressure_label.text) |
158 | 149 | print(pressure_label.text)
|
159 | 150 |
|
160 | 151 | banner.x = 0
|
|
168 | 159 | duration.x = 10
|
169 | 160 | duration.y = 30 + Y_OFFSET
|
170 | 161 |
|
| 162 | + min_pressure_label.x = 0 |
| 163 | + min_pressure_label.y = BOTTOM_ROW - 10 |
| 164 | + |
171 | 165 | x, y, w, h = pressure_label.bounding_box
|
172 | 166 | pressure_label.x = DISPLAY_WIDTH - w
|
173 |
| - pressure_label.y = BOTTOM_ROW + Y_OFFSET |
| 167 | + pressure_label.y = BOTTOM_ROW |
174 | 168 |
|
| 169 | + high_pressure_label.x = 0 |
| 170 | + high_pressure_label.y = BOTTOM_ROW |
| 171 | + |
| 172 | + splash = displayio.Group(max_size=10) |
175 | 173 | splash.append(banner)
|
176 | 174 | splash.append(state)
|
177 | 175 | splash.append(detector_result)
|
178 | 176 | splash.append(duration)
|
| 177 | + splash.append(min_pressure_label) |
| 178 | + splash.append(high_pressure_label) |
179 | 179 | splash.append(pressure_label)
|
180 | 180 | # Show it
|
181 | 181 | display.show(splash)
|
|
0 commit comments