diff --git a/src/DirectoryNode.cpp b/src/DirectoryNode.cpp
index c00d6e5..6af7cd6 100644
--- a/src/DirectoryNode.cpp
+++ b/src/DirectoryNode.cpp
@@ -102,7 +102,7 @@ void DirectoryNode::buildDirectoryTree(const char *currentPath)
subdirectories.push_back(newNode);
newNode->buildDirectoryTree((String(currentPath) + entry.name()).c_str());
}
- else if (String(entry.name()).endsWith(".mp3"))
+ else if (String(entry.name()).endsWith(".mp3")||String(entry.name()).endsWith(".MP3"))
{
mp3Files.push_back(entry.name());
ids.push_back(getNextId());
diff --git a/src/WebContent.h b/src/WebContent.h
index bbf8908..e96a378 100644
--- a/src/WebContent.h
+++ b/src/WebContent.h
@@ -12,6 +12,7 @@ const char index_html[] PROGMEM = R"rawliteral(
+
@@ -128,6 +129,7 @@ const char index_html[] PROGMEM = R"rawliteral(
document.getElementById("state").innerHTML = state['title'];
document.getElementById("progressLabel").innerHTML = state['time'];
document.getElementById("voltage").innerHTML = state['voltage']+' mV';
+ document.getElementById("heap").innerHTML = state['heap']+' bytes free heap';
document.getElementById("uid").innerHTML = 'Last NFC ID: '+state['uid'];
var elements = document.getElementsByClassName('play-button');
var btn = elements[0];
diff --git a/src/globals.h b/src/globals.h
index febda89..91c78ea 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -69,8 +69,6 @@ uint32_t lastVoltage = 0;
uint loopCounter = 0;
-const int startDelay = 250;
-
String lastUid = "";
uint16_t currentSongId = 0;
diff --git a/src/main.cpp b/src/main.cpp
index 3e360e2..15c9fed 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -37,7 +37,13 @@
#define VOLTAGE_LOOP_INTERVAL 5000
-#define VOLTAGE_THRESHOLD 3800
+#define VOLTAGE_THRESHOLD 0
+
+#define SHORT_PRESS_TIME 250
+
+#define LONG_PRESS_TIME 1000
+
+#define MAX_VOL 15
#include "globals.h"
#include "WebContent.h"
@@ -86,6 +92,8 @@ bool asyncPrev = false;
uint16_t voltage_threshold_counter = 0;
+size_t free_heap = 0;
+
/*
std::map rfid_map{{"67 152 204 14", "01-The_Box_Tops-The_Letter.mp3"},
{"67 175 148 160", "068-Der_Schatz_im_Bergsee"}};
@@ -297,6 +305,7 @@ String getState()
jsonState["length"] = audio.getAudioFileDuration();
jsonState["voltage"] = lastVoltage;
jsonState["uid"] = lastUid;
+ jsonState["heap"] = free_heap;
String output;
serializeJson(jsonState, output);
jsonState.clear();
@@ -519,6 +528,8 @@ void setup()
lastVoltage = getBatteryVoltageMv();
+ free_heap = xPortGetFreeHeapSize();
+
// first parameter is name of access point, second is the password
AsyncWiFiManager wifiManager(&server, &dns);
@@ -652,6 +663,11 @@ void volume_action(AsyncWebServerRequest *request)
request->send_P(200, "text/plain", "ok");
}
+String getStartupSoundDir() {
+ static String tempPath = "/"+sys_dir+"/"+startup_sound;
+ return tempPath;
+}
+
void loop()
{
if (audio.isRunning())
@@ -681,8 +697,7 @@ void loop()
playSongById(currentSongId,currentSongSeconds);
} else if (!startupSoundPlayed) {
startupSoundPlayed = true;
- String tempPath = "/"+sys_dir+"/"+startup_sound;
- playSongByPath(tempPath.c_str());
+ playSongByPath(getStartupSoundDir().c_str());
}
@@ -719,13 +734,33 @@ void loop()
else if (asyncNext)
{
asyncNext = false;
- next();
+ if (audio.isRunning()) {
+ next();
+ } else {
+ uint8_t vol = audio.getVolume();
+ if (vol!=MAX_VOL) {
+ vol++;
+ }
+ audio.setVolume(vol);
+ playSongByPath(getStartupSoundDir().c_str());
+
+ }
+
}
else if (asyncPrev)
{
asyncPrev = false;
- Serial.println("Previous");
- previous();
+ if (audio.isRunning()) {
+ previous();
+ } else {
+ uint8_t vol = audio.getVolume();
+ if (vol!=0) {
+ vol--;
+ }
+ audio.setVolume(vol);
+ playSongByPath(getStartupSoundDir().c_str());
+ }
+
}
@@ -744,6 +779,7 @@ void loop()
if (loopCounter % VOLTAGE_LOOP_INTERVAL == 0)
{
lastVoltage = getBatteryVoltageMv();
+ free_heap = xPortGetFreeHeapSize();
if (lastVoltage3) {
Serial.println("entering deep sleep due to low voltage...");
@@ -766,10 +802,7 @@ void loop2(void *parameter)
Serial.println("loop2 started");
for (;;)
{
- if (buttonPressed(BTN_START_STOP))
- {
- asyncTogglePlayPause = true;
- }
+
if (buttonPressed(BTN_NEXT))
{
asyncNext = true;
@@ -778,6 +811,10 @@ void loop2(void *parameter)
{
asyncPrev = true;
}
+ if (buttonPressed(BTN_START_STOP))
+ {
+ asyncTogglePlayPause = true;
+ }
}
}
@@ -788,7 +825,7 @@ boolean buttonPressed(const uint8_t pin)
{
unsigned long now = millis();
- if (now - lastStart > startDelay)
+ if (now - lastStart > SHORT_PRESS_TIME)
{
lastStart = now;
Serial.println("button pressed.");
@@ -802,3 +839,4 @@ boolean buttonPressed(const uint8_t pin)
return false;
}
+