|
19 | 19 | TEXT_HEIGHT = 8
|
20 | 20 | BOTTOM_ROW = DISPLAY_HEIGHT - TEXT_HEIGHT - Y_OFFSET
|
21 | 21 |
|
22 |
| - |
23 | 22 | i2c = board.I2C()
|
24 | 23 | # 128x32
|
25 | 24 | # display_bus = displayio.I2CDisplay(i2c, device_address=0x3C, reset=oled_reset)
|
|
49 | 48 |
|
50 | 49 | lps.filter_config = True
|
51 | 50 | # 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) |
53 | 52 | time.sleep(1)
|
54 | 53 |
|
55 | 54 |
|
|
61 | 60 | if DEBUG and CONSOLE:
|
62 | 61 | print("Debug CONSOLE")
|
63 | 62 |
|
| 63 | +color = 0xFAFAFA |
| 64 | + |
| 65 | +font = terminalio.FONT |
64 | 66 |
|
| 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 |
65 | 74 | while True:
|
66 | 75 | ######################################
|
67 | 76 | splash = displayio.Group(max_size=10)
|
68 | 77 | # 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 | 78 |
|
94 | 79 | ######################################
|
95 | 80 | current_pressure = lps.pressure
|
| 81 | + pressure_string = "Pressure: %0.3f" % current_pressure |
96 | 82 | if not CONSOLE:
|
97 | 83 | print((current_pressure,))
|
98 | 84 | puff_polarity, puff_peak_level, puff_duration = detector.check_for_puff(
|
99 | 85 | current_pressure
|
100 | 86 | )
|
101 | 87 |
|
102 | 88 | if CONSOLE and puff_duration is None and puff_polarity:
|
103 |
| - print("START", end=" ") |
104 | 89 | if puff_polarity == 1:
|
105 |
| - print("PUFF") |
| 90 | + state_string = "PUFF" |
106 | 91 | if puff_polarity == -1:
|
107 |
| - print("SIP") |
| 92 | + state_string = "SIP" |
| 93 | + state_string += " START" |
| 94 | + |
108 | 95 | if CONSOLE and puff_duration:
|
109 | 96 |
|
110 |
| - print("END", end=" ") |
| 97 | + state_string = "DETECTED:" |
| 98 | + print(state_string) |
111 | 99 | if puff_peak_level == 1:
|
112 |
| - print("SOFT", end=" ") |
| 100 | + input_type_string = "SOFT" |
113 | 101 | if puff_peak_level == 2:
|
114 |
| - print("HARD", end=" ") |
| 102 | + input_type_string = "HARD" |
115 | 103 |
|
116 | 104 | if puff_polarity == 1:
|
117 |
| - print("PUFF") |
| 105 | + input_type_string += " PUFF" |
118 | 106 | 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) |
122 | 139 | time.sleep(0.01)
|
0 commit comments