Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions examples/companion_radio/MyMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions examples/companion_radio/MyMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
#define BLE_NAME_PREFIX "MeshCore-"
#endif

#ifndef BUZZER_QUIET
#define BUZZER_QUIET 1
#endif

#include <helpers/BaseChatMesh.h>
#include <helpers/TransportKeyStore.h>

Expand Down
2 changes: 1 addition & 1 deletion examples/companion_radio/NodePrefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
72 changes: 52 additions & 20 deletions examples/companion_radio/ui-new/UITask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}*/
3 changes: 3 additions & 0 deletions examples/companion_radio/ui-new/UITask.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
43 changes: 27 additions & 16 deletions examples/companion_radio/ui-orig/UITask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> ");
Expand Down
1 change: 1 addition & 0 deletions examples/companion_radio/ui-orig/UITask.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/ui/buzzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down