diff --git a/docs/source/Plugin/P000_Buzzer_RTTTL.rst b/docs/source/Plugin/P000_Buzzer_RTTTL.rst index 11c0d77dad..e3c7dd127f 100644 --- a/docs/source/Plugin/P000_Buzzer_RTTTL.rst +++ b/docs/source/Plugin/P000_Buzzer_RTTTL.rst @@ -57,7 +57,7 @@ From ESP Easy v2.0.0 its possible to play melodies via `RTTTL /control?cmd=rtttl,14:d=4,o=5,b=112:8a,8a,a,8a,8a,a,8a,8c6,8f.,16g,2a,8a-,8a-,8a-.,16a-,8a-,8a,8a.,16a,8a,8g,8g,8a,g,c6 + http:///control?cmd=rtttl,14,:d=4,o=5,b=112:8a,8a,a,8a,8a,a,8a,8c6,8f.,16g,2a,8a-,8a-,8a-.,16a-,8a-,8a,8a.,16a,8a,8g,8g,8a,g,c6 This plays a melody on pin 14. @@ -68,7 +68,7 @@ To make a boot-sound on startup, create a rule like this: .. code-block:: none On System#Boot do - rtttl,14:d=10,o=6,b=180,c,e,g + rtttl,14,:d=10,o=6,b=180,c,e,g endon `A place to find more tunes `_, all saved as txt files. diff --git a/docs/source/Plugin/P000_Piezo_element_RTTTL.rst b/docs/source/Plugin/P000_Piezo_element_RTTTL.rst index cd28215a05..59d2f49692 100644 --- a/docs/source/Plugin/P000_Piezo_element_RTTTL.rst +++ b/docs/source/Plugin/P000_Piezo_element_RTTTL.rst @@ -54,7 +54,7 @@ From ESP Easy v2.0.0 its possible to play melodies via `RTTTL /control?cmd=rtttl,14:d=4,o=5,b=112:8a,8a,a,8a,8a,a,8a,8c6,8f.,16g,2a,8a-,8a-,8a-.,16a-,8a-,8a,8a.,16a,8a,8g,8g,8a,g,c6 + http:///control?cmd=rtttl,14,:d=4,o=5,b=112:8a,8a,a,8a,8a,a,8a,8c6,8f.,16g,2a,8a-,8a-,8a-.,16a-,8a-,8a,8a.,16a,8a,8g,8g,8a,g,c6 This plays a melody on pin 14. @@ -65,7 +65,7 @@ To make a boot-sound on startup, create a rule like this: .. code-block:: none On System#Boot do - rtttl,14:d=10,o=6,b=180,c,e,g + rtttl,14,:d=10,o=6,b=180,c,e,g endon `A place to find more tunes `_, all saved as txt files. diff --git a/docs/source/Plugin/P000_Speaker_RTTTL.rst b/docs/source/Plugin/P000_Speaker_RTTTL.rst index 67c860fda1..ecaccd9005 100644 --- a/docs/source/Plugin/P000_Speaker_RTTTL.rst +++ b/docs/source/Plugin/P000_Speaker_RTTTL.rst @@ -54,7 +54,7 @@ From ESP Easy v2.0.0 its possible to play melodies via `RTTTL /control?cmd=rtttl,14:d=4,o=5,b=112:8a,8a,a,8a,8a,a,8a,8c6,8f.,16g,2a,8a-,8a-,8a-.,16a-,8a-,8a,8a.,16a,8a,8g,8g,8a,g,c6 + http:///control?cmd=rtttl,14,:d=4,o=5,b=112:8a,8a,a,8a,8a,a,8a,8c6,8f.,16g,2a,8a-,8a-,8a-.,16a-,8a-,8a,8a.,16a,8a,8g,8g,8a,g,c6 This plays a melody on pin 14. @@ -65,7 +65,7 @@ To make a boot-sound on startup, create a rule like this: .. code-block:: none On System#Boot do - rtttl,14:d=10,o=6,b=180,c,e,g + rtttl,14,:d=10,o=6,b=180,c,e,g endon `A place to find more tunes `_, all saved as txt files. diff --git a/src/src/Commands/GPIO.cpp b/src/src/Commands/GPIO.cpp index 9ae29158a0..17c5319704 100644 --- a/src/src/Commands/GPIO.cpp +++ b/src/src/Commands/GPIO.cpp @@ -385,8 +385,16 @@ const __FlashStringHelper * Command_GPIO_RTTTL(struct EventStruct *event, const // play a tune via a RTTTL string, look at https://www.letscontrolit.com/forum/viewtopic.php?f=4&t=343&hilit=speaker&start=10 for // more info. + // First assume 'old' syntax: rtttl, + // No comma between the GPIO argument and the melody String melody = parseStringToEndKeepCase(Line, 2); + if (melody.indexOf(':') == -1) { + // Apparently this is now using the 'new' (correct) syntax: + // rtttl,, + melody = parseStringToEndKeepCase(Line, 3); + } melody.replace('-', '#'); + melody.replace('_', '#'); if (loglevelActiveFor(LOG_LEVEL_INFO)) { addLog(LOG_LEVEL_INFO, strformat(F("RTTTL: pin: %d melody: %s"), event->Par1, melody.c_str())); diff --git a/src/src/Helpers/Audio.cpp b/src/src/Helpers/Audio.cpp index d0b5ea793e..f9509b4995 100644 --- a/src/src/Helpers/Audio.cpp +++ b/src/src/Helpers/Audio.cpp @@ -35,12 +35,17 @@ static bool rtttlPlaying = false; # endif // if FEATURE_RTTTL_EVENTS # if FEATURE_ANYRTTTL_ASYNC static String rtttlMelody; + +void clear_rtttl_melody() { + // The non-blocking play will read from a char pointer. + // So we must stop the playing before changing the string as it could otherwise lead to a crash. + anyrtttl::nonblocking::stop(); + rtttlMelody = String(); +} + void set_rtttl_melody(String& melody) { - if (melody.isEmpty()) { - rtttlMelody = String(); - } else { - rtttlMelody = String(melody); - } + clear_rtttl_melody(); + rtttlMelody = melody; } # endif // if FEATURE_ANYRTTTL_ASYNC @@ -106,8 +111,7 @@ void update_rtttl() { rtttlPlaying = false; } # endif // if FEATURE_RTTTL_EVENTS - String dummy; - set_rtttl_melody(dummy); // Release memory + clear_rtttl_melody(); // Release memory } } diff --git a/src/src/Helpers/Audio.h b/src/src/Helpers/Audio.h index 58b8c199a7..bff26501a7 100644 --- a/src/src/Helpers/Audio.h +++ b/src/src/Helpers/Audio.h @@ -19,6 +19,7 @@ bool play_rtttl(int8_t _pin, const char *p); # if FEATURE_ANYRTTTL_LIB && FEATURE_ANYRTTTL_ASYNC void update_rtttl(); +void clear_rtttl_melody(); void set_rtttl_melody(String& melody); # endif // if FEATURE_ANYRTTTL_LIB && FEATURE_ANYRTTTL_ASYNC #endif // if FEATURE_RTTTL