feat: started game design

This commit is contained in:
2021-12-10 17:15:22 +01:00
parent 94017d771c
commit 7e73a3fbd4
18 changed files with 351 additions and 146 deletions

View File

@@ -10,6 +10,8 @@ uint8_t n = 0;
bool audio_start = false;
bool audioInitOk = false;
const char *waveFile[] =
{"/ringoffire.mp3",
"/Let_it_be.mp3",
@@ -19,24 +21,7 @@ const char *waveFile[] =
void MDCallback(void *cbData, const char *type, bool isUnicode, const char *string)
{
(void)cbData;
Serial.printf("ID3 callback for: %s = '", type);
if (isUnicode)
{
string += 2;
}
while (*string)
{
char a = *(string++);
if (isUnicode)
{
string++;
}
Serial.printf("%c", a);
}
Serial.printf("'\n");
Serial.flush();
log_i("ID3 callback for: %s = '", type);
}
// Called when there's a warning or error (like a buffer underflow or decode hiccup)
@@ -47,15 +32,14 @@ void StatusCallback(void *cbData, int code, const char *string)
char s1[64];
strncpy_P(s1, string, sizeof(s1));
s1[sizeof(s1) - 1] = 0;
Serial.printf("STATUS(%s) '%d' = '%s'\n", ptr, code, s1);
Serial.flush();
log_i("STATUS(%s) '%d' = '%s'\n", ptr, code, s1);
}
void playSong(uint8_t index)
{
if (index > AUDIONSONGS)
return;
Serial.printf("now playing %s\n", waveFile[index]);
log_i("now playing %s\n", waveFile[index]);
file = new AudioFileSourceLittleFS(waveFile[index]);
id3 = new AudioFileSourceID3(file);
id3->RegisterMetadataCB(MDCallback, (void *)"ID3TAG");
@@ -64,7 +48,7 @@ void playSong(uint8_t index)
void initAudio()
{
Serial.println("init Audio");
log_i("init Audio");
audioLogger = &Serial;
delay(500);
out = new AudioOutputI2S();
@@ -73,28 +57,34 @@ void initAudio()
mp3 = new AudioGeneratorMP3();
mp3->RegisterStatusCB(StatusCallback, (void *)"mp3");
Serial.println("init Audio Done");
audioInitOk = true;
log_i("init Audio Done");
//playSong(audio_current_Song);
}
bool getAudioInitStatus(void)
{
return audioInitOk;
}
void handleAudio()
{
// if (hallIsIdle())
// {
// if (mp3->isRunning())
// {
// Serial.println("Audio: stop playback");
// mp3->stop();
// audio_start = false;
// }
// }
// else
// {
// if(!audio_start)
// {
// playSong(audio_current_Song);
// audio_start = true;
// }
if (hallIsIdle())
{
if (mp3->isRunning())
{
log_w("Audio: stop playback");
mp3->stop();
audio_start = false;
}
}
else
{
if(!audio_start)
{
playSong(audio_current_Song);
audio_start = true;
}
if (mp3->isRunning())
{
@@ -104,5 +94,5 @@ void handleAudio()
playSong(audio_current_Song);
}
}
//}
}
}