Skip to content
Snippets Groups Projects
Commit 97bee4ff authored by Stefan Gehr's avatar Stefan Gehr
Browse files

using queue for error sound; setting LONG_TIME_ERROR time to 10 seconds for testing and showing

parent 4595e086
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define MP3_H #define MP3_H
void mp3Setup(void); void mp3Setup(void);
uint8_t queueLength(void);
void playFile(uint8_t fileNumber, bool respectBusyPin); void playFile(uint8_t fileNumber, bool respectBusyPin);
void mp3Loop(void); void mp3Loop(void);
void playFileQueue(uint8_t fileNumber); void playFileQueue(uint8_t fileNumber);
......
...@@ -7,6 +7,10 @@ static SoftwareSerial mp3(MP3RX, MP3TX); ...@@ -7,6 +7,10 @@ static SoftwareSerial mp3(MP3RX, MP3TX);
// the queue for playing sounds // the queue for playing sounds
#define QUEUESIZE 64 #define QUEUESIZE 64
static uint8_t fileQueue[QUEUESIZE]; 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 // needs to be run once at the start
void mp3Setup(void) { void mp3Setup(void) {
...@@ -15,6 +19,15 @@ void mp3Setup(void) { ...@@ -15,6 +19,15 @@ void mp3Setup(void) {
//mp3.sendCommand(CMD_SEL_DEV, 0, 2); //select sd-card //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 // immediately play a file
void playFile(uint8_t fileNumber, bool respectBusyPin) { void playFile(uint8_t fileNumber, bool respectBusyPin) {
// do nothing if we want to wait for the BUSY pin // do nothing if we want to wait for the BUSY pin
...@@ -34,8 +47,6 @@ void mp3Loop(void) { ...@@ -34,8 +47,6 @@ void mp3Loop(void) {
* now we can wait for the flank from LOW to HIGH => then the playing is done * now we can wait for the flank from LOW to HIGH => then the playing is done
*/ */
static bool waitForBusy = false; static bool waitForBusy = false;
// next playing position in the queue
static uint8_t currentPlayPos = 0;
// check if we are busy // check if we are busy
if (digitalRead(MP3BUSY) == LOW) { if (digitalRead(MP3BUSY) == LOW) {
...@@ -72,8 +83,6 @@ void mp3Loop(void) { ...@@ -72,8 +83,6 @@ void mp3Loop(void) {
// add a file to the queue and start playing the queue // add a file to the queue and start playing the queue
void playFileQueue(uint8_t fileNumber) { void playFileQueue(uint8_t fileNumber) {
// position of end of queue
static uint8_t currentQueueEnd = 0;
// save file to queue // save file to queue
fileQueue[currentQueueEnd] = fileNumber; fileQueue[currentQueueEnd] = fileNumber;
......
...@@ -246,7 +246,10 @@ void loop(void) { ...@@ -246,7 +246,10 @@ void loop(void) {
if (t1upState == LONG_TIME_ERROR || t1downState == LONG_TIME_ERROR || t2upState == LONG_TIME_ERROR || t2downState == LONG_TIME_ERROR) { if (t1upState == LONG_TIME_ERROR || t1downState == LONG_TIME_ERROR || t2upState == LONG_TIME_ERROR || t2downState == LONG_TIME_ERROR) {
// continuously say that there is an 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 // control pump of system 1
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
/* No new valid temperature for < 60 seconds? I sleep. /* No new valid temperature for < 60 seconds? I sleep.
* No new valid temperature for > 60 seconds? REAL PROBLEM! */ * 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 // Update the temperature only every second
const uint32_t TEMPUPDATETIME = 1000; const uint32_t TEMPUPDATETIME = 1000;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment