Skip to content

Commit

Permalink
Merge pull request #785 from MartinMueller2003/main
Browse files Browse the repository at this point in the history
Fixed incorrect temperature sensor GPIO settings
  • Loading branch information
forkineye authored Sep 18, 2024
2 parents adbcba2 + 73c082d commit 972841d
Show file tree
Hide file tree
Showing 19 changed files with 138 additions and 166 deletions.
38 changes: 22 additions & 16 deletions ESPixelStick/ESPixelStick.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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");
Expand Down
28 changes: 28 additions & 0 deletions ESPixelStick/src/EFUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -86,14 +90,24 @@ 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 ();
_record.type = RecordType(ntohs((uint16_t)_record.type));
_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
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions ESPixelStick/src/FileMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
8 changes: 4 additions & 4 deletions ESPixelStick/src/input/InputEffectEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ("");
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions ESPixelStick/src/input/InputMQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
65 changes: 22 additions & 43 deletions ESPixelStick/src/input/InputMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<JsonObject> ();
}
// DEBUG_V ("");
Expand All @@ -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 ("");
Expand All @@ -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 ("");
Expand All @@ -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 ("");
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions ESPixelStick/src/network/NetworkMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 972841d

Please sign in to comment.