diff --git a/ESPixelStick/src/FileMgr.cpp b/ESPixelStick/src/FileMgr.cpp index e3ba5f562..5f2a5bb08 100644 --- a/ESPixelStick/src/FileMgr.cpp +++ b/ESPixelStick/src/FileMgr.cpp @@ -676,7 +676,7 @@ void c_FileMgr::InitSdFileList () int index = 0; for (auto& currentFileListEntry : FileList) { - currentFileListEntry.handle = 0; + currentFileListEntry.handle = INVALID_FILE_HANDLE; currentFileListEntry.entryId = index++; } @@ -692,15 +692,18 @@ int c_FileMgr::FileListFindSdFileHandle (FileId HandleToFind) int response = -1; // DEBUG_V (String ("HandleToFind: ") + String (HandleToFind)); - for (auto & currentFileListEntry : FileList) + if(INVALID_FILE_HANDLE != HandleToFind) { - // DEBUG_V (String ("currentFileListEntry.handle: ") + String (currentFileListEntry.handle)); - // DEBUG_V (String ("currentFileListEntry.entryId: ") + String (currentFileListEntry.entryId)); - - if (currentFileListEntry.handle == HandleToFind) + for (auto & currentFileListEntry : FileList) { - response = currentFileListEntry.entryId; - break; + // DEBUG_V (String ("currentFileListEntry.handle: ") + String (currentFileListEntry.handle)); + // DEBUG_V (String ("currentFileListEntry.entryId: ") + String (currentFileListEntry.entryId)); + + if (currentFileListEntry.handle == HandleToFind) + { + response = currentFileListEntry.entryId; + break; + } } } @@ -714,7 +717,7 @@ c_FileMgr::FileId c_FileMgr::CreateSdFileHandle () { // DEBUG_START; - FileId response = 0; + FileId response = INVALID_FILE_HANDLE; FileId FileHandle = millis (); // create a unique handle @@ -726,7 +729,7 @@ c_FileMgr::FileId c_FileMgr::CreateSdFileHandle () // find an empty slot for (auto & currentFileListEntry : FileList) { - if (currentFileListEntry.handle == 0) + if (currentFileListEntry.handle == INVALID_FILE_HANDLE) { currentFileListEntry.handle = FileHandle; response = FileHandle; @@ -734,7 +737,7 @@ c_FileMgr::FileId c_FileMgr::CreateSdFileHandle () } } - if (0 == response) + if (INVALID_FILE_HANDLE == response) { logcon (String (CN_stars) + F (" Could not allocate another file handle ") + CN_stars); } @@ -968,7 +971,7 @@ void c_FileMgr::SaveSdFile (const String & FileName, String & FileData) do // once { - FileId FileHandle = 0; + FileId FileHandle = INVALID_FILE_HANDLE; if (false == OpenSdFile (FileName, FileMode::FileWrite, FileHandle)) { logcon (String (F ("Could not open '")) + FileName + F ("' for writting.")); @@ -1047,7 +1050,7 @@ bool c_FileMgr::OpenSdFile (const String & FileName, FileMode Mode, FileId & Fil logcon(String(F("ERROR: Cannot open '")) + FileName + F("'.")); // release the file list entry - FileList[FileListIndex].handle = 0; + FileList[FileListIndex].handle = INVALID_FILE_HANDLE; break; } @@ -1079,7 +1082,7 @@ bool c_FileMgr::ReadSdFile (const String & FileName, String & FileData) // DEBUG_START; bool GotFileData = false; - FileId FileHandle = 0; + FileId FileHandle = INVALID_FILE_HANDLE; // DEBUG_V (String("File '") + FileName + "' is being opened."); if (true == OpenSdFile (FileName, FileMode::FileRead, FileHandle)) @@ -1115,7 +1118,7 @@ bool c_FileMgr::ReadSdFile (const String & FileName, JsonDocument & FileData) // DEBUG_START; bool GotFileData = false; - FileId FileHandle = 0; + FileId FileHandle = INVALID_FILE_HANDLE; // DEBUG_V (String("File '") + FileName + "' is being opened."); if (true == OpenSdFile (FileName, FileMode::FileRead, FileHandle)) @@ -1232,7 +1235,7 @@ void c_FileMgr::CloseSdFile (const FileId& FileHandle) if (-1 != (FileListIndex = FileListFindSdFileHandle (FileHandle))) { FileList[FileListIndex].info.close (); - FileList[FileListIndex].handle = 0; + FileList[FileListIndex].handle = INVALID_FILE_HANDLE; } else { @@ -1286,7 +1289,7 @@ size_t c_FileMgr::WriteSdFile (const FileId& FileHandle, byte* FileData, size_t size_t c_FileMgr::GetSdFileSize (const String& FileName) { size_t response = 0; - FileId Handle; + FileId Handle = INVALID_FILE_HANDLE; if(OpenSdFile (FileName, FileMode::FileRead, Handle)) { response = GetSdFileSize(Handle); diff --git a/ESPixelStick/src/FileMgr.hpp b/ESPixelStick/src/FileMgr.hpp index 4e2ba4b6d..941c7c7e7 100644 --- a/ESPixelStick/src/FileMgr.hpp +++ b/ESPixelStick/src/FileMgr.hpp @@ -49,6 +49,7 @@ class c_FileMgr virtual ~c_FileMgr (); typedef uint32_t FileId; + const static FileId INVALID_FILE_HANDLE = 0; void Begin (); void Poll () {} diff --git a/ESPixelStick/src/input/InputFPPRemotePlayEffectFsm.cpp b/ESPixelStick/src/input/InputFPPRemotePlayEffectFsm.cpp index bc2d42a88..7194a7f60 100644 --- a/ESPixelStick/src/input/InputFPPRemotePlayEffectFsm.cpp +++ b/ESPixelStick/src/input/InputFPPRemotePlayEffectFsm.cpp @@ -127,7 +127,7 @@ void fsm_PlayEffect_state_PlayingEffect::Poll () if (p_InputFPPRemotePlayEffect->PlayEffectTimer.IsExpired()) { // DEBUG_V (""); - Stop (); + p_InputFPPRemotePlayEffect->Stop (); } // DEBUG_END; diff --git a/ESPixelStick/src/input/InputFPPRemotePlayFile.cpp b/ESPixelStick/src/input/InputFPPRemotePlayFile.cpp index 9f4e4ca4f..d2e40ff9d 100644 --- a/ESPixelStick/src/input/InputFPPRemotePlayFile.cpp +++ b/ESPixelStick/src/input/InputFPPRemotePlayFile.cpp @@ -284,7 +284,12 @@ bool c_InputFPPRemotePlayFile::ParseFseqFile () FSEQRawHeader fsqRawHeader; FSEQParsedHeader fsqParsedHeader; - FileHandleForFileBeingPlayed = -1; + if(c_FileMgr::INVALID_FILE_HANDLE != FileHandleForFileBeingPlayed) + { + // DEBUG_V("Unexpected File Handle at fseq Parse."); + Stop(); + } + if (false == FileMgr.OpenSdFile (PlayItemName, c_FileMgr::FileMode::FileRead, FileHandleForFileBeingPlayed)) @@ -459,7 +464,8 @@ bool c_InputFPPRemotePlayFile::ParseFseqFile () //----------------------------------------------------------------------------- void c_InputFPPRemotePlayFile::ClearFileInfo() { - PlayItemName = String (""); + // DEBUG_START; + PlayItemName = emptyString; RemainingPlayCount = 0; SyncControl.LastRcvdElapsedSeconds = 0.0; FrameControl.ElapsedPlayTimeMS = 0; @@ -467,7 +473,7 @@ void c_InputFPPRemotePlayFile::ClearFileInfo() FrameControl.ChannelsPerFrame = 0; FrameControl.FrameStepTimeMS = 25; FrameControl.TotalNumberOfFramesInSequence = 0; - + // DEBUG_END; } // ClearFileInfo uint32_t c_InputFPPRemotePlayFile::ReadFile(uint32_t DestinationIntensityId, uint32_t NumBytesToRead, uint32_t FileOffset) diff --git a/ESPixelStick/src/input/InputFPPRemotePlayFile.hpp b/ESPixelStick/src/input/InputFPPRemotePlayFile.hpp index 6aa912fe7..98a41a70d 100644 --- a/ESPixelStick/src/input/InputFPPRemotePlayFile.hpp +++ b/ESPixelStick/src/input/InputFPPRemotePlayFile.hpp @@ -68,7 +68,7 @@ class c_InputFPPRemotePlayFile : public c_InputFPPRemotePlayItem fsm_PlayFile_state * pCurrentFsmState = &fsm_PlayFile_state_Idle_imp; - c_FileMgr::FileId FileHandleForFileBeingPlayed = 0; + c_FileMgr::FileId FileHandleForFileBeingPlayed = c_FileMgr::INVALID_FILE_HANDLE; struct FrameControl_t { diff --git a/ESPixelStick/src/input/InputFPPRemotePlayFileFsm.cpp b/ESPixelStick/src/input/InputFPPRemotePlayFileFsm.cpp index b80c096cd..1908b3bd0 100644 --- a/ESPixelStick/src/input/InputFPPRemotePlayFileFsm.cpp +++ b/ESPixelStick/src/input/InputFPPRemotePlayFileFsm.cpp @@ -207,7 +207,7 @@ void fsm_PlayFile_state_PlayingFile::Poll () { // DEBUG_V (String ("TotalNumberOfFramesInSequence: ") + String (p_Parent->TotalNumberOfFramesInSequence)); // DEBUG_V (String (" Done Playing:: FileName: '") + p_Parent->GetFileName () + "'"); - Stop (); + p_Parent->Stop (); break; } } @@ -284,11 +284,8 @@ IRAM_ATTR void fsm_PlayFile_state_PlayingFile::TimerPoll () // xDEBUG_V (String ("TotalNumberOfFramesInSequence: ") + String (p_Parent->TotalNumberOfFramesInSequence)); // xDEBUG_V (String (" CurrentFrame: ") + String (CurrentFrame)); - if (0 != p_Parent->FileHandleForFileBeingPlayed) - { - // logcon (F ("File Playback Failed to read enough data")); - Stop (); - } + // logcon (F ("File Playback Failed to read enough data")); + p_Parent->Stop (); } } @@ -319,7 +316,7 @@ void fsm_PlayFile_state_PlayingFile::Init (c_InputFPPRemotePlayFile* Parent) // DEBUG_V (String ("RemainingPlayCount: ") + p_Parent->RemainingPlayCount); if (0 == p_Parent->RemainingPlayCount) { - Stop (); + p_Parent->Stop (); break; } @@ -358,7 +355,7 @@ void fsm_PlayFile_state_PlayingFile::Start (String& FileName, float ElapsedSecon // DEBUG_V (String ("TotalNumberOfFramesInSequence: ") + String (p_Parent->TotalNumberOfFramesInSequence)); // DEBUG_V (String ("RemainingPlayCount: ") + p_Parent->RemainingPlayCount); - Stop (); + p_Parent->Stop (); p_Parent->Start (FileName, ElapsedSeconds, PlayCount); // DEBUG_END; @@ -396,7 +393,7 @@ bool fsm_PlayFile_state_PlayingFile::Sync (String& FileName, float ElapsedSecond if (FileName != p_Parent->GetFileName ()) { // DEBUG_V ("Sync: Filename change"); - Stop (); + p_Parent->Stop (); p_Parent->Start (FileName, ElapsedSeconds, 1); break; } @@ -457,10 +454,10 @@ void fsm_PlayFile_state_Stopping::Poll () // DEBUG_V (String ("FileHandleForFileBeingPlayed: ") + String (p_Parent->FileHandleForFileBeingPlayed)); FileMgr.CloseSdFile (p_Parent->FileHandleForFileBeingPlayed); - p_Parent->FileHandleForFileBeingPlayed = 0; + p_Parent->FileHandleForFileBeingPlayed = c_FileMgr::INVALID_FILE_HANDLE; p_Parent->fsm_PlayFile_state_Idle_imp.Init (p_Parent); - if (FileName != "") + if (!FileName.equals(emptyString)) { // DEBUG_V ("Restarting File"); p_Parent->Start (FileName, StartingElapsedTime, PlayCount); diff --git a/ESPixelStick/src/input/InputFPPRemotePlayListFsm.cpp b/ESPixelStick/src/input/InputFPPRemotePlayListFsm.cpp index 91ffedc2e..19dfa10d4 100644 --- a/ESPixelStick/src/input/InputFPPRemotePlayListFsm.cpp +++ b/ESPixelStick/src/input/InputFPPRemotePlayListFsm.cpp @@ -160,7 +160,7 @@ void fsm_PlayList_state_PlayingFile::Poll () if (pInputFPPRemotePlayList->pInputFPPRemotePlayItem->IsIdle ()) { // DEBUG_V ("Done with all entries"); - Stop (); + pInputFPPRemotePlayList->Stop (); } // DEBUG_END; @@ -236,7 +236,7 @@ void fsm_PlayList_state_PlayingEffect::Poll () if (pInputFPPRemotePlayList->pInputFPPRemotePlayItem->IsIdle ()) { // DEBUG_V ("Effect Processing Done"); - Stop (); + pInputFPPRemotePlayList->Stop (); } // DEBUG_END; @@ -311,7 +311,7 @@ void fsm_PlayList_state_Paused::Poll () if (pInputFPPRemotePlayList->PauseDelayTimer.IsExpired()) { - Stop(); + pInputFPPRemotePlayList->Stop(); } // DEBUG_END;