mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-22 02:32:23 +00:00
Better implementation of ExternalNotificationModule::stopNow (#8492)
* Better implementation of ExternalNotificationModule::stopNow * Label external states turning off * Optimize original code to actually fix issues
This commit is contained in:
@@ -94,22 +94,10 @@ int32_t ExternalNotificationModule::runOnce()
|
|||||||
// audioThread->isPlaying() also handles actually playing the RTTTL, needs to be called in loop
|
// audioThread->isPlaying() also handles actually playing the RTTTL, needs to be called in loop
|
||||||
isRtttlPlaying = isRtttlPlaying || audioThread->isPlaying();
|
isRtttlPlaying = isRtttlPlaying || audioThread->isPlaying();
|
||||||
#endif
|
#endif
|
||||||
if ((nagCycleCutoff <= millis())) {
|
if ((nagCycleCutoff < millis()) && !isRtttlPlaying) {
|
||||||
// Turn off external notification immediately when timeout is reached, regardless of song state
|
// Turn off external notification immediately when timeout is reached, regardless of song state
|
||||||
nagCycleCutoff = UINT32_MAX;
|
nagCycleCutoff = UINT32_MAX;
|
||||||
LOG_INFO("Turning off external notification: ");
|
ExternalNotificationModule::stopNow();
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
setExternalState(i, false);
|
|
||||||
externalTurnedOn[i] = 0;
|
|
||||||
LOG_INFO("%d ", i);
|
|
||||||
}
|
|
||||||
#ifdef HAS_I2S
|
|
||||||
// GPIO0 is used as mclk for I2S audio and set to OUTPUT by the sound library
|
|
||||||
// T-Deck uses GPIO0 as trackball button, so restore the mode
|
|
||||||
#if defined(T_DECK) || (defined(BUTTON_PIN) && BUTTON_PIN == 0)
|
|
||||||
pinMode(0, INPUT);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
isNagging = false;
|
isNagging = false;
|
||||||
return INT32_MAX; // save cycles till we're needed again
|
return INT32_MAX; // save cycles till we're needed again
|
||||||
}
|
}
|
||||||
@@ -317,22 +305,33 @@ bool ExternalNotificationModule::nagging()
|
|||||||
|
|
||||||
void ExternalNotificationModule::stopNow()
|
void ExternalNotificationModule::stopNow()
|
||||||
{
|
{
|
||||||
|
LOG_INFO("Turning off external notification: ");
|
||||||
|
LOG_INFO("Stop RTTTL playback");
|
||||||
rtttl::stop();
|
rtttl::stop();
|
||||||
#ifdef HAS_I2S
|
#ifdef HAS_I2S
|
||||||
|
LOG_INFO("Stop audioThread playback");
|
||||||
if (audioThread->isPlaying())
|
if (audioThread->isPlaying())
|
||||||
audioThread->stop();
|
audioThread->stop();
|
||||||
#endif
|
#endif
|
||||||
nagCycleCutoff = 1; // small value
|
|
||||||
isNagging = false;
|
|
||||||
// Turn off all outputs
|
// Turn off all outputs
|
||||||
|
LOG_INFO("Turning off setExternalStates: ");
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
setExternalState(i, false);
|
setExternalState(i, false);
|
||||||
externalTurnedOn[i] = 0;
|
externalTurnedOn[i] = 0;
|
||||||
|
LOG_INFO("%d ", i);
|
||||||
}
|
}
|
||||||
setIntervalFromNow(0);
|
setIntervalFromNow(0);
|
||||||
#ifdef T_WATCH_S3
|
#ifdef T_WATCH_S3
|
||||||
drv.stop();
|
drv.stop();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAS_I2S
|
||||||
|
// GPIO0 is used as mclk for I2S audio and set to OUTPUT by the sound library
|
||||||
|
// T-Deck uses GPIO0 as trackball button, so restore the mode
|
||||||
|
#if defined(T_DECK) || (defined(BUTTON_PIN) && BUTTON_PIN == 0)
|
||||||
|
pinMode(0, INPUT);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
ExternalNotificationModule::ExternalNotificationModule()
|
ExternalNotificationModule::ExternalNotificationModule()
|
||||||
|
|||||||
Reference in New Issue
Block a user