Skip to content

Commit

Permalink
Merge pull request forkineye#782 from MartinMueller2003/main
Browse files Browse the repository at this point in the history
Updated framework and arduino release
  • Loading branch information
forkineye authored Aug 20, 2024
2 parents 4a86c5d + 5dfa036 commit adbcba2
Show file tree
Hide file tree
Showing 27 changed files with 176 additions and 96 deletions.
33 changes: 25 additions & 8 deletions ESPixelStick/src/FastTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,54 @@ FastTimer::~FastTimer ()

//-----------------------------------------------------------------------------
///< Start the module
void FastTimer::StartTimer (uint32_t DurationMS)
void FastTimer::StartTimer (uint32_t _DurationMS, bool _continuous)
{
// DEBUG_START;

DurationMS = _DurationMS;
Continuous = _continuous;

uint64_t now = uint64_t(millis());

EndTimeMS = now + uint64_t(DurationMS);
offsetMS = uint64_t((EndTimeMS > uint32_t(-1)) ? uint32_t(-1) : uint32_t(0));
OffsetMS = uint64_t((EndTimeMS > uint32_t(-1)) ? uint32_t(-1) : uint32_t(0));

// DEBUG_V(String("DurationMS: ") + String(DurationMS));
// DEBUG_V(String("continuous: ") + String(Continuous));
// DEBUG_V(String(" now: ") + String(now));
// DEBUG_V(String(" EndTimeMS: ") + String(EndTimeMS));
// DEBUG_V(String(" OffsetMS: ") + String(OffsetMS));

// DEBUG_END;
} // StartTimer

//-----------------------------------------------------------------------------
bool FastTimer::IsExpired ()
{
return ((uint64_t(millis ()) + uint64_t(offsetMS)) >= EndTimeMS);
bool Expired = ((uint64_t(millis ()) + uint64_t(OffsetMS)) >= EndTimeMS);

// do we need to restart the timer?
if(Expired && Continuous)
{
// adjust for next invocation
EndTimeMS += DurationMS;
}
return Expired;

} // IsExpired

//-----------------------------------------------------------------------------
void FastTimer::CancelTimer()
{
EndTimeMS = millis();
offsetMS = 0;

EndTimeMS = 0;
OffsetMS = 0;
DurationMS = 0;
Continuous = false;
} // CancelTimer

//-----------------------------------------------------------------------------
uint32_t FastTimer::GetTimeRemaining()
{

return (IsExpired()) ? 0 : uint32_t(EndTimeMS - (uint64_t(millis()) + uint64_t(offsetMS)));
return (IsExpired()) ? 0 : uint32_t(EndTimeMS - (uint64_t(millis()) + uint64_t(OffsetMS)));

} // GetTimeRemaining
7 changes: 4 additions & 3 deletions ESPixelStick/src/FastTimer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ class FastTimer
FastTimer ();
virtual ~FastTimer ();

void StartTimer (uint32_t durationMS);
void StartTimer (uint32_t DurationMS, bool continuous);
bool IsExpired();
void CancelTimer();
uint32_t GetTimeRemaining();

private:

bool Continuous = false;
uint32_t DurationMS = 0;
uint64_t EndTimeMS = 0;
uint32_t offsetMS = 0;
uint32_t OffsetMS = 0;

protected:

Expand Down
4 changes: 0 additions & 4 deletions ESPixelStick/src/FileMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,7 @@ bool c_FileMgr::LoadFlashFile (const String& FileName, DeserializationHandler Ha
break;
}

size_t JsonDocSize = file.size () * 3;
// DEBUG_V(String("Allocate JSON document. Size = ") + String(JsonDocSize));
// DEBUG_V(String("Heap: ") + ESP.getFreeHeap());
JsonDocument jsonDoc;
// DEBUG_V(String("jsonDoc.capacity: ") + String(jsonDoc.capacity()));

// DEBUG_V ("Convert File to JSON document");
DeserializationError error = deserializeJson (jsonDoc, file);
Expand Down
24 changes: 16 additions & 8 deletions ESPixelStick/src/input/InputEffectEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ void c_InputEffectEngine::PollFlash ()
uint32_t NextDelay = random(FlashInfo.MinDelayMS, FlashInfo.MaxDelayMS);
uint32_t NextDuration = random(FlashInfo.MinDurationMS, FlashInfo.MaxDurationMS);

FlashInfo.delaytimer.StartTimer(NextDelay);
FlashInfo.durationtimer.StartTimer(NextDelay + NextDuration);
FlashInfo.delaytimer.StartTimer(NextDelay, false);
FlashInfo.durationtimer.StartTimer(NextDelay + NextDuration, false);

// force the effect to overwrite the buffer
EffectDelayTimer.CancelTimer();
Expand Down Expand Up @@ -354,10 +354,15 @@ void c_InputEffectEngine::Process ()
break;
}

// DEBUG_V ("Update output");
// timer has expired
uint32_t wait = (this->*ActiveEffect->func)();
EffectWait = max ((int)wait, MIN_EFFECT_DELAY);
EffectDelayTimer.StartTimer(EffectWait);
uint32_t NewEffectWait = max ((int)wait, MIN_EFFECT_DELAY);
if(NewEffectWait != EffectWait)
{
EffectWait = NewEffectWait;
// DEBUG_V ("Update timer");
EffectDelayTimer.StartTimer(EffectWait, true);
}
EffectCounter++;
InputMgr.RestartBlankTimer (GetInputChannelId ());

Expand Down Expand Up @@ -570,6 +575,7 @@ void c_InputEffectEngine::setBrightness (float brightness)
void c_InputEffectEngine::setSpeed (uint16_t speed)
{
EffectSpeed = speed;
// DEBUG_V(String("EffectSpeed: ") + String(speed));
setDelay (pow (10, (10 - speed) / 4.0 + 2));
}

Expand All @@ -583,6 +589,8 @@ void c_InputEffectEngine::setDelay (uint16_t delay)
{
EffectDelay = MIN_EFFECT_DELAY;
}
// DEBUG_V(String("EffectDelay: ") + String(EffectDelay));

// DEBUG_END;
} // setDelay

Expand All @@ -599,9 +607,9 @@ void c_InputEffectEngine::setEffect (const String & effectName)
// DEBUG_V ("Found desired effect");
if (!ActiveEffect->name.equalsIgnoreCase (currentEffect.name))
{
// DEBUG_V ("Starting Effect");
// DEBUG_V ("Starting New Effect");
ActiveEffect = &ListOfEffects[EffectIndex];
EffectDelayTimer.StartTimer(EffectDelay);
EffectDelayTimer.StartTimer(EffectDelay, true);
EffectWait = MIN_EFFECT_DELAY;
EffectCounter = 0;
EffectStep = 0;
Expand Down Expand Up @@ -761,7 +769,7 @@ uint16_t c_InputEffectEngine::effectSolidColor ()
//-----------------------------------------------------------------------------
void c_InputEffectEngine::outputEffectColor (uint16_t pixelId, CRGB outputColor)
{
// DEBUG_START;
// DEBUG_START;

uint16_t NumPixels = MirroredPixelCount;

Expand Down
10 changes: 3 additions & 7 deletions ESPixelStick/src/input/InputEffectEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,13 @@ class c_InputEffectEngine : public c_InputCommon
bool HasBeenInitialized = false;

#define MIN_EFFECT_DELAY 10
#define MAX_EFFECT_DELAY 65535
#define DEFAULT_EFFECT_DELAY 1000

using timeType = decltype(millis());


uint32_t EffectWait = 32; /* How long to wait for the effect to run again */

uint32_t EffectWait = 0; /* How long to wait for the effect to run again */
uint32_t EffectCounter = 0; /* Counter for the number of calls to the active effect */
uint16_t EffectSpeed = 6; /* Externally controlled effect speed 1..10 */
uint16_t EffectDelay = DEFAULT_EFFECT_DELAY; /* Internal representation of speed */
uint32_t EffectSpeed = 6; /* Externally controlled effect speed 1..10 */
uint32_t EffectDelay = 0; /* Internal representation of speed */
bool EffectReverse = false; /* Externally controlled effect reverse option */
bool EffectMirror = false; /* Externally controlled effect mirroring (start at center) */
bool EffectAllLeds = false; /* Externally controlled effect all leds = 1st led */
Expand Down
2 changes: 1 addition & 1 deletion ESPixelStick/src/input/InputFPPRemotePlayEffectFsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void fsm_PlayEffect_state_Idle::Start (String & ConfigString, float )
// DEBUG_START;

// DEBUG_V (String ("ConfigString: '") + ConfigString + "'");
p_InputFPPRemotePlayEffect->PlayEffectTimer.StartTimer(1000 * p_InputFPPRemotePlayEffect->PlayDurationSec);
p_InputFPPRemotePlayEffect->PlayEffectTimer.StartTimer(1000 * p_InputFPPRemotePlayEffect->PlayDurationSec, false);

// tell the effect engine what it is supposed to be doing
JsonDocument EffectConfig;
Expand Down
8 changes: 4 additions & 4 deletions ESPixelStick/src/input/InputFPPRemotePlayList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ bool c_InputFPPRemotePlayList::ProcessPlayListEntry ()
// DEBUG_V ("");
uint32_t FrameId = 0;
uint32_t PlayCount = 1;
PauseDelayTimer.StartTimer(10000);
PauseDelayTimer.StartTimer(10000, false);

// Get the playlist file
String FileData;
Expand Down Expand Up @@ -165,7 +165,7 @@ bool c_InputFPPRemotePlayList::ProcessPlayListEntry ()
{
// DEBUG_V ("Entry is empty. Do a Pause");

PauseDelayTimer.StartTimer(1000);
PauseDelayTimer.StartTimer(1000, false);
fsm_PlayList_state_Paused_imp.Init (this);
pCurrentFsmState->Start (PlayItemName, PauseDelayTimer.GetTimeRemaining() / 1000, PlayCount);
break;
Expand Down Expand Up @@ -209,7 +209,7 @@ bool c_InputFPPRemotePlayList::ProcessPlayListEntry ()
uint32_t PlayListEntryDuration = 0;
setFromJSON (PlayListEntryDuration, JsonPlayListArrayEntry, CN_duration);
// DEBUG_V (String ("PlayListEntryDuration: '") + String (PlayListEntryDuration) + "'");
PauseDelayTimer.StartTimer(PlayListEntryDuration * 1000);
PauseDelayTimer.StartTimer(PlayListEntryDuration * 1000, false);
// DEBUG_V (String (" PauseEndTime: '") + String (PauseEndTime) + "'");

fsm_PlayList_state_Paused_imp.Init (this);
Expand All @@ -219,7 +219,7 @@ bool c_InputFPPRemotePlayList::ProcessPlayListEntry ()
else
{
logcon (String (F ("Unsupported Play List Entry type: '")) + PlayListEntryType + "'");
PauseDelayTimer.StartTimer(10000);
PauseDelayTimer.StartTimer(10000, false);
fsm_PlayList_state_Paused_imp.Init (this);
pCurrentFsmState->Start (PlayListEntryName, FrameId, PlayCount);
break;
Expand Down
2 changes: 1 addition & 1 deletion ESPixelStick/src/input/InputMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class c_InputMgr
void DeleteConfig () { FileMgr.DeleteFlashFile (ConfigFileName); }
bool GetNetworkState () { return IsConnected; }
void GetDriverName (String & Name) { Name = "InputMgr"; }
void RestartBlankTimer (e_InputChannelIds Selector) { BlankEndTime[int(Selector)].StartTimer(config.BlankDelay * 1000); }
void RestartBlankTimer (e_InputChannelIds Selector) { BlankEndTime[int(Selector)].StartTimer(config.BlankDelay * 1000, false); }
bool BlankTimerHasExpired (e_InputChannelIds Selector) { return (BlankEndTime[int(Selector)].IsExpired()); }
void ProcessButtonActions (c_ExternalInput::InputValue_t value);

Expand Down
2 changes: 1 addition & 1 deletion ESPixelStick/src/input/externalInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void fsm_ExternalInput_on_wait_long_state::Init (c_ExternalInput& pExternalInput
// DEBUG_START;

// DEBUG_V ("Entring Wait Long State");
pExternalInput.InputHoldTimer.StartTimer(pExternalInput.LongPushDelayMS);
pExternalInput.InputHoldTimer.StartTimer(pExternalInput.LongPushDelayMS, false);
pExternalInput.CurrentFsmState = &fsm_ExternalInput_on_wait_long_state_imp;

// DEBUG_END;
Expand Down
12 changes: 6 additions & 6 deletions ESPixelStick/src/network/EthernetDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void c_EthernetDriver::Begin ()
WiFi.onEvent ([this](WiFiEvent_t event, arduino_event_info_t info) {this->onEventHandler (event, info); });

// set up the poll interval
NextPollTimer.StartTimer(PollInterval);
NextPollTimer.StartTimer(PollInterval, false);

// DEBUG_END;

Expand Down Expand Up @@ -284,7 +284,7 @@ void c_EthernetDriver::Poll ()
if (NextPollTimer.IsExpired())
{
// DEBUG_V ("Polling");
NextPollTimer.StartTimer(PollInterval);
NextPollTimer.StartTimer(PollInterval, false);
pCurrentFsmState->Poll ();
}

Expand Down Expand Up @@ -464,7 +464,7 @@ void fsm_Eth_state_Boot::Init ()

pEthernetDriver->SetFsmState (this);
// pEthernetDriver->AnnounceState ();
pEthernetDriver->GetFsmTimer().StartTimer(10000);
pEthernetDriver->GetFsmTimer().StartTimer(10000, false);

// DEBUG_V(String("pEthernetDriver: 0x") + String(uint32_t(pEthernetDriver), HEX));

Expand Down Expand Up @@ -497,7 +497,7 @@ void fsm_Eth_state_PoweringUp::Init ()

pEthernetDriver->SetFsmState (this);
pEthernetDriver->AnnounceState ();
pEthernetDriver->GetFsmTimer().StartTimer (pEthernetDriver->GetPowerPinActiveDelayMs());
pEthernetDriver->GetFsmTimer().StartTimer (pEthernetDriver->GetPowerPinActiveDelayMs(), false);

pEthernetDriver->InitPowerPin ();

Expand Down Expand Up @@ -530,7 +530,7 @@ void fsm_Eth_state_ConnectingToEth::Init ()

pEthernetDriver->SetFsmState (this);
pEthernetDriver->AnnounceState ();
pEthernetDriver->GetFsmTimer().StartTimer (5000);
pEthernetDriver->GetFsmTimer().StartTimer (5000, false);

// DEBUG_END;

Expand Down Expand Up @@ -581,7 +581,7 @@ void fsm_Eth_state_WaitForIP::Init ()

pEthernetDriver->SetFsmState (this);
pEthernetDriver->AnnounceState ();
pEthernetDriver->GetFsmTimer().StartTimer (5000);
pEthernetDriver->GetFsmTimer().StartTimer (5000, false);

// DEBUG_END;

Expand Down
10 changes: 5 additions & 5 deletions ESPixelStick/src/network/WiFiDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void c_WiFiDriver::Begin ()
#endif

// set up the poll interval
NextPoll.StartTimer(PollInterval);
NextPoll.StartTimer(PollInterval, false);

// Main loop should start polling for us
// pCurrentFsmState->Poll ();
Expand Down Expand Up @@ -435,7 +435,7 @@ void c_WiFiDriver::Poll ()
if (NextPoll.IsExpired())
{
// DEBUG_V ("Start Poll");
NextPoll.StartTimer(PollInterval);
NextPoll.StartTimer(PollInterval, false);
// displayFsmState ();
pCurrentFsmState->Poll ();
// displayFsmState ();
Expand Down Expand Up @@ -733,7 +733,7 @@ void fsm_WiFi_state_ConnectingUsingConfig::Init ()
{
pWiFiDriver->SetFsmState (this);
pWiFiDriver->AnnounceState ();
pWiFiDriver->GetFsmTimer().StartTimer(1000 * pWiFiDriver->Get_sta_timeout());
pWiFiDriver->GetFsmTimer().StartTimer(1000 * pWiFiDriver->Get_sta_timeout(), false);

pWiFiDriver->connectWifi (CurrentSsid, CurrentPassphrase);
}
Expand Down Expand Up @@ -788,7 +788,7 @@ void fsm_WiFi_state_ConnectingUsingDefaults::Init ()
{
pWiFiDriver->SetFsmState (this);
pWiFiDriver->AnnounceState ();
pWiFiDriver->GetFsmTimer().StartTimer(1000 * pWiFiDriver->Get_sta_timeout ());
pWiFiDriver->GetFsmTimer().StartTimer(1000 * pWiFiDriver->Get_sta_timeout (), false);
pWiFiDriver->connectWifi (default_ssid, default_passphrase);
}
else
Expand Down Expand Up @@ -848,7 +848,7 @@ void fsm_WiFi_state_ConnectingAsAP::Init ()

pWiFiDriver->SetFsmState (this);
pWiFiDriver->AnnounceState ();
pWiFiDriver->GetFsmTimer ().StartTimer(1000 * pWiFiDriver->Get_ap_timeout ());
pWiFiDriver->GetFsmTimer ().StartTimer(1000 * pWiFiDriver->Get_ap_timeout (), false);

if (true == pWiFiDriver->Get_ap_fallbackIsEnabled() || pWiFiDriver->Get_ap_StayInApMode())
{
Expand Down
4 changes: 2 additions & 2 deletions ESPixelStick/src/output/OutputAPA102Spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ void c_OutputAPA102Spi::GetConfig (ArduinoJson::JsonObject& jsonConfig)
// DEBUG_START;

c_OutputAPA102::GetConfig (jsonConfig);

jsonConfig[CN_clock_pin] = DEFAULT_SPI_CLOCK_GPIO;
Spi.GetConfig(jsonConfig);

// DEBUG_END;
} // GetConfig
Expand All @@ -83,6 +82,7 @@ bool c_OutputAPA102Spi::SetConfig (ArduinoJson::JsonObject& jsonConfig)
// DEBUG_START;

bool response = c_OutputAPA102::SetConfig (jsonConfig);
response |= Spi.SetConfig(jsonConfig);

// DEBUG_END;
return response;
Expand Down
6 changes: 2 additions & 4 deletions ESPixelStick/src/output/OutputCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ void c_OutputCommon::GetStatus (JsonObject & jsonStatus)
// DEBUG_START;

jsonStatus[CN_id] = OutputChannelId;
jsonStatus["framerefreshrate"] = (0 == FrameRefreshTimeInMicroSec) ? 0 : int(MicroSecondsInASecond / FrameDurationInMicroSec);
jsonStatus["framerefreshrate"] = int(MicroSecondsInASecond / FrameDurationInMicroSec);
jsonStatus["FrameCount"] = FrameCount;

// jsonStatus["ActualFrameDurationMicroSec"] = ActualFrameDurationMicroSec;
// jsonStatus["FrameDurationInMicroSec"] = FrameDurationInMicroSec;
// jsonStatus["FrameRefreshTimeInMicroSec"] = FrameRefreshTimeInMicroSec;
Expand All @@ -91,9 +91,7 @@ void c_OutputCommon::ReportNewFrame ()

uint32_t Now = micros ();

FrameRefreshTimeInMicroSec = Now - FrameStartTimeInMicroSec;
FrameStartTimeInMicroSec = Now;
FrameEndTimeInMicroSec = FrameStartTimeInMicroSec + FrameDurationInMicroSec;
FrameCount++;

// DEBUG_END;
Expand Down
Loading

0 comments on commit adbcba2

Please sign in to comment.