diff --git a/ESPixelStick/src/input/InputFPPRemote.cpp b/ESPixelStick/src/input/InputFPPRemote.cpp index bc7da0933..9c72f0ed9 100644 --- a/ESPixelStick/src/input/InputFPPRemote.cpp +++ b/ESPixelStick/src/input/InputFPPRemote.cpp @@ -153,6 +153,8 @@ bool c_InputFPPRemote::SetConfig (JsonObject & jsonConfig) pInputFPPRemotePlayItem->SetSyncOffsetMS (SyncOffsetMS); } + FPPDiscovery.SetSyncOffsetMS (SyncOffsetMS); + // DEBUG_V ("Config Processing"); // Clear outbuffer on config change memset (OutputMgr.GetBufferAddress(), 0x0, OutputMgr.GetBufferUsedSize ()); diff --git a/ESPixelStick/src/input/InputFPPRemotePlayFile.cpp b/ESPixelStick/src/input/InputFPPRemotePlayFile.cpp index 6dfe7effa..b8e7dd77d 100644 --- a/ESPixelStick/src/input/InputFPPRemotePlayFile.cpp +++ b/ESPixelStick/src/input/InputFPPRemotePlayFile.cpp @@ -22,13 +22,23 @@ #include "../service/FPPDiscovery.h" #include "../service/fseq.h" +static void TimerHandler (void * p) +{ + reinterpret_cast(p)->IsrPoll (); + +}// TimerHandler + //----------------------------------------------------------------------------- c_InputFPPRemotePlayFile::c_InputFPPRemotePlayFile (c_InputMgr::e_InputChannelIds InputChannelId) : c_InputFPPRemotePlayItem (InputChannelId) { // DEBUG_START; + fsm_PlayFile_state_Idle_imp.Init (this); + LastIsrTimeStampMS = millis (); + MsTicker.attach_ms (uint32_t (25), &TimerHandler, (void*)this); // Add ISR Function + // DEBUG_END; } // c_InputFPPRemotePlayFile @@ -36,7 +46,7 @@ c_InputFPPRemotePlayFile::c_InputFPPRemotePlayFile (c_InputMgr::e_InputChannelId c_InputFPPRemotePlayFile::~c_InputFPPRemotePlayFile () { // DEBUG_START; - + MsTicker.detach (); for (uint32_t LoopCount = 10000; (LoopCount != 0) && (!IsIdle ()); LoopCount--) { Stop (); @@ -71,10 +81,10 @@ void c_InputFPPRemotePlayFile::Sync (String & FileName, uint32_t FrameId) { // DEBUG_START; - SyncCount++; + SyncControl.SyncCount++; if (pCurrentFsmState->Sync (FileName, FrameId)) { - SyncAdjustmentCount++; + SyncControl.SyncAdjustmentCount++; } // DEBUG_END; @@ -82,33 +92,51 @@ void c_InputFPPRemotePlayFile::Sync (String & FileName, uint32_t FrameId) } // Sync //----------------------------------------------------------------------------- -void c_InputFPPRemotePlayFile::Poll (uint8_t * Buffer, size_t BufferSize) +void c_InputFPPRemotePlayFile::Poll (uint8_t * _Buffer, size_t _BufferSize) { - // DEBUG_START; + // xDEBUG_START; + + Buffer = _Buffer; + BufferSize = _BufferSize; InitTimeCorrectionFactor (); - pCurrentFsmState->Poll (Buffer, BufferSize); + pCurrentFsmState->Poll (); - // DEBUG_END; + // xDEBUG_END; } // Poll +//----------------------------------------------------------------------------- +void c_InputFPPRemotePlayFile::IsrPoll () +{ + // xDEBUG_START; + + uint32_t now = millis (); + uint32_t elapsedMS = now - LastIsrTimeStampMS; + LastIsrTimeStampMS = now; + FrameControl.ElapsedPlayTimeMS += elapsedMS; + pCurrentFsmState->IsrPoll (); + + // xDEBUG_END; + +} // IsrPoll + //----------------------------------------------------------------------------- void c_InputFPPRemotePlayFile::GetStatus (JsonObject& JsonStatus) { - // DEBUG_START; + // xDEBUG_START; // uint32_t mseconds = millis () - StartTimeMS; - time_t AdjustedFrameStepTimeMS = time_t (float (FrameStepTimeMS) * TimeCorrectionFactor); - uint32_t mseconds = AdjustedFrameStepTimeMS * LastPlayedFrameId; - uint32_t msecondsTotal = FrameStepTimeMS * TotalNumberOfFramesInSequence; + time_t AdjustedFrameStepTimeMS = time_t (float (FrameControl.FrameStepTimeMS) * SyncControl.TimeCorrectionFactor); + uint32_t mseconds = AdjustedFrameStepTimeMS * FrameControl.LastPlayedFrameId; + uint32_t msecondsTotal = FrameControl.FrameStepTimeMS * FrameControl.TotalNumberOfFramesInSequence; uint32_t secs = mseconds / 1000; uint32_t secsTot = msecondsTotal / 1000; - JsonStatus[F ("SyncCount")] = SyncCount; - JsonStatus[F ("SyncAdjustmentCount")] = SyncAdjustmentCount; - JsonStatus[F ("TimeOffset")] = TimeCorrectionFactor; + JsonStatus[F ("SyncCount")] = SyncControl.SyncCount; + JsonStatus[F ("SyncAdjustmentCount")] = SyncControl.SyncAdjustmentCount; + JsonStatus[F ("TimeOffset")] = SyncControl.TimeCorrectionFactor; String temp = GetFileName (); @@ -135,47 +163,53 @@ void c_InputFPPRemotePlayFile::GetStatus (JsonObject& JsonStatus) JsonStatus[CN_errors] = LastFailedPlayStatusMsg; - // DEBUG_END; + // xDEBUG_END; } // GetStatus //----------------------------------------------------------------------------- -uint32_t c_InputFPPRemotePlayFile::CalculateFrameId (time_t now, int32_t SyncOffsetMS) +uint32_t c_InputFPPRemotePlayFile::CalculateFrameId (int32_t SyncOffsetMS) { // DEBUG_START; - time_t CurrentPlayTime = now - StartTimeMS; + uint32_t CurrentFrameId = 0; - // has the counter wrapped? - if (now < StartTimeMS) + do // once { - CurrentPlayTime = now + (0 - StartTimeMS); - } + if (FrameControl.ElapsedPlayTimeMS < FrameControl.FrameStepTimeMS) + { + break; + } + + uint32_t AdjustedPlayTime = FrameControl.ElapsedPlayTimeMS + SyncOffsetMS; + // DEBUG_V (String ("AdjustedPlayTime: ") + String (AdjustedPlayTime)); + if ((0 > SyncOffsetMS) && (FrameControl.ElapsedPlayTimeMS < abs(SyncOffsetMS))) + { + break; + } - time_t AdjustedPlayTime = CurrentPlayTime + SyncOffsetMS; - time_t AdjustedFrameStepTimeMS = time_t (float (FrameStepTimeMS) * TimeCorrectionFactor); - uint32_t CurrentFrameId = AdjustedPlayTime / AdjustedFrameStepTimeMS; + CurrentFrameId = (AdjustedPlayTime / SyncControl.AdjustedFrameStepTimeMS); + // DEBUG_V (String (" CurrentFrameId: ") + String (CurrentFrameId)); + + } while (false); // DEBUG_END; - return max (CurrentFrameId, LastPlayedFrameId); + return CurrentFrameId; } // CalculateFrameId //----------------------------------------------------------------------------- -void c_InputFPPRemotePlayFile::CalculatePlayStartTime () +void c_InputFPPRemotePlayFile::CalculatePlayStartTime (uint32_t StartingFrameId) { // DEBUG_START; - time_t now = millis (); - time_t StartOffset = time_t ((float (FrameStepTimeMS) * TimeCorrectionFactor) * float (LastPlayedFrameId)); - StartTimeMS = now - StartOffset; - // DEBUG_V (String (" now: ") + String (now)); - // DEBUG_V (String (" StartOffset: ") + String (StartOffset)); - // DEBUG_V (String (" FrameStepTimeMS: ") + String (FrameStepTimeMS)); - // DEBUG_V (String ("TimeCorrectionFactor: ") + String (TimeCorrectionFactor)); - // DEBUG_V (String (" LastPlayedFrameId: ") + String (LastPlayedFrameId)); - // DEBUG_V (String (" StartTimeMS: ") + String (StartTimeMS)); + FrameControl.ElapsedPlayTimeMS = uint32_t ((float (FrameControl.FrameStepTimeMS) * SyncControl.TimeCorrectionFactor) * float (StartingFrameId)); + + // DEBUG_V (String (" FrameStepTimeMS: ") + String (FrameControl.FrameStepTimeMS)); + // DEBUG_V (String ("TimeCorrectionFactor: ") + String (SyncControl.TimeCorrectionFactor)); + // DEBUG_V (String (" StartingFrameId: ") + String (StartingFrameId)); + // DEBUG_V (String (" ElapsedPlayTIme: ") + String (FrameControl.ElapsedPlayTimeMS)); // DEBUG_END; @@ -264,12 +298,12 @@ bool c_InputFPPRemotePlayFile::ParseFseqFile () break; } - // FrameStepTimeMS = max ((uint8_t)1, fsqParsedHeader.stepTime) * 30; - FrameStepTimeMS = max ((uint8_t)1, fsqParsedHeader.stepTime); - TotalNumberOfFramesInSequence = fsqParsedHeader.TotalNumberOfFramesInSequence; + FrameControl.FrameStepTimeMS = max ((uint8_t)25, fsqParsedHeader.stepTime); + FrameControl.TotalNumberOfFramesInSequence = fsqParsedHeader.TotalNumberOfFramesInSequence; + SyncControl.AdjustedFrameStepTimeMS = uint32_t (float (FrameControl.FrameStepTimeMS) * SyncControl.TimeCorrectionFactor); - DataOffset = fsqParsedHeader.dataOffset; - ChannelsPerFrame = fsqParsedHeader.channelCount; + FrameControl.DataOffset = fsqParsedHeader.dataOffset; + FrameControl.ChannelsPerFrame = fsqParsedHeader.channelCount; memset ((void*)&SparseRanges, 0x00, sizeof (SparseRanges)); if (fsqParsedHeader.numSparseRanges) @@ -369,13 +403,13 @@ void c_InputFPPRemotePlayFile::InitTimeCorrectionFactor () do // once { - if (INVALID_TIME_CORRECTION_FACTOR != SavedTimeCorrectionFactor) + if (INVALID_TIME_CORRECTION_FACTOR != SyncControl.SavedTimeCorrectionFactor) { break; } // only do this once after boot. - TimeCorrectionFactor = SavedTimeCorrectionFactor = INITIAL_TIME_CORRECTION_FACTOR; + SyncControl.TimeCorrectionFactor = SyncControl.SavedTimeCorrectionFactor = INITIAL_TIME_CORRECTION_FACTOR; String FileData; FileMgr.ReadSdFile (String (CN_time), FileData); @@ -402,8 +436,8 @@ void c_InputFPPRemotePlayFile::InitTimeCorrectionFactor () // extern void PrettyPrint (JsonObject & jsonStuff, String Name); // PrettyPrint (JsonData, String ("InitTimeCorrectionFactor")); - setFromJSON (TimeCorrectionFactor, JsonData, CN_time); - SavedTimeCorrectionFactor = TimeCorrectionFactor; + setFromJSON (SyncControl.TimeCorrectionFactor, JsonData, CN_time); + SyncControl.SavedTimeCorrectionFactor = SyncControl.TimeCorrectionFactor; // DEBUG_V (String ("TimeCorrectionFactor: ") + String (TimeCorrectionFactor, 10)); } while (false); @@ -419,7 +453,7 @@ void c_InputFPPRemotePlayFile::SaveTimeCorrectionFactor () do // once { - if (fabs (SavedTimeCorrectionFactor - TimeCorrectionFactor) < 0.000005F ) + if (fabs (SyncControl.SavedTimeCorrectionFactor - SyncControl.TimeCorrectionFactor) < 0.000005F ) { // DEBUG_V ("Nothing to save"); break; @@ -429,8 +463,8 @@ void c_InputFPPRemotePlayFile::SaveTimeCorrectionFactor () JsonObject JsonData = jsonDoc.createNestedObject ("x"); // JsonObject JsonData = jsonDoc.as (); - JsonData[CN_time] = TimeCorrectionFactor; - SavedTimeCorrectionFactor = TimeCorrectionFactor; + JsonData[CN_time] = SyncControl.TimeCorrectionFactor; + SyncControl.SavedTimeCorrectionFactor = SyncControl.TimeCorrectionFactor; // extern void PrettyPrint (JsonObject & jsonStuff, String Name); // PrettyPrint (JsonData, String ("SaveTimeCorrectionFactor")); @@ -445,3 +479,18 @@ void c_InputFPPRemotePlayFile::SaveTimeCorrectionFactor () // DEBUG_END; } // SaveTimeCorrectionFactor + +//----------------------------------------------------------------------------- +void c_InputFPPRemotePlayFile::ClearFileInfo() +{ + PlayItemName = String (""); + FrameControl.StartingFrameId = 0; + FrameControl.LastPlayedFrameId = 0; + RemainingPlayCount = 0; + SyncControl.LastRcvdSyncFrameId = 0; + FrameControl.DataOffset = 0; + FrameControl.ChannelsPerFrame = 0; + FrameControl.FrameStepTimeMS = 25; + FrameControl.TotalNumberOfFramesInSequence = 0; + FrameControl.ElapsedPlayTimeMS = 0; +} // ClearFileInfo diff --git a/ESPixelStick/src/input/InputFPPRemotePlayFile.hpp b/ESPixelStick/src/input/InputFPPRemotePlayFile.hpp index 0df906bc7..e5b9b8f20 100644 --- a/ESPixelStick/src/input/InputFPPRemotePlayFile.hpp +++ b/ESPixelStick/src/input/InputFPPRemotePlayFile.hpp @@ -23,6 +23,7 @@ #include "InputFPPRemotePlayItem.hpp" #include "InputFPPRemotePlayFileFsm.hpp" #include "../service/fseq.h" +#include class c_InputFPPRemotePlayFile : public c_InputFPPRemotePlayItem { @@ -36,16 +37,20 @@ class c_InputFPPRemotePlayFile : public c_InputFPPRemotePlayItem virtual void Poll (uint8_t* Buffer, size_t BufferSize); virtual void GetStatus (JsonObject & jsonStatus); virtual bool IsIdle () { return (pCurrentFsmState == &fsm_PlayFile_state_Idle_imp); } + + void IsrPoll (); - uint32_t GetLastFrameId () { return LastPlayedFrameId; } - float GetTimeCorrectionFactor () { return TimeCorrectionFactor; } + uint32_t GetLastFrameId () { return FrameControl.LastPlayedFrameId; } + float GetTimeCorrectionFactor () { return SyncControl.TimeCorrectionFactor; } private: #define INVALID_TIME_CORRECTION_FACTOR -1.0 #define INITIAL_TIME_CORRECTION_FACTOR 1.0 +#define ELAPSED_PLAY_TIMER_INTERVAL_MS 10 void InitTimeCorrectionFactor (); void SaveTimeCorrectionFactor (); + void ClearFileInfo (); friend class fsm_PlayFile_state_Idle; friend class fsm_PlayFile_state_Starting; @@ -61,23 +66,40 @@ class c_InputFPPRemotePlayFile : public c_InputFPPRemotePlayItem fsm_PlayFile_state * pCurrentFsmState = &fsm_PlayFile_state_Idle_imp; c_FileMgr::FileId FileHandleForFileBeingPlayed = 0; - uint32_t LastPlayedFrameId = 0; - uint32_t LastRcvdSyncFrameId = 0; - size_t DataOffset = 0; - uint32_t ChannelsPerFrame = 0; - time_t FrameStepTimeMS = 1; - uint32_t TotalNumberOfFramesInSequence = 0; - uint32_t StartTimeMS = 0; - double TimeCorrectionFactor = INITIAL_TIME_CORRECTION_FACTOR; - double SavedTimeCorrectionFactor = INVALID_TIME_CORRECTION_FACTOR; - uint32_t SyncCount = 0; - uint32_t SyncAdjustmentCount = 0; + + struct FrameControl_t + { + size_t DataOffset = 0; + uint32_t ChannelsPerFrame = 0; + time_t FrameStepTimeMS = 1; + uint32_t TotalNumberOfFramesInSequence = 0; + uint32_t ElapsedPlayTimeMS = 0; + + uint32_t StartingFrameId = 0; + uint32_t LastPlayedFrameId = 0; + } FrameControl; + + struct SyncControl_t + { + uint32_t SyncCount = 0; + uint32_t SyncAdjustmentCount = 0; + uint32_t LastRcvdSyncFrameId = 0; + + double TimeCorrectionFactor = INITIAL_TIME_CORRECTION_FACTOR; + double SavedTimeCorrectionFactor = INVALID_TIME_CORRECTION_FACTOR; + uint32_t AdjustedFrameStepTimeMS = 0; + } SyncControl; + + uint8_t * Buffer = nullptr; + size_t BufferSize = 0; + Ticker MsTicker; + uint32_t LastIsrTimeStampMS = 0; #define MAX_NUM_SPARSE_RANGES 5 FSEQParsedRangeEntry SparseRanges[MAX_NUM_SPARSE_RANGES]; - uint32_t CalculateFrameId (time_t now, int32_t SyncOffsetMS = 0); - void CalculatePlayStartTime (); + uint32_t CalculateFrameId (int32_t SyncOffsetMS = 0); + void CalculatePlayStartTime (uint32_t FrameId); bool ParseFseqFile (); String LastFailedPlayStatusMsg; diff --git a/ESPixelStick/src/input/InputFPPRemotePlayFileFsm.cpp b/ESPixelStick/src/input/InputFPPRemotePlayFileFsm.cpp index d3db686bb..b1843801e 100644 --- a/ESPixelStick/src/input/InputFPPRemotePlayFileFsm.cpp +++ b/ESPixelStick/src/input/InputFPPRemotePlayFileFsm.cpp @@ -22,7 +22,7 @@ #include "InputMgr.hpp" //----------------------------------------------------------------------------- -void fsm_PlayFile_state_Idle::Poll (uint8_t * Buffer, size_t BufferSize) +void fsm_PlayFile_state_Idle::Poll () { // DEBUG_START; @@ -32,45 +32,43 @@ void fsm_PlayFile_state_Idle::Poll (uint8_t * Buffer, size_t BufferSize) } // fsm_PlayFile_state_Idle::Poll +//----------------------------------------------------------------------------- +IRAM_ATTR void fsm_PlayFile_state_Idle::IsrPoll () +{ + // nothing to do + +} // fsm_PlayFile_state_Idle::IsrPoll + //----------------------------------------------------------------------------- void fsm_PlayFile_state_Idle::Init (c_InputFPPRemotePlayFile* Parent) { // DEBUG_START; - // DEBUG_V (String (" Parent: '") + String ((uint32_t)Parent) + "'"); - p_InputFPPRemotePlayFile = Parent; - Parent->pCurrentFsmState = &(Parent->fsm_PlayFile_state_Idle_imp); - - p_InputFPPRemotePlayFile->PlayItemName = String (""); - p_InputFPPRemotePlayFile->LastPlayedFrameId = 0; - p_InputFPPRemotePlayFile->RemainingPlayCount = 0; - p_InputFPPRemotePlayFile->LastRcvdSyncFrameId = 0; - p_InputFPPRemotePlayFile->DataOffset = 0; - p_InputFPPRemotePlayFile->ChannelsPerFrame = 0; - p_InputFPPRemotePlayFile->FrameStepTimeMS = 1; - p_InputFPPRemotePlayFile->TotalNumberOfFramesInSequence = 0; - p_InputFPPRemotePlayFile->StartTimeMS = 0; + // DEBUG_V (String (" Parent: 0x") + String ((uint32_t)Parent, HEX)); + p_Parent = Parent; + p_Parent->pCurrentFsmState = &(p_Parent->fsm_PlayFile_state_Idle_imp); + p_Parent->ClearFileInfo (); // DEBUG_END; } // fsm_PlayFile_state_Idle::Init //----------------------------------------------------------------------------- -void fsm_PlayFile_state_Idle::Start (String & FileName, uint32_t FrameId, uint32_t RemainingPlayCount) +void fsm_PlayFile_state_Idle::Start (String & FileName, uint32_t StartingFrameId, uint32_t RemainingPlayCount) { // DEBUG_START; // DEBUG_V (String ("FileName: ") + FileName); - p_InputFPPRemotePlayFile->PlayItemName = FileName; - p_InputFPPRemotePlayFile->LastPlayedFrameId = FrameId; - p_InputFPPRemotePlayFile->RemainingPlayCount = RemainingPlayCount; + p_Parent->PlayItemName = FileName; + p_Parent->FrameControl.StartingFrameId = StartingFrameId; + p_Parent->RemainingPlayCount = RemainingPlayCount; - // DEBUG_V (String (" FileName: ") + p_InputFPPRemotePlayFile->PlayItemName); - // DEBUG_V (String (" FrameId: ") + p_InputFPPRemotePlayFile->LastPlayedFrameId); - // DEBUG_V (String (" RemainingPlayCount: ") + p_InputFPPRemotePlayFile->RemainingPlayCount); + // DEBUG_V (String (" FileName: ") + p_Parent->PlayItemName); + // DEBUG_V (String (" StartingFrameId: ") + p_Parent->FrameControl.StartingFrameId); + // DEBUG_V (String (" RemainingPlayCount: ") + p_Parent->RemainingPlayCount); - p_InputFPPRemotePlayFile->fsm_PlayFile_state_Starting_imp.Init (p_InputFPPRemotePlayFile); + p_Parent->fsm_PlayFile_state_Starting_imp.Init (p_Parent); // DEBUG_END; @@ -103,23 +101,30 @@ bool fsm_PlayFile_state_Idle::Sync (String & FileName, uint32_t FrameId) //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -void fsm_PlayFile_state_Starting::Poll (uint8_t * Buffer, size_t BufferSize) +void fsm_PlayFile_state_Starting::Poll () { // DEBUG_START; - p_InputFPPRemotePlayFile->fsm_PlayFile_state_PlayingFile_imp.Init (p_InputFPPRemotePlayFile); - // DEBUG_V (String ("RemainingPlayCount: ") + p_InputFPPRemotePlayFile->RemainingPlayCount); + p_Parent->fsm_PlayFile_state_PlayingFile_imp.Init (p_Parent); + // DEBUG_V (String ("RemainingPlayCount: ") + p_Parent->RemainingPlayCount); // DEBUG_END; } // fsm_PlayFile_state_Starting::Poll +//----------------------------------------------------------------------------- +IRAM_ATTR void fsm_PlayFile_state_Starting::IsrPoll () +{ + // nothing to do + +} // fsm_PlayFile_state_Starting::IsrPoll + //----------------------------------------------------------------------------- void fsm_PlayFile_state_Starting::Init (c_InputFPPRemotePlayFile* Parent) { // DEBUG_START; - p_InputFPPRemotePlayFile = Parent; + p_Parent = Parent; Parent->pCurrentFsmState = &(Parent->fsm_PlayFile_state_Starting_imp); // DEBUG_END; @@ -132,10 +137,10 @@ void fsm_PlayFile_state_Starting::Start (String & FileName, uint32_t FrameId, ui // DEBUG_START; // DEBUG_V (String ("FileName: ") + FileName); - p_InputFPPRemotePlayFile->PlayItemName = FileName; - p_InputFPPRemotePlayFile->LastPlayedFrameId = FrameId; - p_InputFPPRemotePlayFile->RemainingPlayCount = RemainingPlayCount; - // DEBUG_V (String ("RemainingPlayCount: ") + p_InputFPPRemotePlayFile->RemainingPlayCount); + p_Parent->PlayItemName = FileName; + p_Parent->FrameControl.StartingFrameId = FrameId; + p_Parent->RemainingPlayCount = RemainingPlayCount; + // DEBUG_V (String ("RemainingPlayCount: ") + p_Parent->RemainingPlayCount); // DEBUG_END; @@ -146,11 +151,8 @@ void fsm_PlayFile_state_Starting::Stop (void) { // DEBUG_START; - p_InputFPPRemotePlayFile->PlayItemName = String(""); - p_InputFPPRemotePlayFile->LastPlayedFrameId = 0; - p_InputFPPRemotePlayFile->RemainingPlayCount = 0; - - p_InputFPPRemotePlayFile->fsm_PlayFile_state_Idle_imp.Init (p_InputFPPRemotePlayFile); + p_Parent->RemainingPlayCount = 0; + p_Parent->fsm_PlayFile_state_Idle_imp.Init (p_Parent); // DEBUG_END; @@ -172,55 +174,78 @@ bool fsm_PlayFile_state_Starting::Sync (String& FileName, uint32_t FrameId) //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -void fsm_PlayFile_state_PlayingFile::Poll (uint8_t* Buffer, size_t BufferSize) +void fsm_PlayFile_state_PlayingFile::Poll () { - // DEBUG_START; + // xDEBUG_START; do // once { - time_t now = millis (); - int32_t SyncOffset = p_InputFPPRemotePlayFile->GetSyncOffsetMS (); - uint32_t CurrentFrame = p_InputFPPRemotePlayFile->CalculateFrameId (now, SyncOffset); - // have we reached the end of the file? - if (p_InputFPPRemotePlayFile->TotalNumberOfFramesInSequence <= CurrentFrame) + if (p_Parent->FrameControl.TotalNumberOfFramesInSequence <= p_Parent->FrameControl.LastPlayedFrameId) { - // DEBUG_V (String ("RemainingPlayCount: ") + p_InputFPPRemotePlayFile->RemainingPlayCount); - if (0 != p_InputFPPRemotePlayFile->RemainingPlayCount) + // DEBUG_V (String ("RemainingPlayCount: ") + p_Parent->RemainingPlayCount); + if (0 != p_Parent->RemainingPlayCount) { - // DEBUG_V (String ("RemainingPlayCount: ") + String (p_InputFPPRemotePlayFile->RemainingPlayCount)); - logcon (String ("Replaying:: FileName: '") + p_InputFPPRemotePlayFile->GetFileName () + "'"); - --p_InputFPPRemotePlayFile->RemainingPlayCount; - // DEBUG_V (String ("RemainingPlayCount: ") + p_InputFPPRemotePlayFile->RemainingPlayCount); - - p_InputFPPRemotePlayFile->StartTimeMS = now; - p_InputFPPRemotePlayFile->LastPlayedFrameId = -1; - CurrentFrame = 0; + // DEBUG_V (String ("RemainingPlayCount: ") + String (p_Parent->RemainingPlayCount)); + logcon (String ("Replaying:: FileName: '") + p_Parent->GetFileName () + "'"); + --p_Parent->RemainingPlayCount; + // DEBUG_V (String ("RemainingPlayCount: ") + p_Parent->RemainingPlayCount); + + p_Parent->FrameControl.LastPlayedFrameId = 0; + p_Parent->CalculatePlayStartTime (0); } else { - // DEBUG_V (String ("TotalNumberOfFramesInSequence: ") + String (p_InputFPPRemotePlayFile->TotalNumberOfFramesInSequence)); - // DEBUG_V (String (" CurrentFrame: ") + String (CurrentFrame)); - // DEBUG_V (String (" Done Playing:: FileName: '") + p_InputFPPRemotePlayFile->GetFileName () + "'"); + // DEBUG_V (String ("TotalNumberOfFramesInSequence: ") + String (p_Parent->TotalNumberOfFramesInSequence)); + // DEBUG_V (String (" Done Playing:: FileName: '") + p_Parent->GetFileName () + "'"); Stop (); break; } } - if (CurrentFrame == p_InputFPPRemotePlayFile->LastPlayedFrameId) + InputMgr.RestartBlankTimer (p_Parent->GetInputChannelId ()); + + } while (false); + + // xDEBUG_END; + +} // fsm_PlayFile_state_PlayingFile::Poll + +//----------------------------------------------------------------------------- +IRAM_ATTR void fsm_PlayFile_state_PlayingFile::IsrPoll () +{ + // xDEBUG_START; + + do // once + { + int32_t SyncOffsetMS = p_Parent->GetSyncOffsetMS (); + uint32_t CurrentFrame = p_Parent->CalculateFrameId (SyncOffsetMS); + + // xDEBUG_V (String ("TotalNumberOfFramesInSequence: ") + String (p_Parent->TotalNumberOfFramesInSequence)); + // xDEBUG_V (String (" CurrentFrame: ") + String (CurrentFrame)); + + // have we reached the end of the file? + if (p_Parent->FrameControl.TotalNumberOfFramesInSequence <= CurrentFrame) { - // DEBUG_V (String ("keep waiting")); + // trigger the background task to stop playing this file + p_Parent->FrameControl.LastPlayedFrameId = CurrentFrame; break; } - uint32_t FilePosition = p_InputFPPRemotePlayFile->DataOffset + (p_InputFPPRemotePlayFile->ChannelsPerFrame * CurrentFrame); - size_t MaxBytesToRead = (p_InputFPPRemotePlayFile->ChannelsPerFrame > BufferSize) ? BufferSize : p_InputFPPRemotePlayFile->ChannelsPerFrame; - byte* CurrentDestination = Buffer; - // DEBUG_V (String (" MaxBytesToRead: ") + String (MaxBytesToRead)); + if (CurrentFrame == p_Parent->FrameControl.LastPlayedFrameId) + { + // xDEBUG_V (String ("keep waiting")); + break; + } + + uint32_t FilePosition = p_Parent->FrameControl.DataOffset + (p_Parent->FrameControl.ChannelsPerFrame * CurrentFrame); + size_t MaxBytesToRead = (p_Parent->FrameControl.ChannelsPerFrame > p_Parent->BufferSize) ? p_Parent->BufferSize : p_Parent->FrameControl.ChannelsPerFrame; + byte * CurrentDestination = p_Parent->Buffer; + // xDEBUG_V (String (" MaxBytesToRead: ") + String (MaxBytesToRead)); - p_InputFPPRemotePlayFile->LastPlayedFrameId = CurrentFrame; + p_Parent->FrameControl.LastPlayedFrameId = CurrentFrame; - for (auto & CurrentSparseRange : p_InputFPPRemotePlayFile->SparseRanges) + for (auto& CurrentSparseRange : p_Parent->SparseRanges) { size_t ActualBytesToRead = min (MaxBytesToRead, CurrentSparseRange.ChannelCount); if (0 == ActualBytesToRead) @@ -231,82 +256,78 @@ void fsm_PlayFile_state_PlayingFile::Poll (uint8_t* Buffer, size_t BufferSize) uint32_t AdjustedFilePosition = FilePosition + CurrentSparseRange.DataOffset; - // DEBUG_V (String (" FilePosition: ") + String (FilePosition)); - // DEBUG_V (String (" AdjustedFilePosition: ") + String (uint32_t(AdjustedFilePosition), HEX)); - // DEBUG_V (String (" CurrentDestination: ") + String (uint32_t(CurrentDestination), HEX)); - // DEBUG_V (String (" ActualBytesToRead: ") + String (ActualBytesToRead)); - size_t ActualBytesRead = FileMgr.ReadSdFile (p_InputFPPRemotePlayFile->FileHandleForFileBeingPlayed, - CurrentDestination, - ActualBytesToRead, - AdjustedFilePosition); + // xDEBUG_V (String (" FilePosition: ") + String (FilePosition)); + // xDEBUG_V (String (" AdjustedFilePosition: ") + String (uint32_t(AdjustedFilePosition), HEX)); + // xDEBUG_V (String (" CurrentDestination: ") + String (uint32_t(CurrentDestination), HEX)); + // xDEBUG_V (String (" ActualBytesToRead: ") + String (ActualBytesToRead)); + size_t ActualBytesRead = FileMgr.ReadSdFile (p_Parent->FileHandleForFileBeingPlayed, + CurrentDestination, + ActualBytesToRead, + AdjustedFilePosition); MaxBytesToRead -= ActualBytesRead; CurrentDestination += ActualBytesRead; if (ActualBytesRead != ActualBytesToRead) { - // DEBUG_V (String ("TotalNumberOfFramesInSequence: ") + String (p_InputFPPRemotePlayFile->TotalNumberOfFramesInSequence)); - // DEBUG_V (String (" CurrentFrame: ") + String (CurrentFrame)); + // xDEBUG_V (String ("TotalNumberOfFramesInSequence: ") + String (p_Parent->TotalNumberOfFramesInSequence)); + // xDEBUG_V (String (" CurrentFrame: ") + String (CurrentFrame)); - if (0 != p_InputFPPRemotePlayFile->FileHandleForFileBeingPlayed) + if (0 != p_Parent->FileHandleForFileBeingPlayed) { - logcon (F ("File Playback Failed to read enough data")); + // logcon (F ("File Playback Failed to read enough data")); Stop (); } } } - // DEBUG_V (String (" DataOffset: ") + String (p_InputFPPRemotePlayFile->DataOffset)); - // DEBUG_V (String (" BufferSize: ") + String (BufferSize)); - // DEBUG_V (String ("ChannelsPerFrame: ") + String (p_InputFPPRemotePlayFile->ChannelsPerFrame)); - // DEBUG_V (String (" FilePosition: ") + String (FilePosition)); - // DEBUG_V (String (" MaxBytesToRead: ") + String (MaxBytesToRead)); - // DEBUG_V (String ("GetInputChannelId: ") + String (p_InputFPPRemotePlayFile->GetInputChannelId ())); - - InputMgr.RestartBlankTimer (p_InputFPPRemotePlayFile->GetInputChannelId ()); + // xDEBUG_V (String (" DataOffset: ") + String (p_Parent->DataOffset)); + // xDEBUG_V (String (" BufferSize: ") + String (p_Parent->BufferSize)); + // xDEBUG_V (String (" ChannelsPerFrame: ") + String (p_Parent->ChannelsPerFrame)); + // xDEBUG_V (String (" FilePosition: ") + String (FilePosition)); + // xDEBUG_V (String (" MaxBytesToRead: ") + String (MaxBytesToRead)); + // xDEBUG_V (String ("GetInputChannelId: ") + String (p_Parent->GetInputChannelId ())); } while (false); - // DEBUG_END; - -} // fsm_PlayFile_state_PlayingFile::Poll +} // fsm_PlayFile_state_PlayingFile::IsrPoll //----------------------------------------------------------------------------- void fsm_PlayFile_state_PlayingFile::Init (c_InputFPPRemotePlayFile* Parent) { // DEBUG_START; - p_InputFPPRemotePlayFile = Parent; - Parent->pCurrentFsmState = &(Parent->fsm_PlayFile_state_PlayingFile_imp); + p_Parent = Parent; do // once { - // DEBUG_V (String ("FileName: '") + p_InputFPPRemotePlayFile->PlayItemName + "'"); - // DEBUG_V (String (" FrameId: '") + p_InputFPPRemotePlayFile->LastPlayedFrameId + "'"); - // DEBUG_V (String ("RemainingPlayCount: ") + p_InputFPPRemotePlayFile->RemainingPlayCount); - if (0 == p_InputFPPRemotePlayFile->RemainingPlayCount) + // DEBUG_V (String ("FileName: '") + p_Parent->PlayItemName + "'"); + // DEBUG_V (String (" FrameId: '") + p_Parent->LastPlayedFrameId + "'"); + // DEBUG_V (String ("RemainingPlayCount: ") + p_Parent->RemainingPlayCount); + if (0 == p_Parent->RemainingPlayCount) { Stop (); break; } - --p_InputFPPRemotePlayFile->RemainingPlayCount; - // DEBUG_V (String ("RemainingPlayCount: ") + p_InputFPPRemotePlayFile->RemainingPlayCount); + --p_Parent->RemainingPlayCount; + // DEBUG_V (String ("RemainingPlayCount: ") + p_Parent->RemainingPlayCount); - if (!p_InputFPPRemotePlayFile->ParseFseqFile ()) + if (!p_Parent->ParseFseqFile ()) { - p_InputFPPRemotePlayFile->fsm_PlayFile_state_Stopping_imp.Init (p_InputFPPRemotePlayFile); + p_Parent->fsm_PlayFile_state_Stopping_imp.Init (p_Parent); break; } - p_InputFPPRemotePlayFile->CalculatePlayStartTime (); + p_Parent->CalculatePlayStartTime (p_Parent->FrameControl.StartingFrameId); - // DEBUG_V (String (" LastPlayedFrameId: ") + String (p_InputFPPRemotePlayFile->LastPlayedFrameId)); - // DEBUG_V (String (" StartTimeMS: ") + String (p_InputFPPRemotePlayFile->StartTimeMS)); - // DEBUG_V (String (" RemainingPlayCount: ") + p_InputFPPRemotePlayFile->RemainingPlayCount); + // DEBUG_V (String (" LastPlayedFrameId: ") + String (p_Parent->LastPlayedFrameId)); + // DEBUG_V (String (" StartTimeMS: ") + String (p_Parent->StartTimeMS)); + // DEBUG_V (String (" RemainingPlayCount: ") + p_Parent->RemainingPlayCount); - logcon (String (F ("Start Playing:: FileName: '")) + p_InputFPPRemotePlayFile->PlayItemName + "'"); + logcon (String (F ("Start Playing:: FileName: '")) + p_Parent->PlayItemName + "'"); Parent->pCurrentFsmState = &(Parent->fsm_PlayFile_state_PlayingFile_imp); + Parent->FrameControl.ElapsedPlayTimeMS = 0; } while (false); @@ -320,12 +341,12 @@ void fsm_PlayFile_state_PlayingFile::Start (String& FileName, uint32_t FrameId, // DEBUG_START; // DEBUG_V (String (" FileName: ") + FileName); - // DEBUG_V (String (" LastPlayedFrameId: ") + String (p_InputFPPRemotePlayFile->LastPlayedFrameId)); - // DEBUG_V (String ("TotalNumberOfFramesInSequence: ") + String (p_InputFPPRemotePlayFile->TotalNumberOfFramesInSequence)); - // DEBUG_V (String ("RemainingPlayCount: ") + p_InputFPPRemotePlayFile->RemainingPlayCount); + // DEBUG_V (String (" LastPlayedFrameId: ") + String (p_Parent->LastPlayedFrameId)); + // DEBUG_V (String ("TotalNumberOfFramesInSequence: ") + String (p_Parent->TotalNumberOfFramesInSequence)); + // DEBUG_V (String ("RemainingPlayCount: ") + p_Parent->RemainingPlayCount); Stop (); - p_InputFPPRemotePlayFile->Start (FileName, FrameId, PlayCount); + p_Parent->Start (FileName, FrameId, PlayCount); // DEBUG_END; @@ -336,13 +357,12 @@ void fsm_PlayFile_state_PlayingFile::Stop (void) { // DEBUG_START; - logcon (String (F ("Stop Playing:: FileName: '")) + p_InputFPPRemotePlayFile->PlayItemName + "'"); - // DEBUG_V (String (" FileHandleForFileBeingPlayed: ") + String (FileHandleForFileBeingPlayed)); - // DEBUG_V (String (" LastPlayedFrameId: ") + String (p_InputFPPRemotePlayFile->LastPlayedFrameId)); - // DEBUG_V (String ("TotalNumberOfFramesInSequence: ") + String (p_InputFPPRemotePlayFile->TotalNumberOfFramesInSequence)); - // DEBUG_V (String ("RemainingPlayCount: ") + p_InputFPPRemotePlayFile->RemainingPlayCount); + logcon (String (F ("Stop Playing:: FileName: '")) + p_Parent->PlayItemName + "'"); + // DEBUG_V (String (" LastPlayedFrameId: ") + String (p_Parent->LastPlayedFrameId)); + // DEBUG_V (String ("TotalNumberOfFramesInSequence: ") + String (p_Parent->TotalNumberOfFramesInSequence)); + // DEBUG_V (String (" RemainingPlayCount: ") + p_Parent->RemainingPlayCount); - p_InputFPPRemotePlayFile->fsm_PlayFile_state_Stopping_imp.Init (p_InputFPPRemotePlayFile); + p_Parent->fsm_PlayFile_state_Stopping_imp.Init (p_Parent); // DEBUG_END; @@ -357,24 +377,22 @@ bool fsm_PlayFile_state_PlayingFile::Sync (String& FileName, uint32_t TargetFram do // once { // are we on the correct file? - if (FileName != p_InputFPPRemotePlayFile->GetFileName ()) + if (FileName != p_Parent->GetFileName ()) { // DEBUG_V ("Sync: Filename change"); Stop (); - p_InputFPPRemotePlayFile->Start (FileName, TargetFrameId, 1); + p_Parent->Start (FileName, TargetFrameId, 1); break; } - if (p_InputFPPRemotePlayFile->LastRcvdSyncFrameId >= TargetFrameId) + if (p_Parent->SyncControl.LastRcvdSyncFrameId >= TargetFrameId) { // DEBUG_V ("Duplicate or older sync msg"); break; } - p_InputFPPRemotePlayFile->LastRcvdSyncFrameId = TargetFrameId; - - time_t now = millis (); + p_Parent->SyncControl.LastRcvdSyncFrameId = TargetFrameId; - uint32_t CurrentFrame = p_InputFPPRemotePlayFile->CalculateFrameId (now); + uint32_t CurrentFrame = p_Parent->CalculateFrameId (); uint32_t FrameDiff = CurrentFrame - TargetFrameId; if (CurrentFrame < TargetFrameId) @@ -393,22 +411,23 @@ bool fsm_PlayFile_state_PlayingFile::Sync (String& FileName, uint32_t TargetFram } // DEBUG_V ("Need to adjust the start time"); - // DEBUG_V (String ("StartTimeMS: ") + String (p_InputFPPRemotePlayFile->StartTimeMS)); + // DEBUG_V (String ("StartTimeMS: ") + String (p_Parent->StartTimeMS)); if (CurrentFrame > TargetFrameId) { - p_InputFPPRemotePlayFile->TimeCorrectionFactor += TimeOffsetStep; + // p_Parent->SyncControl.TimeCorrectionFactor += TimeOffsetStep; } else { - p_InputFPPRemotePlayFile->TimeCorrectionFactor -= TimeOffsetStep; + // p_Parent->SyncControl.TimeCorrectionFactor -= TimeOffsetStep; } + // p_Parent->SyncControl.AdjustedFrameStepTimeMS = uint32_t (float (p_Parent->FrameControl.FrameStepTimeMS) * p_Parent->SyncControl.TimeCorrectionFactor); - p_InputFPPRemotePlayFile->LastPlayedFrameId = TargetFrameId-1; - // p_InputFPPRemotePlayFile->CalculatePlayStartTime (); + // p_Parent->LastPlayedFrameId = TargetFrameId-1; + p_Parent->CalculatePlayStartTime (TargetFrameId); response = true; - // DEBUG_V (String ("StartTimeMS: ") + String (p_InputFPPRemotePlayFile->StartTimeMS)); + // DEBUG_V (String ("StartTimeMS: ") + String (p_Parent->StartTimeMS)); } while (false); @@ -420,37 +439,44 @@ bool fsm_PlayFile_state_PlayingFile::Sync (String& FileName, uint32_t TargetFram //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -void fsm_PlayFile_state_Stopping::Poll (uint8_t* Buffer, size_t BufferSize) +void fsm_PlayFile_state_Stopping::Poll () { // DEBUG_START; - // DEBUG_V (String ("FileHandleForFileBeingPlayed: ") + String (p_InputFPPRemotePlayFile->FileHandleForFileBeingPlayed)); + // DEBUG_V (String ("FileHandleForFileBeingPlayed: ") + String (p_Parent->FileHandleForFileBeingPlayed)); - FileMgr.CloseSdFile (p_InputFPPRemotePlayFile->FileHandleForFileBeingPlayed); - p_InputFPPRemotePlayFile->FileHandleForFileBeingPlayed = 0; - p_InputFPPRemotePlayFile->PlayItemName = String (""); - p_InputFPPRemotePlayFile->SaveTimeCorrectionFactor (); - p_InputFPPRemotePlayFile->fsm_PlayFile_state_Idle_imp.Init (p_InputFPPRemotePlayFile); + FileMgr.CloseSdFile (p_Parent->FileHandleForFileBeingPlayed); + p_Parent->FileHandleForFileBeingPlayed = 0; + p_Parent->SaveTimeCorrectionFactor (); + p_Parent->fsm_PlayFile_state_Idle_imp.Init (p_Parent); if (FileName != "") { - p_InputFPPRemotePlayFile->Start (FileName, FrameId, PlayCount); + // DEBUG_V ("Restarting File"); + p_Parent->Start (FileName, StartingFrameId, PlayCount); } // DEBUG_END; } // fsm_PlayFile_state_Stopping::Poll +//----------------------------------------------------------------------------- +IRAM_ATTR void fsm_PlayFile_state_Stopping::IsrPoll () +{ + // nothing to do + +} // fsm_PlayFile_state_Stopping::IsrPoll + //----------------------------------------------------------------------------- void fsm_PlayFile_state_Stopping::Init (c_InputFPPRemotePlayFile* Parent) { // DEBUG_START; - FileName = ""; - FrameId = 0; - PlayCount = 0; + FileName = ""; + StartingFrameId = 0; + PlayCount = 0; - p_InputFPPRemotePlayFile = Parent; + p_Parent = Parent; Parent->pCurrentFsmState = &(Parent->fsm_PlayFile_state_Stopping_imp); // DEBUG_END; @@ -462,9 +488,9 @@ void fsm_PlayFile_state_Stopping::Start (String& _FileName, uint32_t _FrameId, u { // DEBUG_START; - FileName = _FileName; - FrameId = _FrameId; - PlayCount = _PlayCount; + FileName = _FileName; + StartingFrameId = _FrameId; + PlayCount = _PlayCount; // DEBUG_END @@ -483,10 +509,8 @@ void fsm_PlayFile_state_Stopping::Stop (void) bool fsm_PlayFile_state_Stopping::Sync (String& FileName, uint32_t TargetFrameId) { // DEBUG_START; - bool response = false; - // DEBUG_END; - return response; + return false; } // fsm_PlayFile_state_Stopping::Sync diff --git a/ESPixelStick/src/input/InputFPPRemotePlayFileFsm.hpp b/ESPixelStick/src/input/InputFPPRemotePlayFileFsm.hpp index 1213ee8c8..66a718529 100644 --- a/ESPixelStick/src/input/InputFPPRemotePlayFileFsm.hpp +++ b/ESPixelStick/src/input/InputFPPRemotePlayFileFsm.hpp @@ -33,16 +33,17 @@ class c_InputFPPRemotePlayFile; class fsm_PlayFile_state { public: - virtual void Poll (uint8_t * Buffer, size_t BufferSize) = 0; + virtual void Poll () = 0; virtual void Init (c_InputFPPRemotePlayFile * Parent) = 0; virtual void GetStateName (String & sName) = 0; virtual void Start (String & FileName, uint32_t FrameId, uint32_t RemainingPlayCount) = 0; virtual void Stop (void) = 0; virtual bool Sync (String& FileName, uint32_t FrameId) = 0; void GetDriverName (String& Name) { Name = "InputMgr"; } + virtual IRAM_ATTR void IsrPoll (); protected: - c_InputFPPRemotePlayFile * p_InputFPPRemotePlayFile = nullptr; + c_InputFPPRemotePlayFile * p_Parent = nullptr; }; // fsm_PlayFile_state @@ -50,12 +51,13 @@ class fsm_PlayFile_state class fsm_PlayFile_state_Idle : public fsm_PlayFile_state { public: - virtual void Poll (uint8_t * Buffer, size_t BufferSize); + virtual void Poll (); virtual void Init (c_InputFPPRemotePlayFile* Parent); virtual void GetStateName (String & sName) { sName = CN_Idle; } virtual void Start (String & FileName, uint32_t FrameId, uint32_t RemainingPlayCount); virtual void Stop (void); virtual bool Sync (String& FileName, uint32_t FrameId); + virtual IRAM_ATTR void IsrPoll (); }; // fsm_PlayFile_state_Idle @@ -63,12 +65,13 @@ class fsm_PlayFile_state_Idle : public fsm_PlayFile_state class fsm_PlayFile_state_Starting : public fsm_PlayFile_state { public: - virtual void Poll (uint8_t* Buffer, size_t BufferSize); + virtual void Poll (); virtual void Init (c_InputFPPRemotePlayFile* Parent); virtual void GetStateName (String& sName) { sName = F ("Starting"); } virtual void Start (String& FileName, uint32_t FrameId, uint32_t RemainingPlayCount); virtual void Stop (void); virtual bool Sync (String& FileName, uint32_t FrameId); + virtual IRAM_ATTR void IsrPoll (); }; // fsm_PlayFile_state_Starting @@ -76,12 +79,14 @@ class fsm_PlayFile_state_Starting : public fsm_PlayFile_state class fsm_PlayFile_state_PlayingFile : public fsm_PlayFile_state { public: - virtual void Poll (uint8_t * Buffer, size_t BufferSize); + virtual void Poll (); virtual void Init (c_InputFPPRemotePlayFile* Parent); virtual void GetStateName (String & sName) { sName = CN_File; } virtual void Start (String & FileName, uint32_t FrameId, uint32_t RemainingPlayCount); virtual void Stop (void); virtual bool Sync (String & FileName, uint32_t FrameId); + virtual IRAM_ATTR void IsrPoll (); + private: struct SparseRange { @@ -95,16 +100,17 @@ class fsm_PlayFile_state_PlayingFile : public fsm_PlayFile_state class fsm_PlayFile_state_Stopping : public fsm_PlayFile_state { public: - virtual void Poll (uint8_t* Buffer, size_t BufferSize); + virtual void Poll (); virtual void Init (c_InputFPPRemotePlayFile* Parent); virtual void GetStateName (String& sName) { sName = F("Stopping"); } virtual void Start (String& FileName, uint32_t FrameId, uint32_t RemainingPlayCount); virtual void Stop (void); virtual bool Sync (String& FileName, uint32_t FrameId); + virtual IRAM_ATTR void IsrPoll (); private: - String FileName = ""; - uint32_t FrameId = 0; - uint32_t PlayCount = 0; + String FileName = ""; + uint32_t StartingFrameId = 0; + uint32_t PlayCount = 0; }; // fsm_PlayFile_state_Stopping diff --git a/ESPixelStick/src/service/FPPDiscovery.h b/ESPixelStick/src/service/FPPDiscovery.h index 2be3443d3..bb4846955 100644 --- a/ESPixelStick/src/service/FPPDiscovery.h +++ b/ESPixelStick/src/service/FPPDiscovery.h @@ -112,6 +112,8 @@ class c_FPPDiscovery void Disable (void); void GetStatus (JsonObject& jsonStatus); void NetworkStateChanged (bool NewNetworkState); + void SetSyncOffsetMS (int32_t value) { InputFPPRemotePlayFile.SetSyncOffsetMS (value); } + }; extern c_FPPDiscovery FPPDiscovery;