diff --git a/src/_C002.cpp b/src/_C002.cpp index 97757a3dd..98f716207 100644 --- a/src/_C002.cpp +++ b/src/_C002.cpp @@ -84,9 +84,9 @@ bool CPlugin_002(CPlugin::Function function, struct EventStruct *event, String& // We need the index of the controller we are: 0...CONTROLLER_MAX if (Settings.TaskDeviceEnabled[x] && (Settings.TaskDeviceSendData[ControllerID][x] - || (Settings.TaskDeviceNumber[x] == pluginID_t::toPluginID(29)) // Domoticz helper doesn't have controller checkboxes... + || (Settings.getPluginID_for_task(x) == pluginID_t::toPluginID(29)) // Domoticz helper doesn't have controller checkboxes... # if defined(USES_P088) - || (Settings.TaskDeviceNumber[x] == pluginID_t::toPluginID(88)) // Heatpump IR doesn't have controller checkboxes... + || (Settings.getPluginID_for_task(x) == pluginID_t::toPluginID(88)) // Heatpump IR doesn't have controller checkboxes... # endif // if defined(USES_P088) ) && (Settings.TaskDeviceID[ControllerID][x] == idx)) // get idx for our controller index @@ -94,7 +94,7 @@ bool CPlugin_002(CPlugin::Function function, struct EventStruct *event, String& String action; bool mustSendEvent = false; - switch (Settings.TaskDeviceNumber[x].value) { + switch (Settings.getPluginID_for_task(x).value) { case 1: // temp solution, if input switch, update state { action = F("inputSwitchState,"); diff --git a/src/_C013.cpp b/src/_C013.cpp index eab1b2e7f..15454377c 100644 --- a/src/_C013.cpp +++ b/src/_C013.cpp @@ -106,7 +106,7 @@ void C013_SendUDPTaskInfo(uint8_t destUnit, uint8_t sourceTaskIndex, uint8_t des if (!validTaskIndex(sourceTaskIndex) || !validTaskIndex(destTaskIndex)) { return; } - pluginID_t pluginID = Settings.TaskDeviceNumber[sourceTaskIndex]; + pluginID_t pluginID = Settings.getPluginID_for_task(sourceTaskIndex); if (!validPluginID_fullcheck(pluginID)) { return; @@ -148,7 +148,7 @@ void C013_SendUDPTaskData(struct EventStruct *event, uint8_t destUnit, uint8_t d dataReply.sourceUnit = Settings.Unit; dataReply.sourceTaskIndex = event->TaskIndex; dataReply.destTaskIndex = destTaskIndex; - dataReply.deviceNumber = Settings.TaskDeviceNumber[event->TaskIndex]; + dataReply.deviceNumber = Settings.getPluginID_for_task(event->TaskIndex); // FIXME TD-er: We should check for sensorType and pluginID on both sides. // For example sending different sensor type data from one dummy to another is probably not going to work well @@ -247,11 +247,11 @@ void C013_Receive(struct EventStruct *event) { // to prevent flash wear out (bugs in communication?) we can only write to an empty task // so it will write only once and has to be cleared manually through webgui // Also check the receiving end does support the plugin ID. - if (!validPluginID_fullcheck(Settings.TaskDeviceNumber[infoReply.destTaskIndex]) && + if (!validPluginID_fullcheck(Settings.getPluginID_for_task(infoReply.destTaskIndex)) && supportedPluginID(infoReply.deviceNumber)) { taskClear(infoReply.destTaskIndex, false); - Settings.TaskDeviceNumber[infoReply.destTaskIndex] = infoReply.deviceNumber; + Settings.TaskDeviceNumber[infoReply.destTaskIndex] = infoReply.deviceNumber.value; Settings.TaskDeviceDataFeed[infoReply.destTaskIndex] = infoReply.sourceUnit; // remote feed store unit nr sending the data if ((infoReply.deviceNumber == pluginID_t::toPluginID(33)) && (infoReply.sensorType != Sensor_VType::SENSOR_TYPE_NONE)) { @@ -297,13 +297,13 @@ void C013_Receive(struct EventStruct *event) { if ((remoteFeed != 0) && (remoteFeed == dataReply.sourceUnit)) { - if (!dataReply.matchesPluginID(Settings.TaskDeviceNumber[dataReply.destTaskIndex])) { + if (!dataReply.matchesPluginID(Settings.getPluginID_for_task(dataReply.destTaskIndex))) { // Mismatch in plugin ID from sending node if (loglevelActiveFor(LOG_LEVEL_ERROR)) { String log = concat(F("P2P data : PluginID mismatch for task "), dataReply.destTaskIndex + 1); log += concat(F(" from unit "), dataReply.sourceUnit); log += concat(F(" remote: "), dataReply.deviceNumber.value); - log += concat(F(" local: "), Settings.TaskDeviceNumber[dataReply.destTaskIndex].value); + log += concat(F(" local: "), Settings.getPluginID_for_task(dataReply.destTaskIndex).value); addLogMove(LOG_LEVEL_ERROR, log); } } else { diff --git a/src/_C014.cpp b/src/_C014.cpp index 0ece7b5d2..5516a4ff5 100644 --- a/src/_C014.cpp +++ b/src/_C014.cpp @@ -398,7 +398,7 @@ bool CPlugin_014(CPlugin::Function function, struct EventStruct *event, String& // SECOND Plugins for (taskIndex_t x = 0; x < TASKS_MAX; x++) { - if (validPluginID_fullcheck((Settings.TaskDeviceNumber[x]))) + if (validPluginID_fullcheck((Settings.getPluginID_for_task(x)))) { LoadTaskSettings(x); deviceIndex_t DeviceIndex = getDeviceIndex_from_TaskIndex(x); @@ -416,7 +416,7 @@ bool CPlugin_014(CPlugin::Function function, struct EventStruct *event, String& if (Device[DeviceIndex].Number == 86) // Homie receiver { for (uint8_t varNr = 0; varNr < valueCount; varNr++) { - if (validPluginID_fullcheck(Settings.TaskDeviceNumber[x])) { + if (validPluginID_fullcheck(Settings.getPluginID_for_task(x))) { if (ExtraTaskSettings.TaskDeviceValueNames[varNr][0] != 0) { // do not send if Value Name is empty! CPLUGIN_014_addToList(valuesList, ExtraTaskSettings.TaskDeviceValueNames[varNr]); @@ -502,7 +502,7 @@ bool CPlugin_014(CPlugin::Function function, struct EventStruct *event, String& { // standard Values for (uint8_t varNr = 0; varNr < valueCount; varNr++) { - if (validPluginID_fullcheck(Settings.TaskDeviceNumber[x])) + if (validPluginID_fullcheck(Settings.getPluginID_for_task(x))) { if (ExtraTaskSettings.TaskDeviceValueNames[varNr][0] != 0) // do not send if Value Name is empty! { diff --git a/src/_P037_MQTTImport.ino b/src/_P037_MQTTImport.ino index a082f65a7..9be10fe2b 100644 --- a/src/_P037_MQTTImport.ino +++ b/src/_P037_MQTTImport.ino @@ -743,7 +743,7 @@ bool MQTT_unsubscribe_037(struct EventStruct *event) for (taskIndex_t task = 0; task < INVALID_TASK_INDEX && canUnsubscribe; ++task) { if (task != event->TaskIndex) { if (Settings.TaskDeviceEnabled[task] && - (Settings.TaskDeviceNumber[task] == pluginID_t::toPluginID(PLUGIN_ID_037))) { + (Settings.getPluginID_for_task(task) == pluginID_t::toPluginID(PLUGIN_ID_037))) { P037_data_struct *P037_data_other = static_cast(getPluginTaskData(task)); if (nullptr != P037_data_other) { diff --git a/src/_P040_ID12.ino b/src/_P040_ID12.ino index eb71f3dbb..bef2518a9 100644 --- a/src/_P040_ID12.ino +++ b/src/_P040_ID12.ino @@ -121,7 +121,7 @@ boolean Plugin_040(uint8_t function, struct EventStruct *event, String& string) // temp woraround, ESP Easy framework does not currently prepare this... taskIndex_t index = INVALID_TASK_INDEX; for (taskIndex_t y = 0; y < TASKS_MAX; y++) - if (Settings.TaskDeviceNumber[y].value == PLUGIN_ID_040) + if (Settings.getPluginID_for_task(y).value == PLUGIN_ID_040) index = y; const deviceIndex_t DeviceIndex = getDeviceIndex_from_TaskIndex(index); if (!validDeviceIndex(DeviceIndex)) { diff --git a/src/_Plugin_Helper.cpp b/src/_Plugin_Helper.cpp index 00b365351..6d4915c34 100644 --- a/src/_Plugin_Helper.cpp +++ b/src/_Plugin_Helper.cpp @@ -52,7 +52,7 @@ void initPluginTaskData(taskIndex_t taskIndex, PluginTaskData_base *data) { if (data != nullptr) { if (Settings.TaskDeviceEnabled[taskIndex]) { Plugin_task_data[taskIndex] = data; - Plugin_task_data[taskIndex]->_taskdata_pluginID = Settings.TaskDeviceNumber[taskIndex]; + Plugin_task_data[taskIndex]->_taskdata_pluginID = Settings.getPluginID_for_task(taskIndex); #if FEATURE_PLUGIN_STATS const uint8_t valueCount = getValueCountForTask(taskIndex); @@ -96,7 +96,7 @@ bool pluginTaskData_initialized(taskIndex_t taskIndex) { return false; } return Plugin_task_data[taskIndex] != nullptr && - (Plugin_task_data[taskIndex]->_taskdata_pluginID == Settings.TaskDeviceNumber[taskIndex]); + (Plugin_task_data[taskIndex]->_taskdata_pluginID == Settings.getPluginID_for_task(taskIndex)); } String getPluginCustomArgName(int varNr) { diff --git a/src/src/Commands/Notifications.cpp b/src/src/Commands/Notifications.cpp index eb5a5c2c1..38ca3fb41 100644 --- a/src/src/Commands/Notifications.cpp +++ b/src/src/Commands/Notifications.cpp @@ -19,8 +19,9 @@ const __FlashStringHelper * Command_Notifications_Notify(struct EventStruct *eve if (event->Par1 > 0) { int index = event->Par1 - 1; - if (Settings.NotificationEnabled[index] && Settings.Notification[index] != INVALID_N_PLUGIN_ID) { - nprotocolIndex_t NotificationProtocolIndex = getNProtocolIndex(Settings.Notification[index]); + if (Settings.NotificationEnabled[index] && Settings.Notification[index] != INVALID_N_PLUGIN_ID.value) { + nprotocolIndex_t NotificationProtocolIndex = + getNProtocolIndex(npluginID_t::toPluginID(Settings.Notification[index])); if (validNProtocolIndex(NotificationProtocolIndex )) { struct EventStruct TempEvent(event->TaskIndex); // TempEvent.NotificationProtocolIndex = NotificationProtocolIndex; diff --git a/src/src/DataStructs/DeviceStruct.cpp b/src/src/DataStructs/DeviceStruct.cpp index 8fc9c186f..682d2edf9 100644 --- a/src/src/DataStructs/DeviceStruct.cpp +++ b/src/src/DataStructs/DeviceStruct.cpp @@ -78,16 +78,15 @@ pluginID_t DeviceStruct::getPluginID() const } + +#ifndef ESP8266 + DeviceCount_t& DeviceCount_t::operator++() { // pre-increment, ++a ++value; return *this; } - - -#ifndef ESP8266 - const DeviceStruct& DeviceVector::operator[](deviceIndex_t index) const { return _vector[index.value]; diff --git a/src/src/DataStructs/ESPEasyControllerCache_CSV_dumper.cpp b/src/src/DataStructs/ESPEasyControllerCache_CSV_dumper.cpp index bf53173fe..ac671cde3 100644 --- a/src/src/DataStructs/ESPEasyControllerCache_CSV_dumper.cpp +++ b/src/src/DataStructs/ESPEasyControllerCache_CSV_dumper.cpp @@ -39,7 +39,7 @@ ESPEasyControllerCache_CSV_dumper::ESPEasyControllerCache_CSV_dumper(bool joinTi } for (size_t task = 0; validTaskIndex(task); ++task) { - _includeTask[task] = _onlySetTasks ? validPluginID(Settings.TaskDeviceNumber[task]) : true; + _includeTask[task] = _onlySetTasks ? validPluginID(Settings.getPluginID_for_task(task)) : true; } if (_target == Target::CSV_file) { diff --git a/src/src/DataStructs/SettingsStruct.h b/src/src/DataStructs/SettingsStruct.h index f39f56431..4043c0a6c 100644 --- a/src/src/DataStructs/SettingsStruct.h +++ b/src/src/DataStructs/SettingsStruct.h @@ -282,6 +282,8 @@ public: float getWiFi_TX_power() const; void setWiFi_TX_power(float dBm); + pluginID_t getPluginID_for_task(taskIndex_t taskIndex) const; + unsigned long PID = 0; int Version = 0; @@ -325,10 +327,10 @@ public: uint8_t InitSPI = 0; //0 = disabled, 1= enabled but for ESP32 there is option 2= SPI2 9 = User defined, see src/src/WebServer/HardwarePage.h enum SPI_Options_e // FIXME TD-er: Must change to cpluginID_t, but then also another check must be added since changing the pluginID_t will also render settings incompatible uint8_t Protocol[CONTROLLER_MAX] = {0}; - npluginID_t Notification[NOTIFICATION_MAX]{}; //notifications, point to a NPLUGIN id + uint8_t Notification[NOTIFICATION_MAX] = {0}; //notifications, point to a NPLUGIN id // FIXME TD-er: Must change to pluginID_t, but then also another check must be added since changing the pluginID_t will also render settings incompatible - pluginID_t TaskDeviceNumber[N_TASKS]{}; // The "plugin number" set at as task (e.g. 4 for P004_dallas) - unsigned int OLD_TaskDeviceID[N_TASKS] = {0}; //UNUSED: this can be removed + uint8_t TaskDeviceNumber[N_TASKS] = {0}; // The "plugin number" set at as task (e.g. 4 for P004_dallas) + unsigned int OLD_TaskDeviceID[N_TASKS] = {0}; //UNUSED: this can be reused union { struct { int8_t TaskDevicePin1[N_TASKS]; @@ -350,7 +352,7 @@ public: uint8_t VariousTaskBits[N_TASKS] = {0}; uint8_t TaskDeviceDataFeed[N_TASKS] = {0}; // When set to 0, only read local connected sensorsfeeds unsigned long TaskDeviceTimer[N_TASKS] = {0}; - TaskEnabledState TaskDeviceEnabled[N_TASKS]{}; + boolean TaskDeviceEnabled[N_TASKS] = {0}; boolean ControllerEnabled[CONTROLLER_MAX] = {0}; boolean NotificationEnabled[NOTIFICATION_MAX] = {0}; unsigned int TaskDeviceID[CONTROLLER_MAX][N_TASKS]{}; // IDX number (mainly used by Domoticz) diff --git a/src/src/DataStructs_templ/SettingsStruct.cpp b/src/src/DataStructs_templ/SettingsStruct.cpp index 11fd7bc42..8e0bd08a5 100644 --- a/src/src/DataStructs_templ/SettingsStruct.cpp +++ b/src/src/DataStructs_templ/SettingsStruct.cpp @@ -471,7 +471,8 @@ void SettingsStruct_tmpl::validate() { #endif #endif for (uint8_t i = 0; i < N_TASKS; ++i) { - TaskDeviceEnabled[i].clearTempDisableFlags(); +// TaskDeviceEnabled[i].clearTempDisableFlags(); + TaskDeviceEnabled[i] = false; } } @@ -509,7 +510,7 @@ void SettingsStruct_tmpl::clearTimeSettings() { template void SettingsStruct_tmpl::clearNotifications() { for (uint8_t i = 0; i < NOTIFICATION_MAX; ++i) { - Notification[i].setInvalid(); + Notification[i] = 0u;// .setInvalid(); NotificationEnabled[i] = false; } } @@ -652,7 +653,7 @@ void SettingsStruct_tmpl::clearTask(taskIndex_t task) { TaskDeviceID[i][task] = 0u; TaskDeviceSendData[i][task] = false; } - TaskDeviceNumber[task] = INVALID_PLUGIN_ID; + TaskDeviceNumber[task] = 0u; //.setInvalid(); OLD_TaskDeviceID[task] = 0u; // UNUSED: this can be removed TaskDevicePin1[task] = -1; TaskDevicePin2[task] = -1; @@ -676,7 +677,8 @@ void SettingsStruct_tmpl::clearTask(taskIndex_t task) { VariousTaskBits[task] = 0; TaskDeviceDataFeed[task] = 0u; TaskDeviceTimer[task] = 0u; - TaskDeviceEnabled[task].value = 0u; // Should also clear any temporary flags. +// TaskDeviceEnabled[task].value = 0u; // Should also clear any temporary flags. + TaskDeviceEnabled[task] = false; I2C_Multiplexer_Channel[task] = -1; } @@ -972,4 +974,12 @@ void SettingsStruct_tmpl::setWiFi_TX_power(float dBm) { WiFi_TX_power = dBm * 4.0f; } +template +pluginID_t SettingsStruct_tmpl::getPluginID_for_task(taskIndex_t taskIndex) const { + if (validTaskIndex(taskIndex)) { + return pluginID_t::toPluginID(TaskDeviceNumber[taskIndex]); + } + return INVALID_PLUGIN_ID; +} + #endif // ifndef DATASTRUCTS_SETTINGSSTRUCT_CPP diff --git a/src/src/DataTypes/NPluginID.cpp b/src/src/DataTypes/NPluginID.cpp index caf11d477..0f6103245 100644 --- a/src/src/DataTypes/NPluginID.cpp +++ b/src/src/DataTypes/NPluginID.cpp @@ -2,6 +2,8 @@ #include "../Helpers/StringConverter.h" +npluginID_t::npluginID_t() : value(0) {} + npluginID_t npluginID_t::toPluginID(unsigned other) { npluginID_t res; diff --git a/src/src/DataTypes/NPluginID.h b/src/src/DataTypes/NPluginID.h index e4e0ab47f..56d5d3f89 100644 --- a/src/src/DataTypes/NPluginID.h +++ b/src/src/DataTypes/NPluginID.h @@ -4,7 +4,7 @@ #include "../../ESPEasy_common.h" struct npluginID_t { - npluginID_t() = default; + npluginID_t(); static npluginID_t toPluginID(unsigned other); diff --git a/src/src/DataTypes/PluginID.cpp b/src/src/DataTypes/PluginID.cpp index c96c2c51d..61a50bcf3 100644 --- a/src/src/DataTypes/PluginID.cpp +++ b/src/src/DataTypes/PluginID.cpp @@ -2,38 +2,41 @@ #include "../Helpers/StringConverter.h" +pluginID_t::pluginID_t() : value(0) {} + pluginID_t pluginID_t::toPluginID(unsigned other) { - pluginID_t res; - if (other <= 255) res.value = other; + pluginID_t res; - return res; + if (other <= 255) { res.value = other; } + + return res; } pluginID_t& pluginID_t::operator=(const pluginID_t& other) { - value = other.value; - return *this; + value = other.value; + return *this; } bool pluginID_t::operator==(const pluginID_t& other) const { - return this->value == other.value; + return this->value == other.value; } bool pluginID_t::operator!=(const pluginID_t& other) const { - return this->value != other.value; + return this->value != other.value; } void pluginID_t::setInvalid() { - value = 0; + value = 0; } String pluginID_t::toDisplayString() const { - if (value == 0) return F("P---"); - return strformat(F("P%03d"), value); + if (value == 0) { return F("P---"); } + return strformat(F("P%03d"), value); } const pluginID_t INVALID_PLUGIN_ID; diff --git a/src/src/DataTypes/PluginID.h b/src/src/DataTypes/PluginID.h index b29399720..0c39bb364 100644 --- a/src/src/DataTypes/PluginID.h +++ b/src/src/DataTypes/PluginID.h @@ -4,7 +4,7 @@ #include "../../ESPEasy_common.h" struct pluginID_t { - pluginID_t() = default; + pluginID_t(); static pluginID_t toPluginID(unsigned other); diff --git a/src/src/ESPEasyCore/Controller.cpp b/src/src/ESPEasyCore/Controller.cpp index c9f379b76..8656a85d9 100644 --- a/src/src/ESPEasyCore/Controller.cpp +++ b/src/src/ESPEasyCore/Controller.cpp @@ -140,7 +140,7 @@ void incoming_mqtt_callback(char *c_topic, uint8_t *b_payload, unsigned int leng // Here we loop over all tasks and call each 037 plugin with function PLUGIN_MQTT_IMPORT for (taskIndex_t taskIndex = 0; taskIndex < TASKS_MAX; taskIndex++) { - if (Settings.TaskDeviceEnabled[taskIndex] && (Settings.TaskDeviceNumber[taskIndex] == PLUGIN_ID_MQTT_IMPORT)) + if (Settings.TaskDeviceEnabled[taskIndex] && (Settings.getPluginID_for_task(taskIndex) == PLUGIN_ID_MQTT_IMPORT)) { Scheduler.schedule_mqtt_plugin_import_event_timer( DeviceIndex, taskIndex, PLUGIN_MQTT_IMPORT, diff --git a/src/src/Globals/NPlugins.cpp b/src/src/Globals/NPlugins.cpp index a9d4f7347..bbb913809 100644 --- a/src/src/Globals/NPlugins.cpp +++ b/src/src/Globals/NPlugins.cpp @@ -101,7 +101,7 @@ nprotocolIndex_t getNProtocolIndex(npluginID_t Number) nprotocolIndex_t getNProtocolIndex_from_NotifierIndex(notifierIndex_t index) { if (validNotifierIndex(index)) { - return getNProtocolIndex(Settings.Notification[index]); + return getNProtocolIndex(npluginID_t::toPluginID(Settings.Notification[index])); } return INVALID_NPROTOCOL_INDEX; } diff --git a/src/src/Globals/Plugins.cpp b/src/src/Globals/Plugins.cpp index 12794ce64..5ce86633b 100644 --- a/src/src/Globals/Plugins.cpp +++ b/src/src/Globals/Plugins.cpp @@ -71,7 +71,7 @@ bool supportedPluginID(pluginID_t pluginID) { deviceIndex_t getDeviceIndex_from_TaskIndex(taskIndex_t taskIndex) { if (validTaskIndex(taskIndex)) { - return getDeviceIndex(Settings.TaskDeviceNumber[taskIndex]); + return getDeviceIndex(Settings.getPluginID_for_task(taskIndex)); } return INVALID_DEVICE_INDEX; } @@ -81,7 +81,7 @@ deviceIndex_t getDeviceIndex_from_TaskIndex(taskIndex_t taskIndex) { ********************************************************************************************/ pluginID_t getPluginID_from_TaskIndex(taskIndex_t taskIndex) { if (validTaskIndex(taskIndex)) { - const pluginID_t pluginID = Settings.TaskDeviceNumber[taskIndex]; + const pluginID_t pluginID = Settings.getPluginID_for_task(taskIndex); if (supportedPluginID(pluginID)) return pluginID; } @@ -279,10 +279,10 @@ bool PluginCallForTask(taskIndex_t taskIndex, uint8_t Function, EventStruct *Tem #endif bool retval = false; - const bool considerTaskEnabled = Settings.TaskDeviceEnabled[taskIndex] || - (Settings.TaskDeviceEnabled[taskIndex].enabled && Function == PLUGIN_INIT); + const bool considerTaskEnabled = Settings.TaskDeviceEnabled[taskIndex]; + //|| (Settings.TaskDeviceEnabled[taskIndex].enabled && Function == PLUGIN_INIT); - if (considerTaskEnabled && validPluginID_fullcheck(Settings.TaskDeviceNumber[taskIndex])) + if (considerTaskEnabled && validPluginID_fullcheck(Settings.getPluginID_for_task(taskIndex))) { const deviceIndex_t DeviceIndex = getDeviceIndex_from_TaskIndex(taskIndex); if (validDeviceIndex(DeviceIndex)) { @@ -488,7 +488,7 @@ bool PluginCall(uint8_t Function, struct EventStruct *event, String& str) if (validTaskIndex(thisTask)) { // Known taskindex? #ifdef USES_P022 // Exclude P022 as it has rather explicit differences in commands when used with the []. prefix if (Settings.TaskDeviceEnabled[thisTask] // and internally needs to know wether it was called with the taskname prefixed - && validPluginID_fullcheck(Settings.TaskDeviceNumber[thisTask]) + && validPluginID_fullcheck(Settings.getPluginID_for_task(thisTask)) && Settings.TaskDeviceDataFeed[thisTask] == 0) { const deviceIndex_t DeviceIndex = getDeviceIndex_from_TaskIndex(thisTask); if (validDeviceIndex(DeviceIndex) && Device[DeviceIndex].Number == 22 /* PLUGIN_ID_022 define no longer available, 'assume' 22 for now */) { diff --git a/src/src/Helpers/Dallas1WireHelper.cpp b/src/src/Helpers/Dallas1WireHelper.cpp index 36c49943e..eb3b21246 100644 --- a/src/src/Helpers/Dallas1WireHelper.cpp +++ b/src/src/Helpers/Dallas1WireHelper.cpp @@ -111,7 +111,7 @@ void Dallas_addr_selector_webform_load(taskIndex_t TaskIndex, int8_t gpio_pin_rx std::map addr_task_map; for (taskIndex_t task = 0; validTaskIndex(task); ++task) { - if (Dallas_plugin(Settings.TaskDeviceNumber[task])) { + if (Dallas_plugin(Settings.getPluginID_for_task(task))) { uint8_t tmpAddress[8] = { 0 }; for (uint8_t var_index = 0; var_index < VARS_PER_TASK; ++var_index) { diff --git a/src/src/Helpers/ESPEasy_Storage.cpp b/src/src/Helpers/ESPEasy_Storage.cpp index 6bafb18ac..fc48edb7f 100644 --- a/src/src/Helpers/ESPEasy_Storage.cpp +++ b/src/src/Helpers/ESPEasy_Storage.cpp @@ -371,7 +371,7 @@ bool BuildFixes() #ifdef USES_P003 // P003_Pulse was always using the pull-up, now it is a setting. for (taskIndex_t taskIndex = 0; taskIndex < TASKS_MAX; ++taskIndex) { - if (Settings.TaskDeviceNumber[taskIndex].value == 3) { + if (Settings.getPluginID_for_task(taskIndex).value == 3) { Settings.TaskDevicePin1PullUp[taskIndex] = true; } } @@ -388,7 +388,7 @@ bool BuildFixes() if (Settings.Build < 20116) { // Added PWR button, init to "-none-" for (taskIndex_t taskIndex = 0; taskIndex < TASKS_MAX; ++taskIndex) { - if (Settings.TaskDeviceNumber[taskIndex].value == 53) { + if (Settings.getPluginID_for_task(taskIndex).value == 53) { Settings.TaskDevicePluginConfig[taskIndex][3] = -1; } } diff --git a/src/src/Helpers/Hardware.cpp b/src/src/Helpers/Hardware.cpp index 8a214d89d..b12c223f2 100644 --- a/src/src/Helpers/Hardware.cpp +++ b/src/src/Helpers/Hardware.cpp @@ -2426,7 +2426,7 @@ void setTaskDevice_to_TaskIndex(pluginID_t taskdevicenumber, taskIndex_t taskInd taskClear(taskIndex, false); // clear settings, but do not save ClearCustomTaskSettings(taskIndex); - Settings.TaskDeviceNumber[taskIndex] = taskdevicenumber; + Settings.getPluginID_for_task(taskIndex) = taskdevicenumber; if (validPluginID_fullcheck(taskdevicenumber)) // set default values if a new device has been selected { @@ -2465,7 +2465,8 @@ void setBasicTaskValues(taskIndex_t taskIndex, unsigned long taskdevicetimer, Settings.TaskDeviceTimer[taskIndex] = 0; } } - Settings.TaskDeviceEnabled[taskIndex].enabled = enabled; + Settings.TaskDeviceEnabled[taskIndex] = enabled; + //Settings.TaskDeviceEnabled[taskIndex].enabled = enabled; safe_strncpy(ExtraTaskSettings.TaskDeviceName, name.c_str(), sizeof(ExtraTaskSettings.TaskDeviceName)); // FIXME TD-er: Check for valid GPIO pin (and -1 for "not set") diff --git a/src/src/Helpers/Misc.cpp b/src/src/Helpers/Misc.cpp index 8bf45944c..309695f13 100644 --- a/src/src/Helpers/Misc.cpp +++ b/src/src/Helpers/Misc.cpp @@ -97,7 +97,7 @@ bool setTaskEnableStatus(struct EventStruct *event, bool enabled) #endif // ifndef BUILD_NO_RAM_TRACKER // Only enable task if it has a Plugin configured - if (validPluginID(Settings.TaskDeviceNumber[event->TaskIndex]) || !enabled) { + if (validPluginID(Settings.getPluginID_for_task(event->TaskIndex)) || !enabled) { String dummy; if (!enabled) { @@ -105,7 +105,8 @@ bool setTaskEnableStatus(struct EventStruct *event, bool enabled) } // Toggle enable/disable state via command // FIXME TD-er: Should this be a 'runtime' change, or actually change the intended state? - Settings.TaskDeviceEnabled[event->TaskIndex].enabled = enabled; + //Settings.TaskDeviceEnabled[event->TaskIndex].enabled = enabled; + Settings.TaskDeviceEnabled[event->TaskIndex] = enabled; if (enabled) { // Schedule the plugin to be read. diff --git a/src/src/Helpers/PeriodicalActions.cpp b/src/src/Helpers/PeriodicalActions.cpp index 20d3be121..6bb0318fd 100644 --- a/src/src/Helpers/PeriodicalActions.cpp +++ b/src/src/Helpers/PeriodicalActions.cpp @@ -278,7 +278,7 @@ void schedule_all_MQTTimport_tasks() { deviceIndex_t DeviceIndex = getDeviceIndex(PLUGIN_MQTT_IMPORT); // Check if P037_MQTTimport is present in the build if (validDeviceIndex(DeviceIndex)) { for (taskIndex_t task = 0; task < TASKS_MAX; task++) { - if ((Settings.TaskDeviceNumber[task] == PLUGIN_MQTT_IMPORT) && + if ((Settings.getPluginID_for_task(task) == PLUGIN_MQTT_IMPORT) && (Settings.TaskDeviceEnabled[task])) { // Schedule a call to each enabled MQTT import plugin to notify the broker connection state EventStruct event(task); diff --git a/src/src/Helpers/_CPlugin_LoRa_TTN_helper.cpp b/src/src/Helpers/_CPlugin_LoRa_TTN_helper.cpp index 2a1b9f2b5..ebf4e4aa7 100644 --- a/src/src/Helpers/_CPlugin_LoRa_TTN_helper.cpp +++ b/src/src/Helpers/_CPlugin_LoRa_TTN_helper.cpp @@ -24,7 +24,7 @@ String getPackedFromPlugin(struct EventStruct *event, uint8_t sampleSetCount) String packed; packed.reserve(32); - packed += LoRa_addInt(Settings.TaskDeviceNumber[event->TaskIndex].value, PackedData_uint8); + packed += LoRa_addInt(Settings.getPluginID_for_task(event->TaskIndex).value, PackedData_uint8); packed += LoRa_addInt(event->idx, PackedData_uint16); packed += LoRa_addInt(sampleSetCount, PackedData_uint8); packed += LoRa_addInt(value_count, PackedData_uint8); diff --git a/src/src/Helpers/_Plugin_init.cpp b/src/src/Helpers/_Plugin_init.cpp index c05609e52..38146c071 100644 --- a/src/src/Helpers/_Plugin_init.cpp +++ b/src/src/Helpers/_Plugin_init.cpp @@ -2198,7 +2198,7 @@ void PluginInit(bool priorityOnly) // Set all not supported plugins to disabled. for (taskIndex_t taskIndex = 0; taskIndex < TASKS_MAX; ++taskIndex) { - if (!supportedPluginID(Settings.TaskDeviceNumber[taskIndex])) { + if (!supportedPluginID(Settings.getPluginID_for_task(taskIndex))) { Settings.TaskDeviceEnabled[taskIndex] = false; } } diff --git a/src/src/WebServer/CustomPage.cpp b/src/src/WebServer/CustomPage.cpp index 9b980abcc..7634cdf17 100644 --- a/src/src/WebServer/CustomPage.cpp +++ b/src/src/WebServer/CustomPage.cpp @@ -189,7 +189,7 @@ bool handle_custom(const String& path) { for (taskIndex_t x = 0; x < TASKS_MAX; x++) { - if (validPluginID_fullcheck(Settings.TaskDeviceNumber[x])) + if (validPluginID_fullcheck(Settings.getPluginID_for_task(x))) { const deviceIndex_t DeviceIndex = getDeviceIndex_from_TaskIndex(x); diff --git a/src/src/WebServer/DevicesPage.cpp b/src/src/WebServer/DevicesPage.cpp index 6296c43c1..6b408c0b5 100644 --- a/src/src/WebServer/DevicesPage.cpp +++ b/src/src/WebServer/DevicesPage.cpp @@ -143,7 +143,7 @@ void handle_devices() { // FIXME TD-er: Might have to clear any caches here. if ((edit != 0) && !taskIndexNotSet) // when form submitted { - if (Settings.TaskDeviceNumber[taskIndex] != taskdevicenumber) + if (Settings.getPluginID_for_task(taskIndex) != taskdevicenumber) { // change of device: cleanup old device and reset default settings setTaskDevice_to_TaskIndex(taskdevicenumber, taskIndex); @@ -248,7 +248,7 @@ void handle_devices_CopySubmittedSettings(taskIndex_t taskIndex, pluginID_t task unsigned long taskdevicetimer = getFormItemInt(F("TDT"), 0); - Settings.TaskDeviceNumber[taskIndex] = taskdevicenumber; + Settings.getPluginID_for_task(taskIndex) = taskdevicenumber; uint8_t flags = 0; @@ -473,11 +473,11 @@ void handle_devicess_ShowAllTasksTable(uint8_t page) for (taskIndex_t x = (page - 1) * TASKS_PER_PAGE; x < ((page) * TASKS_PER_PAGE) && validTaskIndex(x); x++) { const deviceIndex_t DeviceIndex = getDeviceIndex_from_TaskIndex(x); - const bool pluginID_set = INVALID_PLUGIN_ID != Settings.TaskDeviceNumber[x]; + const bool pluginID_set = INVALID_PLUGIN_ID != Settings.getPluginID_for_task(x); html_TR_TD(); - if (pluginID_set && !supportedPluginID(Settings.TaskDeviceNumber[x])) { + if (pluginID_set && !supportedPluginID(Settings.getPluginID_for_task(x))) { html_add_button_prefix(F("red"), true); } else { html_add_button_prefix(); @@ -503,7 +503,7 @@ void handle_devicess_ShowAllTasksTable(uint8_t page) addEnabled(Settings.TaskDeviceEnabled[x] && validDeviceIndex(DeviceIndex)); html_TD(); - addHtml(getPluginNameFromPluginID(Settings.TaskDeviceNumber[x])); + addHtml(getPluginNameFromPluginID(Settings.getPluginID_for_task(x))); html_TD(); addHtml(getTaskDeviceName(x)); html_TD(); @@ -728,7 +728,7 @@ void handle_devicess_ShowAllTasksTable(uint8_t page) for (uint8_t varNr = 0; varNr < valueCount; varNr++) { - if (validPluginID_fullcheck(Settings.TaskDeviceNumber[x])) + if (validPluginID_fullcheck(Settings.getPluginID_for_task(x))) { pluginWebformShowValue(x, varNr, getTaskValueName(x, varNr), formatUserVarNoCheck(x, varNr)); } @@ -857,10 +857,10 @@ void handle_devices_TaskSettingsPage(taskIndex_t taskIndex, uint8_t page) addHtml(F("Device:")); // no (supported) device selected, this effectively checks for validDeviceIndex - if (!supportedPluginID(Settings.TaskDeviceNumber[taskIndex])) + if (!supportedPluginID(Settings.getPluginID_for_task(taskIndex))) { // takes lots of memory/time so call this only when needed. - addDeviceSelect(F("TDNUM"), Settings.TaskDeviceNumber[taskIndex].value); // ="taskdevicenumber" + addDeviceSelect(F("TDNUM"), Settings.getPluginID_for_task(taskIndex).value); // ="taskdevicenumber" addFormSeparator(4); } @@ -871,18 +871,21 @@ void handle_devices_TaskSettingsPage(taskIndex_t taskIndex, uint8_t page) addHtml(F("'); // show selected device name and delete button addHtml(getPluginNameFromDeviceIndex(DeviceIndex)); - addHelpButton(concat(F("Plugin"), Settings.TaskDeviceNumber[taskIndex].value)); - addRTDPluginButton(Settings.TaskDeviceNumber[taskIndex]); + addHelpButton(concat(F("Plugin"), Settings.getPluginID_for_task(taskIndex).value)); + addRTDPluginButton(Settings.getPluginID_for_task(taskIndex)); addFormTextBox(F("Name"), F("TDN"), getTaskDeviceName(taskIndex), NAME_FORMULA_LENGTH_MAX); // ="taskdevicename" - addFormCheckBox(F("Enabled"), F("TDE"), Settings.TaskDeviceEnabled[taskIndex].enabled, Settings.isTaskEnableReadonly(taskIndex)); // ="taskdeviceenabled" + addFormCheckBox(F("Enabled"), F("TDE"), + Settings.TaskDeviceEnabled[taskIndex], +// Settings.TaskDeviceEnabled[taskIndex].enabled, + Settings.isTaskEnableReadonly(taskIndex)); // ="taskdeviceenabled" #if FEATURE_PLUGIN_PRIORITY if (Device[DeviceIndex].PowerManager) { // Check extra priority device flags when available @@ -1028,7 +1031,7 @@ void handle_devices_TaskSettingsPage(taskIndex_t taskIndex, uint8_t page) addHtml(F("")); // if user selected a device, add the delete button, except for Priority tasks - if (validPluginID_fullcheck(Settings.TaskDeviceNumber[taskIndex]) + if (validPluginID_fullcheck(Settings.getPluginID_for_task(taskIndex)) #if FEATURE_PLUGIN_PRIORITY && !Settings.isPriorityTask(taskIndex) #endif // if FEATURE_PLUGIN_PRIORITY diff --git a/src/src/WebServer/ESPEasy_WebServer.cpp b/src/src/WebServer/ESPEasy_WebServer.cpp index 58b98bbf6..47af86c75 100644 --- a/src/src/WebServer/ESPEasy_WebServer.cpp +++ b/src/src/WebServer/ESPEasy_WebServer.cpp @@ -680,7 +680,7 @@ void addTaskSelect(const String& name, taskIndex_t choice) } } - if (validTaskIndex(x) && !validPluginID_fullcheck(Settings.TaskDeviceNumber[x])) { + if (validTaskIndex(x) && !validPluginID_fullcheck(Settings.getPluginID_for_task(x))) { addDisabled(); } { diff --git a/src/src/WebServer/JSON.cpp b/src/src/WebServer/JSON.cpp index 764e1fd95..2d22473f1 100644 --- a/src/src/WebServer/JSON.cpp +++ b/src/src/WebServer/JSON.cpp @@ -361,7 +361,7 @@ void handle_json() taskIndex_t lastActiveTaskIndex = 0; for (taskIndex_t TaskIndex = firstTaskIndex; TaskIndex <= lastTaskIndex; TaskIndex++) { - if (validPluginID_fullcheck(Settings.TaskDeviceNumber[TaskIndex])) { + if (validPluginID_fullcheck(Settings.getPluginID_for_task(TaskIndex))) { lastActiveTaskIndex = TaskIndex; } } @@ -449,7 +449,7 @@ void handle_json() stream_next_json_object_value(F("TaskInterval"), taskInterval); stream_next_json_object_value(F("Type"), getPluginNameFromDeviceIndex(DeviceIndex)); stream_next_json_object_value(F("TaskName"), getTaskDeviceName(TaskIndex)); - stream_next_json_object_value(F("TaskDeviceNumber"), Settings.TaskDeviceNumber[TaskIndex].value); + stream_next_json_object_value(F("TaskDeviceNumber"), Settings.getPluginID_for_task(TaskIndex).value); for(int i = 0; i < 3; i++) { if (Settings.TaskDevicePin[i][TaskIndex] >= 0) { stream_next_json_object_value(concat(F("TaskDeviceGPIO"), i + 1) , String(Settings.TaskDevicePin[i][TaskIndex])); @@ -484,7 +484,10 @@ void handle_json() } #endif // if FEATURE_I2CMULTIPLEXER } - stream_next_json_object_value(F("TaskEnabled"), jsonBool(Settings.TaskDeviceEnabled[TaskIndex].enabled)); + stream_next_json_object_value(F("TaskEnabled"), + // jsonBool(Settings.TaskDeviceEnabled[TaskIndex].enabled)); + jsonBool(Settings.TaskDeviceEnabled[TaskIndex])); + stream_last_json_object_value(F("TaskNumber"), TaskIndex + 1); if (TaskIndex != lastActiveTaskIndex) { diff --git a/src/src/WebServer/Metrics.cpp b/src/src/WebServer/Metrics.cpp index 41b6d0c22..31c0ca04f 100644 --- a/src/src/WebServer/Metrics.cpp +++ b/src/src/WebServer/Metrics.cpp @@ -91,7 +91,7 @@ void handle_metrics() { void handle_metrics_devices() { for (taskIndex_t x = 0; validTaskIndex(x); x++) { const deviceIndex_t DeviceIndex = getDeviceIndex_from_TaskIndex(x); - const bool pluginID_set = INVALID_PLUGIN_ID != Settings.TaskDeviceNumber[x]; + const bool pluginID_set = INVALID_PLUGIN_ID != Settings.getPluginID_for_task(x); if (pluginID_set) { if (Settings.TaskDeviceEnabled[x]) { @@ -118,7 +118,7 @@ void handle_metrics_devices() { const uint8_t valueCount = getValueCountForTask(x); for (uint8_t varNr = 0; varNr < valueCount; varNr++) { - if (validPluginID_fullcheck(Settings.TaskDeviceNumber[x])) { + if (validPluginID_fullcheck(Settings.getPluginID_for_task(x))) { addHtml(F("espeasy_device_")); addHtml(deviceName); addHtml(F("{valueName=\"")); diff --git a/src/src/WebServer/NotificationPage.cpp b/src/src/WebServer/NotificationPage.cpp index 7f4dc564e..a43ea8d99 100644 --- a/src/src/WebServer/NotificationPage.cpp +++ b/src/src/WebServer/NotificationPage.cpp @@ -51,13 +51,13 @@ void handle_notifications() { { MakeNotificationSettings(NotificationSettings); - if (Settings.Notification[notificationindex] != notification) + if (Settings.Notification[notificationindex] != notification.value) { - Settings.Notification[notificationindex] = notification; + Settings.Notification[notificationindex] = notification.value; } else { - if (Settings.Notification[notificationindex] != INVALID_N_PLUGIN_ID) + if (Settings.Notification[notificationindex] != INVALID_N_PLUGIN_ID.value) { nprotocolIndex_t NotificationProtocolIndex = getNProtocolIndex_from_NotifierIndex(notificationindex); @@ -125,12 +125,12 @@ void handle_notifications() { addHtmlInt(x + 1); html_TD(); - if (Settings.Notification[x] != INVALID_N_PLUGIN_ID) + if (Settings.Notification[x] != INVALID_N_PLUGIN_ID.value) { addEnabled(Settings.NotificationEnabled[x]); html_TD(); - uint8_t NotificationProtocolIndex = getNProtocolIndex(Settings.Notification[x]); + uint8_t NotificationProtocolIndex = getNProtocolIndex(npluginID_t::toPluginID(Settings.Notification[x])); String NotificationName = F("(plugin not found?)"); if (validNProtocolIndex(NotificationProtocolIndex)) @@ -166,7 +166,7 @@ void handle_notifications() { html_table_class_normal(); addFormHeader(F("Notification Settings")); addRowLabel(F("Notification")); - uint8_t choice = Settings.Notification[notificationindex].value; + uint8_t choice = Settings.Notification[notificationindex]; addSelector_Head_reloadOnChange(F("notification")); addSelector_Item(F("- None -"), 0, false); @@ -182,7 +182,7 @@ void handle_notifications() { addHelpButton(F("EasyNotifications")); - if (Settings.Notification[notificationindex] != INVALID_N_PLUGIN_ID) + if (Settings.Notification[notificationindex] != INVALID_N_PLUGIN_ID.value) { MakeNotificationSettings(NotificationSettings); LoadNotificationSettings(notificationindex, reinterpret_cast(&NotificationSettings), sizeof(NotificationSettingsStruct));