Skip to content

Commit

Permalink
Merge pull request #681 from MartinMueller2003/main
Browse files Browse the repository at this point in the history
Fixed config download issue for 8 port implementations.
  • Loading branch information
forkineye committed Nov 1, 2023
2 parents 973b06f + 1f7936e commit c89a214
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 36 deletions.
28 changes: 23 additions & 5 deletions ESPixelStick/ESPixelStick.ino
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ const String BUILD_DATE = String(__DATE__) + " - " + String(__TIME__);
const uint8_t CurrentConfigVersion = 1;

config_t config; // Current configuration
bool reboot = false; // Reboot flag
static const uint32_t NotRebootingValue = uint32_t(-1);
uint32_t RebootCount = NotRebootingValue;
uint32_t lastUpdate; // Update timeout tracker
bool ResetWiFi = false;
bool IsBooting = true; // Configuration initialization flag
Expand Down Expand Up @@ -495,11 +496,14 @@ void loop()
} // end discard loop

// Reboot handler
if (reboot)
if (NotRebootingValue != RebootCount)
{
logcon (String(CN_stars) + CN_minussigns + F ("Internal Reboot Requested. Rebooting Now"));
delay (REBOOT_DELAY);
ESP.restart ();
if(0 == --RebootCount)
{
logcon (String(CN_stars) + CN_minussigns + F ("Internal Reboot Requested. Rebooting Now"));
delay (REBOOT_DELAY);
ESP.restart ();
}
}

if (ConfigLoadNeeded)
Expand All @@ -516,6 +520,20 @@ void loop()

} // loop

bool RebootInProgress()
{
return RebootCount != NotRebootingValue;
}

void RequestReboot(uint32_t LoopDelay)
{
RebootCount = LoopDelay;

InputMgr.SetOperationalState(false);
OutputMgr.PauseOutputs(true);

} // RequestReboot

void _logcon (String & DriverName, String Message)
{
char Spaces[7];
Expand Down
5 changes: 4 additions & 1 deletion ESPixelStick/src/ESPixelStick.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
#define STRINGIFY(X) #X
#define STRING(X) STRINGIFY(X)

extern void RequestReboot(uint32_t LoopDelay);
extern bool RebootInProgress();

/// Core configuration structure
typedef struct {
// Device
Expand All @@ -72,7 +75,7 @@ void deserializeCoreHandler (DynamicJsonDocument& jsonDoc);
bool deserializeCore (JsonObject & json);
bool dsDevice (JsonObject & json);
bool dsNetwork (JsonObject & json);
extern bool reboot;

extern bool IsBooting;
extern bool ResetWiFi;
extern const String ConfigFileName;
Expand Down
10 changes: 4 additions & 6 deletions ESPixelStick/src/WebMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void c_WebMgr::init ()
}
else
{
reboot = true;
RequestReboot(100000);
request->send (200, CN_textSLASHplain, "Rebooting");
}
});
Expand All @@ -188,8 +188,7 @@ void c_WebMgr::init ()

request->send (200, CN_textSLASHplain, "Rebooting");
// DEBUG_V ("");
extern bool reboot;
reboot = true;
RequestReboot(100000);;
}
});

Expand Down Expand Up @@ -364,7 +363,7 @@ void c_WebMgr::init ()
webServer.on ("/updatefw", HTTP_POST,
[](AsyncWebServerRequest* request)
{
reboot = true;
RequestReboot(100000);;
},
[](AsyncWebServerRequest* request, String filename, uint32_t index, uint8_t* data, uint32_t len, bool final)
{WebMgr.FirmwareUpload (request, filename, index, data, len, final); }).setFilter (ON_STA_FILTER);
Expand Down Expand Up @@ -715,8 +714,7 @@ void c_WebMgr::FirmwareUpload (AsyncWebServerRequest* request,
efupdate.end ();
// LittleFS.begin ();

extern bool reboot;
reboot = true;
RequestReboot(100000);;
}

} while (false);
Expand Down
5 changes: 2 additions & 3 deletions ESPixelStick/src/input/InputE131.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ bool c_InputE131::SetConfig (ArduinoJson::JsonObject& jsonConfig)
if ((OldPortId != PortId) && (ESPAsyncE131Initialized))
{
// ask for a reboot.
reboot = true;
RequestReboot(100000);
logcon (String (F ("Requesting reboot on change of UDP port.")));
}

Expand Down Expand Up @@ -390,8 +390,7 @@ void c_InputE131::NetworkStateChanged (bool IsConnected, bool ReBootAllowed)
{
// handle a disconnect
// E1.31 does not do this gracefully. A loss of connection needs a reboot
// extern bool reboot;
reboot = true;
RequestReboot(100000);
logcon (String (F ("Input requesting reboot on loss of WiFi connection.")));
}

Expand Down
11 changes: 5 additions & 6 deletions ESPixelStick/src/input/InputMQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ void c_InputMQTT::Process ()
// DEBUG_V ("");
pEffectsEngine->Process ();
}
}

if (nullptr != pPlayFileEngine)
{
pPlayFileEngine->Poll ();
if (nullptr != pPlayFileEngine)
{
pPlayFileEngine->Poll ();
}
}

// DEBUG_END;
Expand Down Expand Up @@ -772,8 +772,7 @@ void c_InputMQTT::NetworkStateChanged (bool IsConnected, bool ReBootAllowed)
else if (ReBootAllowed)
{
// handle a disconnect
extern bool reboot;
reboot = true;
RequestReboot(100000);
logcon (String (F ("Requesting reboot on loss of network connection.")));
}

Expand Down
11 changes: 8 additions & 3 deletions ESPixelStick/src/input/InputMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ void c_InputMgr::LoadConfig ()
else
{
logcon (CN_stars + String (F (" Error loading Input Manager Config File. Rebooting ")) + CN_stars);
reboot = true;
RequestReboot(100000);
}
}

Expand Down Expand Up @@ -659,10 +659,15 @@ void c_InputMgr::Process ()
configInProgress = false;
}

if(RebootInProgress())
{
break;
}

bool aBlankTimerIsRunning = false;
for (auto & CurrentInput : InputChannelDrivers)
{
// DEBUG_V("");
// DEBUG_V(String("pInputChannelDriver: 0x") + String(uint32_t(CurrentInput.pInputChannelDriver), HEX));
CurrentInput.pInputChannelDriver->Process ();

if (!BlankTimerHasExpired (CurrentInput.pInputChannelDriver->GetInputChannelId()))
Expand All @@ -683,7 +688,7 @@ void c_InputMgr::Process ()
if (rebootNeeded)
{
// DEBUG_V("Requesting Reboot");
reboot = true;
RequestReboot(100000);
}

} while (false);
Expand Down
2 changes: 1 addition & 1 deletion ESPixelStick/src/network/EthernetDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ bool c_EthernetDriver::SetConfig (JsonObject & json)
if (ConfigChanged && HasBeenPreviouslyConfigured)
{
logcon (F ("Configuration change requires system reboot."));
reboot = true;
RequestReboot(100000);
}

HasBeenPreviouslyConfigured = true;
Expand Down
4 changes: 1 addition & 3 deletions ESPixelStick/src/network/WiFiDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,10 +957,8 @@ void fsm_WiFi_state_ConnectionFailed::Init ()
{
if (true == pWiFiDriver->Get_RebootOnWiFiFailureToConnect())
{
extern bool reboot;
logcon (F ("WiFi Requesting Reboot"));

reboot = true;
RequestReboot(100000);
}
else
{
Expand Down
8 changes: 4 additions & 4 deletions ESPixelStick/src/output/OutputMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void c_OutputMgr::Begin ()
if (0 == OutputChannelId_End)
{
logcon("ERROR: No output Channels defined. Rebooting");
reboot = true;
RequestReboot(100000);
break;
}

Expand Down Expand Up @@ -1030,7 +1030,7 @@ void c_OutputMgr::LoadConfig ()
else
{
logcon(CN_stars + String(MN_15) + CN_stars);
reboot = true;
RequestReboot(100000);
}
}

Expand Down Expand Up @@ -1297,7 +1297,7 @@ void c_OutputMgr::Poll()
LoadConfig ();
} // done need to save the current config

if ((false == IsOutputPaused) && (false == ConfigInProgress))
if ((false == IsOutputPaused) && (false == ConfigInProgress) && (false == RebootInProgress()) )
{
// //DEBUG_V();
for (DriverInfo_t & OutputChannel : OutputChannelDrivers)
Expand Down Expand Up @@ -1326,7 +1326,7 @@ void c_OutputMgr::TaskPoll()
// DEBUG_V("Done config processing");
} // done need to save the current config

if ((false == IsOutputPaused) && (false == ConfigInProgress))
if ((false == IsOutputPaused) && (false == ConfigInProgress) && (false == RebootInProgress()) )
{
// PollCount ++;
bool FoundAnActiveOutputChannel = false;
Expand Down
4 changes: 2 additions & 2 deletions ESPixelStick/src/output/OutputRmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ c_OutputRmt::~c_OutputRmt ()
if (HasBeenInitialized)
{
logcon(F("Shutting down an RMT channel requires a reboot"));
reboot = true;
RequestReboot(100000);

DisableRmtInterrupts;
ClearRmtInterrupts;
Expand Down Expand Up @@ -131,7 +131,7 @@ void c_OutputRmt::Begin (OutputRmtConfig_t config )

{
LOG_PORT.println (F("Invalid RMT configuration parameters. Rebooting"));
reboot = true;
RequestReboot(100000);;
break;
}

Expand Down
2 changes: 1 addition & 1 deletion ESPixelStick/src/output/OutputSpi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ c_OutputSpi::~c_OutputSpi ()
if (OutputPixel)
{
logcon(CN_stars + String(F(" SPI Interface Shutdown requires a reboot ")) + CN_stars);
reboot = true;
RequestReboot(100000);
}
}
// DEBUG_END;
Expand Down
2 changes: 1 addition & 1 deletion ESPixelStick/src/output/OutputUart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void c_OutputUart::Begin (OutputUartConfig_t & config )

{
LOG_PORT.println (F("Invalid UART configuration parameters. Rebooting"));
reboot = true;
RequestReboot(100000);
break;
}

Expand Down

0 comments on commit c89a214

Please sign in to comment.