SD Card handling
This commit is contained in:
parent
2326cd7eab
commit
dfea791a2f
10
README.md
10
README.md
|
|
@ -2,6 +2,16 @@
|
||||||
|
|
||||||
The HannaBox is a Wifi enabled music player for toddlers and small children. It features an sd card reader, three buttons, a speaker up to 3 watts and an RFID reader. It is powered by a ESP32 microcontroller module.
|
The HannaBox is a Wifi enabled music player for toddlers and small children. It features an sd card reader, three buttons, a speaker up to 3 watts and an RFID reader. It is powered by a ESP32 microcontroller module.
|
||||||
|
|
||||||
|
## Preparation
|
||||||
|
|
||||||
|
The library https://github.com/schreibfaul1/ESP32-audioI2S is not available for Platformio in a working version. It is linked into the `lib` folder as a git submodule.
|
||||||
|
|
||||||
|
Init and pull the submodule before continuing:
|
||||||
|
|
||||||
|
```
|
||||||
|
git submodule update --init
|
||||||
|
```
|
||||||
|
|
||||||
## Microcontroller
|
## Microcontroller
|
||||||
|
|
||||||
We are using an ESP-WROOM-32 module. For the mp3 decoding we need a multicore CPU, be careful, there are some ESP32 with only one core.
|
We are using an ESP-WROOM-32 module. For the mp3 decoding we need a multicore CPU, be careful, there are some ESP32 with only one core.
|
||||||
|
|
|
||||||
37
src/main.cpp
37
src/main.cpp
|
|
@ -90,6 +90,10 @@ bool asyncNext = false;
|
||||||
|
|
||||||
bool asyncPrev = false;
|
bool asyncPrev = false;
|
||||||
|
|
||||||
|
bool SDActive = false;
|
||||||
|
|
||||||
|
bool RFIDActive = false;
|
||||||
|
|
||||||
uint16_t voltage_threshold_counter = 0;
|
uint16_t voltage_threshold_counter = 0;
|
||||||
|
|
||||||
size_t free_heap = 0;
|
size_t free_heap = 0;
|
||||||
|
|
@ -102,22 +106,35 @@ std::map<String, String> rfid_map{{"67 152 204 14", "01-The_Box_Tops-The_Letter.
|
||||||
|
|
||||||
void activateSD()
|
void activateSD()
|
||||||
{
|
{
|
||||||
|
if (SDActive)
|
||||||
|
return;
|
||||||
digitalWrite(CS_SDCARD, LOW);
|
digitalWrite(CS_SDCARD, LOW);
|
||||||
|
if (!SD.begin(CS_SDCARD))
|
||||||
|
{
|
||||||
|
Serial.println("SD initialization failed!");
|
||||||
|
while (1)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
SDActive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void deactivateSD()
|
void deactivateSD()
|
||||||
{
|
{
|
||||||
|
//SD.end();
|
||||||
digitalWrite(CS_SDCARD, HIGH);
|
digitalWrite(CS_SDCARD, HIGH);
|
||||||
|
SDActive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void activateRFID()
|
void activateRFID()
|
||||||
{
|
{
|
||||||
digitalWrite(CS_RFID, LOW);
|
digitalWrite(CS_RFID, LOW);
|
||||||
|
RFIDActive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void deactivateRFID()
|
void deactivateRFID()
|
||||||
{
|
{
|
||||||
digitalWrite(CS_RFID, HIGH);
|
digitalWrite(CS_RFID, HIGH);
|
||||||
|
RFIDActive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make size of files human readable
|
// Make size of files human readable
|
||||||
|
|
@ -508,25 +525,24 @@ void setup()
|
||||||
pinMode(CS_SDCARD, OUTPUT);
|
pinMode(CS_SDCARD, OUTPUT);
|
||||||
|
|
||||||
deactivateRFID();
|
deactivateRFID();
|
||||||
|
|
||||||
|
|
||||||
|
Serial.print("Initializing SD card...");
|
||||||
activateSD();
|
activateSD();
|
||||||
|
Serial.println("SD initialization done.");
|
||||||
|
|
||||||
|
|
||||||
//deep sleep wakeup
|
//deep sleep wakeup
|
||||||
esp_sleep_enable_ext0_wakeup((gpio_num_t)BTN_START_STOP, LOW);
|
esp_sleep_enable_ext0_wakeup((gpio_num_t)BTN_START_STOP, LOW);
|
||||||
|
|
||||||
Serial.print("Initializing SD card...");
|
|
||||||
|
|
||||||
if (!SD.begin(CS_SDCARD))
|
|
||||||
{
|
|
||||||
Serial.println("SD initialization failed!");
|
|
||||||
while (1)
|
|
||||||
;
|
|
||||||
}
|
|
||||||
Serial.println("SD initialization done.");
|
|
||||||
|
|
||||||
rootNode.buildDirectoryTree("/");
|
rootNode.buildDirectoryTree("/");
|
||||||
rootNode.printDirectoryTree();
|
rootNode.printDirectoryTree();
|
||||||
|
|
||||||
readDataFromFile(mapping_file.c_str());
|
readDataFromFile(mapping_file.c_str());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String progressPath = "/"+sys_dir+"/"+progress_file;
|
String progressPath = "/"+sys_dir+"/"+progress_file;
|
||||||
|
|
||||||
|
|
@ -710,6 +726,9 @@ String getStartupSoundDir() {
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
|
deactivateRFID();
|
||||||
|
activateSD();
|
||||||
|
|
||||||
if (audio.isRunning())
|
if (audio.isRunning())
|
||||||
{
|
{
|
||||||
if (asyncStop)
|
if (asyncStop)
|
||||||
|
|
@ -717,8 +736,6 @@ void loop()
|
||||||
asyncStop = false;
|
asyncStop = false;
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
deactivateRFID();
|
|
||||||
activateSD();
|
|
||||||
audio.loop();
|
audio.loop();
|
||||||
if (currentNode != nullptr && !prepareSleepMode)
|
if (currentNode != nullptr && !prepareSleepMode)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue