From 57304b1dc986f10402664581dbf9e69a13abc26b Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 23 Aug 2024 13:43:52 -0400 Subject: [PATCH 1/6] Added debug output --- ESPixelStick/src/EFUpdate.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ESPixelStick/src/EFUpdate.cpp b/ESPixelStick/src/EFUpdate.cpp index 17de93fab..b993b3753 100644 --- a/ESPixelStick/src/EFUpdate.cpp +++ b/ESPixelStick/src/EFUpdate.cpp @@ -66,13 +66,17 @@ bool EFUpdate::process(uint8_t *data, uint32_t len) { switch (_state) { case State::HEADER: + // DEBUG_V (String (" len: 0x") + String (len, HEX)); + // DEBUG_V (String ("index: ") + String (index)); // DEBUG_V ("Process HEADER record"); _header.raw[_loc++] = data[index++]; // DEBUG_V (); if (_loc == sizeof(efuheader_t)) { + // DEBUG_V (String("signature: 0x") + String(_header.signature, HEX)); if (_header.signature == EFU_ID) { // DEBUG_V (); _header.version = ntohs(_header.version); + // DEBUG_V (String("version: ") + String(_header.version)); memset(&_record, 0, sizeof(efurecord_t)); _loc = 0; _state = State::RECORD; @@ -86,6 +90,14 @@ bool EFUpdate::process(uint8_t *data, uint32_t len) { break; case State::RECORD: // DEBUG_V ("Process Data RECORD Type"); + // DEBUG_V (String (" len: 0x") + String (len, HEX)); + // DEBUG_V (String ("AccumulatedLentgh: 0x") + String (AccumulatedLentgh, HEX)); + // DEBUG_V (String (" index: ") + String (index)); + // DEBUG_V (String (" AccumulatedIndex: ") + String (AccumulatedIndex)); + // DEBUG_V (String (" AccumulatedIndex: 0x") + String (AccumulatedIndex, HEX)); + // DEBUG_V (String (" Data: 0x") + String (data[index], HEX)); + // DEBUG_V (String (" Data: ") + String (data[index])); + _record.raw[_loc++] = data[index++]; if (_loc == sizeof(efurecord_t)) { // DEBUG_V (); @@ -93,7 +105,9 @@ bool EFUpdate::process(uint8_t *data, uint32_t len) { _record.size = ntohl(_record.size); _loc = 0; // DEBUG_V (String("_record.type: ") + uint32_t(_record.type)); + // DEBUG_V (String("_record.type: 0x") + String(uint32_t(_record.type), HEX)); // DEBUG_V (String("_record.size: ") + _record.size); + // DEBUG_V (String("_record.size: 0x") + String(_record.size, HEX)); if (_record.type == RecordType::SKETCH_IMAGE) { logcon ("Starting Sketch Image Update\n"); // Begin sketch update @@ -104,6 +118,20 @@ bool EFUpdate::process(uint8_t *data, uint32_t len) { } else { // DEBUG_V ("PASS"); _state = State::DATA; + // esp_image_header_t *esp_image_header = (esp_image_header_t*)&data[index]; + // DEBUG_V(String(" magic: 0x") + String(esp_image_header->magic, HEX)); + // DEBUG_V(String(" segment_count: 0x") + String(esp_image_header->segment_count, HEX)); + // DEBUG_V(String(" spi_mode: 0x") + String(esp_image_header->spi_mode, HEX)); + // DEBUG_V(String(" spi_speed: 0x") + String(esp_image_header->spi_speed, HEX)); + // DEBUG_V(String(" spi_size: 0x") + String(esp_image_header->spi_size, HEX)); + // DEBUG_V(String(" entry_addr: 0x") + String(esp_image_header->entry_addr, HEX)); + // DEBUG_V(String(" wp_pin: 0x") + String(esp_image_header->wp_pin, HEX)); + // DEBUG_V(String(" spi_pin_drv: 0x") + String(esp_image_header->spi_pin_drv, HEX)); + // DEBUG_V(String(" chip_id: 0x") + String(esp_image_header->chip_id, HEX)); + // DEBUG_V(String(" min_chip_rev: 0x") + String(esp_image_header->min_chip_rev, HEX)); + // DEBUG_V(String("min_chip_rev_full: 0x") + String(esp_image_header->min_chip_rev_full, HEX)); + // DEBUG_V(String("max_chip_rev_full: 0x") + String(esp_image_header->max_chip_rev_full, HEX)); + // esp_image_header->min_chip_rev_full = 0; } #ifdef ARDUINO_ARCH_ESP8266 Update.runAsync (true); From f951757e980ec2b0389178d03cef122d967479c1 Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 11 Sep 2024 14:10:20 -0400 Subject: [PATCH 2/6] Updates to reduce the use of json.containsKey --- ESPixelStick/ESPixelStick.ino | 38 +++++----- ESPixelStick/src/FileMgr.cpp | 4 +- ESPixelStick/src/input/InputEffectEngine.cpp | 8 +-- ESPixelStick/src/input/InputMQTT.cpp | 4 +- ESPixelStick/src/input/InputMgr.cpp | 65 ++++++----------- ESPixelStick/src/network/NetworkMgr.cpp | 12 ++-- ESPixelStick/src/output/OutputMgr.cpp | 70 ++++++++----------- ESPixelStick/src/output/OutputRelay.cpp | 6 +- .../src/output/OutputServoPCA9685.cpp | 4 +- ESPixelStick/src/service/SensorDS18B20.cpp | 5 +- 10 files changed, 94 insertions(+), 122 deletions(-) diff --git a/ESPixelStick/ESPixelStick.ino b/ESPixelStick/ESPixelStick.ino index 6c335bcff..9a067c9d1 100644 --- a/ESPixelStick/ESPixelStick.ino +++ b/ESPixelStick/ESPixelStick.ino @@ -257,9 +257,9 @@ bool dsDevice(JsonObject & json) // PrettyPrint (json, "dsDevice"); bool ConfigChanged = false; - if (json.containsKey(CN_device)) + JsonObject JsonDeviceConfig = json[CN_device]; + if (JsonDeviceConfig) { - JsonObject JsonDeviceConfig = json[CN_device]; //TODO: Add configuration upgrade handling - cfgver moved to root level ConfigChanged |= setFromJSON (config.id, JsonDeviceConfig, CN_id); @@ -300,18 +300,22 @@ bool deserializeCore (JsonObject & json) // extern void PrettyPrint (JsonObject & jsonStuff, String Name); // PrettyPrint (json, "Main Config"); + JsonObject SystemConfig = json[CN_system]; + JsonObject InitConfig = json[CN_init]; + JsonObject NetworkConfig = json[CN_network]; JsonObject DeviceConfig; do // once { // was this saved by the ESP itself - if (json.containsKey(CN_system)) + if (SystemConfig) { - // DEBUG_V(""); + // DEBUG_V("Detected a System Config"); DeviceConfig = json[CN_system]; + // PrettyPrint (DeviceConfig, "System based DeviceConfig"); } // is this an initial config from the flash tool? - else if (json.containsKey(CN_init) || json.containsKey(CN_network)) + else if (InitConfig || NetworkConfig) { // trigger a save operation ConfigSaveNeeded = true; @@ -325,22 +329,24 @@ bool deserializeCore (JsonObject & json) break; } // DEBUG_V(""); + // PrettyPrint (DeviceConfig, "Selected DeviceConfig"); - if (DeviceConfig.containsKey(CN_cfgver)) + uint8_t TempVersion = uint8_t(-1); + setFromJSON(TempVersion, DeviceConfig, CN_cfgver); + + if (TempVersion == uint8_t(-1)) { - // DEBUG_V(""); - uint8_t TempVersion = uint8_t(-1); - setFromJSON(TempVersion, DeviceConfig, CN_cfgver); - if (TempVersion != CurrentConfigVersion) - { - // TODO: Add configuration update handler - logcon(String(F("Incorrect Config Version ID"))); - } + logcon(String(F("Missing Config Version ID"))); + // break; // ignoring this error for now. + } + else if (TempVersion != CurrentConfigVersion) + { + // TODO: Add configuration update handler + logcon(String(F("Incorrect Config Version ID"))); } else { - logcon(String(F("Missing Config Version ID"))); - // break; // ignoring this error for now. + // DEBUG_V("A valid config version ID is present"); } // DEBUG_V("Checking to see if the config is from the web flash tool"); diff --git a/ESPixelStick/src/FileMgr.cpp b/ESPixelStick/src/FileMgr.cpp index a21a55e64..ed41c67ba 100644 --- a/ESPixelStick/src/FileMgr.cpp +++ b/ESPixelStick/src/FileMgr.cpp @@ -226,9 +226,9 @@ bool c_FileMgr::SetConfig (JsonObject & json) // DEBUG_START; bool ConfigChanged = false; - if (json.containsKey (CN_device)) + JsonObject JsonDeviceConfig = json[CN_device]; + if (JsonDeviceConfig) { - JsonObject JsonDeviceConfig = json[CN_device]; /* extern void PrettyPrint (JsonObject& jsonStuff, String Name); PrettyPrint (JsonDeviceConfig, "c_FileMgr"); diff --git a/ESPixelStick/src/input/InputEffectEngine.cpp b/ESPixelStick/src/input/InputEffectEngine.cpp index 0bd26c206..e1d389fd9 100644 --- a/ESPixelStick/src/input/InputEffectEngine.cpp +++ b/ESPixelStick/src/input/InputEffectEngine.cpp @@ -454,11 +454,11 @@ bool c_InputEffectEngine::SetConfig (ArduinoJson::JsonObject& jsonConfig) FlashInfo.MinIntensity = FlashInfo.MaxIntensity; } - if(jsonConfig.containsKey(CN_transitions)) + JsonArray TransitionsArray = jsonConfig[CN_transitions]; + if(TransitionsArray) { TransitionColorTable.clear(); - JsonArray TransitionsArray = jsonConfig[CN_transitions]; for (auto currentTransition : TransitionsArray) { // DEBUG_V (""); @@ -474,11 +474,11 @@ bool c_InputEffectEngine::SetConfig (ArduinoJson::JsonObject& jsonConfig) } } - if(jsonConfig.containsKey(CN_MarqueeGroups)) + JsonArray MarqueeGroupArray = jsonConfig[CN_MarqueeGroups]; + if(MarqueeGroupArray) { MarqueueGroupTable.clear(); - JsonArray MarqueeGroupArray = jsonConfig[CN_MarqueeGroups]; for (auto currentMarqueeGroup : MarqueeGroupArray) { MarqueeGroup NewGroup; diff --git a/ESPixelStick/src/input/InputMQTT.cpp b/ESPixelStick/src/input/InputMQTT.cpp index debedc3aa..53b9b2ea6 100644 --- a/ESPixelStick/src/input/InputMQTT.cpp +++ b/ESPixelStick/src/input/InputMQTT.cpp @@ -797,9 +797,9 @@ void c_InputMQTT::UpdateEffectConfiguration (JsonObject & JsonConfig) setFromJSON (effectConfig.brightness, JsonConfig, CN_brightness); setFromJSON (effectConfig.whiteChannel, JsonConfig, CN_EffectWhiteChannel); - if (JsonConfig.containsKey (CN_color)) + JsonObject JsonColor = JsonConfig[CN_color]; + if (JsonColor) { - JsonObject JsonColor = JsonConfig[CN_color]; setFromJSON (effectConfig.color.r, JsonColor, CN_r); setFromJSON (effectConfig.color.g, JsonColor, CN_g); setFromJSON (effectConfig.color.b, JsonColor, CN_b); diff --git a/ESPixelStick/src/input/InputMgr.cpp b/ESPixelStick/src/input/InputMgr.cpp index 8ee15d532..a9a59e345 100644 --- a/ESPixelStick/src/input/InputMgr.cpp +++ b/ESPixelStick/src/input/InputMgr.cpp @@ -145,16 +145,11 @@ void c_InputMgr::CreateJsonConfig (JsonObject & jsonConfig) // add IM config parameters // DEBUG_V (""); - JsonObject InputMgrButtonData; + JsonObject InputMgrButtonData = jsonConfig[IM_EffectsControlButtonName]; - if (true == jsonConfig.containsKey (IM_EffectsControlButtonName)) + if (!InputMgrButtonData) { - // DEBUG_V (""); - InputMgrButtonData = jsonConfig[IM_EffectsControlButtonName]; - } - else - { - // DEBUG_V (""); + // DEBUG_V ("Create button data"); InputMgrButtonData = jsonConfig[IM_EffectsControlButtonName].to (); } // DEBUG_V (""); @@ -167,13 +162,8 @@ void c_InputMgr::CreateJsonConfig (JsonObject & jsonConfig) // DEBUG_V (""); // add the channels header - JsonObject InputMgrChannelsData; - if (true == jsonConfig.containsKey (CN_channels)) - { - // DEBUG_V (""); - InputMgrChannelsData = jsonConfig[CN_channels]; - } - else + JsonObject InputMgrChannelsData = jsonConfig[CN_channels]; + if (!InputMgrChannelsData) { // add our section header // DEBUG_V (""); @@ -192,14 +182,9 @@ void c_InputMgr::CreateJsonConfig (JsonObject & jsonConfig) // DEBUG_V (String("Create Section in Config file for the Input channel: '") + CurrentChannel.pInputChannelDriver->GetInputChannelId() + "'"); // create a record for this channel - JsonObject ChannelConfigData; String sChannelId = String (CurrentChannel.pInputChannelDriver->GetInputChannelId ()); - if (true == InputMgrChannelsData.containsKey (sChannelId)) - { - // DEBUG_V (""); - ChannelConfigData = InputMgrChannelsData[sChannelId]; - } - else + JsonObject ChannelConfigData = InputMgrChannelsData[sChannelId]; + if (!ChannelConfigData) { // add our section header // DEBUG_V (""); @@ -210,13 +195,8 @@ void c_InputMgr::CreateJsonConfig (JsonObject & jsonConfig) ChannelConfigData[CN_type] = int (CurrentChannel.pInputChannelDriver->GetInputType ()); String DriverTypeId = String (int (CurrentChannel.pInputChannelDriver->GetInputType ())); - JsonObject ChannelConfigByTypeData; - if (true == ChannelConfigData.containsKey (String (DriverTypeId))) - { - ChannelConfigByTypeData = ChannelConfigData[DriverTypeId]; - // DEBUG_V (""); - } - else + JsonObject ChannelConfigByTypeData = ChannelConfigData[(String (DriverTypeId))]; + if (!ChannelConfigByTypeData) { // add our section header // DEBUG_V (""); @@ -743,14 +723,14 @@ bool c_InputMgr::FindJsonChannelConfig (JsonObject& jsonConfig, do // once { - if (false == jsonConfig.containsKey (CN_input_config)) + JsonObject InputChannelMgrData = jsonConfig[CN_input_config]; + if (!InputChannelMgrData) { logcon (String (F ("No Input Interface Settings Found. Using Defaults"))); extern void PrettyPrint (JsonObject & jsonStuff, String Name); PrettyPrint (jsonConfig, String(F ("c_InputMgr::ProcessJsonConfig"))); break; } - JsonObject InputChannelMgrData = jsonConfig[CN_input_config]; // DEBUG_V (""); uint8_t TempVersion = !InputChannelMgrData; @@ -763,40 +743,40 @@ bool c_InputMgr::FindJsonChannelConfig (JsonObject& jsonConfig, if (TempVersion != CurrentConfigVersion) { - logcon (String (F ("InputMgr: Incorrect Version found. Using existing/default config."))); + logcon (String (F ("Incorrect Version found. Using existing/default config."))); // break; } // extract my own config data here - if (true == InputChannelMgrData.containsKey (IM_EffectsControlButtonName)) + JsonObject InputButtonConfig = InputChannelMgrData[IM_EffectsControlButtonName]; + if (InputButtonConfig) { // DEBUG_V ("Found Input Button Config"); - JsonObject InputButtonConfig = InputChannelMgrData[IM_EffectsControlButtonName]; ExternalInput.ProcessConfig (InputButtonConfig); } else { - logcon (String (F ("InputMgr: No Input Button Settings Found. Using Defaults"))); + logcon (String (F ("No Input Button Settings Found. Using Defaults"))); } // do we have a channel configuration array? - if (false == InputChannelMgrData.containsKey (CN_channels)) + JsonObject InputChannelArray = InputChannelMgrData[CN_channels]; + if (!InputChannelArray) { // if not, flag an error and stop processing logcon (String (F ("No Input Channel Settings Found. Using Defaults"))); break; } - JsonObject InputChannelArray = InputChannelMgrData[CN_channels]; // DEBUG_V (""); // get access to the channel config - if (false == InputChannelArray.containsKey (String (ChanId))) + ChanConfig = InputChannelArray[String(ChanId)]; + if (!ChanConfig) { // 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 @@ -844,22 +824,21 @@ bool c_InputMgr::ProcessJsonConfig (JsonObject & jsonConfig) if (/*(ChannelType < uint32_t (InputType_Start)) ||*/ (ChannelType >= uint32_t (InputType_End))) { // if not, flag an error and move on to the next channel - logcon (String (F ("Invalid Channel Type in config '")) + ChannelType + String (F ("'. Specified for channel '")) + ChannelIndex + "'. Disabling channel"); + logcon (String (MN_19) + ChannelType + String (MN_20) + ChannelIndex + String(MN_03)); InstantiateNewInputChannel (e_InputChannelIds (ChannelIndex), e_InputType::InputType_Disabled); continue; } // DEBUG_V (""); // do we have a configuration for the channel type? - if (false == InputChannelConfig.containsKey (String (ChannelType))) + JsonObject InputChannelDriverConfig = InputChannelConfig[String (ChannelType)]; + if (!InputChannelDriverConfig) { // if not, flag an error and stop processing logcon (String (F ("No Input Settings Found for Channel '")) + ChannelIndex + String (F ("'. Using Defaults"))); InstantiateNewInputChannel (e_InputChannelIds (ChannelIndex), e_InputType::InputType_Disabled); continue; } - - JsonObject InputChannelDriverConfig = InputChannelConfig[String (ChannelType)]; // DEBUG_V (""); // make sure the proper Input type is running diff --git a/ESPixelStick/src/network/NetworkMgr.cpp b/ESPixelStick/src/network/NetworkMgr.cpp index 0468613cc..4f7bdadc9 100644 --- a/ESPixelStick/src/network/NetworkMgr.cpp +++ b/ESPixelStick/src/network/NetworkMgr.cpp @@ -165,7 +165,8 @@ bool c_NetworkMgr::SetConfig (JsonObject & json) do // once { - if (!json.containsKey (CN_network)) + JsonObject network = json[CN_network]; + if (!network) { logcon (String (F ("No network config found. Use default settings"))); // request config save @@ -174,15 +175,14 @@ bool c_NetworkMgr::SetConfig (JsonObject & json) } // DEBUG_V(""); - JsonObject network = json[CN_network]; HostnameChanged = setFromJSON (hostname, network, CN_hostname); // DEBUG_V(""); - if (network.containsKey (CN_wifi)) + JsonObject networkWiFi = network[CN_wifi]; + if (networkWiFi) { // DEBUG_V(""); - JsonObject networkWiFi = network[CN_wifi]; ConfigChanged |= WiFiDriver.SetConfig (networkWiFi); } else @@ -205,9 +205,9 @@ bool c_NetworkMgr::SetConfig (JsonObject & json) #ifdef SUPPORT_ETHERNET ConfigChanged = setFromJSON (AllowWiFiAndEthUpSimultaneously, network, CN_weus); - if (network.containsKey (CN_eth)) + JsonObject networkEth = network[CN_eth]; + if (networkEth) { - JsonObject networkEth = network[CN_eth]; ConfigChanged |= EthernetDriver.SetConfig (networkEth); } else diff --git a/ESPixelStick/src/output/OutputMgr.cpp b/ESPixelStick/src/output/OutputMgr.cpp index d77dc80d0..6be24bbee 100644 --- a/ESPixelStick/src/output/OutputMgr.cpp +++ b/ESPixelStick/src/output/OutputMgr.cpp @@ -303,13 +303,12 @@ void c_OutputMgr::CreateJsonConfig (JsonObject& jsonConfig) // DEBUG_V (); // add the channels header - JsonObject OutputMgrChannelsData; - if (!jsonConfig.containsKey (CN_channels)) + JsonObject OutputMgrChannelsData = jsonConfig[CN_channels]; + if (!OutputMgrChannelsData) { // DEBUG_V (); - jsonConfig[CN_channels].to (); + OutputMgrChannelsData = jsonConfig[CN_channels].to (); } - OutputMgrChannelsData = jsonConfig[CN_channels]; // add the channel configurations // DEBUG_V ("For Each Output Channel"); @@ -317,14 +316,9 @@ void c_OutputMgr::CreateJsonConfig (JsonObject& jsonConfig) { // DEBUG_V (String("Create Section in Config file for the output channel: '") + CurrentChannel.pOutputChannelDriver->GetOutputChannelId() + "'"); // create a record for this channel - JsonObject ChannelConfigData; String sChannelId = String(CurrentChannel.pOutputChannelDriver->GetOutputChannelId()); - if (true == OutputMgrChannelsData.containsKey (sChannelId)) - { - // DEBUG_V (String("Channel Exists: ") + sChannelId); - ChannelConfigData = OutputMgrChannelsData[sChannelId]; - } - else + JsonObject ChannelConfigData = OutputMgrChannelsData[sChannelId]; + if (!ChannelConfigData) { // DEBUG_V (String ("add our channel section header. Chan: ") + sChannelId); ChannelConfigData = OutputMgrChannelsData[sChannelId].to (); @@ -334,13 +328,8 @@ void c_OutputMgr::CreateJsonConfig (JsonObject& jsonConfig) ChannelConfigData[CN_type] = int(CurrentChannel.pOutputChannelDriver->GetOutputType()); String DriverTypeId = String(int(CurrentChannel.pOutputChannelDriver->GetOutputType())); - JsonObject ChannelConfigByTypeData; - if (true == ChannelConfigData.containsKey (String (DriverTypeId))) - { - // DEBUG_V (String("Channel Type Data exists for chan: ") + sChannelId + " Type: " + DriverTypeId); - ChannelConfigByTypeData = ChannelConfigData[DriverTypeId]; - } - else + JsonObject ChannelConfigByTypeData = ChannelConfigData[String (DriverTypeId)]; + if (!ChannelConfigByTypeData) { // DEBUG_V (String("Add Channel Type Data for chan: ") + sChannelId + " Type: " + DriverTypeId); ChannelConfigByTypeData = ChannelConfigData[DriverTypeId].to (); @@ -1060,7 +1049,7 @@ void c_OutputMgr::LoadConfig () } // LoadConfig //----------------------------------------------------------------------------- -bool c_OutputMgr::FindJsonChannelConfig (JsonDocument& jsonConfig, +bool c_OutputMgr::FindJsonChannelConfig (JsonDocument& jsonConfig, e_OutputChannelIds ChanId, e_OutputType Type, JsonObject& ChanConfig) @@ -1068,18 +1057,21 @@ bool c_OutputMgr::FindJsonChannelConfig (JsonDocument& jsonConfig, // DEBUG_START; bool Response = false; // DEBUG_V (); + // DEBUG_V(String("ChanId: ") + String(ChanId)); + // DEBUG_V(String(" Type: ") + String(Type)); + // extern void PrettyPrint(JsonDocument & jsonStuff, String Name); // extern void PrettyPrint(JsonObject & jsonStuff, String Name); - // PrettyPrint(jsonConfig, "ProcessJsonConfig"); + // PrettyPrint(jsonConfig, "FindJsonChannelConfig"); do // once { - if (!jsonConfig.containsKey (CN_output_config)) + JsonObject OutputChannelMgrData = jsonConfig[CN_output_config]; + if (!OutputChannelMgrData) { logcon(String(MN_16) + MN_18); break; } - JsonObject OutputChannelMgrData = jsonConfig[CN_output_config]; // DEBUG_V (); uint8_t TempVersion = !CurrentConfigVersion; @@ -1087,7 +1079,6 @@ bool c_OutputMgr::FindJsonChannelConfig (JsonDocument& jsonConfig, // DEBUG_V (String ("TempVersion: ") + String (TempVersion)); // DEBUG_V (String ("CurrentConfigVersion: ") + String (CurrentConfigVersion)); - // extern void PrettyPrint (JsonObject & jsonStuff, String Name); // PrettyPrint (OutputChannelMgrData, "Output Config"); if (TempVersion != CurrentConfigVersion) { @@ -1096,38 +1087,42 @@ bool c_OutputMgr::FindJsonChannelConfig (JsonDocument& jsonConfig, } // do we have a channel configuration array? - if (!OutputChannelMgrData.containsKey (CN_channels)) + JsonObject OutputChannelArray = OutputChannelMgrData[CN_channels]; + if (!OutputChannelArray) { // if not, flag an error and stop processing - logcon(String(MN_16) + MN_18); + logcon(String(MN_16) + MN_18); break; } - JsonObject OutputChannelArray = OutputChannelMgrData[CN_channels]; // DEBUG_V (); // get access to the channel config - if (false == OutputChannelArray.containsKey(String(ChanId))) + ChanConfig = OutputChannelArray[String(ChanId)]; + if (!ChanConfig) { // if not, flag an error and stop processing logcon(String(MN_16) + ChanId + MN_18); break; } + // PrettyPrint(ChanConfig, "ProcessJson Channel Config"); // do we need to go deeper into the config? if(e_OutputType::OutputType_End == Type) { - // only looking for the overall channel config - ChanConfig = OutputChannelArray[String(ChanId)]; + // DEBUG_V("only looking for the overall channel config"); Response = true; break; } // go deeper and get the config for the specific channel type + // PrettyPrint(ChanConfig, "ProcessJson Channel Config"); // DEBUG_V (); JsonObject OutputChannelConfig = OutputChannelArray[String(ChanId)]; + // PrettyPrint (OutputChannelConfig, "Output Channel Config"); // do we have a configuration for the channel type? - if (!OutputChannelConfig.containsKey (String (Type))) + ChanConfig = OutputChannelConfig[String (Type)]; + if (!ChanConfig) { // Not found logcon(String(MN_16) + ChanId + MN_18); @@ -1137,11 +1132,6 @@ bool c_OutputMgr::FindJsonChannelConfig (JsonDocument& jsonConfig, // DEBUG_V (); // PrettyPrint(OutputChannelConfig, "ProcessJson Channel Config"); - ChanConfig = OutputChannelConfig[String (Type)]; - // DEBUG_V (); - // PrettyPrint(ChanConfig, "ProcessJson Channel Driver Config before driver create"); - // DEBUG_V (); - // all went well Response = true; @@ -1160,6 +1150,7 @@ bool c_OutputMgr::ProcessJsonConfig (JsonDocument& jsonConfig) // DEBUG_V (); + // extern void PrettyPrint(JsonDocument & jsonStuff, String Name); // extern void PrettyPrint(JsonObject & jsonStuff, String Name); // PrettyPrint(jsonConfig, "ProcessJsonConfig"); @@ -1187,6 +1178,7 @@ bool c_OutputMgr::ProcessJsonConfig (JsonDocument& jsonConfig) // is it a valid / supported channel type if (ChannelType >= uint32_t (OutputType_End)) { + // DEBUG_V (String("OutputType_End: ") + String(OutputType_End)); // if not, flag an error and move on to the next channel logcon(String(MN_19) + ChannelType + MN_20 + CurrentOutputChannelDriver.DriverId + MN_03); InstantiateNewOutputChannel(CurrentOutputChannelDriver, e_OutputType::OutputType_Disabled); @@ -1195,18 +1187,14 @@ bool c_OutputMgr::ProcessJsonConfig (JsonDocument& jsonConfig) // DEBUG_V (); // do we have a configuration for the channel type? - if (false == OutputChannelConfig.containsKey (String (ChannelType))) + JsonObject OutputChannelDriverConfig = OutputChannelConfig[String (ChannelType)]; + if (!OutputChannelDriverConfig) { // if not, flag an error and stop processing logcon(String(MN_16) + CurrentOutputChannelDriver.DriverId + MN_18); InstantiateNewOutputChannel(CurrentOutputChannelDriver, e_OutputType::OutputType_Disabled); continue; } - - // DEBUG_V (); - // PrettyPrint(OutputChannelConfig, "ProcessJson Channel Config"); - - JsonObject OutputChannelDriverConfig = OutputChannelConfig[String (ChannelType)]; // DEBUG_V (); // PrettyPrint(OutputChannelDriverConfig, "ProcessJson Channel Driver Config before driver create"); // DEBUG_V (); diff --git a/ESPixelStick/src/output/OutputRelay.cpp b/ESPixelStick/src/output/OutputRelay.cpp index affbd73d3..e04fb55ab 100644 --- a/ESPixelStick/src/output/OutputRelay.cpp +++ b/ESPixelStick/src/output/OutputRelay.cpp @@ -142,7 +142,7 @@ bool c_OutputRelay::validate () for (int ChannelIndex = OM_RELAY_CHANNEL_LIMIT - 1; ChannelIndex > Num_Channels; ChannelIndex--) { - logcon (String (CN_stars + String(F (" Disabling channel '")) + String(ChannelIndex + 1) + "' " + CN_stars)); + logcon (String (CN_stars + String(MN_03) + String(ChannelIndex + 1) + "' " + CN_stars)); OutputList[ChannelIndex].Enabled = false; } @@ -226,13 +226,13 @@ bool c_OutputRelay::SetConfig (ArduinoJson::JsonObject & jsonConfig) setFromJSON (UpdateInterval, jsonConfig, OM_RELAY_UPDATE_INTERVAL_NAME); // do we have a channel configuration array? - if (false == jsonConfig.containsKey (CN_channels)) + JsonArray JsonChannelList = jsonConfig[CN_channels]; + if (!JsonChannelList) { // if not, flag an error and stop processing logcon (F ("No output channel settings found. Using defaults.")); break; } - JsonArray JsonChannelList = jsonConfig[CN_channels]; for (JsonVariant JsonChannelData : JsonChannelList) { diff --git a/ESPixelStick/src/output/OutputServoPCA9685.cpp b/ESPixelStick/src/output/OutputServoPCA9685.cpp index 486d15f61..cc4c209ad 100644 --- a/ESPixelStick/src/output/OutputServoPCA9685.cpp +++ b/ESPixelStick/src/output/OutputServoPCA9685.cpp @@ -164,13 +164,13 @@ bool c_OutputServoPCA9685::SetConfig (ArduinoJson::JsonObject & jsonConfig) pwm->setPWMFreq (UpdateFrequency); // do we have a channel configuration array? - if (false == jsonConfig.containsKey (OM_SERVO_PCA9685_CHANNELS_NAME)) + JsonArray JsonChannelList = jsonConfig[OM_SERVO_PCA9685_CHANNELS_NAME]; + if (!JsonChannelList) { // if not, flag an error and stop processing logcon (MN_04); break; } - JsonArray JsonChannelList = jsonConfig[OM_SERVO_PCA9685_CHANNELS_NAME]; for (JsonVariant JsonChannelData : JsonChannelList) { diff --git a/ESPixelStick/src/service/SensorDS18B20.cpp b/ESPixelStick/src/service/SensorDS18B20.cpp index f9e4224da..2d40e47ef 100644 --- a/ESPixelStick/src/service/SensorDS18B20.cpp +++ b/ESPixelStick/src/service/SensorDS18B20.cpp @@ -60,14 +60,13 @@ bool c_SensorDS18B20::SetConfig (JsonObject& json) do // once { - if (!json.containsKey (CN_sensor)) + JsonObject JsonDeviceConfig = json[CN_sensor]; + if (!JsonDeviceConfig) { logcon (F ("No Sensor settings found.")); break; } - JsonObject JsonDeviceConfig = json[CN_sensor]; - ConfigChanged |= setFromJSON (TempUnit, JsonDeviceConfig, CN_units); LastReadingTime = 0; // force a reading } while(false); From 83a8f5fa70612daf2a0e192777940a2db007ffb0 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 16 Sep 2024 08:22:20 -0400 Subject: [PATCH 3/6] Upated the configuration for temperature sensor to match the HW. --- .../src/platformDefinitions/GPIO_Defs_ESP32_QUINLED_QUAD.hpp | 2 +- .../GPIO_Defs_ESP32_QUINLED_QUAD_AE_Plus.hpp | 2 +- .../GPIO_Defs_ESP32_QUINLED_QUAD_AE_Plus_8.hpp | 2 +- .../platformDefinitions/GPIO_Defs_ESP32_QUINLED_QUAD_ETH.hpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ESPixelStick/src/platformDefinitions/GPIO_Defs_ESP32_QUINLED_QUAD.hpp b/ESPixelStick/src/platformDefinitions/GPIO_Defs_ESP32_QUINLED_QUAD.hpp index 45d442bba..ec0c840d5 100644 --- a/ESPixelStick/src/platformDefinitions/GPIO_Defs_ESP32_QUINLED_QUAD.hpp +++ b/ESPixelStick/src/platformDefinitions/GPIO_Defs_ESP32_QUINLED_QUAD.hpp @@ -41,7 +41,7 @@ // Temperature Sensor #define SUPPORT_SENSOR_DS18B20 -#define ONEWIRE_PIN gpio_num_t::GPIO_NUM_18 +#define ONEWIRE_PIN gpio_num_t::GPIO_NUM_13 // Output Types // Not Finished - #define SUPPORT_OutputType_TLS3001 diff --git a/ESPixelStick/src/platformDefinitions/GPIO_Defs_ESP32_QUINLED_QUAD_AE_Plus.hpp b/ESPixelStick/src/platformDefinitions/GPIO_Defs_ESP32_QUINLED_QUAD_AE_Plus.hpp index 76094f108..c5e3c91d1 100644 --- a/ESPixelStick/src/platformDefinitions/GPIO_Defs_ESP32_QUINLED_QUAD_AE_Plus.hpp +++ b/ESPixelStick/src/platformDefinitions/GPIO_Defs_ESP32_QUINLED_QUAD_AE_Plus.hpp @@ -46,7 +46,7 @@ // Temperature Sensor #define SUPPORT_SENSOR_DS18B20 -#define ONEWIRE_PIN gpio_num_t::GPIO_NUM_18 +#define ONEWIRE_PIN gpio_num_t::GPIO_NUM_13 // Output Types // Not Finished - #define SUPPORT_OutputType_TLS3001 diff --git a/ESPixelStick/src/platformDefinitions/GPIO_Defs_ESP32_QUINLED_QUAD_AE_Plus_8.hpp b/ESPixelStick/src/platformDefinitions/GPIO_Defs_ESP32_QUINLED_QUAD_AE_Plus_8.hpp index 03c59bfcc..4093846cc 100644 --- a/ESPixelStick/src/platformDefinitions/GPIO_Defs_ESP32_QUINLED_QUAD_AE_Plus_8.hpp +++ b/ESPixelStick/src/platformDefinitions/GPIO_Defs_ESP32_QUINLED_QUAD_AE_Plus_8.hpp @@ -41,7 +41,7 @@ // Temperature Sensor #define SUPPORT_SENSOR_DS18B20 -#define ONEWIRE_PIN gpio_num_t::GPIO_NUM_18 +#define ONEWIRE_PIN gpio_num_t::GPIO_NUM_13 // Output Types // Not Finished - #define SUPPORT_OutputType_TLS3001 diff --git a/ESPixelStick/src/platformDefinitions/GPIO_Defs_ESP32_QUINLED_QUAD_ETH.hpp b/ESPixelStick/src/platformDefinitions/GPIO_Defs_ESP32_QUINLED_QUAD_ETH.hpp index 4a924f207..7cd54ea12 100644 --- a/ESPixelStick/src/platformDefinitions/GPIO_Defs_ESP32_QUINLED_QUAD_ETH.hpp +++ b/ESPixelStick/src/platformDefinitions/GPIO_Defs_ESP32_QUINLED_QUAD_ETH.hpp @@ -43,7 +43,7 @@ // Temperature Sensor #define SUPPORT_SENSOR_DS18B20 -#define ONEWIRE_PIN gpio_num_t::GPIO_NUM_18 +#define ONEWIRE_PIN gpio_num_t::GPIO_NUM_13 #include From afcdd5cbf358aecc04d1c66c8788bb5137d8b7ad Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 18 Sep 2024 14:53:35 -0400 Subject: [PATCH 4/6] Preparing for Ethernet switch support --- .../GPIO_Defs_ESP32_kr_lights_msm.hpp | 37 ++----------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/ESPixelStick/src/platformDefinitions/GPIO_Defs_ESP32_kr_lights_msm.hpp b/ESPixelStick/src/platformDefinitions/GPIO_Defs_ESP32_kr_lights_msm.hpp index 61adcec8f..91e8482ad 100644 --- a/ESPixelStick/src/platformDefinitions/GPIO_Defs_ESP32_kr_lights_msm.hpp +++ b/ESPixelStick/src/platformDefinitions/GPIO_Defs_ESP32_kr_lights_msm.hpp @@ -19,6 +19,7 @@ */ // #define SUPPORT_ETHERNET +// #define SUPPORT_ETHERNET_KSZ8863 //Output Manager #define DEFAULT_RMT_0_GPIO gpio_num_t::GPIO_NUM_15 @@ -36,45 +37,15 @@ // File Manager // #define SUPPORT_SD +// used by the ethernet interface #define SD_CARD_MISO_PIN gpio_num_t::GPIO_NUM_4 #define SD_CARD_MOSI_PIN gpio_num_t::GPIO_NUM_4 #define SD_CARD_CLK_PIN gpio_num_t::GPIO_NUM_4 #define SD_CARD_CS_PIN gpio_num_t::GPIO_NUM_4 -// #include - -/* - * ETH_CLOCK_GPIO0_IN - default: external clock from crystal oscillator - * ETH_CLOCK_GPIO0_OUT - 50MHz clock from internal APLL output on GPIO0 - possibly an inverter is needed for LAN8720 - * ETH_CLOCK_GPIO16_OUT - 50MHz clock from internal APLL output on GPIO16 - possibly an inverter is needed for LAN8720 - * ETH_CLOCK_GPIO17_OUT - 50MHz clock from internal APLL inverted output on GPIO17 - tested with LAN8720 -*/ -#define DEFAULT_ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT - -// Pin# of the enable signal for the external crystal oscillator (-1 to disable for internal APLL source) -// #define DEFAULT_ETH_POWER_PIN gpio_num_t(-1) -// #define DEFAULT_ETH_POWER_PIN_ACTIVE HIGH - -// Type of the Ethernet PHY (LAN8720 or TLK110) -// #define DEFAULT_ETH_TYPE ETH_PHY_LAN8720 - -// I2C-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110) -// #define ETH_ADDR_PHY_LAN8720 0 -// #define ETH_ADDR_PHY_LAN8720 1 -//#define ETH_ADDR_PHY_TLK110 31 -// #define DEFAULT_ETH_ADDR ETH_ADDR_PHY_LAN8720 -#define DEFAULT_ETH_TXEN gpio_num_t::GPIO_NUM_21 -#define DEFAULT_ETH_TXD0 gpio_num_t::GPIO_NUM_19 -#define DEFAULT_ETH_TXD1 gpio_num_t::GPIO_NUM_22 -#define DEFAULT_ETH_CRSDV gpio_num_t::GPIO_NUM_27 -#define DEFAULT_ETH_RXD0 gpio_num_t::GPIO_NUM_25 -#define DEFAULT_ETH_RXD1 gpio_num_t::GPIO_NUM_26 -#define DEFAULT_ETH_MDC_PIN gpio_num_t::GPIO_NUM_23 -#define DEFAULT_ETH_MDIO_PIN gpio_num_t::GPIO_NUM_18 - // Output Types // Not Finished - #define SUPPORT_OutputType_TLS3001 -// #define SUPPORT_OutputType_APA102 // SPI +// used by ethernet chip #define SUPPORT_OutputType_APA102 // SPI #define SUPPORT_OutputType_DMX // UART / RMT #define SUPPORT_OutputType_GECE // UART / RMT #define SUPPORT_OutputType_GS8208 // UART / RMT @@ -83,7 +54,7 @@ #define SUPPORT_OutputType_TM1814 // UART / RMT #define SUPPORT_OutputType_UCS1903 // UART / RMT #define SUPPORT_OutputType_UCS8903 // UART / RMT -// #define SUPPORT_OutputType_WS2801 // SPI +// used by ethernet chip #define SUPPORT_OutputType_WS2801 // SPI #define SUPPORT_OutputType_WS2811 // UART / RMT #define SUPPORT_OutputType_Relay // GPIO // #define SUPPORT_OutputType_Servo_PCA9685 // I2C (default pins) From 8d4079d0bc4fb8fef818336ecefc58be20837be8 Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 18 Sep 2024 14:55:00 -0400 Subject: [PATCH 5/6] Removed magic number --- ESPixelStick/src/output/OutputRmt.cpp | 10 +++++----- ESPixelStick/src/output/OutputRmt.hpp | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ESPixelStick/src/output/OutputRmt.cpp b/ESPixelStick/src/output/OutputRmt.cpp index 3ae48764c..e78a18e11 100644 --- a/ESPixelStick/src/output/OutputRmt.cpp +++ b/ESPixelStick/src/output/OutputRmt.cpp @@ -2,7 +2,7 @@ * OutputRmt.cpp - driver code for ESPixelStick RMT Channel * * Project: ESPixelStick - An ESP8266 / ESP32 and E1.31 based pixel driver -* Copyright (c) 2015, 2022 Shelby Merrick +* Copyright (c) 2015, 2024 Shelby Merrick * http://www.forkineye.com * * This program is provided free for you to use in any way that you wish, @@ -24,7 +24,7 @@ // forward declaration for the isr handler static void IRAM_ATTR rmt_intr_handler (void* param); static rmt_isr_handle_t RMT_intr_handle = NULL; -static c_OutputRmt * rmt_isr_ThisPtrs[8]; +static c_OutputRmt * rmt_isr_ThisPtrs[MAX_NUM_RMT_CHANNELS]; static bool InIsr = false; #ifdef USE_RMT_DEBUG_COUNTERS @@ -39,7 +39,7 @@ c_OutputRmt::c_OutputRmt() memset((void *)&Intensity2Rmt[0], 0x00, sizeof(Intensity2Rmt)); memset((void *)&SendBuffer[0], 0x00, sizeof(SendBuffer)); - if(NULL == RMT_intr_handle) + if(NULL != RMT_intr_handle) { for(auto & currentThisPtr : rmt_isr_ThisPtrs) { @@ -89,7 +89,7 @@ static void IRAM_ATTR rmt_intr_handler (void* param) if(!InIsr) { InIsr = true; - + // read the current ISR flags uint32_t isrFlags = RMT.int_st.val; RMT.int_clr.val = uint32_t(-1); @@ -230,7 +230,7 @@ void c_OutputRmt::Begin (OutputRmtConfig_t config ) void c_OutputRmt::GetStatus (ArduinoJson::JsonObject& jsonStatus) { // //DEBUG_START; - + jsonStatus[F("NumRmtSlotOverruns")] = NumRmtSlotOverruns; #ifdef USE_RMT_DEBUG_COUNTERS jsonStatus[F("OutputIsPaused")] = OutputIsPaused; diff --git a/ESPixelStick/src/output/OutputRmt.hpp b/ESPixelStick/src/output/OutputRmt.hpp index 7e72bd882..87ef02c87 100644 --- a/ESPixelStick/src/output/OutputRmt.hpp +++ b/ESPixelStick/src/output/OutputRmt.hpp @@ -3,7 +3,7 @@ * OutputRmt.hpp - RMT driver code for ESPixelStick RMT Channel * * Project: ESPixelStick - An ESP8266 / ESP32 and E1.31 based pixel driver -* Copyright (c) 2015, 2022 Shelby Merrick +* Copyright (c) 2015, 2024 Shelby Merrick * http://www.forkineye.com * * This program is provided free for you to use in any way that you wish, @@ -76,6 +76,7 @@ class c_OutputRmt }; private: +#define MAX_NUM_RMT_CHANNELS 8 #define RMT_INT_TX_END (1) #define RMT_INT_RX_END (2) #define RMT_INT_ERROR (4) From 73c082db01d69526e31602d0d7f415de08e15c04 Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 18 Sep 2024 15:14:45 -0400 Subject: [PATCH 6/6] Updated to latest ArduinoJson --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 9a37b4367..d476c78ca 100644 --- a/platformio.ini +++ b/platformio.ini @@ -23,7 +23,7 @@ upload_speed = 921600 lib_compat_mode = strict lib_deps = adafruit/Adafruit PWM Servo Driver Library @ 2.4.0 - https://github.com/bblanchon/ArduinoJson @ 7.1.0 + https://github.com/bblanchon/ArduinoJson # 7.2.0 https://github.com/djGrrr/Int64String @ 1.1.1 https://github.com/esphome/ESPAsyncWebServer#4fd0a1fdf421664214a27373c0eb0247f94b7a79 https://github.com/forkineye/ESPAsyncE131