Skip to content

Commit

Permalink
Complete restructure of the way Input data is processed.
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinMueller2003 committed Jan 5, 2025
1 parent dd5375c commit 5a1649c
Show file tree
Hide file tree
Showing 15 changed files with 472 additions and 511 deletions.
4 changes: 2 additions & 2 deletions include/input/InputFPPRemote.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ class c_InputFPPRemote : public c_InputCommon
void GetDriverName (String& sDriverName) { sDriverName = "FPP Remote"; } ///< get the name for the instantiated driver
void SetBufferInfo (uint32_t BufferSize);
void ProcessButtonActions(c_ExternalInput::InputValue_t value);
void SetOperationalState (bool ActiveFlag);

protected:
# define No_LocalFileToPlay "..."
# define FPP_REMOTE_TASK_PRIORITY 6

c_InputFPPRemotePlayItem * pInputFPPRemotePlayItem = nullptr;
int32_t GetSyncOffsetMS () { return SyncOffsetMS; }
bool GetSendFppSync () { return SendFppSync; }
bool GetSendFppSync () { return SendFppSync; }

String StatusType;

Expand Down
26 changes: 1 addition & 25 deletions include/input/InputFPPRemotePlayFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@
#include "InputFPPRemotePlayItem.hpp"
#include "InputFPPRemotePlayFileFsm.hpp"
#include "service/fseq.h"
#include <Ticker.h>

#ifdef ARDUINO_ARCH_ESP32
#include <esp_task.h>
#endif // def ARDUINO_ARCH_ESP32


class c_InputFPPRemotePlayFile : public c_InputFPPRemotePlayItem
{
public:
Expand All @@ -43,7 +41,6 @@ class c_InputFPPRemotePlayFile : public c_InputFPPRemotePlayItem
virtual void GetStatus (JsonObject & jsonStatus);
virtual bool IsIdle () { return (pCurrentFsmState == &fsm_PlayFile_state_Idle_imp); }

void TimerPoll ();
#ifdef ARDUINO_ARCH_ESP32
TaskHandle_t GetTaskHandle () { return TimerPollTaskHandle; }
volatile bool TimerPollInProgress = false;
Expand All @@ -52,7 +49,7 @@ class c_InputFPPRemotePlayFile : public c_InputFPPRemotePlayItem
private:
#define ELAPSED_PLAY_TIMER_INTERVAL_MS 10

void ClearFileInfo ();
void ClearFileInfo ();

friend class fsm_PlayFile_state_Idle;
friend class fsm_PlayFile_state_Starting;
Expand All @@ -69,36 +66,15 @@ class c_InputFPPRemotePlayFile : public c_InputFPPRemotePlayItem

fsm_PlayFile_state * pCurrentFsmState = &fsm_PlayFile_state_Idle_imp;

c_FileMgr::FileId FileHandleForFileBeingPlayed = c_FileMgr::INVALID_FILE_HANDLE;

struct FrameControl_t
{
uint32_t DataOffset = 0;
uint32_t ChannelsPerFrame = 0;
uint32_t FrameStepTimeMS = 1;
uint32_t TotalNumberOfFramesInSequence = 0;
uint32_t ElapsedPlayTimeMS = 0;

} FrameControl;

struct SyncControl_t
{
uint32_t SyncCount = 0;
uint32_t SyncAdjustmentCount = 0;
float LastRcvdElapsedSeconds = 0.0;
} SyncControl;

# define FPP_TICKER_PERIOD_MS 25
// # define FPP_TICKER_PERIOD_MS 1000
Ticker MsTicker;
uint32_t LastIsrTimeStampMS = 0;
uint32_t PlayedFileCount = 0;

// Logic to detect if polls have stopped coming in.
// This is part of the blanking logic.
int PollDetectionCounter = 0;
static const int PollDetectionCounterLimit = 5;

#define MAX_NUM_SPARSE_RANGES 5
FSEQParsedRangeEntry SparseRanges[MAX_NUM_SPARSE_RANGES];

Expand Down
23 changes: 7 additions & 16 deletions include/input/InputFPPRemotePlayFileFsm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ class fsm_PlayFile_state
fsm_PlayFile_state() {}
virtual ~fsm_PlayFile_state() {}

virtual bool Poll () = 0;
virtual IRAM_ATTR bool Poll () = 0;
virtual void Init (c_InputFPPRemotePlayFile * Parent) = 0;
virtual void GetStateName (String & sName) = 0;
virtual void Start (String & FileName, float SecondsElapsed, uint32_t RemainingPlayCount) = 0;
virtual void Stop (void) = 0;
virtual bool Sync (String& FileName, float SecondsElapsed) = 0;
void GetDriverName (String& Name) { Name = "InputMgr"; }
virtual IRAM_ATTR void TimerPoll () = 0;

protected:
c_InputFPPRemotePlayFile * p_Parent = nullptr;
Expand All @@ -57,13 +56,12 @@ class fsm_PlayFile_state_Idle : public fsm_PlayFile_state
fsm_PlayFile_state_Idle() {}
virtual ~fsm_PlayFile_state_Idle() {}

virtual bool Poll ();
virtual IRAM_ATTR bool Poll ();
virtual void Init (c_InputFPPRemotePlayFile* Parent);
virtual void GetStateName (String & sName) { sName = CN_Idle; }
virtual void Start (String & FileName, float SecondsElapsed, uint32_t RemainingPlayCount);
virtual void Stop (void);
virtual bool Sync (String& FileName, float SecondsElapsed);
virtual IRAM_ATTR void TimerPoll ();

}; // fsm_PlayFile_state_Idle

Expand All @@ -74,13 +72,12 @@ class fsm_PlayFile_state_Starting : public fsm_PlayFile_state
fsm_PlayFile_state_Starting() {}
virtual ~fsm_PlayFile_state_Starting() {}

virtual bool Poll ();
virtual IRAM_ATTR bool Poll ();
virtual void Init (c_InputFPPRemotePlayFile* Parent);
virtual void GetStateName (String& sName) { sName = F ("Starting"); }
virtual void Start (String& FileName, float SecondsElapsed, uint32_t RemainingPlayCount);
virtual void Stop (void);
virtual bool Sync (String& FileName, float SecondsElapsed);
virtual IRAM_ATTR void TimerPoll ();

}; // fsm_PlayFile_state_Starting

Expand All @@ -91,21 +88,20 @@ class fsm_PlayFile_state_PlayingFile : public fsm_PlayFile_state
fsm_PlayFile_state_PlayingFile() {}
virtual ~fsm_PlayFile_state_PlayingFile() {}

virtual bool Poll ();
virtual IRAM_ATTR bool Poll ();
virtual void Init (c_InputFPPRemotePlayFile* Parent);
virtual void GetStateName (String & sName) { sName = CN_File; }
virtual void Start (String & FileName, float SecondsElapsed, uint32_t RemainingPlayCount);
virtual void Stop (void);
virtual bool Sync (String & FileName, float SecondsElapsed);
virtual IRAM_ATTR void TimerPoll ();

private:
struct SparseRange
{
uint32_t DataOffset;
uint32_t ChannelCount;
};
uint32_t LastPlayedFrameId = 0;
// uint32_t LastPlayedFrameId = 0;

}; // fsm_PlayFile_state_PlayingFile

Expand All @@ -116,18 +112,14 @@ class fsm_PlayFile_state_Stopping : public fsm_PlayFile_state
fsm_PlayFile_state_Stopping() {}
virtual ~fsm_PlayFile_state_Stopping() {}

virtual bool Poll ();
virtual IRAM_ATTR bool Poll ();
virtual void Init (c_InputFPPRemotePlayFile* Parent);
virtual void GetStateName (String& sName) { sName = F("Stopping"); }
virtual void Start (String& FileName, float SecondsElapsed, uint32_t RemainingPlayCount);
virtual void Stop (void);
virtual bool Sync (String& FileName, float SecondsElapsed);
virtual IRAM_ATTR void TimerPoll ();

private:
String FileName = "";
uint32_t StartingElapsedTime = 0.0;
uint32_t PlayCount = 0;

}; // fsm_PlayFile_state_Stopping

Expand All @@ -138,13 +130,12 @@ class fsm_PlayFile_state_Error : public fsm_PlayFile_state
fsm_PlayFile_state_Error() {}
virtual ~fsm_PlayFile_state_Error() {}

virtual bool Poll ();
virtual IRAM_ATTR bool Poll ();
virtual void Init (c_InputFPPRemotePlayFile* Parent);
virtual void GetStateName (String& sName) { sName = F ("Error"); }
virtual void Start (String& FileName, float SecondsElapsed, uint32_t RemainingPlayCount);
virtual void Stop (void);
virtual bool Sync (String& FileName, float SecondsElapsed);
virtual IRAM_ATTR void TimerPoll ();

private:

Expand Down
42 changes: 31 additions & 11 deletions include/input/InputFPPRemotePlayItem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,52 @@

class c_InputFPPRemotePlayItem
{
protected:
time_t PlayDurationSec = 0;
bool SendFppSync = false;

private:
bool InputPaused = false;
int32_t SyncOffsetMS = 0;
c_InputMgr::e_InputChannelIds InputChannelId = c_InputMgr::e_InputChannelIds::InputChannelId_ALL;

public:
c_InputFPPRemotePlayItem (c_InputMgr::e_InputChannelIds InputChannelId);
virtual ~c_InputFPPRemotePlayItem ();

struct FileControl_t
{
String FileName;
c_FileMgr::FileId FileHandleForFileBeingPlayed = c_FileMgr::INVALID_FILE_HANDLE;
uint32_t RemainingPlayCount = 0;
uint32_t DataOffset = 0;
uint32_t ChannelsPerFrame = 0;
uint32_t FrameStepTimeMS = 25;
uint32_t TotalNumberOfFramesInSequence = 0;
uint32_t ElapsedPlayTimeMS = 0;
uint32_t StartingTimeMS = 0;
uint32_t LastPollTimeMS = 0;
uint32_t LastPlayedFrameId = 0;
} FileControl[2];
#define CurrentFile 0
#define NextFile 1

virtual bool Poll () = 0;
virtual void Start (String & FileName, float SecondsElapsed, uint32_t RemainingPlayCount) = 0;
virtual void Stop () = 0;
virtual void SetPauseState (bool _PauseInput) {InputPaused = _PauseInput;}
virtual void Sync (String & FileName, float SecondsElapsed) = 0;
virtual void GetStatus (JsonObject & jsonStatus) = 0;
virtual bool IsIdle () = 0;
String GetFileName () { return PlayItemName; }
uint32_t GetRepeatCount () { return RemainingPlayCount; }
String GetFileName () { return FileControl[CurrentFile].FileName; }
uint32_t GetRepeatCount () { return FileControl[CurrentFile].RemainingPlayCount; }
void SetDuration (time_t value) { PlayDurationSec = value; }
void GetDriverName (String& Name) { Name = "InputMgr"; }
int32_t GetSyncOffsetMS () { return SyncOffsetMS; }
void SetSyncOffsetMS (int32_t value) { SyncOffsetMS = value; }
void SetSendFppSync (bool value) { SendFppSync = value; }
c_InputMgr::e_InputChannelIds GetInputChannelId () { return InputChannelId; }
protected:
String PlayItemName;
uint32_t RemainingPlayCount = 0;
time_t PlayDurationSec = 0;
bool SendFppSync = false;

private:
int32_t SyncOffsetMS = 0;
c_InputMgr::e_InputChannelIds InputChannelId = c_InputMgr::e_InputChannelIds::InputChannelId_ALL;
bool InputIsPaused () { return InputPaused; }
void SetOperationalState (bool ActiveFlag) {InputPaused = !ActiveFlag;}

}; // c_InputFPPRemotePlayItem
7 changes: 6 additions & 1 deletion include/input/InputMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "output/OutputMgr.hpp"
#include "externalInput.h"
#include <TimeLib.h>
#include <Ticker.h>

class c_InputCommon; ///< forward declaration to the pure virtual Input class that will be defined later.

Expand Down Expand Up @@ -94,7 +95,7 @@ class c_InputMgr
};

#define NO_CONFIG_NEEDED time_t(-1)
#define INPUTMGR_TASK_PRIORITY 6
#define INPUTMGR_TASK_PRIORITY 5

DriverInfo_t InputChannelDrivers[InputChannelId_End]; ///< pointer(s) to the current active Input driver
uint32_t InputDataBufferSize = 0;
Expand All @@ -120,6 +121,10 @@ class c_InputMgr

FastTimer BlankEndTime[InputChannelId_End];

# define FPP_TICKER_PERIOD_MS 25
Ticker MsTicker;
uint32_t LastTickerTimeStampMS = 0;

}; // c_InputMgr

extern c_InputMgr InputMgr;
31 changes: 16 additions & 15 deletions include/service/FPPDiscovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,24 +116,25 @@ SystemDebugStats_t SystemDebugStats;

void begin ();

void ProcessFPPJson (AsyncWebServerRequest* request);
void ProcessFPPDJson (AsyncWebServerRequest* request);
void ProcessGET (AsyncWebServerRequest* request);
void ProcessPOST (AsyncWebServerRequest* request);
void ProcessFile (AsyncWebServerRequest* request, String filename, uint32_t index, uint8_t* data, uint32_t len, bool final, uint32_t contentLength = 0);
void ProcessBody (AsyncWebServerRequest* request, uint8_t* data, uint32_t len, uint32_t index, uint32_t total);
void sendPingPacket (IPAddress destination = IPAddress(255, 255, 255, 255));
void PlayFile (String & FileToPlay);
void Enable (void);
void Disable (void);
void GetStatus (JsonObject& jsonStatus);
void ProcessFPPJson (AsyncWebServerRequest* request);
void ProcessFPPDJson (AsyncWebServerRequest* request);
void ProcessGET (AsyncWebServerRequest* request);
void ProcessPOST (AsyncWebServerRequest* request);
void ProcessFile (AsyncWebServerRequest* request, String filename, uint32_t index, uint8_t* data, uint32_t len, bool final, uint32_t contentLength = 0);
void ProcessBody (AsyncWebServerRequest* request, uint8_t* data, uint32_t len, uint32_t index, uint32_t total);
void sendPingPacket (IPAddress destination = IPAddress(255, 255, 255, 255));
void PlayFile (String & FileToPlay);
void Enable (void);
void Disable (void);
void GetStatus (JsonObject& jsonStatus);
void NetworkStateChanged (bool NewNetworkState);
void SetOperationalState (bool ActiveFlag);

void SetBlankOnStop (bool value) {BlankOnStop = value;}
bool GetBlankOnStop (void) {return BlankOnStop;}
void SetInputFPPRemotePlayFile (c_InputFPPRemotePlayFile * value);
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);
void GenerateFppSyncMsg (uint8_t Action, const String & FileName, uint32_t CurrentFrame, const float & ElpsedTime);

# define SYNC_PKT_START 0
# define SYNC_PKT_STOP 1
Expand Down
22 changes: 21 additions & 1 deletion src/input/InputFPPRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,21 @@ bool c_InputFPPRemote::SetConfig (JsonObject& jsonConfig)
return true;
} // SetConfig

//-----------------------------------------------------------------------------
void c_InputFPPRemote::SetOperationalState (bool ActiveFlag)
{
// DEBUG_START;

if(pInputFPPRemotePlayItem)
{
pInputFPPRemotePlayItem->SetOperationalState (ActiveFlag);
}

FPPDiscovery.SetOperationalState(ActiveFlag);

// DEBUG_END;
} // SetOperationalState

//-----------------------------------------------------------------------------
void c_InputFPPRemote::StopPlaying ()
{
Expand All @@ -309,7 +324,7 @@ void c_InputFPPRemote::StopPlaying ()
Stopping = true;

// DEBUG_V ("Disable FPP Discovery");
FPPDiscovery.Disable ();
// FPPDiscovery.Disable ();
FPPDiscovery.ForgetInputFPPRemotePlayFile ();

if(PlayingFile())
Expand Down Expand Up @@ -347,6 +362,11 @@ void c_InputFPPRemote::StartPlaying (String& FileName)

do // once
{
if(!IsInputChannelActive)
{
break;
}

// DEBUG_V (String ("FileName: '") + FileName + "'");
if ((FileName.isEmpty ()) ||
(FileName.equals("null")))
Expand Down
Loading

0 comments on commit 5a1649c

Please sign in to comment.