Skip to content

Commit a62e1cf

Browse files
authored
Merge pull request #7957 from ford-jones/7943-mute-target
Mute: channels
2 parents ca02808 + 51ad9d0 commit a62e1cf

File tree

3 files changed

+37
-27
lines changed

3 files changed

+37
-27
lines changed

src/graphics/Screen.cpp

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ namespace graphics
100100
#define NUM_EXTRA_FRAMES 3 // text message and debug frame
101101
// if defined a pixel will blink to show redraws
102102
// #define SHOW_REDRAWS
103-
103+
#define ASCII_BELL '\x07'
104104
// A text message frame + debug frame + all the node infos
105105
FrameCallback *normalFrames;
106106
static uint32_t targetFramerate = IDLE_FRAMERATE;
@@ -1458,28 +1458,36 @@ int Screen::handleTextMessage(const meshtastic_MeshPacket *packet)
14581458
}
14591459
// === Prepare banner content ===
14601460
const meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(packet->from);
1461+
const meshtastic_Channel channel =
1462+
channels.getByIndex(packet->channel ? packet->channel : channels.getPrimaryIndex());
14611463
const char *longName = (node && node->has_user) ? node->user.long_name : nullptr;
14621464

14631465
const char *msgRaw = reinterpret_cast<const char *>(packet->decoded.payload.bytes);
14641466

14651467
char banner[256];
14661468

1467-
// Check for bell character in message to determine alert type
14681469
bool isAlert = false;
1469-
for (size_t i = 0; i < packet->decoded.payload.size && i < 100; i++) {
1470-
if (msgRaw[i] == '\x07') {
1471-
isAlert = true;
1472-
break;
1470+
1471+
if (moduleConfig.external_notification.alert_bell || moduleConfig.external_notification.alert_bell_vibra ||
1472+
moduleConfig.external_notification.alert_bell_buzzer)
1473+
// Check for bell character to determine if this message is an alert
1474+
for (size_t i = 0; i < packet->decoded.payload.size && i < 100; i++) {
1475+
if (msgRaw[i] == ASCII_BELL) {
1476+
isAlert = true;
1477+
break;
1478+
}
14731479
}
1474-
}
14751480

1481+
// Unlike generic messages, alerts (when enabled via the ext notif module) ignore any
1482+
// 'mute' preferences set to any specific node or channel.
14761483
if (isAlert) {
14771484
if (longName && longName[0]) {
14781485
snprintf(banner, sizeof(banner), "Alert Received from\n%s", longName);
14791486
} else {
14801487
strcpy(banner, "Alert Received");
14811488
}
1482-
} else {
1489+
screen->showSimpleBanner(banner, 3000);
1490+
} else if (!channel.settings.mute) {
14831491
if (longName && longName[0]) {
14841492
#if defined(M5STACK_UNITC6L)
14851493
strcpy(banner, "New Message");
@@ -1490,20 +1498,21 @@ int Screen::handleTextMessage(const meshtastic_MeshPacket *packet)
14901498
} else {
14911499
strcpy(banner, "New Message");
14921500
}
1493-
}
14941501
#if defined(M5STACK_UNITC6L)
1495-
screen->setOn(true);
1496-
screen->showSimpleBanner(banner, 1500);
1497-
if (config.device.buzzer_mode != meshtastic_Config_DeviceConfig_BuzzerMode_DIRECT_MSG_ONLY ||
1498-
(isAlert && moduleConfig.external_notification.alert_bell_buzzer) || (!isBroadcast(packet->to) && isToUs(p))) {
1499-
// Beep if not in DIRECT_MSG_ONLY mode or if in DIRECT_MSG_ONLY mode and either
1500-
// - packet contains an alert and alert bell buzzer is enabled
1501-
// - packet is a non-broadcast that is addressed to this node
1502-
playLongBeep();
1503-
}
1502+
screen->setOn(true);
1503+
screen->showSimpleBanner(banner, 1500);
1504+
if (config.device.buzzer_mode != meshtastic_Config_DeviceConfig_BuzzerMode_DIRECT_MSG_ONLY ||
1505+
(isAlert && moduleConfig.external_notification.alert_bell_buzzer) ||
1506+
(!isBroadcast(packet->to) && isToUs(p))) {
1507+
// Beep if not in DIRECT_MSG_ONLY mode or if in DIRECT_MSG_ONLY mode and either
1508+
// - packet contains an alert and alert bell buzzer is enabled
1509+
// - packet is a non-broadcast that is addressed to this node
1510+
playLongBeep();
1511+
}
15041512
#else
1505-
screen->showSimpleBanner(banner, 3000);
1513+
screen->showSimpleBanner(banner, 3000);
15061514
#endif
1515+
}
15071516
}
15081517
}
15091518

src/modules/ExternalNotificationModule.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ ExternalNotificationModule::ExternalNotificationModule()
442442

443443
ProcessMessage ExternalNotificationModule::handleReceived(const meshtastic_MeshPacket &mp)
444444
{
445-
if (moduleConfig.external_notification.enabled && !isMuted) {
445+
if (moduleConfig.external_notification.enabled && !isSilenced) {
446446
#ifdef T_WATCH_S3
447447
drv.setWaveform(0, 75);
448448
drv.setWaveform(1, 56);
@@ -453,12 +453,13 @@ ProcessMessage ExternalNotificationModule::handleReceived(const meshtastic_MeshP
453453
// Check if the message contains a bell character. Don't do this loop for every pin, just once.
454454
auto &p = mp.decoded;
455455
bool containsBell = false;
456-
for (int i = 0; i < p.payload.size; i++) {
456+
for (size_t i = 0; i < p.payload.size; i++) {
457457
if (p.payload.bytes[i] == ASCII_BELL) {
458458
containsBell = true;
459459
}
460460
}
461461

462+
meshtastic_Channel ch = channels.getByIndex(mp.channel ? mp.channel : channels.getPrimaryIndex());
462463
if (moduleConfig.external_notification.alert_bell) {
463464
if (containsBell) {
464465
LOG_INFO("externalNotificationModule - Notification Bell");
@@ -509,7 +510,7 @@ ProcessMessage ExternalNotificationModule::handleReceived(const meshtastic_MeshP
509510
}
510511
}
511512

512-
if (moduleConfig.external_notification.alert_message) {
513+
if (moduleConfig.external_notification.alert_message && !ch.settings.mute) {
513514
LOG_INFO("externalNotificationModule - Notification Module");
514515
isNagging = true;
515516
setExternalState(0, true);
@@ -520,7 +521,7 @@ ProcessMessage ExternalNotificationModule::handleReceived(const meshtastic_MeshP
520521
}
521522
}
522523

523-
if (moduleConfig.external_notification.alert_message_vibra) {
524+
if (moduleConfig.external_notification.alert_message_vibra && !ch.settings.mute) {
524525
LOG_INFO("externalNotificationModule - Notification Module (Vibra)");
525526
isNagging = true;
526527
setExternalState(1, true);
@@ -531,7 +532,7 @@ ProcessMessage ExternalNotificationModule::handleReceived(const meshtastic_MeshP
531532
}
532533
}
533534

534-
if (moduleConfig.external_notification.alert_message_buzzer) {
535+
if (moduleConfig.external_notification.alert_message_buzzer && !ch.settings.mute) {
535536
LOG_INFO("externalNotificationModule - Notification Module (Buzzer)");
536537
if (config.device.buzzer_mode != meshtastic_Config_DeviceConfig_BuzzerMode_DIRECT_MSG_ONLY ||
537538
(!isBroadcast(mp.to) && isToUs(&mp))) {

src/modules/ExternalNotificationModule.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class ExternalNotificationModule : public SinglePortModule, private concurrency:
4343
void setExternalState(uint8_t index = 0, bool on = false);
4444
bool getExternal(uint8_t index = 0);
4545

46-
void setMute(bool mute) { isMuted = mute; }
47-
bool getMute() { return isMuted; }
46+
void setMute(bool mute) { isSilenced = mute; }
47+
bool getMute() { return isSilenced; }
4848

4949
bool canBuzz();
5050
bool nagging();
@@ -67,7 +67,7 @@ class ExternalNotificationModule : public SinglePortModule, private concurrency:
6767

6868
bool isNagging = false;
6969

70-
bool isMuted = false;
70+
bool isSilenced = false;
7171

7272
virtual AdminMessageHandleResult handleAdminMessageForModule(const meshtastic_MeshPacket &mp,
7373
meshtastic_AdminMessage *request,

0 commit comments

Comments
 (0)