@@ -53,6 +53,31 @@ void UITask::begin(DisplayDriver* display, NodePrefs* node_prefs, const char* bu
5353
5454 // v1.2.3 (1 Jan 2025)
5555 sprintf (_version_info, " %s (%s)" , version, build_date);
56+
57+ #ifdef PIN_BUZZER
58+ buzzer.begin ();
59+ #endif
60+ }
61+
62+ void UITask::soundBuzzer (UIEventType bet) {
63+ #if defined(PIN_BUZZER)
64+ switch (bet){
65+ case UIEventType::contactMessage:
66+ // gemini's pick
67+ buzzer.play (" MsgRcv3:d=4,o=6,b=200:32e,32g,32b,16c7" );
68+ break ;
69+ case UIEventType::channelMessage:
70+ buzzer.play (" kerplop:d=16,o=6,b=120:32g#,32c#" );
71+ break ;
72+ case UIEventType::roomMessage:
73+ case UIEventType::newContactMessage:
74+ case UIEventType::none:
75+ default :
76+ break ;
77+ }
78+ #endif
79+ // Serial.print("DBG: Buzzzzzz -> ");
80+ // Serial.println((int) bet);
5681}
5782
5883void UITask::msgRead (int msgcount) {
@@ -85,7 +110,7 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, i
85110 }
86111}
87112
88- void renderBatteryIndicator (DisplayDriver* _display, uint16_t batteryMilliVolts) {
113+ void UITask:: renderBatteryIndicator (uint16_t batteryMilliVolts) {
89114 // Convert millivolts to percentage
90115 const int minMilliVolts = 3000 ; // Minimum voltage (e.g., 3.0V)
91116 const int maxMilliVolts = 4200 ; // Maximum voltage (e.g., 4.2V)
@@ -107,8 +132,8 @@ void renderBatteryIndicator(DisplayDriver* _display, uint16_t batteryMilliVolts)
107132 _display->fillRect (iconX + iconWidth, iconY + (iconHeight / 4 ), 3 , iconHeight / 2 );
108133
109134 // fill the battery based on the percentage
110- int fillWidth = (batteryPercentage * (iconWidth - 2 )) / 100 ;
111- _display->fillRect (iconX + 1 , iconY + 1 , fillWidth, iconHeight - 2 );
135+ int fillWidth = (batteryPercentage * (iconWidth - 4 )) / 100 ;
136+ _display->fillRect (iconX + 2 , iconY + 2 , fillWidth, iconHeight - 4 );
112137}
113138
114139void UITask::renderCurrScreen () {
@@ -155,7 +180,7 @@ void UITask::renderCurrScreen() {
155180 _display->print (_node_prefs->node_name );
156181
157182 // battery voltage
158- renderBatteryIndicator (_display, _board->getBattMilliVolts ());
183+ renderBatteryIndicator (_board->getBattMilliVolts ());
159184
160185 // freq / sf
161186 _display->setCursor (0 , 20 );
@@ -209,45 +234,58 @@ void UITask::userLedHandler() {
209234}
210235
211236void UITask::buttonHandler () {
212- #ifdef PIN_USER_BTN
213- static int prev_btn_state = !USER_BTN_PRESSED;
214- static unsigned long btn_state_change_time = 0 ;
215- static unsigned long next_read = 0 ;
216- int cur_time = millis ();
217- if (cur_time >= next_read) {
218- int btn_state = digitalRead (PIN_USER_BTN);
219- if (btn_state != prev_btn_state) {
220- if (btn_state == USER_BTN_PRESSED) { // pressed?
221- if (_display != NULL ) {
222- if (_display->isOn ()) {
223- clearMsgPreview ();
224- } else {
225- _display->turnOn ();
226- _need_refresh = true ;
237+ #if defined(PIN_USER_BTN) || defined(PIN_USER_BTN_ANA)
238+ static int prev_btn_state = !USER_BTN_PRESSED;
239+ static int prev_btn_state_ana = !USER_BTN_PRESSED;
240+ static unsigned long btn_state_change_time = 0 ;
241+ static unsigned long next_read = 0 ;
242+ int cur_time = millis ();
243+ if (cur_time >= next_read) {
244+ int btn_state = 0 ;
245+ int btn_state_ana = 0 ;
246+ #ifdef PIN_USER_BTN
247+ btn_state = digitalRead (PIN_USER_BTN);
248+ #endif
249+ #ifdef PIN_USER_BTN_ANA
250+ btn_state_ana = (analogRead (PIN_USER_BTN_ANA) < 20 ); // analogRead returns a value hopefully below 20 when button is pressed.
251+ #endif
252+ if (btn_state != prev_btn_state || btn_state_ana != prev_btn_state_ana) { // check for either digital or analogue button change of state
253+ if (btn_state == USER_BTN_PRESSED || btn_state_ana == USER_BTN_PRESSED) { // pressed?
254+ if (_display != NULL ) {
255+ if (_display->isOn ()) {
256+ clearMsgPreview ();
257+ } else {
258+ _display->turnOn ();
259+ _need_refresh = true ;
260+ }
261+ _auto_off = cur_time + AUTO_OFF_MILLIS; // extend auto-off timer
262+ }
263+ } else { // unpressed ? check pressed time ...
264+ if ((cur_time - btn_state_change_time) > 5000 ) {
265+ #ifdef PIN_STATUS_LED
266+ digitalWrite (PIN_STATUS_LED, LOW);
267+ delay (10 );
268+ #endif
269+ _board->powerOff ();
227270 }
228- _auto_off = cur_time + AUTO_OFF_MILLIS; // extend auto-off timer
229- }
230- } else { // unpressed ? check pressed time ...
231- if ((cur_time - btn_state_change_time) > 5000 ) {
232- #ifdef PIN_STATUS_LED
233- digitalWrite (PIN_STATUS_LED, LOW);
234- delay (10 );
235- #endif
236- _board->powerOff ();
237271 }
272+ btn_state_change_time = millis ();
273+ prev_btn_state = btn_state;
274+ prev_btn_state_ana = btn_state_ana;
238275 }
239- btn_state_change_time = millis ();
240- prev_btn_state = btn_state;
276+ next_read = millis () + 100 ; // 10 reads per second
241277 }
242- next_read = millis () + 100 ; // 10 reads per second
278+ # endif
243279 }
244- #endif
245- }
246280
247281void UITask::loop () {
248282 buttonHandler ();
249283 userLedHandler ();
250284
285+ #ifdef PIN_BUZZER
286+ if (buzzer.isPlaying ()) buzzer.loop ();
287+ #endif
288+
251289 if (_display != NULL && _display->isOn ()) {
252290 static bool _firstBoot = true ;
253291 if (_firstBoot && millis () >= BOOT_SCREEN_MILLIS) {
0 commit comments