diff --git a/tasmota/tasmota_xdrv_driver/xdrv_42_0_i2s_audio.ino b/tasmota/tasmota_xdrv_driver/xdrv_42_0_i2s_audio.ino index e6031ce31..0b2d6301a 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_42_0_i2s_audio.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_42_0_i2s_audio.ino @@ -223,6 +223,10 @@ void sayTime(int hour, int minutes); void Cmd_MicRec(void); void Cmd_wav2mp3(void); void Cmd_Time(void); +#ifdef USE_I2S_RTTTL +void Rtttl(char *buffer); +void Cmd_I2SRtttl(void); +#endif void copy_micpars(uint32_t port) { audio_i2s.mic_mclk = audio_i2s.mclk; @@ -606,6 +610,9 @@ const char kI2SAudio_Commands[] PROGMEM = "I2S|" #ifdef USE_I2S_SAY_TIME "|Time" #endif // USE_I2S_SAY_TIME +#ifdef USE_I2S_RTTTL + "|Rtttl" +#endif #ifdef ESP32 "|Play" #ifdef USE_I2S_WEBRADIO @@ -629,6 +636,9 @@ void (* const I2SAudio_Command[])(void) PROGMEM = { #ifdef USE_I2S_SAY_TIME ,&Cmd_Time #endif // USE_I2S_SAY_TIME +#ifdef USE_I2S_RTTTL + ,&Cmd_I2SRtttl +#endif #ifdef ESP32 ,&Cmd_Play #ifdef USE_I2S_WEBRADIO @@ -671,6 +681,15 @@ void Cmd_Say(void) { ResponseCmndChar(XdrvMailbox.data); } +#ifdef USE_I2S_RTTTL +void Cmd_I2SRtttl(void) { + if (XdrvMailbox.data_len > 0) { + Rtttl(XdrvMailbox.data); + } + ResponseCmndChar(XdrvMailbox.data); +} +#endif + /*********************************************************************************************\ * Interface \*********************************************************************************************/ diff --git a/tasmota/tasmota_xdrv_driver/xdrv_42_6_i2s_rtttl.ino b/tasmota/tasmota_xdrv_driver/xdrv_42_6_i2s_rtttl.ino new file mode 100644 index 000000000..21ab060e5 --- /dev/null +++ b/tasmota/tasmota_xdrv_driver/xdrv_42_6_i2s_rtttl.ino @@ -0,0 +1,54 @@ + +/* + audio is2 RTTTL + + Copyright (C) 2023 Fernando Pena López + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#if (defined(USE_I2S_AUDIO) || defined(USE_TTGO_WATCH) || defined(USE_M5STACK_CORE2) || defined(ESP32S3_BOX)) +#ifdef USE_I2S_RTTTL +#include "AudioFileSourcePROGMEM.h" +#include "AudioGeneratorRTTTL.h" + +void Rtttl(char *buffer); + +void Rtttl(char *buffer) { + + if (!audio_i2s.out) return; + + AudioGeneratorRTTTL *rtttl; + AudioFileSourcePROGMEM *file = NULL; + + file = new AudioFileSourcePROGMEM(buffer, strlen(buffer)); + rtttl = new AudioGeneratorRTTTL(); + + AUDIO_PWR_ON + rtttl->begin(file, audio_i2s.out); + + while(rtttl->isRunning()) { + if (!rtttl->loop()) { + rtttl->stop(); + } else { + delay(1); // Keep the dog happy + } + } + + audio_i2s.out->stop(); + AUDIO_PWR_OFF + delete rtttl; + delete file; +} +#endif // USE_I2S_RTTTL +#endif // is2audio