Skip to content

Commit 043f37a

Browse files
committed
♻️ refactor: unify UI notification methods into single notify() function
Consolidates soundBuzzer() and triggerVibration() into a unified notify() method that handles both audio and haptic feedback based on UIEventType.
1 parent 2da5088 commit 043f37a

File tree

6 files changed

+26
-40
lines changed

6 files changed

+26
-40
lines changed

examples/companion_radio/AbstractUITask.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ class AbstractUITask {
4141
void disableSerial() { _serial->disable(); }
4242
virtual void msgRead(int msgcount) = 0;
4343
virtual void newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) = 0;
44-
virtual void soundBuzzer(UIEventType bet = UIEventType::none) = 0;
45-
#ifdef PIN_VIBRATION
46-
virtual void triggerVibration() = 0;
47-
#endif
44+
virtual void notify(UIEventType t = UIEventType::none) = 0;
4845
virtual void loop() = 0;
4946
};

examples/companion_radio/MyMesh.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,7 @@ void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path
243243
}
244244
} else {
245245
#ifdef DISPLAY_CLASS
246-
if (_ui) _ui->soundBuzzer(UIEventType::newContactMessage);
247-
if (_ui) {
248-
#ifdef PIN_VIBRATION
249-
if (is_new) _ui->triggerVibration();
250-
#endif
251-
}
246+
if (_ui) _ui->notify(UIEventType::newContactMessage);
252247
#endif
253248
}
254249

@@ -358,7 +353,7 @@ void MyMesh::queueMessage(const ContactInfo &from, uint8_t txt_type, mesh::Packe
358353
if (should_display && _ui) {
359354
_ui->newMsg(path_len, from.name, text, offline_queue_len);
360355
if (!_serial->isConnected()) {
361-
_ui->soundBuzzer(UIEventType::contactMessage);
356+
_ui->notify(UIEventType::contactMessage);
362357
}
363358
}
364359
#endif
@@ -417,7 +412,7 @@ void MyMesh::onChannelMessageRecv(const mesh::GroupChannel &channel, mesh::Packe
417412
_serial->writeFrame(frame, 1);
418413
} else {
419414
#ifdef DISPLAY_CLASS
420-
if (_ui) _ui->soundBuzzer(UIEventType::channelMessage);
415+
if (_ui) _ui->notify(UIEventType::channelMessage);
421416
#endif
422417
}
423418
#ifdef DISPLAY_CLASS

examples/companion_radio/ui-new/UITask.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,7 @@ class HomeScreen : public UIScreen {
348348
return true;
349349
}
350350
if (c == KEY_ENTER && _page == HomePage::ADVERT) {
351-
#ifdef PIN_BUZZER
352-
_task->soundBuzzer(UIEventType::ack);
353-
#endif
351+
_task->notify(UIEventType::ack);
354352
if (the_mesh.advert()) {
355353
_task->showAlert("Advert sent!", 1000);
356354
} else {
@@ -501,9 +499,9 @@ void UITask::showAlert(const char* text, int duration_millis) {
501499
_alert_expiry = millis() + duration_millis;
502500
}
503501

504-
void UITask::soundBuzzer(UIEventType bet) {
502+
void UITask::notify(UIEventType t) {
505503
#if defined(PIN_BUZZER)
506-
switch(bet){
504+
switch(t){
507505
case UIEventType::contactMessage:
508506
// gemini's pick
509507
buzzer.play("MsgRcv3:d=4,o=6,b=200:32e,32g,32b,16c7");
@@ -521,13 +519,15 @@ switch(bet){
521519
break;
522520
}
523521
#endif
524-
}
525522

526523
#ifdef PIN_VIBRATION
527-
void UITask::triggerVibration() {
528-
vibration.trigger();
529-
}
524+
// Trigger vibration for all UI events except none
525+
if (t != UIEventType::none) {
526+
vibration.trigger();
527+
}
530528
#endif
529+
}
530+
531531

532532
void UITask::msgRead(int msgcount) {
533533
_msgcount = msgcount;
@@ -542,9 +542,6 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, i
542542
((MsgPreviewScreen *) msg_preview)->addPreview(path_len, from_name, text);
543543
setCurrScreen(msg_preview);
544544

545-
#ifdef PIN_VIBRATION
546-
triggerVibration();
547-
#endif
548545

549546
if (_display != NULL) {
550547
if (!_display->isOn()) _display->turnOn();
@@ -773,11 +770,11 @@ void UITask::toggleGPS() {
773770
if (strcmp(_sensors->getSettingName(i), "gps") == 0) {
774771
if (strcmp(_sensors->getSettingValue(i), "1") == 0) {
775772
_sensors->setSettingValue("gps", "0");
776-
soundBuzzer(UIEventType::ack);
773+
notify(UIEventType::ack);
777774
showAlert("GPS: Disabled", 800);
778775
} else {
779776
_sensors->setSettingValue("gps", "1");
780-
soundBuzzer(UIEventType::ack);
777+
notify(UIEventType::ack);
781778
showAlert("GPS: Enabled", 800);
782779
}
783780
_next_refresh = 0;
@@ -792,7 +789,7 @@ void UITask::toggleBuzzer() {
792789
#ifdef PIN_BUZZER
793790
if (buzzer.isQuiet()) {
794791
buzzer.quiet(false);
795-
soundBuzzer(UIEventType::ack);
792+
notify(UIEventType::ack);
796793
showAlert("Buzzer: ON", 800);
797794
} else {
798795
buzzer.quiet(true);

examples/companion_radio/ui-new/UITask.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ class UITask : public AbstractUITask {
7777
// from AbstractUITask
7878
void msgRead(int msgcount) override;
7979
void newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) override;
80-
void soundBuzzer(UIEventType bet = UIEventType::none) override;
81-
#ifdef PIN_VIBRATION
82-
void triggerVibration() override;
83-
#endif
80+
void notify(UIEventType t = UIEventType::none) override;
8481
void loop() override;
8582

8683
void shutdown(bool restart = false);

examples/companion_radio/ui-orig/UITask.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no
8888
ui_started_at = millis();
8989
}
9090

91-
void UITask::soundBuzzer(UIEventType bet) {
91+
void UITask::notify(UIEventType t) {
9292
#if defined(PIN_BUZZER)
93-
switch(bet){
93+
switch(t){
9494
case UIEventType::contactMessage:
9595
// gemini's pick
9696
buzzer.play("MsgRcv3:d=4,o=6,b=200:32e,32g,32b,16c7");
@@ -108,8 +108,8 @@ switch(bet){
108108
break;
109109
}
110110
#endif
111-
// Serial.print("DBG: Buzzzzzz -> ");
112-
// Serial.println((int) bet);
111+
// Serial.print("DBG: Alert user -> ");
112+
// Serial.println((int) t);
113113
}
114114

115115
void UITask::msgRead(int msgcount) {
@@ -370,7 +370,7 @@ void UITask::handleButtonDoublePress() {
370370
MESH_DEBUG_PRINTLN("UITask: double press triggered, sending advert");
371371
// ADVERT
372372
#ifdef PIN_BUZZER
373-
soundBuzzer(UIEventType::ack);
373+
notify(UIEventType::ack);
374374
#endif
375375
if (the_mesh.advert()) {
376376
MESH_DEBUG_PRINTLN("Advert sent!");
@@ -388,7 +388,7 @@ void UITask::handleButtonTriplePress() {
388388
#ifdef PIN_BUZZER
389389
if (buzzer.isQuiet()) {
390390
buzzer.quiet(false);
391-
soundBuzzer(UIEventType::ack);
391+
notify(UIEventType::ack);
392392
sprintf(_alert, "Buzzer: ON");
393393
} else {
394394
buzzer.quiet(true);
@@ -407,11 +407,11 @@ void UITask::handleButtonQuadruplePress() {
407407
if (strcmp(_sensors->getSettingName(i), "gps") == 0) {
408408
if (strcmp(_sensors->getSettingValue(i), "1") == 0) {
409409
_sensors->setSettingValue("gps", "0");
410-
soundBuzzer(UIEventType::ack);
410+
notify(UIEventType::ack);
411411
sprintf(_alert, "GPS: Disabled");
412412
} else {
413413
_sensors->setSettingValue("gps", "1");
414-
soundBuzzer(UIEventType::ack);
414+
notify(UIEventType::ack);
415415
sprintf(_alert, "GPS: Enabled");
416416
}
417417
break;

examples/companion_radio/ui-orig/UITask.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class UITask : public AbstractUITask {
6666
// from AbstractUITask
6767
void msgRead(int msgcount) override;
6868
void newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) override;
69-
void soundBuzzer(UIEventType bet = UIEventType::none) override;
69+
void notify(UIEventType t = UIEventType::none) override;
7070
void loop() override;
7171

7272
void shutdown(bool restart = false);

0 commit comments

Comments
 (0)