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
23 changes: 18 additions & 5 deletions src/modules/ExternalNotificationModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,17 @@ bool ascending = true;

#define ASCII_BELL 0x07

#if !MESHTASTIC_EXCLUDE_RTTTL
meshtastic_RTTTLConfig rtttlConfig;
static const char *rtttlConfigFile = "/prefs/ringtone.proto";
#endif
Comment thread
coderabbitai[bot] marked this conversation as resolved.

ExternalNotificationModule *externalNotificationModule;

bool externalCurrentState[3] = {};

uint32_t externalTurnedOn[3] = {};

static const char *rtttlConfigFile = "/prefs/ringtone.proto";

int32_t ExternalNotificationModule::runOnce()
{
if (!moduleConfig.external_notification.enabled) {
Expand Down Expand Up @@ -135,7 +136,7 @@ int32_t ExternalNotificationModule::runOnce()
}

// Play RTTTL over i2s audio interface if enabled as buzzer
#ifdef HAS_I2S
#if defined(HAS_I2S) && !MESHTASTIC_EXCLUDE_RTTTL
if (moduleConfig.external_notification.use_i2s_as_buzzer) {
if (audioThread->isPlaying()) {
// Continue playing
Expand All @@ -146,6 +147,7 @@ int32_t ExternalNotificationModule::runOnce()
delay = EXT_NOTIFICATION_FAST_THREAD_MS;
}
#endif
#if !MESHTASTIC_EXCLUDE_RTTTL
// now let the PWM buzzer play
if (moduleConfig.external_notification.use_pwm && config.device.buzzer_gpio && canBuzz() && buzzerShouldAlert) {
if (rtttl::isPlaying()) {
Expand All @@ -157,6 +159,7 @@ int32_t ExternalNotificationModule::runOnce()
// we need fast updates to play the RTTTL
delay = EXT_NOTIFICATION_FAST_THREAD_MS;
}
#endif

return delay;
}
Expand Down Expand Up @@ -320,16 +323,18 @@ ExternalNotificationModule::ExternalNotificationModule()
// moduleConfig.external_notification.alert_message_buzzer = true;

if (moduleConfig.external_notification.enabled) {
#if !defined(MESHTASTIC_EXCLUDE_INPUTBROKER)
#if !MESHTASTIC_EXCLUDE_INPUTBROKER
if (inputBroker) // put our callback in the inputObserver list
inputObserver.observe(inputBroker);
#endif
#if !MESHTASTIC_EXCLUDE_RTTTL
if (nodeDB->loadProto(rtttlConfigFile, meshtastic_RTTTLConfig_size, sizeof(meshtastic_RTTTLConfig),
&meshtastic_RTTTLConfig_msg, &rtttlConfig) != LoadFileResult::LOAD_SUCCESS) {
memset(rtttlConfig.ringtone, 0, sizeof(rtttlConfig.ringtone));
// The default ringtone is always loaded from userPrefs.jsonc
strncpy(rtttlConfig.ringtone, USERPREFS_RINGTONE_RTTTL, sizeof(rtttlConfig.ringtone));
}
#endif

LOG_INFO("Init External Notification Module");

Expand Down Expand Up @@ -459,11 +464,13 @@ ProcessMessage ExternalNotificationModule::handleReceived(const meshtastic_MeshP
} else {
// Buzz if buzzer mode is not in DIRECT_MSG_ONLY or is DM to us
if (moduleConfig.external_notification.use_i2s_as_buzzer) {
#ifdef HAS_I2S
#if defined(HAS_I2S) && !MESHTASTIC_EXCLUDE_RTTTL
audioThread->beginRttl(rtttlConfig.ringtone, strlen_P(rtttlConfig.ringtone));
#endif
} else if (moduleConfig.external_notification.use_pwm) {
#if !MESHTASTIC_EXCLUDE_RTTTL
rtttl::begin(config.device.buzzer_gpio, rtttlConfig.ringtone);
#endif
} else {
setExternalState(2, true);
}
Expand Down Expand Up @@ -495,6 +502,7 @@ AdminMessageHandleResult ExternalNotificationModule::handleAdminMessageForModule
AdminMessageHandleResult result;

switch (request->which_payload_variant) {
#if !MESHTASTIC_EXCLUDE_RTTTL
case meshtastic_AdminMessage_get_ringtone_request_tag:
LOG_INFO("Client getting ringtone");
this->handleGetRingtone(mp, response);
Expand All @@ -506,6 +514,7 @@ AdminMessageHandleResult ExternalNotificationModule::handleAdminMessageForModule
this->handleSetRingtone(request->set_canned_message_module_messages);
result = AdminMessageHandleResult::HANDLED;
break;
#endif

default:
result = AdminMessageHandleResult::NOT_HANDLED;
Expand All @@ -514,6 +523,7 @@ AdminMessageHandleResult ExternalNotificationModule::handleAdminMessageForModule
return result;
}

#if !MESHTASTIC_EXCLUDE_RTTTL
void ExternalNotificationModule::handleGetRingtone(const meshtastic_MeshPacket &req, meshtastic_AdminMessage *response)
{
LOG_INFO("*** handleGetRingtone");
Expand All @@ -537,7 +547,9 @@ void ExternalNotificationModule::handleSetRingtone(const char *from_msg)
nodeDB->saveProto(rtttlConfigFile, meshtastic_RTTTLConfig_size, &meshtastic_RTTTLConfig_msg, &rtttlConfig);
}
}
#endif

#if !MESHTASTIC_EXCLUDE_INPUTBROKER
int ExternalNotificationModule::handleInputEvent(const InputEvent *event)
{
if (nagCycleCutoff != UINT32_MAX) {
Expand All @@ -546,3 +558,4 @@ int ExternalNotificationModule::handleInputEvent(const InputEvent *event)
}
return 0;
}
#endif
10 changes: 8 additions & 2 deletions src/modules/ExternalNotificationModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ extern AmbientLightingThread *ambientLightingThread;
#endif
#endif

#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) && !defined(CONFIG_IDF_TARGET_ESP32C6)
#if !MESHTASTIC_EXCLUDE_RTTTL
#include <NonBlockingRtttl.h>
#else
// Noop class for portduino.
// Noop class for portduino/STM32WL/ESP32C6 - none can drive PWM RTTTL playback.
class rtttl
{
public:
Expand All @@ -47,8 +47,10 @@ class rtttl
*/
class ExternalNotificationModule : public SinglePortModule, private concurrency::OSThread
{
#if !MESHTASTIC_EXCLUDE_INPUTBROKER
CallbackObserver<ExternalNotificationModule, const InputEvent *> inputObserver =
CallbackObserver<ExternalNotificationModule, const InputEvent *>(this, &ExternalNotificationModule::handleInputEvent);
#endif
uint32_t output = 0;

#ifdef NEOPIXEL_STATUS_NOTIFICATION_PIN
Expand All @@ -58,7 +60,9 @@ class ExternalNotificationModule : public SinglePortModule, private concurrency:
public:
ExternalNotificationModule();

#if !MESHTASTIC_EXCLUDE_INPUTBROKER
int handleInputEvent(const InputEvent *arg);
#endif

uint32_t nagCycleCutoff = 1;

Expand All @@ -73,8 +77,10 @@ class ExternalNotificationModule : public SinglePortModule, private concurrency:

void stopNow();

#if !MESHTASTIC_EXCLUDE_RTTTL
void handleGetRingtone(const meshtastic_MeshPacket &req, meshtastic_AdminMessage *response);
void handleSetRingtone(const char *from_msg);
#endif

protected:
/** Called to handle a particular incoming message
Expand Down
2 changes: 2 additions & 0 deletions variants/esp32c6/esp32c6.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ build_flags =
; Exclude Paxcounter, it uses 'esp_vhci_host_send_packet' whch is not available on ESP32-C6
; https://github.com/espressif/arduino-esp32/issues/11716
-DMESHTASTIC_EXCLUDE_PAXCOUNTER
; No PWM/RTTTL ringtone playback support on this platform.
-DMESHTASTIC_EXCLUDE_RTTTL

build_src_filter =
${esp32_common.build_src_filter}
Expand Down
1 change: 1 addition & 0 deletions variants/native/portduino.ini
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ build_flags_common =
-fPIC
-Isrc/platform/portduino
-DRADIOLIB_EEPROM_UNSUPPORTED
-DMESHTASTIC_EXCLUDE_RTTTL ; No PWM/RTTTL ringtone playback support on this platform.
-lpthread
-lyaml-cpp
-ljsoncpp
Expand Down
17 changes: 9 additions & 8 deletions variants/stm32/stm32.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@ build_flags =
${arduino_base.build_flags}
-flto
-Isrc/platform/stm32wl -g
-DMESHTASTIC_EXCLUDE_AUDIO=1
-DMESHTASTIC_EXCLUDE_ATAK=1 ; ATAK is quite big, disable it for big flash savings.
-DMESHTASTIC_EXCLUDE_AUDIO=1
-DMESHTASTIC_EXCLUDE_BLUETOOTH=1
-DMESHTASTIC_EXCLUDE_INPUTBROKER=1
-DMESHTASTIC_EXCLUDE_POWERMON=1
-DMESHTASTIC_EXCLUDE_SCREEN=1
-DMESHTASTIC_EXCLUDE_MQTT=1
-DMESHTASTIC_EXCLUDE_BLUETOOTH=1
-DMESHTASTIC_EXCLUDE_WIFI=1
-DMESHTASTIC_EXCLUDE_TZ=1 ; Exclude TZ to save some flash space.
-DMESHTASTIC_EXCLUDE_XEDDSA=1 ; The Ed25519 signing code does not fit in the 256KB flash. Packets are sent unsigned, like pre-XEdDSA firmware.
-DMESHTASTIC_EXCLUDE_PKT_HISTORY_HASH=1
-DMESHTASTIC_EXCLUDE_POWERMON=1
-DMESHTASTIC_EXCLUDE_POWER_TELEMETRY=1
-DMESHTASTIC_EXCLUDE_RANGETEST=1
-DMESHTASTIC_EXCLUDE_RTTTL=1 ; No PWM/RTTTL ringtone playback support on this platform.
-DMESHTASTIC_EXCLUDE_SCREEN=1
-DMESHTASTIC_EXCLUDE_TZ=1 ; Exclude TZ to save some flash space.
-DMESHTASTIC_EXCLUDE_WAYPOINT=1
-DMESHTASTIC_EXCLUDE_POWER_TELEMETRY=1
-DMESHTASTIC_EXCLUDE_WIFI=1
-DMESHTASTIC_EXCLUDE_XEDDSA=1 ; The Ed25519 signing code does not fit in the 256KB flash. Packets are sent unsigned, like pre-XEdDSA firmware.
-DSERIAL_RX_BUFFER_SIZE=256 ; For GPS - the default of 64 is too small.
-DHAS_SCREEN=0 ; Always disable screen for STM32, it is not supported.
;-DPIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF ; Enable this if enabling debugg logging. It is REQUIRED for at least traceroute debug prints - without it the length returned by printf ends up uninitialized.
Expand Down
Loading