Skip to content

Commit

Permalink
Merge pull request #704 from MartinMueller2003/main
Browse files Browse the repository at this point in the history
Fixed issue that causes files not to play after a bad file is found.
  • Loading branch information
forkineye authored Dec 11, 2023
2 parents dad96ac + d9ea429 commit 3af3d8a
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 201 deletions.
1 change: 1 addition & 0 deletions ESPixelStick/src/ConstNames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const CN_PROGMEM char CN_applicationSLASHjson [] = "application/json";
const CN_PROGMEM char CN_b [] = "b";
const CN_PROGMEM char CN_b16 [] = "b16";
const CN_PROGMEM char CN_baudrate [] = "baudrate";
const CN_PROGMEM char CN_blankOnStop [] = "blankOnStop";
const CN_PROGMEM char CN_blanktime [] = "blanktime";
const CN_PROGMEM char CN_bridge [] = "bridge";
const CN_PROGMEM char CN_brightness [] = "brightness";
Expand Down
383 changes: 192 additions & 191 deletions ESPixelStick/src/ConstNames.hpp

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions ESPixelStick/src/FileMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ void c_FileMgr::GetListOfSdFiles (String & Response, uint32_t FirstFileToSend)
#define EntryUsageFactor 3

DynamicJsonDocument ResponseJsonDoc (1 * 1024);
FeedWDT ();

do // once
{
Expand Down Expand Up @@ -1035,6 +1036,7 @@ bool c_FileMgr::OpenSdFile (const String & FileName, FileMode Mode, FileId & Fil
bool FileIsOpen = false;
FileHandle = 0;
char ReadWrite[2] = { XlateFileMode[Mode], 0 };
FileHandle = INVALID_FILE_HANDLE;

do // once
{
Expand Down Expand Up @@ -1077,10 +1079,9 @@ bool c_FileMgr::OpenSdFile (const String & FileName, FileMode Mode, FileId & Fil
if (!FileList[FileListIndex].info)
{
logcon(String(F("ERROR: Cannot open '")) + FileName + F("'."));

// release the file list entry
FileList[FileListIndex].handle = INVALID_FILE_HANDLE;

CloseSdFile(FileHandle);
break;
}
// DEBUG_V("");
Expand Down Expand Up @@ -1255,7 +1256,7 @@ size_t c_FileMgr::ReadSdFile (const FileId& FileHandle, byte* FileData, size_t N
} // ReadSdFile

//-----------------------------------------------------------------------------
void c_FileMgr::CloseSdFile (const FileId& FileHandle)
void c_FileMgr::CloseSdFile (FileId& FileHandle)
{
// DEBUG_START;
// DEBUG_V(String(" FileHandle: ") + String(FileHandle));
Expand All @@ -1270,6 +1271,8 @@ void c_FileMgr::CloseSdFile (const FileId& FileHandle)
{
logcon (String (F ("CloseSdFile::ERROR::Invalid File Handle: ")) + String (FileHandle));
}

FileHandle = INVALID_FILE_HANDLE;

// DEBUG_END;

Expand Down
2 changes: 1 addition & 1 deletion ESPixelStick/src/FileMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class c_FileMgr
bool ReadSdFile (const String & FileName, JsonDocument & FileData);
size_t WriteSdFile (const FileId & FileHandle, byte * FileData, size_t NumBytesToWrite);
size_t WriteSdFile (const FileId & FileHandle, byte * FileData, size_t NumBytesToWrite, size_t StartingPosition);
void CloseSdFile (const FileId & FileHandle);
void CloseSdFile (FileId & FileHandle);
void GetListOfSdFiles (String & Response, uint32_t FirstFileToSend);
void GetListOfSdFiles (std::vector<String> & Response);
size_t GetSdFileSize (const String & FileName);
Expand Down
2 changes: 1 addition & 1 deletion ESPixelStick/src/WebMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class c_WebMgr
#ifdef ARDUINO_ARCH_ESP32
# define STATUS_DOC_SIZE 4000
#else
# define STATUS_DOC_SIZE 2000
# define STATUS_DOC_SIZE 2500
#endif // def ARDUINO_ARCH_ESP32

void init ();
Expand Down
6 changes: 5 additions & 1 deletion ESPixelStick/src/input/InputFPPRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ void c_InputFPPRemote::GetConfig (JsonObject& jsonConfig)
{
jsonConfig[JSON_NAME_FILE_TO_PLAY] = No_LocalFileToPlay;
}
jsonConfig[CN_SyncOffset] = SyncOffsetMS;
jsonConfig[CN_SyncOffset] = SyncOffsetMS;
jsonConfig[CN_SendFppSync] = SendFppSync;
jsonConfig[CN_blankOnStop] = FPPDiscovery.GetBlankOnStop();

// DEBUG_END;

Expand Down Expand Up @@ -268,9 +269,12 @@ bool c_InputFPPRemote::SetConfig (JsonObject& jsonConfig)
// DEBUG_START;

String FileToPlay;
bool BlankOnStop = FPPDiscovery.GetBlankOnStop();
setFromJSON (FileToPlay, jsonConfig, JSON_NAME_FILE_TO_PLAY);
setFromJSON (SyncOffsetMS, jsonConfig, CN_SyncOffset);
setFromJSON (SendFppSync, jsonConfig, CN_SendFppSync);
setFromJSON (BlankOnStop, jsonConfig, CN_blankOnStop);
FPPDiscovery.SetBlankOnStop(BlankOnStop);

if (PlayingFile())
{
Expand Down
3 changes: 3 additions & 0 deletions ESPixelStick/src/input/InputFPPRemotePlayFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ bool c_InputFPPRemotePlayFile::ParseFseqFile ()
{
LastFailedPlayStatusMsg = (String (F ("ParseFseqFile:: Could not read FSEQ header: filename: '")) + PlayItemName + "'");
logcon (LastFailedPlayStatusMsg);
FileMgr.CloseSdFile(FileHandleForFileBeingPlayed);
break;
}

Expand Down Expand Up @@ -350,6 +351,7 @@ bool c_InputFPPRemotePlayFile::ParseFseqFile ()
{
LastFailedPlayStatusMsg = (String (F ("ParseFseqFile:: Could not start. ")) + PlayItemName + F (" is not a v2 uncompressed sequence"));
logcon (LastFailedPlayStatusMsg);
FileMgr.CloseSdFile(FileHandleForFileBeingPlayed);
break;
}
// DEBUG_V ("");
Expand Down Expand Up @@ -377,6 +379,7 @@ bool c_InputFPPRemotePlayFile::ParseFseqFile ()
{
LastFailedPlayStatusMsg = (String (F ("ParseFseqFile:: Could not start. ")) + PlayItemName + F (" Too many sparse ranges defined in file header."));
logcon (LastFailedPlayStatusMsg);
FileMgr.CloseSdFile(FileHandleForFileBeingPlayed);
break;
}

Expand Down
11 changes: 8 additions & 3 deletions ESPixelStick/src/input/InputFPPRemotePlayFileFsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ bool fsm_PlayFile_state_PlayingFile::Poll ()

do // once
{
if(0 == p_Parent->FileHandleForFileBeingPlayed)
if(c_FileMgr::INVALID_FILE_HANDLE == p_Parent->FileHandleForFileBeingPlayed)
{
// DEBUG_V("Bad FileHandleForFileBeingPlayed");
Stop();
Expand Down Expand Up @@ -250,7 +250,7 @@ IRAM_ATTR void fsm_PlayFile_state_PlayingFile::TimerPoll ()

do // once
{
if(0 == p_Parent->FileHandleForFileBeingPlayed)
if(c_FileMgr::INVALID_FILE_HANDLE == p_Parent->FileHandleForFileBeingPlayed)
{
// DEBUG_V("Bad FileHandleForFileBeingPlayed");
Stop();
Expand Down Expand Up @@ -488,7 +488,6 @@ bool fsm_PlayFile_state_Stopping::Poll ()
// DEBUG_V (String ("FileHandleForFileBeingPlayed: ") + String (p_Parent->FileHandleForFileBeingPlayed));

FileMgr.CloseSdFile (p_Parent->FileHandleForFileBeingPlayed);
p_Parent->FileHandleForFileBeingPlayed = c_FileMgr::INVALID_FILE_HANDLE;
p_Parent->fsm_PlayFile_state_Idle_imp.Init (p_Parent);

StartingElapsedTime = 0.0;
Expand Down Expand Up @@ -610,6 +609,12 @@ void fsm_PlayFile_state_Error::Init (c_InputFPPRemotePlayFile* Parent)
p_Parent->FrameControl.FrameStepTimeMS = 0;
p_Parent->FrameControl.TotalNumberOfFramesInSequence = 0;

if(c_FileMgr::INVALID_FILE_HANDLE != p_Parent->FileHandleForFileBeingPlayed)
{
// DEBUG_V("Unexpected File Handle at error init.");
FileMgr.CloseSdFile(p_Parent->FileHandleForFileBeingPlayed);
}

// DEBUG_END;

} // fsm_PlayFile_state_Error::Init
Expand Down
9 changes: 8 additions & 1 deletion ESPixelStick/src/service/FPPDiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,14 @@ void c_FPPDiscovery::ProcessSyncPacket (uint8_t action, String FileName, float S
// DEBUG_V (String ("SecondsElapsed: ") + SecondsElapsed);

MultiSyncStats.pktSyncSeqStop++;
StopPlaying ();
if(BlankOnStop)
{
ProcessBlankPacket();
}
else
{
StopPlaying ();
}
break;
}

Expand Down
3 changes: 3 additions & 0 deletions ESPixelStick/src/service/FPPDiscovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class c_FPPDiscovery
bool inFileUpload = false;
bool hasBeenInitialized = false;
bool IsEnabled = false;
bool BlankOnStop = false;
String UploadFileName;
IPAddress FppRemoteIp = IPAddress (uint32_t(0));
c_InputFPPRemotePlayFile * InputFPPRemotePlayFile = nullptr;
Expand Down Expand Up @@ -124,6 +125,8 @@ SystemDebugStats_t SystemDebugStats;
void GetStatus (JsonObject& jsonStatus);
void NetworkStateChanged (bool NewNetworkState);

void SetBlankOnStop (bool value) {BlankOnStop = value;}
bool GetBlankOnStop (void) {return BlankOnStop;}
void SetInputFPPRemotePlayFile (c_InputFPPRemotePlayFile * value);
void ForgetInputFPPRemotePlayFile ();
void GenerateFppSyncMsg (uint8_t Action, const String & FileName, uint32_t CurrentFrame, const float & ElpsedTime);
Expand Down
4 changes: 4 additions & 0 deletions html/fpp_remote.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@
<div class="col-sm-4">
<input type="checkbox" id="SendFppSync" title="Send FPP Sync.">
</div>
<label class="control-label col-sm-2" for="BlankOnStop">Blank on FPP Sync Stop</label>
<div class="col-sm-4">
<input type="checkbox" id="BlankOnStop" title="Blank Display on FPP Sync Stop.">
</div>
</div>
</fieldset>

0 comments on commit 3af3d8a

Please sign in to comment.