diff --git a/README.md b/README.md index 5302fc1..6031859 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,15 @@ Wake up / Next -> 04 and GND Previous -> 16 and GND ``` +## System sounds + +Place these sounds in the folder `system` on the SD card: + +* sleep.mp3 +* start.mp3 + +sleep.mp3 will be played just before the timed shutdown, start.mp3 will be played if the box started and initialized successfully. + ## TODOs * Card Reader with SPI. Configure hspi, second SPI channel? Or does SD Card + RFID run at the same channel? diff --git a/sounds/sleep.mp3 b/sounds/sleep.mp3 new file mode 100644 index 0000000..7e3183a Binary files /dev/null and b/sounds/sleep.mp3 differ diff --git a/sounds/start.mp3 b/sounds/start.mp3 new file mode 100644 index 0000000..263b637 Binary files /dev/null and b/sounds/start.mp3 differ diff --git a/src/DirectoryNode.cpp b/src/DirectoryNode.cpp index 050d24b..5bbdb6e 100644 --- a/src/DirectoryNode.cpp +++ b/src/DirectoryNode.cpp @@ -64,7 +64,8 @@ void DirectoryNode::buildDirectoryTree(const char *currentPath) { break; } - if (entry.isDirectory()) + + if (entry.isDirectory() && strcmp(entry.name(),sys_dir.c_str())) { DirectoryNode *newNode = new DirectoryNode(entry.name()); subdirectories.push_back(newNode); diff --git a/src/DirectoryNode.h b/src/DirectoryNode.h index 0716c4e..0859ef9 100644 --- a/src/DirectoryNode.h +++ b/src/DirectoryNode.h @@ -4,6 +4,8 @@ #include #include +const String sys_dir = "system"; + class DirectoryNode { private: String name; diff --git a/src/globals.h b/src/globals.h index f7ae102..e2e056c 100644 --- a/src/globals.h +++ b/src/globals.h @@ -56,10 +56,29 @@ unsigned long lastStart = 0; unsigned long lastInteraction = 0; +boolean sleepSoundPlayed = false; + +boolean startupSoundPlayed = false; + +boolean continuousMode = false; + uint8_t buttontoignore = 0; const int startDelay = 250; +const String sleep_sound = "sleep.mp3"; + +const String startup_sound = "start.mp3"; + +/* +const long sleepMessageDelay = 28000; + +// wait until deep sleep: +const long sleepDelay = 30000; +*/ + +const long sleepMessageDelay = 1798000; + // wait until deep sleep: const long sleepDelay = 1800000; diff --git a/src/main.cpp b/src/main.cpp index e4b7ccf..e25f859 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,6 +38,12 @@ #include "css.h" #include "DirectoryNode.h" +#define SOUND_STARTUP "start.mp3" +#define SOUND_SLEEP "sleep.mp3" + + + + File root; File mp3File; @@ -104,6 +110,11 @@ void playSongByName(String song) deactivateSD(); } +void playSongByPath(String path) +{ + playFile(path.c_str()); +} + void playSongByRFID(String id) { String song = rfid_map[id]; @@ -128,6 +139,7 @@ bool playFile(const char *filename, uint32_t resumeFilePos) void playNextMp3() { stop(); + continuousMode = true; if (currentNode == NULL) { currentNode = rootNode.findFirstDirectoryWithMP3s(); @@ -248,7 +260,8 @@ void next() void audio_eof_mp3(const char *info) { Serial.println("audio file ended."); - playNextMp3(); + if (continuousMode) + playNextMp3(); } /* not working, FIXME remove me! */ @@ -472,8 +485,24 @@ void loop() start(); } + if (!startupSoundPlayed) { + startupSoundPlayed = true; + String tempPath = "/"+sys_dir+"/"+startup_sound; + playSongByPath(tempPath.c_str()); + } + + + // send device to sleep: long now = millis(); + + if (!sleepSoundPlayed && now - lastInteraction > sleepMessageDelay) { + sleepSoundPlayed = true; + String tempPath = "/"+sys_dir+"/"+sleep_sound; + playSongByPath(tempPath.c_str()); + } + + if (now - lastInteraction > sleepDelay) { Serial.println("entering deep sleep..."); deactivateRFID();