fixed several crashes
This commit is contained in:
parent
ef30b832ae
commit
efd570fb50
|
|
@ -167,6 +167,19 @@ void DirectoryNode::advanceToFirstMP3InThisNode()
|
|||
|
||||
DirectoryNode *DirectoryNode::advanceToMP3(const uint16_t id)
|
||||
{
|
||||
|
||||
|
||||
for (size_t i = 0; i < ids.size(); i++)
|
||||
{
|
||||
if (id == ids[i])
|
||||
{
|
||||
// Found the current MP3 file
|
||||
currentPlaying = &mp3Files[i];
|
||||
currentPlayingId = id;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto subdir : subdirectories)
|
||||
{
|
||||
if (subdir->getId() == id)
|
||||
|
|
@ -181,12 +194,9 @@ DirectoryNode *DirectoryNode::advanceToMP3(const uint16_t id)
|
|||
if (id == subdir->ids[i])
|
||||
{
|
||||
// Found the current MP3 file
|
||||
if (i < subdir->mp3Files.size() - 1)
|
||||
{
|
||||
subdir->currentPlaying = &subdir->mp3Files[i];
|
||||
subdir->currentPlayingId = id;
|
||||
return subdir;
|
||||
}
|
||||
subdir->currentPlaying = &subdir->mp3Files[i];
|
||||
subdir->currentPlayingId = id;
|
||||
return subdir;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
33
src/main.cpp
33
src/main.cpp
|
|
@ -64,7 +64,7 @@ DNSServer dns;
|
|||
uint16_t DirectoryNode::idCounter = 0;
|
||||
|
||||
DirectoryNode rootNode("/");
|
||||
DirectoryNode *currentNode = NULL;
|
||||
DirectoryNode *currentNode = nullptr;
|
||||
|
||||
|
||||
|
||||
|
|
@ -124,13 +124,25 @@ uint32_t getBatteryVoltageMv() {
|
|||
void playSongById(uint16_t id, uint32_t continueSeconds = 0)
|
||||
{
|
||||
currentNode = rootNode.advanceToMP3(id);
|
||||
|
||||
if (currentNode==nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
String mp3File = currentNode->getCurrentPlayingFilePath();
|
||||
Serial.print("playing by id: ");
|
||||
Serial.print(id);Serial.print(" ");Serial.println(continueSeconds);
|
||||
|
||||
|
||||
Serial.println(mp3File.c_str());
|
||||
deactivateRFID();
|
||||
activateSD();
|
||||
|
||||
if (currentNode != nullptr && currentNode->getCurrentPlaying()==nullptr) {
|
||||
currentNode = nullptr;
|
||||
Serial.println("no node by id found, exiting playSongById");
|
||||
return;
|
||||
}
|
||||
|
||||
playFile(mp3File.c_str());
|
||||
if (continueSeconds!=0) {
|
||||
audio.setAudioPlayPosition(continueSeconds);
|
||||
|
|
@ -178,6 +190,10 @@ void playSongByRFID(String id)
|
|||
*/
|
||||
bool playFile(const char *filename, uint32_t resumeFilePos)
|
||||
{
|
||||
if (filename == nullptr || strlen(filename)==0) {
|
||||
Serial.println("filename is empty.");
|
||||
return false;
|
||||
}
|
||||
return audio.connecttoSD(filename, resumeFilePos);
|
||||
}
|
||||
|
||||
|
|
@ -206,7 +222,7 @@ void playNextMp3()
|
|||
Serial.print("Now advancing to ");
|
||||
String mp3File = currentNode->getCurrentPlayingFilePath();
|
||||
Serial.println(mp3File.c_str());
|
||||
deactivateRFID();
|
||||
deactivateRFID();
|
||||
activateSD();
|
||||
playFile(mp3File.c_str());
|
||||
activateRFID();
|
||||
|
|
@ -270,7 +286,8 @@ String getState()
|
|||
{
|
||||
DynamicJsonDocument jsonState(1024);
|
||||
jsonState["playing"] = audio.isRunning();
|
||||
if (currentNode != NULL)
|
||||
|
||||
if (currentNode != nullptr)
|
||||
jsonState["title"] = *currentNode->getCurrentPlaying();
|
||||
else
|
||||
jsonState["title"] = "Angehalten";
|
||||
|
|
@ -367,12 +384,12 @@ void next()
|
|||
|
||||
void previous()
|
||||
{
|
||||
if (currentNode != nullptr) {
|
||||
if (currentNode != NULL) {
|
||||
|
||||
const String* curr = currentNode->getCurrentPlaying();
|
||||
DirectoryNode* newNode = currentNode->goToPreviousMP3();
|
||||
|
||||
if (newNode != nullptr) {
|
||||
if (newNode != NULL) {
|
||||
if (curr == newNode->getCurrentPlaying()) {
|
||||
// reset to 0 seconds playtime:
|
||||
audio.setAudioPlayPosition(0);
|
||||
|
|
@ -510,6 +527,8 @@ void setup()
|
|||
Serial.println("Deactivating Brownout detector...");
|
||||
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
|
||||
|
||||
//wifiManager.resetSettings();
|
||||
|
||||
if (wifiManager.autoConnect("HannaBox"))
|
||||
{
|
||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
|
||||
|
|
@ -645,7 +664,7 @@ void loop()
|
|||
deactivateRFID();
|
||||
activateSD();
|
||||
audio.loop();
|
||||
if (currentNode != NULL && !prepareSleepMode)
|
||||
if (currentNode != nullptr && !prepareSleepMode)
|
||||
{
|
||||
currentNode->setSecondsPlayed(audio.getAudioCurrentTime());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue