diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index 9bb747e79..5db94c59a 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -331,11 +331,12 @@ void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path memcpy(&out_frame[1], contact.id.pub_key, PUB_KEY_SIZE); _serial->writeFrame(out_frame, 1 + PUB_KEY_SIZE); } - } else { + } #ifdef DISPLAY_CLASS - if (_ui) _ui->notify(UIEventType::newContactMessage); -#endif + if (_ui) { + _ui->notify(UIEventType::newContactMessage); } +#endif // add inbound-path to mem cache if (path && path_len <= sizeof(AdvertPath::path)) { // check path is valid @@ -442,9 +443,7 @@ void MyMesh::queueMessage(const ContactInfo &from, uint8_t txt_type, mesh::Packe bool should_display = txt_type == TXT_TYPE_PLAIN || txt_type == TXT_TYPE_SIGNED_PLAIN; if (should_display && _ui) { _ui->newMsg(path_len, from.name, text, offline_queue_len); - if (!_serial->isConnected()) { - _ui->notify(UIEventType::contactMessage); - } + _ui->notify(UIEventType::contactMessage); } #endif } @@ -529,12 +528,13 @@ void MyMesh::onChannelMessageRecv(const mesh::GroupChannel &channel, mesh::Packe uint8_t frame[1]; frame[0] = PUSH_CODE_MSG_WAITING; // send push 'tickle' _serial->writeFrame(frame, 1); - } else { -#ifdef DISPLAY_CLASS - if (_ui) _ui->notify(UIEventType::channelMessage); -#endif } + #ifdef DISPLAY_CLASS + if (_ui) { + _ui->notify(UIEventType::channelMessage); + } + // Get the channel name from the channel index const char *channel_name = "Unknown"; ChannelDetails channel_details; @@ -800,8 +800,9 @@ MyMesh::MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMe _prefs.bw = LORA_BW; _prefs.cr = LORA_CR; _prefs.tx_power_dbm = LORA_TX_POWER; - _prefs.gps_enabled = 0; // GPS disabled by default - _prefs.gps_interval = 0; // No automatic GPS updates by default + _prefs.buzzer_quiet = BUZZER_QUIET; // buzzer disabled by default + _prefs.gps_enabled = 0; // GPS disabled by default + _prefs.gps_interval = 0; // No automatic GPS updates by default //_prefs.rx_delay_base = 10.0f; enable once new algo fixed } @@ -839,6 +840,7 @@ void MyMesh::begin(bool has_display) { _prefs.sf = constrain(_prefs.sf, 5, 12); _prefs.cr = constrain(_prefs.cr, 5, 8); _prefs.tx_power_dbm = constrain(_prefs.tx_power_dbm, 1, MAX_LORA_TX_POWER); + _prefs.buzzer_quiet = constrain(_prefs.buzzer_quiet, 0, 3); // Ensure int 0-3 _prefs.gps_enabled = constrain(_prefs.gps_enabled, 0, 1); // Ensure boolean 0 or 1 _prefs.gps_interval = constrain(_prefs.gps_interval, 0, 86400); // Max 24 hours diff --git a/examples/companion_radio/MyMesh.h b/examples/companion_radio/MyMesh.h index 95265a19a..afd0417de 100644 --- a/examples/companion_radio/MyMesh.h +++ b/examples/companion_radio/MyMesh.h @@ -67,6 +67,10 @@ #define BLE_NAME_PREFIX "MeshCore-" #endif +#ifndef BUZZER_QUIET +#define BUZZER_QUIET 1 +#endif + #include #include diff --git a/examples/companion_radio/NodePrefs.h b/examples/companion_radio/NodePrefs.h index 62cd41642..d71df6102 100644 --- a/examples/companion_radio/NodePrefs.h +++ b/examples/companion_radio/NodePrefs.h @@ -24,7 +24,7 @@ struct NodePrefs { // persisted to file float rx_delay_base; uint32_t ble_pin; uint8_t advert_loc_policy; - uint8_t buzzer_quiet; + uint8_t buzzer_quiet; // bitmask (0-3) for speaker config uint8_t gps_enabled; // GPS enabled flag (0=disabled, 1=enabled) uint32_t gps_interval; // GPS read interval in seconds uint8_t autoadd_config; // bitmask for auto-add contacts config diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 0690b45ac..828d98a97 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -595,22 +595,24 @@ void UITask::showAlert(const char* text, int duration_millis) { void UITask::notify(UIEventType t) { #if defined(PIN_BUZZER) -switch(t){ - case UIEventType::contactMessage: - // gemini's pick - buzzer.play("MsgRcv3:d=4,o=6,b=200:32e,32g,32b,16c7"); - break; - case UIEventType::channelMessage: - buzzer.play("kerplop:d=16,o=6,b=120:32g#,32c#"); - break; - case UIEventType::ack: - buzzer.play("ack:d=32,o=8,b=120:c"); - break; - case UIEventType::roomMessage: - case UIEventType::newContactMessage: - case UIEventType::none: - default: - break; +if (playNotification()) { + switch(t){ + case UIEventType::contactMessage: + // gemini's pick + buzzer.play("MsgRcv3:d=4,o=6,b=200:32e,32g,32b,16c7"); + break; + case UIEventType::channelMessage: + buzzer.play("kerplop:d=16,o=6,b=120:32g#,32c#"); + break; + case UIEventType::ack: + buzzer.play("ack:d=32,o=8,b=120:c"); + break; + case UIEventType::roomMessage: + case UIEventType::newContactMessage: + case UIEventType::none: + default: + break; + } } #endif @@ -912,18 +914,48 @@ void UITask::toggleGPS() { } } -void UITask::toggleBuzzer() { - // Toggle buzzer quiet mode +bool UITask::playNotification() { + #ifdef PIN_BUZZER + return !(_node_prefs->buzzer_quiet & BUZZER_QUIET_ALWAYS) && + (!(_node_prefs->buzzer_quiet & BUZZER_QUIET_ON_SERIAL) || !hasConnection()); + #else + return false; + #endif +} + +void UITask::toggleBuzzer() { // Master Toggle (bit 0 = 1, buzzer always disabled) #ifdef PIN_BUZZER - if (buzzer.isQuiet()) { + _node_prefs->buzzer_quiet ^= (1 << 0); + if (!(_node_prefs->buzzer_quiet & BUZZER_QUIET_ALWAYS)) { //bit 0 is true buzzer.quiet(false); notify(UIEventType::ack); } else { buzzer.quiet(true); } - _node_prefs->buzzer_quiet = buzzer.isQuiet(); the_mesh.savePrefs(); showAlert(buzzer.isQuiet() ? "Buzzer: OFF" : "Buzzer: ON", 800); _next_refresh = 0; // trigger refresh #endif } + +void UITask::toggleBuzzerOnSerial() { // Serial Toggle (bit 1 = 1, buzzer disabled during serial) + _node_prefs->buzzer_quiet ^= (1 << 1); + the_mesh.savePrefs(); +} + +/*void UITask::toggleBuzzer() { // Toggle between all four settings + #ifdef PIN_BUZZER + _node_prefs->buzzer_quiet = (_node_prefs->buzzer_quiet + 1) % 4; + the_mesh.savePrefs(); + + if (!(_node_prefs->buzzer_quiet & BUZZER_QUIET_ALWAYS)) { //bit 0 is true + buzzer.quiet(false); + if (_node_prefs->buzzer_quiet == 0) { //buzzer always enabled + buzzer.play("ack:d=32,o=8,b=120:c"); + } + } else { + buzzer.quiet(true); + } + _next_refresh = 0; // trigger refresh + #endif +}*/ \ No newline at end of file diff --git a/examples/companion_radio/ui-new/UITask.h b/examples/companion_radio/ui-new/UITask.h index 02c3cafbd..667c65348 100644 --- a/examples/companion_radio/ui-new/UITask.h +++ b/examples/companion_radio/ui-new/UITask.h @@ -78,7 +78,10 @@ class UITask : public AbstractUITask { bool hasDisplay() const { return _display != NULL; } bool isButtonPressed() const; + + bool playNotification(); void toggleBuzzer(); + void toggleBuzzerOnSerial(); bool getGPSState(); void toggleGPS(); diff --git a/examples/companion_radio/ui-orig/UITask.cpp b/examples/companion_radio/ui-orig/UITask.cpp index 3ad36fb00..41c88c592 100644 --- a/examples/companion_radio/ui-orig/UITask.cpp +++ b/examples/companion_radio/ui-orig/UITask.cpp @@ -89,24 +89,35 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no ui_started_at = millis(); } +bool UITask::playNotification() { + #ifdef PIN_BUZZER + return !(_node_prefs->buzzer_quiet & BUZZER_QUIET_ALWAYS) && + (!(_node_prefs->buzzer_quiet & BUZZER_QUIET_ON_SERIAL) || !hasConnection()); + #else + return false; + #endif +} + void UITask::notify(UIEventType t) { #if defined(PIN_BUZZER) -switch(t){ - case UIEventType::contactMessage: - // gemini's pick - buzzer.play("MsgRcv3:d=4,o=6,b=200:32e,32g,32b,16c7"); - break; - case UIEventType::channelMessage: - buzzer.play("kerplop:d=16,o=6,b=120:32g#,32c#"); - break; - case UIEventType::ack: - buzzer.play("ack:d=32,o=8,b=120:c"); - break; - case UIEventType::roomMessage: - case UIEventType::newContactMessage: - case UIEventType::none: - default: - break; +if (playNotification()) { + switch(t){ + case UIEventType::contactMessage: + // gemini's pick + buzzer.play("MsgRcv3:d=4,o=6,b=200:32e,32g,32b,16c7"); + break; + case UIEventType::channelMessage: + buzzer.play("kerplop:d=16,o=6,b=120:32g#,32c#"); + break; + case UIEventType::ack: + buzzer.play("ack:d=32,o=8,b=120:c"); + break; + case UIEventType::roomMessage: + case UIEventType::newContactMessage: + case UIEventType::none: + default: + break; + } } #endif // Serial.print("DBG: Alert user -> "); diff --git a/examples/companion_radio/ui-orig/UITask.h b/examples/companion_radio/ui-orig/UITask.h index 60cd0d042..69c06f6df 100644 --- a/examples/companion_radio/ui-orig/UITask.h +++ b/examples/companion_radio/ui-orig/UITask.h @@ -61,6 +61,7 @@ class UITask : public AbstractUITask { void begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs); bool hasDisplay() const { return _display != NULL; } + bool playNotification(); void clearMsgPreview(); // from AbstractUITask diff --git a/src/helpers/ui/buzzer.h b/src/helpers/ui/buzzer.h index 0a5005528..4834871de 100644 --- a/src/helpers/ui/buzzer.h +++ b/src/helpers/ui/buzzer.h @@ -15,7 +15,8 @@ - make message ring tone configurable */ - +#define BUZZER_QUIET_ALWAYS (1 << 0) // 0x01 - buzzer disabled +#define BUZZER_QUIET_ON_SERIAL (1 << 1) // 0x02 - buzzer disabled on serial class genericBuzzer { public: