Added I2SRtttl command (#18423)

This commit is contained in:
ferix98 2023-04-16 12:04:22 +02:00 committed by GitHub
parent 3d0354b6fb
commit 2a8b859e37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 73 additions and 0 deletions

View File

@ -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
\*********************************************************************************************/

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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