diff --git a/solarpump/mp3.h b/solarpump/mp3.h index 038879b28bcc578f711f45f302d425186d62df47..2c33eb58162c5640c36b05e471ce6763b97b41a1 100644 --- a/solarpump/mp3.h +++ b/solarpump/mp3.h @@ -2,6 +2,7 @@ #define MP3_H void mp3Setup(void); +uint8_t queueLength(void); void playFile(uint8_t fileNumber, bool respectBusyPin); void mp3Loop(void); void playFileQueue(uint8_t fileNumber); diff --git a/solarpump/mp3.ino b/solarpump/mp3.ino index 7b0c7040c62277ff166bfd85d47a45f1e9d91d6b..39e38b9b7e71311c8829b17f89692520ad110712 100644 --- a/solarpump/mp3.ino +++ b/solarpump/mp3.ino @@ -7,6 +7,10 @@ static SoftwareSerial mp3(MP3RX, MP3TX); // the queue for playing sounds #define QUEUESIZE 64 static uint8_t fileQueue[QUEUESIZE]; +// next playing position in the queue +static uint8_t currentPlayPos = 0; +// position of end of queue +static uint8_t currentQueueEnd = 0; // needs to be run once at the start void mp3Setup(void) { @@ -15,6 +19,15 @@ void mp3Setup(void) { //mp3.sendCommand(CMD_SEL_DEV, 0, 2); //select sd-card } +// return the number of files waiting in the queue +uint8_t queueLength(void) { + // in case of wrapround in the queue + if (currentQueueEnd < currentPlayPos) { + return currentQueueEnd + QUEUESIZE - currentPlayPos; + } + return currentPlayPos - currentQueueEnd; +} + // immediately play a file void playFile(uint8_t fileNumber, bool respectBusyPin) { // do nothing if we want to wait for the BUSY pin @@ -34,8 +47,6 @@ void mp3Loop(void) { * now we can wait for the flank from LOW to HIGH => then the playing is done */ static bool waitForBusy = false; - // next playing position in the queue - static uint8_t currentPlayPos = 0; // check if we are busy if (digitalRead(MP3BUSY) == LOW) { @@ -72,8 +83,6 @@ void mp3Loop(void) { // add a file to the queue and start playing the queue void playFileQueue(uint8_t fileNumber) { - // position of end of queue - static uint8_t currentQueueEnd = 0; // save file to queue fileQueue[currentQueueEnd] = fileNumber; diff --git a/solarpump/solarpump.ino b/solarpump/solarpump.ino index e10331c2b0810b3580272e998d45729c808f29ef..67cc7e9f346c2b8a2269c4c8942fb4524837507f 100644 --- a/solarpump/solarpump.ino +++ b/solarpump/solarpump.ino @@ -246,7 +246,10 @@ void loop(void) { if (t1upState == LONG_TIME_ERROR || t1downState == LONG_TIME_ERROR || t2upState == LONG_TIME_ERROR || t2downState == LONG_TIME_ERROR) { // continuously say that there is an error - playFile(SOUND_FEHLER, true); + if (queueLength() == 0) { + playFileQueue(SOUND_FEHLER); + playFileQueue(SOUND_STILLE); + } } // control pump of system 1 diff --git a/solarpump/temperature.ino b/solarpump/temperature.ino index 7b749e6df1197106ba4c2ca6b58383900396c338..a4e9243ddb85ef7dac9fc2f5e915073082545960 100644 --- a/solarpump/temperature.ino +++ b/solarpump/temperature.ino @@ -5,7 +5,7 @@ /* No new valid temperature for < 60 seconds? I sleep. * No new valid temperature for > 60 seconds? REAL PROBLEM! */ -const uint32_t ERRORTIME = 60000; +const uint32_t ERRORTIME = 10000; // Update the temperature only every second const uint32_t TEMPUPDATETIME = 1000;