From f8168e9fe9d09ab01c69ec0f08b23ee3accdca01 Mon Sep 17 00:00:00 2001 From: Gijs Noorlander Date: Wed, 23 Oct 2019 17:07:52 +0200 Subject: [PATCH] [Cleanup] Use taskIndex_t everywhere where a task index is used. --- src/ESPEasy.ino | 4 ++-- src/ESPEasyStorage.ino | 19 ++++++++-------- src/Hardware.ino | 4 ++-- src/Misc.ino | 22 +++++++++---------- src/Scheduler.ino | 4 ++-- src/StringConverter.ino | 4 ++-- src/WebServer.ino | 6 ++--- src/WebServer_CacheControllerPages.ino | 4 ++-- src/WebServer_CustomPage.ino | 2 +- src/WebServer_DevicesPage.ino | 12 +++++----- src/WebServer_JSON.ino | 12 +++++----- src/WebServer_Markup.ino | 2 +- src/WebServer_Markup_Forms.ino | 2 +- src/_C002.ino | 2 +- src/_C014.ino | 2 +- src/_C018.ino | 6 ++--- src/_P004_Dallas.ino | 2 +- src/_P013_HCSR04.ino | 4 ++-- src/_P021_Level.ino | 2 +- src/_P036_FrameOLED.ino | 2 +- src/_P037_MQTTImport.ino | 4 ++-- src/_P040_ID12.ino | 4 ++-- src/_P075_Nextion.ino | 4 ++-- src/_P076_HLW8012.ino | 4 ++-- src/_P080_DallasIButton.ino | 2 +- src/_P089_Ping.ino | 4 ++-- src/_Plugin_Helper.cpp | 12 +++++----- src/_Plugin_Helper.h | 10 ++++----- src/__Plugin.ino | 4 ++-- src/src/Commands/Tasks.h | 2 +- .../DataStructs/ControllerSettingsStruct.cpp | 4 ++-- .../DataStructs/ControllerSettingsStruct.h | 3 ++- src/src/DataStructs/SettingsStruct.cpp | 4 ++-- src/src/DataStructs/SettingsStruct.h | 3 ++- 34 files changed, 92 insertions(+), 89 deletions(-) diff --git a/src/ESPEasy.ino b/src/ESPEasy.ino index 8ea2f88ca..c2df3f58c 100644 --- a/src/ESPEasy.ino +++ b/src/ESPEasy.ino @@ -883,7 +883,7 @@ void runEach30Seconds() \*********************************************************************************************/ // void SensorSendAll() // { -// for (byte x = 0; x < TASKS_MAX; x++) +// for (taskIndex_t x = 0; x < TASKS_MAX; x++) // { // SensorSendTask(x); // } @@ -893,7 +893,7 @@ void runEach30Seconds() /*********************************************************************************************\ * send specific sensor task data \*********************************************************************************************/ -void SensorSendTask(byte TaskIndex) +void SensorSendTask(taskIndex_t TaskIndex) { if (!validTaskIndex(TaskIndex)) return; checkRAM(F("SensorSendTask")); diff --git a/src/ESPEasyStorage.ino b/src/ESPEasyStorage.ino index d03e5b0d1..37d75ebbc 100644 --- a/src/ESPEasyStorage.ino +++ b/src/ESPEasyStorage.ino @@ -1,6 +1,7 @@ #include "src/Globals/Cache.h" -#include "src/Globals/ResetFactoryDefaultPref.h" #include "src/Globals/CRCValues.h" +#include "src/Globals/ResetFactoryDefaultPref.h" +#include "src/Globals/Plugins.h" /********************************************************************************************\ SPIFFS error handling @@ -362,7 +363,7 @@ String LoadSettings() Disable Plugin, based on bootFailedCount \*********************************************************************************************/ byte disablePlugin(byte bootFailedCount) { - for (byte i = 0; i < TASKS_MAX && bootFailedCount > 0; ++i) { + for (taskIndex_t i = 0; i < TASKS_MAX && bootFailedCount > 0; ++i) { if (Settings.TaskDeviceEnabled[i]) { --bootFailedCount; @@ -532,7 +533,7 @@ bool getSettingsParameters(SettingsType settingsType, int index, int& offset, in /********************************************************************************************\ Save Task settings to SPIFFS \*********************************************************************************************/ -String SaveTaskSettings(byte TaskIndex) +String SaveTaskSettings(taskIndex_t TaskIndex) { checkRAM(F("SaveTaskSettings")); @@ -554,12 +555,12 @@ String SaveTaskSettings(byte TaskIndex) /********************************************************************************************\ Load Task settings from SPIFFS \*********************************************************************************************/ -String LoadTaskSettings(byte TaskIndex) +String LoadTaskSettings(taskIndex_t TaskIndex) { if (ExtraTaskSettings.TaskIndex == TaskIndex) { return String(); // already loaded } - if ((TaskIndex < 0) || (TaskIndex >= TASKS_MAX)) { + if (!validTaskIndex(TaskIndex)) { return String(); // Un-initialized task index. } checkRAM(F("LoadTaskSettings")); @@ -591,7 +592,7 @@ String LoadTaskSettings(byte TaskIndex) /********************************************************************************************\ Save Custom Task settings to SPIFFS \*********************************************************************************************/ -String SaveCustomTaskSettings(int TaskIndex, byte *memAddress, int datasize) +String SaveCustomTaskSettings(taskIndex_t TaskIndex, byte *memAddress, int datasize) { checkRAM(F("SaveCustomTaskSettings")); return SaveToFile(CustomTaskSettings_Type, TaskIndex, (char *)FILE_CONFIG, memAddress, datasize); @@ -608,7 +609,7 @@ String getCustomTaskSettingsError(byte varNr) { /********************************************************************************************\ Clear custom task settings \*********************************************************************************************/ -String ClearCustomTaskSettings(int TaskIndex) +String ClearCustomTaskSettings(taskIndex_t TaskIndex) { // addLog(LOG_LEVEL_DEBUG, F("Clearing custom task settings")); return ClearInFile(CustomTaskSettings_Type, TaskIndex, (char *)FILE_CONFIG); @@ -617,7 +618,7 @@ String ClearCustomTaskSettings(int TaskIndex) /********************************************************************************************\ Load Custom Task settings from SPIFFS \*********************************************************************************************/ -String LoadCustomTaskSettings(int TaskIndex, byte *memAddress, int datasize) +String LoadCustomTaskSettings(taskIndex_t TaskIndex, byte *memAddress, int datasize) { START_TIMER; checkRAM(F("LoadCustomTaskSettings")); @@ -629,7 +630,7 @@ String LoadCustomTaskSettings(int TaskIndex, byte *memAddress, int datasize) /********************************************************************************************\ Load array of Strings from Custom Task settings \*********************************************************************************************/ -String LoadCustomTaskSettings(int TaskIndex, String strings[], uint16_t nrStrings, uint16_t maxStringLenght) +String LoadCustomTaskSettings(taskIndex_t TaskIndex, String strings[], uint16_t nrStrings, uint16_t maxStringLenght) { START_TIMER; checkRAM(F("LoadCustomTaskSettings")); diff --git a/src/Hardware.ino b/src/Hardware.ino index d8e989ca0..61c52e89e 100644 --- a/src/Hardware.ino +++ b/src/Hardware.ino @@ -222,7 +222,7 @@ void setFactoryDefault(DeviceModel model) { /********************************************************************************************\ Add pre defined plugins and rules. \*********************************************************************************************/ -void addSwitchPlugin(byte taskIndex, byte gpio, const String& name, bool activeLow) { +void addSwitchPlugin(taskIndex_t taskIndex, byte gpio, const String& name, bool activeLow) { setTaskDevice_to_TaskIndex(1, taskIndex); setBasicTaskValues( taskIndex, @@ -241,7 +241,7 @@ void addSwitchPlugin(byte taskIndex, byte gpio, const String& name, bool activeL } void addPredefinedPlugins(const GpioFactorySettingsStruct& gpio_settings) { - byte taskIndex = 0; + taskIndex_t taskIndex = 0; for (int i = 0; i < 4; ++i) { if (gpio_settings.button[i] >= 0) { diff --git a/src/Misc.ino b/src/Misc.ino index 0f1ef7515..615ce2ec6 100644 --- a/src/Misc.ino +++ b/src/Misc.ino @@ -477,7 +477,7 @@ bool remoteConfig(struct EventStruct *event, const String& string) if ((configTaskName.length() == 0) || (configCommand.length() == 0)) { return success; // TD-er: Should this be return false? } - byte index = findTaskIndexByName(configTaskName); + taskIndex_t index = findTaskIndexByName(configTaskName); if (index != TASKS_MAX) { @@ -811,9 +811,9 @@ void parseCommandString(struct EventStruct *event, const String& string) /********************************************************************************************\ Clear task settings for given task \*********************************************************************************************/ -void taskClear(byte taskIndex, bool save) +void taskClear(taskIndex_t taskIndex, bool save) { - if (taskIndex >= TASKS_MAX) return; + if (!validTaskIndex(taskIndex)) return; checkRAM(F("taskClear")); Settings.clearTask(taskIndex); ExtraTaskSettings.clear(); // Invalidate any cached values. @@ -824,7 +824,7 @@ void taskClear(byte taskIndex, bool save) } } -String checkTaskSettings(byte taskIndex) { +String checkTaskSettings(taskIndex_t taskIndex) { String err = LoadTaskSettings(taskIndex); if (err.length() > 0) return err; if (!ExtraTaskSettings.checkUniqueValueNames()) { @@ -841,7 +841,7 @@ String checkTaskSettings(byte taskIndex) { } } // Do not use the cached function findTaskIndexByName since that one does rely on the fact names should be unique. - for (int i = 0; i < TASKS_MAX; ++i) { + for (taskIndex_t i = 0; i < TASKS_MAX; ++i) { if (i != taskIndex && Settings.TaskDeviceEnabled[i]) { LoadTaskSettings(i); if (ExtraTaskSettings.TaskDeviceName[0] != 0) { @@ -1034,7 +1034,7 @@ uint32_t progMemMD5check(){ /********************************************************************************************\ Handler for keeping ExtraTaskSettings up to date using cache \*********************************************************************************************/ -String getTaskDeviceName(byte TaskIndex) { +String getTaskDeviceName(taskIndex_t TaskIndex) { LoadTaskSettings(TaskIndex); return ExtraTaskSettings.TaskDeviceName; } @@ -1174,7 +1174,7 @@ void ResetFactory() Settings.deepSleep = false; Settings.CustomCSS = false; Settings.InitSPI = false; - for (byte x = 0; x < TASKS_MAX; x++) + for (taskIndex_t x = 0; x < TASKS_MAX; x++) { Settings.TaskDevicePin1[x] = -1; Settings.TaskDevicePin2[x] = -1; @@ -1539,7 +1539,7 @@ String parseTemplate(String& tmpString, byte lineSize) // For example: "[bme#temp]" // If value name is unknown, run a PLUGIN_GET_CONFIG command. // For example: "[#getLevel]" - byte taskIndex = findTaskIndexByName(deviceName); + taskIndex_t taskIndex = findTaskIndexByName(deviceName); if (taskIndex != TASKS_MAX && Settings.TaskDeviceEnabled[taskIndex]) { byte valueNr = findDeviceValueIndexByName(valueName, taskIndex); @@ -1608,7 +1608,7 @@ taskIndex_t findTaskIndexByName(const String& deviceName) if (result != Cache.taskIndexName.end()) { return result->second; } - for (byte taskIndex = 0; taskIndex < TASKS_MAX; taskIndex++) + for (taskIndex_t taskIndex = 0; taskIndex < TASKS_MAX; taskIndex++) { if (Settings.TaskDeviceEnabled[taskIndex]) { String taskDeviceName = getTaskDeviceName(taskIndex); @@ -1628,7 +1628,7 @@ taskIndex_t findTaskIndexByName(const String& deviceName) // Find the first device value index of a taskIndex. // Return VARS_PER_TASK if none found. -byte findDeviceValueIndexByName(const String& valueName, byte taskIndex) +byte findDeviceValueIndexByName(const String& valueName, taskIndex_t taskIndex) { const deviceIndex_t deviceIndex = getDeviceIndex_from_TaskIndex(taskIndex); if (!validDeviceIndex(deviceIndex)) return VARS_PER_TASK; @@ -2336,7 +2336,7 @@ int CalculateParam(const char *TmpStr) { return returnValue; } -void SendValueLogger(byte TaskIndex) +void SendValueLogger(taskIndex_t TaskIndex) { #if !defined(BUILD_NO_DEBUG) || defined(FEATURE_SD) bool featureSD = false; diff --git a/src/Scheduler.ino b/src/Scheduler.ino index 98da3d289..5621f9f6c 100644 --- a/src/Scheduler.ino +++ b/src/Scheduler.ino @@ -465,7 +465,7 @@ void schedule_task_device_timer_at_init(unsigned long task_index) { // Typical use case is to run this when all needed connections are made. void schedule_all_task_device_timers() { - for (byte task = 0; task < TASKS_MAX; task++) { + for (taskIndex_t task = 0; task < TASKS_MAX; task++) { schedule_task_device_timer_at_init(task); } } @@ -476,7 +476,7 @@ void schedule_all_tasks_using_MQTT_controller() { if (ControllerIndex < 0) { return; } - for (byte task = 0; task < TASKS_MAX; task++) { + for (taskIndex_t task = 0; task < TASKS_MAX; task++) { if (Settings.TaskDeviceSendData[ControllerIndex][task] && Settings.ControllerEnabled[ControllerIndex] && Settings.Protocol[ControllerIndex]) diff --git a/src/StringConverter.ino b/src/StringConverter.ino index c5ce39d8e..33500c05a 100644 --- a/src/StringConverter.ino +++ b/src/StringConverter.ino @@ -240,7 +240,7 @@ String doFormatUserVar(struct EventStruct *event, byte rel_index, bool mustCheck return toString(f, ExtraTaskSettings.TaskDeviceValueDecimals[rel_index]); } -String formatUserVarNoCheck(byte TaskIndex, byte rel_index) { +String formatUserVarNoCheck(taskIndex_t TaskIndex, byte rel_index) { bool isvalid; // FIXME TD-er: calls to this function cannot handle SENSOR_TYPE_STRING struct EventStruct TempEvent; @@ -248,7 +248,7 @@ String formatUserVarNoCheck(byte TaskIndex, byte rel_index) { return doFormatUserVar(&TempEvent, rel_index, false, isvalid); } -String formatUserVar(byte TaskIndex, byte rel_index, bool& isvalid) { +String formatUserVar(taskIndex_t TaskIndex, byte rel_index, bool& isvalid) { // FIXME TD-er: calls to this function cannot handle SENSOR_TYPE_STRING struct EventStruct TempEvent; TempEvent.TaskIndex = TaskIndex; diff --git a/src/WebServer.ino b/src/WebServer.ino index 87deb323d..e76cd8116 100644 --- a/src/WebServer.ino +++ b/src/WebServer.ino @@ -853,7 +853,7 @@ void json_prop(const String& name, const String& value) { // ******************************************************************************** // Add a task select dropdown list // ******************************************************************************** -void addTaskSelect(const String& name, int choice) +void addTaskSelect(const String& name, taskIndex_t choice) { String deviceName; @@ -861,7 +861,7 @@ void addTaskSelect(const String& name, int choice) TXBuffer += name; TXBuffer += F("' onchange='return dept_onchange(frmselect)'>"); - for (byte x = 0; x < TASKS_MAX; x++) + for (taskIndex_t x = 0; x < TASKS_MAX; x++) { deviceName = ""; deviceIndex_t DeviceIndex = getDeviceIndex_from_TaskIndex(x); @@ -896,7 +896,7 @@ void addTaskSelect(const String& name, int choice) // ******************************************************************************** // Add a Value select dropdown list, based on TaskIndex // ******************************************************************************** -void addTaskValueSelect(const String& name, int choice, byte TaskIndex) +void addTaskValueSelect(const String& name, int choice, taskIndex_t TaskIndex) { if (!validTaskIndex(TaskIndex)) return; deviceIndex_t DeviceIndex = getDeviceIndex_from_TaskIndex(TaskIndex); diff --git a/src/WebServer_CacheControllerPages.ino b/src/WebServer_CacheControllerPages.ino index acb968b75..eafbeb981 100644 --- a/src/WebServer_CacheControllerPages.ino +++ b/src/WebServer_CacheControllerPages.ino @@ -38,7 +38,7 @@ void handle_dumpcache() { TXBuffer.startStream(); TXBuffer += F("UNIX timestamp;contr. idx;sensortype;taskindex;value count"); - for (int i = 0; i < TASKS_MAX; ++i) { + for (taskIndex_t i = 0; i < TASKS_MAX; ++i) { LoadTaskSettings(i); for (int j = 0; j < VARS_PER_TASK; ++j) { @@ -103,7 +103,7 @@ void handle_cache_json() { TXBuffer += ','; stream_to_json_value(F("task index")); - for (int i = 0; i < TASKS_MAX; ++i) { + for (taskIndex_t i = 0; i < TASKS_MAX; ++i) { LoadTaskSettings(i); for (int j = 0; j < VARS_PER_TASK; ++j) { diff --git a/src/WebServer_CustomPage.ino b/src/WebServer_CustomPage.ino index d1d9a6109..6f042a34f 100644 --- a/src/WebServer_CustomPage.ino +++ b/src/WebServer_CustomPage.ino @@ -148,7 +148,7 @@ boolean handle_custom(String path) { ""); html_table_class_normal(); - for (byte x = 0; x < TASKS_MAX; x++) + for (taskIndex_t x = 0; x < TASKS_MAX; x++) { if (validPluginID(Settings.TaskDeviceNumber[x])) { diff --git a/src/WebServer_DevicesPage.ino b/src/WebServer_DevicesPage.ino index 4e45324ed..2239a7f71 100644 --- a/src/WebServer_DevicesPage.ino +++ b/src/WebServer_DevicesPage.ino @@ -18,7 +18,7 @@ void handle_devices() { // String taskindex = WebServer.arg(F("index")); - byte taskdevicenumber; + pluginID_t taskdevicenumber; if (WebServer.hasArg(F("del"))) { taskdevicenumber = 0; @@ -97,7 +97,7 @@ void handle_devices() { // taskIndex in the URL is 1 ... TASKS_MAX // For use in other functions, set it to 0 ... (TASKS_MAX - 1) - byte taskIndex = getFormItemInt(F("index"), 0); + taskIndex_t taskIndex = getFormItemInt(F("index"), 0); boolean taskIndexNotSet = taskIndex == 0; --taskIndex; @@ -205,7 +205,7 @@ void addDeviceSelect(const String& name, int choice) // ******************************************************************************** // change of device: cleanup old device and reset default settings // ******************************************************************************** -void setTaskDevice_to_TaskIndex(byte taskdevicenumber, byte taskIndex) { +void setTaskDevice_to_TaskIndex(pluginID_t taskdevicenumber, taskIndex_t taskIndex) { struct EventStruct TempEvent; TempEvent.TaskIndex = taskIndex; @@ -232,7 +232,7 @@ void setTaskDevice_to_TaskIndex(byte taskdevicenumber, byte taskIndex) { // ******************************************************************************** // Initialize task with some default values applicable for almost all tasks // ******************************************************************************** -void setBasicTaskValues(byte taskIndex, unsigned long taskdevicetimer, +void setBasicTaskValues(taskIndex_t taskIndex, unsigned long taskdevicetimer, bool enabled, const String& name, int pin1, int pin2, int pin3) { if (!validTaskIndex(taskIndex)) return; deviceIndex_t DeviceIndex = getDeviceIndex_from_TaskIndex(taskIndex); @@ -264,7 +264,7 @@ void setBasicTaskValues(byte taskIndex, unsigned long taskdevicetimer, // ******************************************************************************** // Collect all submitted form data and store the task settings // ******************************************************************************** -void handle_devices_CopySubmittedSettings(byte taskIndex, byte taskdevicenumber) +void handle_devices_CopySubmittedSettings(taskIndex_t taskIndex, pluginID_t taskdevicenumber) { if (!validTaskIndex(taskIndex)) return; deviceIndex_t DeviceIndex = getDeviceIndex(taskdevicenumber); @@ -568,7 +568,7 @@ void handle_devicess_ShowAllTasksTable(byte page) // ******************************************************************************** // Show the task settings page // ******************************************************************************** -void handle_devices_TaskSettingsPage(byte taskIndex, byte page) +void handle_devices_TaskSettingsPage(taskIndex_t taskIndex, byte page) { if (!validTaskIndex(taskIndex)) return; deviceIndex_t DeviceIndex = getDeviceIndex_from_TaskIndex(taskIndex);\ diff --git a/src/WebServer_JSON.ino b/src/WebServer_JSON.ino index b1a392e4a..b9733f2b2 100644 --- a/src/WebServer_JSON.ino +++ b/src/WebServer_JSON.ino @@ -8,7 +8,7 @@ // ******************************************************************************** void handle_json() { - const int taskNr = getFormItemInt(F("tasknr"), -1); + const taskIndex_t taskNr = getFormItemInt(F("tasknr"), -1); const bool showSpecificTask = taskNr > 0; bool showSystem = true; bool showWifi = true; @@ -137,17 +137,17 @@ void handle_json() } } - byte firstTaskIndex = 0; - byte lastTaskIndex = TASKS_MAX - 1; + taskIndex_t firstTaskIndex = 0; + taskIndex_t lastTaskIndex = TASKS_MAX - 1; if (showSpecificTask) { firstTaskIndex = taskNr - 1; lastTaskIndex = taskNr - 1; } - byte lastActiveTaskIndex = 0; + taskIndex_t lastActiveTaskIndex = 0; - for (byte TaskIndex = firstTaskIndex; TaskIndex <= lastTaskIndex; TaskIndex++) { + for (taskIndex_t TaskIndex = firstTaskIndex; TaskIndex <= lastTaskIndex; TaskIndex++) { if (validPluginID(Settings.TaskDeviceNumber[TaskIndex])) { lastActiveTaskIndex = TaskIndex; } @@ -156,7 +156,7 @@ void handle_json() if (!showSpecificTask) { TXBuffer += F("\"Sensors\":[\n"); } unsigned long ttl_json = 60; // The shortest interval per enabled task (with output values) in seconds - for (byte TaskIndex = firstTaskIndex; TaskIndex <= lastActiveTaskIndex && validTaskIndex(TaskIndex); TaskIndex++) + for (taskIndex_t TaskIndex = firstTaskIndex; TaskIndex <= lastActiveTaskIndex && validTaskIndex(TaskIndex); TaskIndex++) { const deviceIndex_t DeviceIndex = getDeviceIndex_from_TaskIndex(TaskIndex); if (validDeviceIndex(DeviceIndex)) diff --git a/src/WebServer_Markup.ino b/src/WebServer_Markup.ino index 07dc0f874..f714cd816 100644 --- a/src/WebServer_Markup.ino +++ b/src/WebServer_Markup.ino @@ -338,7 +338,7 @@ void addHelpButton(const String& url, bool isRTD) isRTD ? F("ℹ") : F("❔")); } -void addRTDPluginButton(int taskDeviceNumber) { +void addRTDPluginButton(pluginID_t taskDeviceNumber) { String url; url.reserve(16); diff --git a/src/WebServer_Markup_Forms.ino b/src/WebServer_Markup_Forms.ino index b76114f7b..d8756acc6 100644 --- a/src/WebServer_Markup_Forms.ino +++ b/src/WebServer_Markup_Forms.ino @@ -65,7 +65,7 @@ void addFormFloatNumberBox(const String& label, const String& id, float value, f // ******************************************************************************** // Add a task selector form // ******************************************************************************** -void addTaskSelectBox(const String& label, const String& id, int choice) +void addTaskSelectBox(const String& label, const String& id, taskIndex_t choice) { addRowLabel_tr_id(label, id); addTaskSelect(id, choice); diff --git a/src/_C002.ino b/src/_C002.ino index bff875acb..67547b3ea 100644 --- a/src/_C002.ino +++ b/src/_C002.ino @@ -83,7 +83,7 @@ bool CPlugin_002(byte function, struct EventStruct *event, String& string) switchtype = "?"; } - for (byte x = 0; x < TASKS_MAX; x++) { + for (taskIndex_t x = 0; x < TASKS_MAX; x++) { // We need the index of the controller we are: 0...CONTROLLER_MAX if (Settings.TaskDeviceEnabled[x] && (Settings.TaskDeviceID[ControllerID][x] == idx)) // get idx for our controller index { diff --git a/src/_C014.ino b/src/_C014.ino index e51b1383b..ef9d56a4b 100644 --- a/src/_C014.ino +++ b/src/_C014.ino @@ -312,7 +312,7 @@ bool CPlugin_014(byte function, struct EventStruct *event, String& string) deviceCount++; // SECOND Plugins - for (byte x = 0; x < TASKS_MAX; x++) + for (taskIndex_t x = 0; x < TASKS_MAX; x++) { if (validPluginID((Settings.TaskDeviceNumber[x]))) { diff --git a/src/_C018.ino b/src/_C018.ino index a047a3ca1..43fc678d4 100644 --- a/src/_C018.ino +++ b/src/_C018.ino @@ -37,7 +37,7 @@ struct C018_data_struct { autobaud_success = false; } - bool init(const int8_t serial_rx, const int8_t serial_tx, unsigned long baudrate, bool joinIsOTAA, uint8_t sampleSet_Initiator) { + bool init(const int8_t serial_rx, const int8_t serial_tx, unsigned long baudrate, bool joinIsOTAA, taskIndex_t sampleSet_Initiator) { if ((serial_rx < 0) || (serial_tx < 0)) { // Both pins are needed, or else no serial possible return false; @@ -186,7 +186,7 @@ struct C018_data_struct { uint8_t getSampleSetCount() const { return sampleSetCounter; } - uint8_t getSampleSetCount(uint8_t taskIndex) { + uint8_t getSampleSetCount(taskIndex_t taskIndex) { if (sampleSetInitiator == taskIndex) { ++sampleSetCounter; @@ -232,7 +232,7 @@ private: String cacheHWEUI; String cacheSysVer; uint8_t sampleSetCounter = 0; - uint8_t sampleSetInitiator = 0; + taskIndex_t sampleSetInitiator = INVALID_TASK_INDEX; bool autobaud_success = false; } C018_data; diff --git a/src/_P004_Dallas.ino b/src/_P004_Dallas.ino index 0c41a5119..c0ad80478 100644 --- a/src/_P004_Dallas.ino +++ b/src/_P004_Dallas.ino @@ -244,7 +244,7 @@ boolean Plugin_004(byte function, struct EventStruct *event, String& string) return success; } -void Plugin_004_get_addr(uint8_t addr[], byte TaskIndex) +void Plugin_004_get_addr(uint8_t addr[], taskIndex_t TaskIndex) { // Load ROM address from tasksettings LoadTaskSettings(TaskIndex); diff --git a/src/_P013_HCSR04.ino b/src/_P013_HCSR04.ino index 60ab532dc..0e39ca3e4 100644 --- a/src/_P013_HCSR04.ino +++ b/src/_P013_HCSR04.ino @@ -275,7 +275,7 @@ boolean Plugin_013(byte function, struct EventStruct *event, String& string) } /*********************************************************************/ -float Plugin_013_read(unsigned int taskIndex) +float Plugin_013_read(taskIndex_t taskIndex) /*********************************************************************/ { if (P_013_sensordefs.count(taskIndex) == 0) @@ -307,7 +307,7 @@ float Plugin_013_read(unsigned int taskIndex) } /*********************************************************************/ -String Plugin_013_getErrorStatusString(unsigned int taskIndex) +String Plugin_013_getErrorStatusString(taskIndex_t taskIndex) /*********************************************************************/ { if (P_013_sensordefs.count(taskIndex) == 0) diff --git a/src/_P021_Level.ino b/src/_P021_Level.ino index e5c1fe8e7..060f32c4c 100644 --- a/src/_P021_Level.ino +++ b/src/_P021_Level.ino @@ -115,7 +115,7 @@ boolean Plugin_021(byte function, struct EventStruct *event, String& string) case PLUGIN_TEN_PER_SECOND: { // we're checking a var from another task, so calculate that basevar - byte TaskIndex = PCONFIG(0); + taskIndex_t TaskIndex = PCONFIG(0); byte BaseVarIndex = TaskIndex * VARS_PER_TASK + PCONFIG(1); float value = UserVar[BaseVarIndex]; byte state = switchstate[event->TaskIndex]; diff --git a/src/_P036_FrameOLED.ino b/src/_P036_FrameOLED.ino index 35f588bdf..30570be3e 100644 --- a/src/_P036_FrameOLED.ino +++ b/src/_P036_FrameOLED.ino @@ -42,7 +42,7 @@ OLEDDisplay *display=NULL; String P036_displayLines[P36_Nlines]; -void Plugin_036_loadDisplayLines(byte taskIndex) { +void Plugin_036_loadDisplayLines(taskIndex_t taskIndex) { LoadCustomTaskSettings(taskIndex, P036_displayLines, P36_Nlines, P36_Nchars); } diff --git a/src/_P037_MQTTImport.ino b/src/_P037_MQTTImport.ino index 7ea3d8498..4304e212f 100644 --- a/src/_P037_MQTTImport.ino +++ b/src/_P037_MQTTImport.ino @@ -308,7 +308,7 @@ boolean MQTTSubscribe_037() // Loop over all tasks looking for a 037 instance - for (byte y = 0; y < TASKS_MAX; y++) + for (taskIndex_t y = 0; y < TASKS_MAX; y++) { if (Settings.TaskDeviceNumber[y] == PLUGIN_ID_037) { @@ -378,7 +378,7 @@ void mqttcallback_037(char* c_topic, byte* b_payload, unsigned int length) // Here we loop over all tasks and call each 037 plugin with function PLUGIN_IMPORT - for (byte y = 0; y < TASKS_MAX; y++) + for (taskIndex_t y = 0; y < TASKS_MAX; y++) { if (Settings.TaskDeviceNumber[y] == PLUGIN_ID_037) // if we have found a 037 device, then give it something to think about! { diff --git a/src/_P040_ID12.ino b/src/_P040_ID12.ino index 9d26ce36b..8ba11dbf2 100644 --- a/src/_P040_ID12.ino +++ b/src/_P040_ID12.ino @@ -109,8 +109,8 @@ boolean Plugin_040(byte function, struct EventStruct *event, String& string) if (code[5] == checksum) { // temp woraround, ESP Easy framework does not currently prepare this... - byte index = 0; - for (byte y = 0; y < TASKS_MAX; y++) + taskIndex_t index = INVALID_TASK_INDEX; + for (taskIndex_t y = 0; y < TASKS_MAX; y++) if (Settings.TaskDeviceNumber[y] == PLUGIN_ID_040) index = y; deviceIndex_t DeviceIndex = getDeviceIndex_from_TaskIndex(index); diff --git a/src/_P075_Nextion.ino b/src/_P075_Nextion.ino index afd2f5892..622a5647f 100644 --- a/src/_P075_Nextion.ino +++ b/src/_P075_Nextion.ino @@ -72,7 +72,7 @@ struct P075_data_struct : public PluginTaskData_base { } } - void loadDisplayLines(byte taskIndex) { + void loadDisplayLines(taskIndex_t taskIndex) { LoadCustomTaskSettings(taskIndex, displayLines, P75_Nlines, P75_Nchars); } @@ -540,7 +540,7 @@ boolean Plugin_075(byte function, struct EventStruct *event, String& string) } -void P075_sendCommand(byte taskIndex, const char *cmd) +void P075_sendCommand(taskIndex_t taskIndex, const char *cmd) { P075_data_struct* P075_data = static_cast(getPluginTaskData(taskIndex)); if (!P075_data) return; diff --git a/src/_P076_HLW8012.ino b/src/_P076_HLW8012.ino index df2afd06e..89fec2dbe 100644 --- a/src/_P076_HLW8012.ino +++ b/src/_P076_HLW8012.ino @@ -518,7 +518,7 @@ bool Plugin076_ReadMultipliers(double& current, double& voltage, double& power) } -bool Plugin076_LoadMultipliers(byte TaskIndex, double& current, double& voltage, double& power) { +bool Plugin076_LoadMultipliers(taskIndex_t TaskIndex, double& current, double& voltage, double& power) { // If multipliers are empty load default ones and save all of them as // "CustomTaskSettings" if (!Plugin076_ReadMultipliers(current, voltage, power)) { @@ -539,7 +539,7 @@ bool Plugin076_LoadMultipliers(byte TaskIndex, double& current, double& voltage, return (current > 1.0) && (voltage > 1.0) && (power > 1.0); } -void Plugin076_Reset(byte TaskIndex) { +void Plugin076_Reset(taskIndex_t TaskIndex) { if (Plugin_076_hlw) { const byte CF_PIN = Settings.TaskDevicePin3[TaskIndex]; const byte CF1_PIN = Settings.TaskDevicePin2[TaskIndex]; diff --git a/src/_P080_DallasIButton.ino b/src/_P080_DallasIButton.ino index 4d20d4c38..6fc7fa5ed 100644 --- a/src/_P080_DallasIButton.ino +++ b/src/_P080_DallasIButton.ino @@ -172,7 +172,7 @@ boolean Plugin_080(byte function, struct EventStruct * event, String& string) return success; } -void Plugin_080_get_addr(uint8_t addr[], byte TaskIndex) +void Plugin_080_get_addr(uint8_t addr[], taskIndex_t TaskIndex) { // Load ROM address from tasksettings LoadTaskSettings(TaskIndex); diff --git a/src/_P089_Ping.ino b/src/_P089_Ping.ino index ba7726720..a011247a5 100644 --- a/src/_P089_Ping.ino +++ b/src/_P089_Ping.ino @@ -212,7 +212,7 @@ boolean Plugin_089(byte function, struct EventStruct *event, String& string) if (command == F("pingset")) { String taskName = parseString(string, 2); - byte taskIndex = findTaskIndexByName(taskName); + taskIndex_t taskIndex = findTaskIndexByName(taskName); if (taskIndex != TASKS_MAX && taskIndex == event->TaskIndex) { success = true; String param1 = parseString(string, 3); @@ -255,7 +255,7 @@ uint8_t PingReceiver (void *origin, struct raw_pcb *pcb, struct pbuf *packetBuff } bool is_found = false; - for (uint8_t index = 0; index < TASKS_MAX; index++) { + for (taskIndex_t index = 0; index < TASKS_MAX; index++) { deviceIndex_t deviceIndex = getDeviceIndex_from_TaskIndex(index); // Match all ping plugin instances and check them if (validDeviceIndex(deviceIndex) && DeviceIndex_to_Plugin_id[deviceIndex] == PLUGIN_ID_089) { diff --git a/src/_Plugin_Helper.cpp b/src/_Plugin_Helper.cpp index 59b22fa17..a1d8addff 100644 --- a/src/_Plugin_Helper.cpp +++ b/src/_Plugin_Helper.cpp @@ -23,12 +23,12 @@ String PCONFIG_LABEL(int n) { void resetPluginTaskData() { - for (byte i = 0; i < TASKS_MAX; ++i) { + for (taskIndex_t i = 0; i < TASKS_MAX; ++i) { Plugin_task_data[i] = nullptr; } } -void clearPluginTaskData(byte taskIndex) { +void clearPluginTaskData(taskIndex_t taskIndex) { if (validTaskIndex(taskIndex)) { if (Plugin_task_data[taskIndex] != nullptr) { delete Plugin_task_data[taskIndex]; @@ -37,7 +37,7 @@ void clearPluginTaskData(byte taskIndex) { } } -void initPluginTaskData(byte taskIndex, PluginTaskData_base *data) { +void initPluginTaskData(taskIndex_t taskIndex, PluginTaskData_base *data) { if (!validTaskIndex(taskIndex)) return; clearPluginTaskData(taskIndex); @@ -47,7 +47,7 @@ void initPluginTaskData(byte taskIndex, PluginTaskData_base *data) { } } -PluginTaskData_base* getPluginTaskData(byte taskIndex) { +PluginTaskData_base* getPluginTaskData(taskIndex_t taskIndex) { if (!validTaskIndex(taskIndex)) { return nullptr; } @@ -58,7 +58,7 @@ PluginTaskData_base* getPluginTaskData(byte taskIndex) { return nullptr; } -bool pluginTaskData_initialized(byte taskIndex) { +bool pluginTaskData_initialized(taskIndex_t taskIndex) { // FIXME TD-er: Must check for type also. if (validTaskIndex(taskIndex)) { return Plugin_task_data[taskIndex] != nullptr; @@ -77,7 +77,7 @@ String getPluginCustomArgName(int varNr) { // if the regular values should also be displayed. // The call to PLUGIN_WEBFORM_SHOW_VALUES should only return success = true when no regular values should be displayed // Note that the varNr of the custom values should not conflict with the existing variable numbers (e.g. start at VARS_PER_TASK) -String pluginWebformShowValue(byte taskIndex, byte varNr, const String& label, const String& value, bool addTrailingBreak) { +String pluginWebformShowValue(taskIndex_t taskIndex, byte varNr, const String& label, const String& value, bool addTrailingBreak) { String result; size_t length = 96 + label.length() + value.length(); String breakStr = F("
"); diff --git a/src/_Plugin_Helper.h b/src/_Plugin_Helper.h index 66a62b154..9400a49d2 100644 --- a/src/_Plugin_Helper.h +++ b/src/_Plugin_Helper.h @@ -57,13 +57,13 @@ struct PluginTaskData_base { void resetPluginTaskData(); -void clearPluginTaskData(byte taskIndex); +void clearPluginTaskData(taskIndex_t taskIndex); -void initPluginTaskData(byte taskIndex, PluginTaskData_base *data); +void initPluginTaskData(taskIndex_t taskIndex, PluginTaskData_base *data); -PluginTaskData_base* getPluginTaskData(byte taskIndex); +PluginTaskData_base* getPluginTaskData(taskIndex_t taskIndex); -bool pluginTaskData_initialized(byte taskIndex); +bool pluginTaskData_initialized(taskIndex_t taskIndex); String getPluginCustomArgName(int varNr); @@ -72,7 +72,7 @@ String getPluginCustomArgName(int varNr); // if the regular values should also be displayed. // The call to PLUGIN_WEBFORM_SHOW_VALUES should only return success = true when no regular values should be displayed // Note that the varNr of the custom values should not conflict with the existing variable numbers (e.g. start at VARS_PER_TASK) -String pluginWebformShowValue(byte taskIndex, byte varNr, const String& label, const String& value, bool addTrailingBreak = false); +String pluginWebformShowValue(taskIndex_t taskIndex, byte varNr, const String& label, const String& value, bool addTrailingBreak = false); diff --git a/src/__Plugin.ino b/src/__Plugin.ino index 4c3974e23..524e802d8 100644 --- a/src/__Plugin.ino +++ b/src/__Plugin.ino @@ -1181,7 +1181,7 @@ byte PluginCall(byte Function, struct EventStruct *event, String& str) case PLUGIN_SERIAL_IN: case PLUGIN_UDP_IN: { - for (byte task = 0; task < TASKS_MAX; task++) + for (taskIndex_t task = 0; task < TASKS_MAX; task++) { if (Settings.TaskDeviceEnabled[task] && validPluginID(Settings.TaskDeviceNumber[task])) { @@ -1217,7 +1217,7 @@ byte PluginCall(byte Function, struct EventStruct *event, String& str) { if (Function == PLUGIN_INIT_ALL) Function = PLUGIN_INIT; - for (byte task = 0; task < TASKS_MAX; task++) + for (taskIndex_t task = 0; task < TASKS_MAX; task++) { if (Settings.TaskDeviceEnabled[task] && validPluginID(Settings.TaskDeviceNumber[task])) { diff --git a/src/src/Commands/Tasks.h b/src/src/Commands/Tasks.h index d4a342348..1410bef73 100644 --- a/src/src/Commands/Tasks.h +++ b/src/src/Commands/Tasks.h @@ -11,7 +11,7 @@ String Command_Task_Clear(struct EventStruct *event, const char* Line) String Command_Task_ClearAll(struct EventStruct *event, const char* Line) { - for (byte t = 0; t < TASKS_MAX; t++) + for (taskIndex_t t = 0; t < TASKS_MAX; t++) taskClear(t, false); return return_command_success(); } diff --git a/src/src/DataStructs/ControllerSettingsStruct.cpp b/src/src/DataStructs/ControllerSettingsStruct.cpp index f8c34788e..afd77c91b 100644 --- a/src/src/DataStructs/ControllerSettingsStruct.cpp +++ b/src/src/DataStructs/ControllerSettingsStruct.cpp @@ -24,7 +24,7 @@ DeleteOldest = false; ClientTimeout = CONTROLLER_CLIENTTIMEOUT_DFLT; MustCheckReply = false; - SampleSetInitiator = 0; + SampleSetInitiator = INVALID_TASK_INDEX; for (byte i = 0; i < 4; ++i) { IP[i] = 0; } @@ -51,7 +51,7 @@ boolean DeleteOldest; // Action to perform when buffer full, delete oldest, or ignore newest. unsigned int ClientTimeout; boolean MustCheckReply; // When set to false, a sent message is considered always successful. - uint8_t SampleSetInitiator; // The first plugin to start a sample set. + taskIndex_t SampleSetInitiator; // The first task to start a sample set. void ControllerSettingsStruct::validate() { if (Port > 65535) Port = 0; diff --git a/src/src/DataStructs/ControllerSettingsStruct.h b/src/src/DataStructs/ControllerSettingsStruct.h index 3a1a2c1c6..b5ad3ea0f 100644 --- a/src/src/DataStructs/ControllerSettingsStruct.h +++ b/src/src/DataStructs/ControllerSettingsStruct.h @@ -8,6 +8,7 @@ #include // For std::shared_ptr #include "../../ESPEasy_common.h" +#include "../../src/src/Globals/Plugins.h" class IPAddress; class WiFiClient; @@ -109,7 +110,7 @@ struct ControllerSettingsStruct boolean DeleteOldest; // Action to perform when buffer full, delete oldest, or ignore newest. unsigned int ClientTimeout; boolean MustCheckReply; // When set to false, a sent message is considered always successful. - uint8_t SampleSetInitiator; // The first plugin to start a sample set. + taskIndex_t SampleSetInitiator; // The first task to start a sample set. private: diff --git a/src/src/DataStructs/SettingsStruct.cpp b/src/src/DataStructs/SettingsStruct.cpp index c13bbc23b..643ade2a5 100644 --- a/src/src/DataStructs/SettingsStruct.cpp +++ b/src/src/DataStructs/SettingsStruct.cpp @@ -150,7 +150,7 @@ void SettingsStruct_tmpl::clearControllers() { template void SettingsStruct_tmpl::clearTasks() { - for (byte task = 0; task < N_TASKS; ++task) { + for (taskIndex_t task = 0; task < N_TASKS; ++task) { clearTask(task); } } @@ -229,7 +229,7 @@ void SettingsStruct_tmpl::clearAll() { } template -void SettingsStruct_tmpl::clearTask(byte task) { +void SettingsStruct_tmpl::clearTask(taskIndex_t task) { if (task >= N_TASKS) { return; } for (byte i = 0; i < CONTROLLER_MAX; ++i) { diff --git a/src/src/DataStructs/SettingsStruct.h b/src/src/DataStructs/SettingsStruct.h index 44df33143..14d53b028 100644 --- a/src/src/DataStructs/SettingsStruct.h +++ b/src/src/DataStructs/SettingsStruct.h @@ -4,6 +4,7 @@ #include "../DataStructs/ESPEasyLimits.h" +#include "../../src/src/Globals/Plugins.h" /*********************************************************************************************\ @@ -63,7 +64,7 @@ class SettingsStruct_tmpl void clearAll(); - void clearTask(byte task); + void clearTask(taskIndex_t task); unsigned long PID; int Version;