|
19 | 19 | TEXT_HEIGHT = 8
|
20 | 20 | BOTTOM_ROW = DISPLAY_HEIGHT - TEXT_HEIGHT - Y_OFFSET
|
21 | 21 |
|
| 22 | +# States: |
| 23 | +WAITING = 0 |
| 24 | +STARTED = 1 |
| 25 | +DETECTED = 2 |
22 | 26 | i2c = board.I2C()
|
23 | 27 | # 128x32
|
24 | 28 | # display_bus = displayio.I2CDisplay(i2c, device_address=0x3C, reset=oled_reset)
|
|
48 | 52 |
|
49 | 53 | lps.filter_config = True
|
50 | 54 | # if CONSOLE: print("Filter Config:", lps.low_pass_config)
|
51 |
| -detector = PuffDetector(min_pressure=8, high_pressure=40) |
| 55 | +detector = PuffDetector() |
52 | 56 | time.sleep(1)
|
53 | 57 |
|
54 |
| - |
55 |
| -puff_start = time.monotonic() |
56 |
| - |
57 |
| - |
58 | 58 | if CONSOLE:
|
59 | 59 | print("CONSOLE?")
|
60 | 60 | if DEBUG and CONSOLE:
|
61 | 61 | print("Debug CONSOLE")
|
62 | 62 |
|
63 |
| -color = 0xFAFAFA |
| 63 | +color = 0xFFFFFF |
64 | 64 |
|
65 | 65 | font = terminalio.FONT
|
66 | 66 |
|
67 | 67 | banner_string = "PUFF-O-TRON-9000"
|
68 | 68 | state_string = " "
|
69 | 69 | pressure_string = " "
|
70 | 70 | input_type_string = " "
|
| 71 | +duration_string = " " |
71 | 72 |
|
72 | 73 | state_display_timeout = 1.0
|
73 | 74 | state_display_start = 0
|
74 | 75 | while True:
|
| 76 | + curr_time = time.monotonic() |
75 | 77 | ######################################
|
76 | 78 | splash = displayio.Group(max_size=10)
|
77 | 79 | # Set text, font, and color
|
|
84 | 86 | puff_polarity, puff_peak_level, puff_duration = detector.check_for_puff(
|
85 | 87 | current_pressure
|
86 | 88 | )
|
87 |
| - |
88 |
| - if CONSOLE and puff_duration is None and puff_polarity: |
89 |
| - if puff_polarity == 1: |
90 |
| - state_string = "PUFF" |
91 |
| - if puff_polarity == -1: |
92 |
| - state_string = "SIP" |
93 |
| - state_string += " START" |
94 |
| - |
95 |
| - if CONSOLE and puff_duration: |
96 |
| - |
| 89 | + if DEBUG and CONSOLE: |
| 90 | + print( |
| 91 | + "Pol: %s Peak: %s Dir: %s" |
| 92 | + % (str(puff_polarity), str(puff_peak_level), str(puff_duration)) |
| 93 | + ) |
| 94 | + |
| 95 | + # if puff_duration: |
| 96 | + if detector.state == DETECTED: |
| 97 | + state = DETECTED |
| 98 | + duration_string = "Duration: %0.2f" % puff_duration |
97 | 99 | state_string = "DETECTED:"
|
98 | 100 | print(state_string)
|
99 | 101 | if puff_peak_level == 1:
|
|
105 | 107 | input_type_string += " PUFF"
|
106 | 108 | if puff_polarity == -1:
|
107 | 109 | 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) |
| 110 | + state_display_start = curr_time |
| 111 | + |
| 112 | + if CONSOLE: |
| 113 | + print("END", end=" ") |
| 114 | + if CONSOLE: |
| 115 | + print(input_type_string) |
| 116 | + if CONSOLE: |
| 117 | + print(duration_string) |
| 118 | + |
| 119 | + elif detector.state == STARTED: |
| 120 | + # elif puff_duration is None and puff_polarity: |
| 121 | + dir_string = "" |
| 122 | + if puff_polarity == 1: |
| 123 | + dir_string = "PUFF" |
| 124 | + if puff_polarity == -1: |
| 125 | + dir_string = "SIP" |
| 126 | + state_string = "%s START" % dir_string |
| 127 | + if CONSOLE: |
| 128 | + print(state_string) |
| 129 | + else: |
| 130 | + state = WAITING |
| 131 | + if (curr_time - state_display_start) > state_display_timeout: |
| 132 | + state_string = "Waiting for Input" |
| 133 | + detector_result_string = " " |
| 134 | + duration_string = " " |
| 135 | + |
| 136 | + if CONSOLE: |
| 137 | + print("STATE:", state) |
112 | 138 | # Create the tet label
|
113 |
| - if puff_polarity == 0: |
114 |
| - state_string = "Waiting for Input" |
| 139 | + print((curr_time - state_display_start)) |
| 140 | + |
| 141 | + # if it's been >timeout since we started displaying puff result |
| 142 | + |
115 | 143 | banner = label.Label(font, text=banner_string, color=color)
|
116 | 144 | state = label.Label(font, text=state_string, color=color)
|
117 | 145 | detector_result = label.Label(font, text=input_type_string, color=color)
|
118 |
| - text_area4 = label.Label(font, text=state_string, color=color) |
| 146 | + duration = label.Label(font, text=duration_string, color=color) |
119 | 147 | pressure_label = label.Label(font, text=pressure_string, color=color)
|
120 | 148 |
|
121 | 149 | banner.x = 0
|
|
126 | 154 | detector_result.x = 20
|
127 | 155 | detector_result.y = 20 + Y_OFFSET
|
128 | 156 |
|
| 157 | + duration.x = 10 |
| 158 | + duration.y = 30 + Y_OFFSET |
| 159 | + |
129 | 160 | x, y, w, h = pressure_label.bounding_box
|
130 | 161 | pressure_label.x = DISPLAY_WIDTH - w
|
131 | 162 | pressure_label.y = BOTTOM_ROW + Y_OFFSET
|
132 | 163 |
|
133 | 164 | splash.append(banner)
|
134 | 165 | splash.append(state)
|
135 | 166 | splash.append(detector_result)
|
| 167 | + splash.append(duration) |
136 | 168 | splash.append(pressure_label)
|
137 | 169 | # Show it
|
138 | 170 | display.show(splash)
|
| 171 | + if CONSOLE: |
| 172 | + print("----------------------------------------------") |
139 | 173 | time.sleep(0.01)
|
0 commit comments