This commit is contained in:
Stefan Ostermann 2024-02-08 22:12:06 +01:00
parent efd570fb50
commit 2ea4874455
4 changed files with 52 additions and 14 deletions

View File

@ -102,7 +102,7 @@ void DirectoryNode::buildDirectoryTree(const char *currentPath)
subdirectories.push_back(newNode); subdirectories.push_back(newNode);
newNode->buildDirectoryTree((String(currentPath) + entry.name()).c_str()); 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()); mp3Files.push_back(entry.name());
ids.push_back(getNextId()); ids.push_back(getNextId());

View File

@ -12,6 +12,7 @@ const char index_html[] PROGMEM = R"rawliteral(
<span id="state"></span><br/><br/> <span id="state"></span><br/><br/>
<span id="voltage"></span><br/> <span id="voltage"></span><br/>
<span id="uid"></span><br/> <span id="uid"></span><br/>
<span id="heap"></span><br/>
<div> <div>
<button class="prev-button" onclick="simpleGetCall('previous');""></button> <button class="prev-button" onclick="simpleGetCall('previous');""></button>
@ -128,6 +129,7 @@ const char index_html[] PROGMEM = R"rawliteral(
document.getElementById("state").innerHTML = state['title']; document.getElementById("state").innerHTML = state['title'];
document.getElementById("progressLabel").innerHTML = state['time']; document.getElementById("progressLabel").innerHTML = state['time'];
document.getElementById("voltage").innerHTML = state['voltage']+' mV'; 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']; document.getElementById("uid").innerHTML = 'Last NFC ID: '+state['uid'];
var elements = document.getElementsByClassName('play-button'); var elements = document.getElementsByClassName('play-button');
var btn = elements[0]; var btn = elements[0];

View File

@ -69,8 +69,6 @@ uint32_t lastVoltage = 0;
uint loopCounter = 0; uint loopCounter = 0;
const int startDelay = 250;
String lastUid = ""; String lastUid = "";
uint16_t currentSongId = 0; uint16_t currentSongId = 0;

View File

@ -37,7 +37,13 @@
#define VOLTAGE_LOOP_INTERVAL 5000 #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 "globals.h"
#include "WebContent.h" #include "WebContent.h"
@ -86,6 +92,8 @@ bool asyncPrev = false;
uint16_t voltage_threshold_counter = 0; uint16_t voltage_threshold_counter = 0;
size_t free_heap = 0;
/* /*
std::map<String, String> rfid_map{{"67 152 204 14", "01-The_Box_Tops-The_Letter.mp3"}, std::map<String, String> rfid_map{{"67 152 204 14", "01-The_Box_Tops-The_Letter.mp3"},
{"67 175 148 160", "068-Der_Schatz_im_Bergsee"}}; {"67 175 148 160", "068-Der_Schatz_im_Bergsee"}};
@ -297,6 +305,7 @@ String getState()
jsonState["length"] = audio.getAudioFileDuration(); jsonState["length"] = audio.getAudioFileDuration();
jsonState["voltage"] = lastVoltage; jsonState["voltage"] = lastVoltage;
jsonState["uid"] = lastUid; jsonState["uid"] = lastUid;
jsonState["heap"] = free_heap;
String output; String output;
serializeJson(jsonState, output); serializeJson(jsonState, output);
jsonState.clear(); jsonState.clear();
@ -519,6 +528,8 @@ void setup()
lastVoltage = getBatteryVoltageMv(); lastVoltage = getBatteryVoltageMv();
free_heap = xPortGetFreeHeapSize();
// first parameter is name of access point, second is the password // first parameter is name of access point, second is the password
AsyncWiFiManager wifiManager(&server, &dns); AsyncWiFiManager wifiManager(&server, &dns);
@ -652,6 +663,11 @@ void volume_action(AsyncWebServerRequest *request)
request->send_P(200, "text/plain", "ok"); request->send_P(200, "text/plain", "ok");
} }
String getStartupSoundDir() {
static String tempPath = "/"+sys_dir+"/"+startup_sound;
return tempPath;
}
void loop() void loop()
{ {
if (audio.isRunning()) if (audio.isRunning())
@ -681,8 +697,7 @@ void loop()
playSongById(currentSongId,currentSongSeconds); playSongById(currentSongId,currentSongSeconds);
} else if (!startupSoundPlayed) { } else if (!startupSoundPlayed) {
startupSoundPlayed = true; startupSoundPlayed = true;
String tempPath = "/"+sys_dir+"/"+startup_sound; playSongByPath(getStartupSoundDir().c_str());
playSongByPath(tempPath.c_str());
} }
@ -719,13 +734,33 @@ void loop()
else if (asyncNext) else if (asyncNext)
{ {
asyncNext = false; 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) else if (asyncPrev)
{ {
asyncPrev = false; asyncPrev = false;
Serial.println("Previous"); if (audio.isRunning()) {
previous(); 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) if (loopCounter % VOLTAGE_LOOP_INTERVAL == 0)
{ {
lastVoltage = getBatteryVoltageMv(); lastVoltage = getBatteryVoltageMv();
free_heap = xPortGetFreeHeapSize();
if (lastVoltage<VOLTAGE_THRESHOLD) { if (lastVoltage<VOLTAGE_THRESHOLD) {
if (voltage_threshold_counter>3) { if (voltage_threshold_counter>3) {
Serial.println("entering deep sleep due to low voltage..."); Serial.println("entering deep sleep due to low voltage...");
@ -766,10 +802,7 @@ void loop2(void *parameter)
Serial.println("loop2 started"); Serial.println("loop2 started");
for (;;) for (;;)
{ {
if (buttonPressed(BTN_START_STOP))
{
asyncTogglePlayPause = true;
}
if (buttonPressed(BTN_NEXT)) if (buttonPressed(BTN_NEXT))
{ {
asyncNext = true; asyncNext = true;
@ -778,6 +811,10 @@ void loop2(void *parameter)
{ {
asyncPrev = true; asyncPrev = true;
} }
if (buttonPressed(BTN_START_STOP))
{
asyncTogglePlayPause = true;
}
} }
} }
@ -788,7 +825,7 @@ boolean buttonPressed(const uint8_t pin)
{ {
unsigned long now = millis(); unsigned long now = millis();
if (now - lastStart > startDelay) if (now - lastStart > SHORT_PRESS_TIME)
{ {
lastStart = now; lastStart = now;
Serial.println("button pressed."); Serial.println("button pressed.");
@ -802,3 +839,4 @@ boolean buttonPressed(const uint8_t pin)
return false; return false;
} }