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

mp3 stuff

parent f259e6c9
Branches
No related tags found
No related merge requests found
...@@ -3,5 +3,7 @@ ...@@ -3,5 +3,7 @@
void mp3Setup(void); void mp3Setup(void);
void playFile(uint8_t fileNumber); void playFile(uint8_t fileNumber);
void mp3Loop(void);
void playFileQueue(uint8_t fileNumber);
#endif #endif
...@@ -3,13 +3,75 @@ ...@@ -3,13 +3,75 @@
static SoftwareSerial mp3(MP3RX, MP3TX); static SoftwareSerial mp3(MP3RX, MP3TX);
static uint8_t fileQueue[16]; #define QUEUESIZE 16
static uint8_t fileQueue[QUEUESIZE];
static uint8_t currentPlayPos = 0; // fileQueue[currentPlayPos] is currently played
static uint8_t currentQueueEnd = 0; // fileQueue[currentQueue] is the next free place in the queue
void mp3Setup(void) { void mp3Setup(void) {
mp3.begin(4800); mp3.begin(4800);
pinMode(MP3BUSY, INPUT_PULLUP);
//mp3.sendCommand(CMD_SEL_DEV, 0, 2); //select sd-card //mp3.sendCommand(CMD_SEL_DEV, 0, 2); //select sd-card
} }
void playFile(uint8_t fileNumber) { void playFile(uint8_t fileNumber) {
mp3.write(fileNumber); mp3.write(fileNumber);
} }
// play next file in queue if device is not busy anymore
void mp3Loop(void) {
// only do things if we were just playing a file
// and we are not busy
if (fileQueue[currentPlayPos] == 0) {
Serial.print("No file was being played at pos ");
Serial.println(currentPlayPos);
return;
}
if (digitalRead(MP3BUSY) == LOW) {
Serial.println("mp3 still busy");
return;
}
Serial.print("Emptying at playpos ");
Serial.println(currentPlayPos);
fileQueue[currentPlayPos] = 0;
// advance one position further
++currentPlayPos;
// in case of wraparound
if (currentPlayPos == QUEUESIZE) {
currentPlayPos = 0;
}
Serial.print("new playpos ");
Serial.println(currentPlayPos);
// here is no file to play?
if (fileQueue[currentPlayPos] == 0) {
Serial.println("There is no file to play here");
return;
}
Serial.print("Playing file ");
Serial.print(fileQueue[currentPlayPos]);
Serial.print(" at playpos ");
Serial.println(currentPlayPos);
mp3.write(fileQueue[currentPlayPos]);
}
// add file to the queue and play start playing the queue
void playFileQueue(uint8_t fileNumber) {
Serial.print("Adding ");
Serial.print(fileNumber);
Serial.print(" to queue at pos ");
Serial.println(currentQueueEnd);
fileQueue[currentQueueEnd] = fileNumber;
// the end is now one pos further
++currentQueueEnd;
// in case of wraparound
if (currentQueueEnd == QUEUESIZE) {
currentQueueEnd = 0;
}
Serial.print("New queue end at pos ");
Serial.println(currentQueueEnd);
mp3Loop();
}
...@@ -8,6 +8,7 @@ const uint8_t T2DOWN = 5; ...@@ -8,6 +8,7 @@ const uint8_t T2DOWN = 5;
const uint8_t PUMP1 = 8; const uint8_t PUMP1 = 8;
const uint8_t PUMP2 = 9; const uint8_t PUMP2 = 9;
const uint8_t BUTTON = 10; const uint8_t BUTTON = 10;
const uint8_t MP3BUSY = 11;
const uint8_t MP3TX = 12; const uint8_t MP3TX = 12;
const uint8_t MP3RX = 13; const uint8_t MP3RX = 13;
#endif #endif
...@@ -125,7 +125,7 @@ void displayText(float t1up_C, float t1down_C, bool pump1, float t2up_C, float t ...@@ -125,7 +125,7 @@ void displayText(float t1up_C, float t1down_C, bool pump1, float t2up_C, float t
} }
void displayLight(bool turnOn) { void displayLight(bool turnOn) {
const uint32_t lightMillis = 10000; const uint32_t lightMillis = 30000;
static bool curState = false; static bool curState = false;
static uint32_t prevMillis = 0; static uint32_t prevMillis = 0;
// turn on // turn on
...@@ -159,11 +159,14 @@ void loop(void) { ...@@ -159,11 +159,14 @@ void loop(void) {
static float t2up_C = 0.0; static float t2up_C = 0.0;
static float t2down_C = 0.0; static float t2down_C = 0.0;
mp3Loop();
if (checkButton() == LOW) { if (checkButton() == LOW) {
displayLight(true); displayLight(true);
playFile(SOUND_TEMPERATURE); Serial.println("Adding temperature to queue");
delay(2000); playFileQueue(SOUND_TEMPERATURE);
playFile(SOUND_HOCHSTER_WERT); Serial.println("Adding höchstwert to queue");
playFileQueue(SOUND_HOCHSTER_WERT);
} else { } else {
displayLight(false); displayLight(false);
} }
...@@ -171,19 +174,15 @@ void loop(void) { ...@@ -171,19 +174,15 @@ void loop(void) {
if (t1up(&t1up_C) == LONG_TIME_ERROR || t1down(&t1down_C) == LONG_TIME_ERROR) { if (t1up(&t1up_C) == LONG_TIME_ERROR || t1down(&t1down_C) == LONG_TIME_ERROR) {
// TODO: Warning sound // TODO: Warning sound
// Turn pump on to be safe // Turn pump on to be safe
Serial.println("LONG TIME ERROR for solar system 1");
digitalWrite(PUMP1, HIGH); digitalWrite(PUMP1, HIGH);
} else { } else {
Serial.println("controlPump for solar system 1");
controlPump(PUMP1, t1up_C, t1down_C); controlPump(PUMP1, t1up_C, t1down_C);
} }
if (t2up(&t2up_C) == LONG_TIME_ERROR || t2down(&t2down_C) == LONG_TIME_ERROR) { if (t2up(&t2up_C) == LONG_TIME_ERROR || t2down(&t2down_C) == LONG_TIME_ERROR) {
// TODO: Warning sound // TODO: Warning sound
// Turn pump on to be safe // Turn pump on to be safe
Serial.println("LONG TIME ERROR for solar system 2");
digitalWrite(PUMP2, HIGH); digitalWrite(PUMP2, HIGH);
} else { } else {
Serial.println("controlPump for solar system 2");
controlPump(PUMP2, t2up_C, t2down_C); controlPump(PUMP2, t2up_C, t2down_C);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment