Skip to content

Commit

Permalink
More work on merging new and old configs. Turned off. restored files …
Browse files Browse the repository at this point in the history
…are used as is.
  • Loading branch information
MartinMueller2003 committed Mar 19, 2024
1 parent ab3d56a commit a5efce9
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 59 deletions.
3 changes: 2 additions & 1 deletion ESPixelStick/ESPixelStick.ino
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void setup()
// TestHeap(uint32_t(10));
// DEBUG_V("");
FileMgr.Begin();

#ifdef SUPPORT_CONFIG_MERGE
if(FileMgr.FlashFileExists (RestoredConfigFileName))
{
// DEBUG_V("Setting Restored Config flag to true");
Expand All @@ -183,6 +183,7 @@ void setup()
{
// DEBUG_V("Setting Restored Config flag to false");
}
#endif // def SUPPORT_CONFIG_MERGE
// Load configuration from the File System and set Hostname
// TestHeap(uint32_t(15));
// DEBUG_V(String("LoadConfig Heap: ") + String(ESP.getFreeHeap()));
Expand Down
60 changes: 46 additions & 14 deletions ESPixelStick/src/input/InputMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,14 @@ void c_InputMgr::CreateNewConfig ()
// do we create a clean config or do we merge from a restored config?
if(RestoredConfig)
{
// DEBUG_V("Merge a Restored Config");
DEBUG_V("Merge a Restored Input Config");
// read the existing file and add to it as needed
FileMgr.ReadFlashFile(ConfigFileName, JsonConfigDoc);
}

if(!JsonConfigDoc.containsKey(CN_input_config))
{
DEBUG_V("Add missing input config fields");
JsonConfigDoc.createNestedObject(CN_input_config);
}
JsonObject JsonConfig = JsonConfigDoc[CN_input_config];
Expand Down Expand Up @@ -746,16 +747,16 @@ void c_InputMgr::ProcessButtonActions (c_ExternalInput::InputValue_t value)
} // ProcessButtonActions

//-----------------------------------------------------------------------------
/*
check the contents of the config and send
the proper portion of the config to the currently instantiated channels
*/
bool c_InputMgr::ProcessJsonConfig (JsonObject & jsonConfig)
bool c_InputMgr::FindJsonChannelConfig (JsonObject& jsonConfig,
e_InputChannelIds ChanId,
JsonObject& ChanConfig)
{
// DEBUG_START;
bool Response = false;
// DEBUG_V ();

// DEBUG_V ("InputDataBufferSize: " + String (InputDataBufferSize));
// extern void PrettyPrint(JsonObject & jsonStuff, String Name);
// PrettyPrint(jsonConfig, "ProcessJsonConfig");

do // once
{
Expand Down Expand Up @@ -805,21 +806,52 @@ bool c_InputMgr::ProcessJsonConfig (JsonObject & jsonConfig)
JsonObject InputChannelArray = InputChannelMgrData[CN_channels];
// DEBUG_V ("");

// get access to the channel config
if (false == InputChannelArray.containsKey (String (ChanId)))
{
// if not, flag an error and stop processing
logcon (String (F ("No Input Settings Found for Channel '")) + ChanId + String (F ("'. Using Defaults")));
continue;
}
ChanConfig = InputChannelArray[String(ChanId)];
// DEBUG_V ();

// all went well
Response = true;

} while (false);

// DEBUG_END;
return Response;

} // FindChannelJsonConfig

//-----------------------------------------------------------------------------
/*
check the contents of the config and send
the proper portion of the config to the currently instantiated channels
*/
bool c_InputMgr::ProcessJsonConfig (JsonObject & jsonConfig)
{
// DEBUG_START;
bool Response = false;

// DEBUG_V ("InputDataBufferSize: " + String (InputDataBufferSize));

do // once
{
// for each Input channel
for (uint32_t ChannelIndex = uint32_t (InputChannelId_Start);
ChannelIndex < uint32_t (InputChannelId_End);
ChannelIndex++)
{
// get access to the channel config
if (false == InputChannelArray.containsKey (String (ChannelIndex)))
JsonObject InputChannelConfig;
// DEBUG_V ("");
if(!FindJsonChannelConfig(jsonConfig, e_InputChannelIds(ChannelIndex), InputChannelConfig))
{
// if not, flag an error and stop processing
logcon (String (F ("No Input Settings Found for Channel '")) + ChannelIndex + String (F ("'. Using Defaults")));
DEBUG_V("Did not find the desired channel configuration");
continue;
}
JsonObject InputChannelConfig = InputChannelArray[String (ChannelIndex)];
// DEBUG_V ("");

// set a default value for channel type
uint32_t ChannelType = uint32_t (InputType_Default);
setFromJSON (ChannelType, InputChannelConfig, CN_type);
Expand Down
1 change: 1 addition & 0 deletions ESPixelStick/src/input/InputMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class c_InputMgr
void CreateJsonConfig (JsonObject & jsonConfig);
bool ProcessJsonChannelConfig (JsonObject & jsonConfig, uint32_t ChannelIndex);
bool InputTypeIsAllowedOnChannel (e_InputType type, e_InputChannelIds ChannelId);
bool FindJsonChannelConfig (JsonObject& jsonConfig, e_InputChannelIds ChanId, JsonObject& ChanConfig);

String ConfigFileName;
bool rebootNeeded = false;
Expand Down
Loading

0 comments on commit a5efce9

Please sign in to comment.