diff --git a/src/_P002_ADC.ino b/src/_P002_ADC.ino index 112d468cc..aac2b84b6 100644 --- a/src/_P002_ADC.ino +++ b/src/_P002_ADC.ino @@ -60,9 +60,10 @@ boolean Plugin_002(uint8_t function, struct EventStruct *event, String& string) P002_data->webformLoad(event); success = true; } else { - P002_data = new (std::nothrow) P002_data_struct(event); + P002_data = new (std::nothrow) P002_data_struct(); if (nullptr != P002_data) { + P002_data->init(event); P002_data->webformLoad(event); success = true; delete P002_data; @@ -94,11 +95,14 @@ boolean Plugin_002(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_INIT: { - initPluginTaskData(event->TaskIndex, new (std::nothrow) P002_data_struct(event)); + initPluginTaskData(event->TaskIndex, new (std::nothrow) P002_data_struct()); P002_data_struct *P002_data = static_cast(getPluginTaskData(event->TaskIndex)); - success = (nullptr != P002_data); + if (nullptr != P002_data) { + success = true; + P002_data->init(event); + } break; } case PLUGIN_TEN_PER_SECOND: diff --git a/src/_P004_Dallas.ino b/src/_P004_Dallas.ino index 3927b4cbd..a5118893f 100644 --- a/src/_P004_Dallas.ino +++ b/src/_P004_Dallas.ino @@ -242,11 +242,12 @@ boolean Plugin_004(uint8_t function, struct EventStruct *event, String& string) if ((addr[0] != 0) && (validGpio(Plugin_004_DallasPin_RX)) && (validGpio(Plugin_004_DallasPin_TX))) { const uint8_t res = P004_RESOLUTION; - initPluginTaskData(event->TaskIndex, new (std::nothrow) P004_data_struct(Plugin_004_DallasPin_RX, Plugin_004_DallasPin_TX, addr, res)); + initPluginTaskData(event->TaskIndex, new (std::nothrow) P004_data_struct()); P004_data_struct *P004_data = static_cast(getPluginTaskData(event->TaskIndex)); if (nullptr != P004_data) { + P004_data->init(Plugin_004_DallasPin_RX, Plugin_004_DallasPin_TX, addr, res); // Address index 0 is already set for (uint8_t i = 1; i < P004_NR_OUTPUT_VALUES; ++i) { Dallas_plugin_get_addr(addr, event->TaskIndex, i); diff --git a/src/_P012_LCD.ino b/src/_P012_LCD.ino index 0c564135e..c11732ec5 100644 --- a/src/_P012_LCD.ino +++ b/src/_P012_LCD.ino @@ -69,6 +69,7 @@ boolean Plugin_012(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_WEBFORM_SHOW_I2C_PARAMS: { const uint8_t i2cAddressValues[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f }; + if (function == PLUGIN_WEBFORM_SHOW_I2C_PARAMS) { addFormSelectorI2C(F("i2c_addr"), 16, i2cAddressValues, P012_I2C_ADDR); } else { @@ -81,9 +82,9 @@ boolean Plugin_012(uint8_t function, struct EventStruct *event, String& string) { { uint8_t choice2 = P012_SIZE; - const __FlashStringHelper * options2[2]; - options2[0] = F("2 x 16"); - options2[1] = F("4 x 20"); + const __FlashStringHelper *options2[2]; + options2[0] = F("2 x 16"); + options2[1] = F("4 x 20"); int optionValues2[2] = { 1, 2 }; addFormSelector(F("Display Size"), F("p012_size"), 2, options2, optionValues2, choice2); } @@ -106,7 +107,7 @@ boolean Plugin_012(uint8_t function, struct EventStruct *event, String& string) addFormNumericBox(F("Display Timeout"), F("p012_timer"), P012_TIMER); { - const __FlashStringHelper * options3[3]; + const __FlashStringHelper *options3[3]; options3[0] = F("Continue to next line (as in v1.4)"); options3[1] = F("Truncate exceeding message"); options3[2] = F("Clear then truncate exceeding message"); @@ -151,14 +152,15 @@ boolean Plugin_012(uint8_t function, struct EventStruct *event, String& string) P012_data_struct *P012_data = static_cast(getPluginTaskData(event->TaskIndex)); - if (nullptr == P012_data) { - break; + if (nullptr != P012_data) { + P012_data->init(); + + if (validGpio(CONFIG_PIN3)) { + pinMode(CONFIG_PIN3, INPUT_PULLUP); + } + success = true; } - if (validGpio(CONFIG_PIN3)) { - pinMode(CONFIG_PIN3, INPUT_PULLUP); - } - success = true; break; } @@ -255,6 +257,4 @@ boolean Plugin_012(uint8_t function, struct EventStruct *event, String& string) return success; } - - #endif // USES_P012 diff --git a/src/_P020_Ser2Net.ino b/src/_P020_Ser2Net.ino index 7682e0630..cd2d1a6c1 100644 --- a/src/_P020_Ser2Net.ino +++ b/src/_P020_Ser2Net.ino @@ -253,6 +253,12 @@ boolean Plugin_020(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_EXIT: { + P020_Task *task = static_cast(getPluginTaskData(event->TaskIndex)); + + if (nullptr != task) { + task->stopServer(); + task->serialEnd(); + } success = true; break; } diff --git a/src/_P037_MQTTImport.ino b/src/_P037_MQTTImport.ino index a1a6d7daa..6dcf87df5 100644 --- a/src/_P037_MQTTImport.ino +++ b/src/_P037_MQTTImport.ino @@ -206,7 +206,7 @@ boolean Plugin_037(uint8_t function, struct EventStruct *event, String& string) if (nullptr == P037_data) { return success; } - success = P037_data->webform_load( + success = P037_data->loadSettings() && P037_data->webform_load( # if P037_MAPPING_SUPPORT P037_APPLY_MAPPINGS # endif // if P037_MAPPING_SUPPORT @@ -229,6 +229,13 @@ boolean Plugin_037(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_WEBFORM_SAVE: { + P037_data_struct *P037_data = new (std::nothrow) P037_data_struct(event->TaskIndex); + + if (nullptr == P037_data) { + return success; + } + P037_data->loadSettings(); // FIXME TD-er: Is this loadSettings still needed or even desired? + # if P037_JSON_SUPPORT P037_PARSE_JSON = getFormItemInt(F("pjson")); # endif // if P037_JSON_SUPPORT @@ -250,11 +257,6 @@ boolean Plugin_037(uint8_t function, struct EventStruct *event, String& string) } # endif // if P037_REPLACE_BY_COMMA_SUPPORT - P037_data_struct *P037_data = new (std::nothrow) P037_data_struct(event->TaskIndex); - - if (nullptr == P037_data) { - return success; - } success = P037_data->webform_save( # if P037_FILTER_SUPPORT P037_APPLY_FILTERS @@ -275,12 +277,16 @@ boolean Plugin_037(uint8_t function, struct EventStruct *event, String& string) { initPluginTaskData(event->TaskIndex, new (std::nothrow) P037_data_struct(event->TaskIndex)); - // When we edit the subscription data from the webserver, the plugin is called again with init. - // In order to resubscribe we have to disconnect and reconnect in order to get rid of any obsolete subscriptions - if (MQTTclient_connected) { - // Subscribe to ALL the topics from ALL instance of this import module - MQTTSubscribe_037(event); - success = true; + P037_data_struct *P037_data = static_cast(getPluginTaskData(event->TaskIndex)); + + if (nullptr != P037_data && P037_data->loadSettings()) { + // When we edit the subscription data from the webserver, the plugin is called again with init. + // In order to resubscribe we have to disconnect and reconnect in order to get rid of any obsolete subscriptions + if (MQTTclient_connected) { + // Subscribe to ALL the topics from ALL instance of this import module + MQTTSubscribe_037(event); + success = true; + } } break; } diff --git a/src/_P044_P1WifiGateway.ino b/src/_P044_P1WifiGateway.ino index a60cbe165..71feba9ad 100644 --- a/src/_P044_P1WifiGateway.ino +++ b/src/_P044_P1WifiGateway.ino @@ -144,6 +144,13 @@ boolean Plugin_044(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_EXIT: { + P044_Task *task = static_cast(getPluginTaskData(event->TaskIndex)); + + if (nullptr != task) { + task->stopServer(); + task->serialEnd(); + } + success = true; break; } diff --git a/src/_P045_MPU6050.ino b/src/_P045_MPU6050.ino index 1a3aeaee0..09d00e865 100644 --- a/src/_P045_MPU6050.ino +++ b/src/_P045_MPU6050.ino @@ -191,6 +191,7 @@ boolean Plugin_045(uint8_t function, struct EventStruct *event, String& string) static_cast(getPluginTaskData(event->TaskIndex)); if (nullptr != P045_data) { + P045_data->init(); success = true; } diff --git a/src/_P050_TCS34725.ino b/src/_P050_TCS34725.ino index 113037a09..dc0a444a5 100644 --- a/src/_P050_TCS34725.ino +++ b/src/_P050_TCS34725.ino @@ -172,6 +172,7 @@ boolean Plugin_050(uint8_t function, struct EventStruct *event, String& string) if (nullptr != P050_data) { addFormSubHeader(F("Transformation matrix")); + P050_data->resetTransformation(); P050_data->loadSettings(event->TaskIndex); // Display current settings @@ -216,7 +217,7 @@ boolean Plugin_050(uint8_t function, struct EventStruct *event, String& string) P050_data_struct *P050_data = new (std::nothrow) P050_data_struct(PCONFIG(0), PCONFIG(1)); if (nullptr != P050_data) { - + P050_data->resetTransformation(); P050_data->loadSettings(event->TaskIndex); if (resetTransformation) { @@ -248,6 +249,7 @@ boolean Plugin_050(uint8_t function, struct EventStruct *event, String& string) P050_data_struct *P050_data = static_cast(getPluginTaskData(event->TaskIndex)); if (nullptr != P050_data) { + P050_data->resetTransformation(); success = true; } break; diff --git a/src/_P053_PMSx003.ino b/src/_P053_PMSx003.ino index 689a16505..c5b31df22 100644 --- a/src/_P053_PMSx003.ino +++ b/src/_P053_PMSx003.ino @@ -329,7 +329,7 @@ boolean Plugin_053(uint8_t function, struct EventStruct *event, String& string) static_cast(getPluginTaskData(event->TaskIndex)); if (nullptr != P053_data) { - success = P053_data->initialized(); + success = P053_data->init(); } break; diff --git a/src/_P073_7DGT.ino b/src/_P073_7DGT.ino index b3672999a..f57253d4e 100644 --- a/src/_P073_7DGT.ino +++ b/src/_P073_7DGT.ino @@ -201,54 +201,34 @@ boolean Plugin_073(uint8_t function, struct EventStruct *event, String& string) P073_data_struct *P073_data = static_cast(getPluginTaskData(event->TaskIndex)); - if (nullptr == P073_data) { - return success; - } + if (nullptr != P073_data) { + P073_data->init(event); - // FIXME tonhuisman: Move to constructor?! - P073_data->pin1 = CONFIG_PIN1; - P073_data->pin2 = CONFIG_PIN2; - P073_data->pin3 = CONFIG_PIN3; - P073_data->displayModel = PCONFIG(0); - P073_data->output = PCONFIG(1); - P073_data->brightness = PCONFIG(2); - P073_data->periods = bitRead(PCONFIG_LONG(0), P073_OPTION_PERIOD); - P073_data->hideDegree = bitRead(PCONFIG_LONG(0), P073_OPTION_HIDEDEGREE); - # ifdef P073_SCROLL_TEXT - P073_data->txtScrolling = bitRead(PCONFIG_LONG(0), P073_OPTION_SCROLLTEXT); - P073_data->scrollFull = bitRead(PCONFIG_LONG(0), P073_OPTION_SCROLLFULL); - P073_data->setScrollSpeed(PCONFIG(3)); - # endif // P073_SCROLL_TEXT - P073_data->rightAlignTempMAX7219 = bitRead(PCONFIG_LONG(0), P073_OPTION_RIGHTALIGN); - P073_data->timesep = true; - # ifdef P073_EXTRA_FONTS - P073_data->fontset = PCONFIG(4); - # endif // P073_EXTRA_FONTS + switch (P073_data->displayModel) { + case P073_TM1637_4DGTCOLON: + case P073_TM1637_4DGTDOTS: + case P073_TM1637_6DGT: { + tm1637_InitDisplay(CONFIG_PIN1, CONFIG_PIN2); + tm1637_SetPowerBrightness(CONFIG_PIN1, CONFIG_PIN2, PCONFIG(2) / 2, true); - switch (P073_data->displayModel) { - case P073_TM1637_4DGTCOLON: - case P073_TM1637_4DGTDOTS: - case P073_TM1637_6DGT: { - tm1637_InitDisplay(CONFIG_PIN1, CONFIG_PIN2); - tm1637_SetPowerBrightness(CONFIG_PIN1, CONFIG_PIN2, PCONFIG(2) / 2, true); - - if (PCONFIG(1) == P073_DISP_MANUAL) { - tm1637_ClearDisplay(CONFIG_PIN1, CONFIG_PIN2); + if (PCONFIG(1) == P073_DISP_MANUAL) { + tm1637_ClearDisplay(CONFIG_PIN1, CONFIG_PIN2); + } + break; } - break; - } - case P073_MAX7219_8DGT: { - max7219_InitDisplay(event, CONFIG_PIN1, CONFIG_PIN2, CONFIG_PIN3); - delay(10); // small poweroff/poweron delay - max7219_SetPowerBrightness(event, CONFIG_PIN1, CONFIG_PIN2, CONFIG_PIN3, PCONFIG(2), true); + case P073_MAX7219_8DGT: { + max7219_InitDisplay(event, CONFIG_PIN1, CONFIG_PIN2, CONFIG_PIN3); + delay(10); // small poweroff/poweron delay + max7219_SetPowerBrightness(event, CONFIG_PIN1, CONFIG_PIN2, CONFIG_PIN3, PCONFIG(2), true); - if (PCONFIG(1) == P073_DISP_MANUAL) { - max7219_ClearDisplay(event, CONFIG_PIN1, CONFIG_PIN2, CONFIG_PIN3); + if (PCONFIG(1) == P073_DISP_MANUAL) { + max7219_ClearDisplay(event, CONFIG_PIN1, CONFIG_PIN2, CONFIG_PIN3); + } + break; } - break; } + success = true; } - success = true; break; } diff --git a/src/_P079_Wemos_Motorshield.ino b/src/_P079_Wemos_Motorshield.ino index 515cd48c2..946ebce5a 100644 --- a/src/_P079_Wemos_Motorshield.ino +++ b/src/_P079_Wemos_Motorshield.ino @@ -351,6 +351,7 @@ boolean Plugin_079(uint8_t function, struct EventStruct *event, String& string) switch (Plugin_079_MotorShield_type) { case P079_BoardType::WemosMotorshield: { WemosMotor Wemos(I2C_ADDR_PCFG_P079, motor_number, MOTOR_FREQ_P079); + Wemos.init(); switch (motor_dir) { case MOTOR_STATES::MOTOR_FWD: diff --git a/src/_P082_GPS.ino b/src/_P082_GPS.ino index 5041f7f0b..75051f125 100644 --- a/src/_P082_GPS.ino +++ b/src/_P082_GPS.ino @@ -368,6 +368,12 @@ boolean Plugin_082(uint8_t function, struct EventStruct *event, String& string) } case PLUGIN_EXIT: { + P082_data_struct *P082_data = + static_cast(getPluginTaskData(event->TaskIndex)); + if (nullptr != P082_data) { + P082_data->powerDown(); + } + const int16_t pps_pin = CONFIG_PIN3; if (validGpio(pps_pin)) { diff --git a/src/_P093_MitsubishiHP.ino b/src/_P093_MitsubishiHP.ino index 4221bbf5a..17bed9bb3 100644 --- a/src/_P093_MitsubishiHP.ino +++ b/src/_P093_MitsubishiHP.ino @@ -73,7 +73,12 @@ boolean Plugin_093(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_INIT: { const ESPEasySerialPort port = static_cast(CONFIG_PORT); initPluginTaskData(event->TaskIndex, new (std::nothrow) P093_data_struct(port, CONFIG_PIN1, CONFIG_PIN2, P093_REQUEST_STATUS)); - success = getPluginTaskData(event->TaskIndex) != nullptr; + P093_data_struct *heatPump = static_cast(getPluginTaskData(event->TaskIndex)); + + if (heatPump != nullptr) { + heatPump->init(); + success = true; + } break; } diff --git a/src/_P120_ADXL345_Accelerometer.ino b/src/_P120_ADXL345_Accelerometer.ino index e4ddeeb06..b753e9665 100644 --- a/src/_P120_ADXL345_Accelerometer.ino +++ b/src/_P120_ADXL345_Accelerometer.ino @@ -104,9 +104,10 @@ boolean Plugin_120(uint8_t function, struct EventStruct *event, String& string) P120_I2C_ADDR = 0x53; // Default I2C Address P120_AVERAGE_BUFFER = 10; // Average averaging ;-) - P120_data_struct *P120_data = new (std::nothrow) P120_data_struct(static_cast(P120_I2C_ADDR), P120_AVERAGE_BUFFER); + P120_data_struct *P120_data = new (std::nothrow) P120_data_struct(P120_AVERAGE_BUFFER); if (nullptr != P120_data) { + P120_data->setI2Caddress(static_cast(P120_I2C_ADDR)); success = P120_data->plugin_set_defaults(event); // This shouldn't fail delete P120_data; } @@ -127,9 +128,10 @@ boolean Plugin_120(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_WEBFORM_LOAD: { - P120_data_struct *P120_data = new (std::nothrow) P120_data_struct(static_cast(P120_I2C_ADDR), P120_AVERAGE_BUFFER); + P120_data_struct *P120_data = new (std::nothrow) P120_data_struct(P120_AVERAGE_BUFFER); if (nullptr != P120_data) { + P120_data->setI2Caddress(static_cast(P120_I2C_ADDR)); success = P120_data->plugin_webform_load(event); // This shouldn't fail delete P120_data; } @@ -141,9 +143,10 @@ boolean Plugin_120(uint8_t function, struct EventStruct *event, String& string) P120_I2C_ADDR = getFormItemInt(F("i2c_addr")); P120_AVERAGE_BUFFER = getFormItemInt(F("p120_average_buf")); - P120_data_struct *P120_data = new (std::nothrow) P120_data_struct(static_cast(P120_I2C_ADDR), P120_AVERAGE_BUFFER); + P120_data_struct *P120_data = new (std::nothrow) P120_data_struct(P120_AVERAGE_BUFFER); if (nullptr != P120_data) { + P120_data->setI2Caddress(static_cast(P120_I2C_ADDR)); success = P120_data->plugin_webform_save(event); // This shouldn't fail delete P120_data; } @@ -152,10 +155,13 @@ boolean Plugin_120(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_INIT: { - initPluginTaskData(event->TaskIndex, new (std::nothrow) P120_data_struct(static_cast(P120_I2C_ADDR), P120_AVERAGE_BUFFER)); + initPluginTaskData(event->TaskIndex, new (std::nothrow) P120_data_struct(P120_AVERAGE_BUFFER)); P120_data_struct *P120_data = static_cast(getPluginTaskData(event->TaskIndex)); - success = nullptr != P120_data; + if (nullptr != P120_data) { + P120_data->setI2Caddress(static_cast(P120_I2C_ADDR)); + success = true; + } break; } diff --git a/src/_P124_MultiRelay.ino b/src/_P124_MultiRelay.ino index 889ec4039..9cce47f5a 100644 --- a/src/_P124_MultiRelay.ino +++ b/src/_P124_MultiRelay.ino @@ -168,6 +168,7 @@ boolean Plugin_124(uint8_t function, struct EventStruct *event, String& string) P124_data_struct *P124_data = new (std::nothrow) P124_data_struct(P124_CONFIG_I2C_ADDRESS, P124_CONFIG_RELAY_COUNT, true); if (nullptr != P124_data) { + P124_data->init(); P124_CONFIG_I2C_ADDRESS++; // Increment, like the Change Address argument does. if (P124_CONFIG_I2C_ADDRESS > 0x18) { P124_CONFIG_I2C_ADDRESS = 0x11; } @@ -190,7 +191,7 @@ boolean Plugin_124(uint8_t function, struct EventStruct *event, String& string) return success; } - if (P124_data->isInitialized()) { + if (P124_data->init()) { if (loglevelActiveFor(LOG_LEVEL_INFO)) { String log; log.reserve(46); diff --git a/src/_P125_ADXL345_SPI.ino b/src/_P125_ADXL345_SPI.ino index a3d0618f5..53f15b990 100644 --- a/src/_P125_ADXL345_SPI.ino +++ b/src/_P125_ADXL345_SPI.ino @@ -91,9 +91,10 @@ boolean Plugin_125(uint8_t function, struct EventStruct *event, String& string) P120_CS_PIN = -1; // Default not selected P120_AVERAGE_BUFFER = 10; // Average averaging ;-) - P120_data_struct *P120_data = new (std::nothrow) P120_data_struct(static_cast(P120_CS_PIN), P120_AVERAGE_BUFFER); + P120_data_struct *P120_data = new (std::nothrow) P120_data_struct(P120_AVERAGE_BUFFER); if (nullptr != P120_data) { + P120_data->setSPI_CSpin(static_cast(P120_CS_PIN)); success = P120_data->plugin_set_defaults(event); // This shouldn't fail delete P120_data; } @@ -114,9 +115,10 @@ boolean Plugin_125(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_WEBFORM_LOAD: { - P120_data_struct *P120_data = new (std::nothrow) P120_data_struct(static_cast(P120_CS_PIN), P120_AVERAGE_BUFFER); + P120_data_struct *P120_data = new (std::nothrow) P120_data_struct(P120_AVERAGE_BUFFER); if (nullptr != P120_data) { + P120_data->setSPI_CSpin(static_cast(P120_CS_PIN)); success = P120_data->plugin_webform_load(event); // This shouldn't fail delete P120_data; } @@ -127,9 +129,10 @@ boolean Plugin_125(uint8_t function, struct EventStruct *event, String& string) { P120_AVERAGE_BUFFER = getFormItemInt(F("p120_average_buf")); - P120_data_struct *P120_data = new (std::nothrow) P120_data_struct(static_cast(P120_CS_PIN), P120_AVERAGE_BUFFER); + P120_data_struct *P120_data = new (std::nothrow) P120_data_struct(P120_AVERAGE_BUFFER); if (nullptr != P120_data) { + P120_data->setSPI_CSpin(static_cast(P120_CS_PIN)); success = P120_data->plugin_webform_save(event); // This shouldn't fail delete P120_data; } @@ -138,10 +141,13 @@ boolean Plugin_125(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_INIT: { - initPluginTaskData(event->TaskIndex, new (std::nothrow) P120_data_struct(static_cast(P120_CS_PIN), P120_AVERAGE_BUFFER)); + initPluginTaskData(event->TaskIndex, new (std::nothrow) P120_data_struct(P120_AVERAGE_BUFFER)); P120_data_struct *P120_data = static_cast(getPluginTaskData(event->TaskIndex)); - success = nullptr != P120_data; + if (nullptr != P120_data) { + P120_data->setSPI_CSpin(static_cast(P120_CS_PIN)); + success = true; + } break; } diff --git a/src/_P132_INA3221.ino b/src/_P132_INA3221.ino index b1116c71b..8fb85afed 100644 --- a/src/_P132_INA3221.ino +++ b/src/_P132_INA3221.ino @@ -209,11 +209,11 @@ boolean Plugin_132(uint8_t function, struct EventStruct *event, String& string) initPluginTaskData(event->TaskIndex, new (std::nothrow) P132_data_struct(event)); P132_data_struct *P132_data = static_cast(getPluginTaskData(event->TaskIndex)); - if (nullptr == P132_data) { - return success; + if (nullptr != P132_data) { + P132_data->setCalibration_INA3221(event); + success = true; } - success = true; break; } diff --git a/src/_P135_SCD4x.ino b/src/_P135_SCD4x.ino index d7921f69c..a0e1ed5d7 100644 --- a/src/_P135_SCD4x.ino +++ b/src/_P135_SCD4x.ino @@ -151,7 +151,7 @@ boolean Plugin_135(uint8_t function, struct EventStruct *event, String& string) P135_data_struct *P135_data = static_cast(getPluginTaskData(event->TaskIndex)); if (nullptr != P135_data) { - success = P135_data->isInitialized(); + success = P135_data->init(); } break; diff --git a/src/src/DataStructs/ExtraTaskSettingsStruct.cpp b/src/src/DataStructs/ExtraTaskSettingsStruct.cpp index 14dfc18f3..735ea75f6 100644 --- a/src/src/DataStructs/ExtraTaskSettingsStruct.cpp +++ b/src/src/DataStructs/ExtraTaskSettingsStruct.cpp @@ -5,11 +5,6 @@ #define EXTRA_TASK_SETTINGS_VERSION 1 ExtraTaskSettingsStruct::ExtraTaskSettingsStruct() : TaskIndex(INVALID_TASK_INDEX) { - clear(); -} - -void ExtraTaskSettingsStruct::clear() { - TaskIndex = INVALID_TASK_INDEX; ZERO_FILL(TaskDeviceName); clearUnusedValueNames(0); @@ -20,6 +15,10 @@ void ExtraTaskSettingsStruct::clear() { } } +void ExtraTaskSettingsStruct::clear() { + *this = ExtraTaskSettingsStruct(); +} + void ExtraTaskSettingsStruct::validate() { ZERO_TERMINATE(TaskDeviceName); diff --git a/src/src/Helpers/Modbus_RTU.cpp b/src/src/Helpers/Modbus_RTU.cpp index 21b191d15..fb8ed60ae 100644 --- a/src/src/Helpers/Modbus_RTU.cpp +++ b/src/src/Helpers/Modbus_RTU.cpp @@ -6,12 +6,11 @@ #include "../Helpers/StringConverter.h" -ModbusRTU_struct::ModbusRTU_struct() : easySerial(nullptr) { - reset(); -} - ModbusRTU_struct::~ModbusRTU_struct() { - reset(); + if (easySerial != nullptr) { + delete easySerial; + easySerial = nullptr; + } } void ModbusRTU_struct::reset() { diff --git a/src/src/Helpers/Modbus_RTU.h b/src/src/Helpers/Modbus_RTU.h index d2d03c9f0..eb727f75e 100644 --- a/src/src/Helpers/Modbus_RTU.h +++ b/src/src/Helpers/Modbus_RTU.h @@ -44,7 +44,7 @@ struct ModbusRTU_struct { - ModbusRTU_struct(); + ModbusRTU_struct() = default; ~ModbusRTU_struct(); diff --git a/src/src/PluginStructs/P002_data_struct.cpp b/src/src/PluginStructs/P002_data_struct.cpp index 7421c09b0..87a8a0366 100644 --- a/src/src/PluginStructs/P002_data_struct.cpp +++ b/src/src/PluginStructs/P002_data_struct.cpp @@ -10,7 +10,9 @@ # endif // ifndef DEFAULT_VREF -P002_data_struct::P002_data_struct(struct EventStruct *event) + + +void P002_data_struct::init(struct EventStruct *event) { _sampleMode = P002_OVERSAMPLING; diff --git a/src/src/PluginStructs/P002_data_struct.h b/src/src/PluginStructs/P002_data_struct.h index 370171724..41e4abfef 100644 --- a/src/src/PluginStructs/P002_data_struct.h +++ b/src/src/PluginStructs/P002_data_struct.h @@ -93,7 +93,10 @@ struct P002_binningRange { }; struct P002_data_struct : public PluginTaskData_base { - P002_data_struct(struct EventStruct *event); + P002_data_struct() = default; + virtual ~P002_data_struct() = default; + + void init(struct EventStruct *event); private: diff --git a/src/src/PluginStructs/P003_data_struct.cpp b/src/src/PluginStructs/P003_data_struct.cpp index 95ab899bf..9f76e4637 100644 --- a/src/src/PluginStructs/P003_data_struct.cpp +++ b/src/src/PluginStructs/P003_data_struct.cpp @@ -2,11 +2,7 @@ #ifdef USES_P003 -P003_data_struct::P003_data_struct(const Internal_GPIO_pulseHelper::pulseCounterConfig& config) - : - pulseHelper(config) -{} +P003_data_struct::P003_data_struct(const Internal_GPIO_pulseHelper::pulseCounterConfig& config) + : pulseHelper(config) {} -P003_data_struct::~P003_data_struct() -{} -#endif \ No newline at end of file +#endif // ifdef USES_P003 diff --git a/src/src/PluginStructs/P003_data_struct.h b/src/src/PluginStructs/P003_data_struct.h index d40fba85f..a516f4a5c 100644 --- a/src/src/PluginStructs/P003_data_struct.h +++ b/src/src/PluginStructs/P003_data_struct.h @@ -9,8 +9,9 @@ struct P003_data_struct : public PluginTaskData_base { P003_data_struct(const Internal_GPIO_pulseHelper::pulseCounterConfig& config); - ~P003_data_struct(); + P003_data_struct() = delete; + virtual ~P003_data_struct() = default; Internal_GPIO_pulseHelper pulseHelper; }; diff --git a/src/src/PluginStructs/P004_data_struct.cpp b/src/src/PluginStructs/P004_data_struct.cpp index d324a384b..1ebb9c41d 100644 --- a/src/src/PluginStructs/P004_data_struct.cpp +++ b/src/src/PluginStructs/P004_data_struct.cpp @@ -3,8 +3,12 @@ #ifdef USES_P004 -P004_data_struct::P004_data_struct(int8_t pin_rx, int8_t pin_tx, const uint8_t addr[], uint8_t res) : _gpio_rx(pin_rx), _gpio_tx(pin_tx), _res(res) +void P004_data_struct::init(int8_t pin_rx, int8_t pin_tx, const uint8_t addr[], uint8_t res) { + _gpio_rx = pin_rx; + _gpio_tx = pin_tx; + _res = res; + // Explicitly set the pinMode using the "slow" pinMode function // This way we know for sure the state of any pull-up or -down resistor is known. pinMode(_gpio_rx, INPUT); diff --git a/src/src/PluginStructs/P004_data_struct.h b/src/src/PluginStructs/P004_data_struct.h index 9f71466f7..ec236293e 100644 --- a/src/src/PluginStructs/P004_data_struct.h +++ b/src/src/PluginStructs/P004_data_struct.h @@ -25,13 +25,16 @@ struct P004_data_struct : public PluginTaskData_base { * If those limitations are not desired, use multiple tasks. \*********************************************************************************************/ + P004_data_struct() = default; + virtual ~P004_data_struct() = default; + // @param pin The GPIO pin used to communicate to the Dallas sensors in this task // @param addr Address of the (1st) Dallas sensor (index = 0) in this task // @param res The resolution of the Dallas sensor(s) used in this task - P004_data_struct(int8_t pin_rx, - int8_t pin_tx, - const uint8_t addr[], - uint8_t res); + void init(int8_t pin_rx, + int8_t pin_tx, + const uint8_t addr[], + uint8_t res); // Add extra sensor address // @param addr The address to add diff --git a/src/src/PluginStructs/P005_data_struct.h b/src/src/PluginStructs/P005_data_struct.h index 2aaa9d96f..81ce37191 100644 --- a/src/src/PluginStructs/P005_data_struct.h +++ b/src/src/PluginStructs/P005_data_struct.h @@ -13,6 +13,9 @@ struct P005_data_struct : public PluginTaskData_base { P005_data_struct(struct EventStruct *event); + P005_data_struct() = delete; + virtual ~P005_data_struct() = default; + /*********************************************************************************************\ * DHT sub to wait until a pin is in a certain state \*********************************************************************************************/ diff --git a/src/src/PluginStructs/P006_data_struct.cpp b/src/src/PluginStructs/P006_data_struct.cpp index eed5ea5b6..76505f097 100644 --- a/src/src/PluginStructs/P006_data_struct.cpp +++ b/src/src/PluginStructs/P006_data_struct.cpp @@ -48,14 +48,14 @@ bool P006_data_struct::begin() return true; } -uint16_t P006_data_struct::readRawTemperature(void) +uint16_t P006_data_struct::readRawTemperature() { I2C_write8_reg(BMP085_I2CADDR, BMP085_CONTROL, BMP085_READTEMPCMD); delay(5); return I2C_read16_reg(BMP085_I2CADDR, BMP085_TEMPDATA); } -uint32_t P006_data_struct::readRawPressure(void) +uint32_t P006_data_struct::readRawPressure() { uint32_t raw; @@ -71,7 +71,7 @@ uint32_t P006_data_struct::readRawPressure(void) return raw; } -int32_t P006_data_struct::readPressure(void) +int32_t P006_data_struct::readPressure() { int32_t UT, UP, B3, B5, B6, X1, X2, X3, p; uint32_t B4, B7; @@ -113,7 +113,7 @@ int32_t P006_data_struct::readPressure(void) return p; } -float P006_data_struct::readTemperature(void) +float P006_data_struct::readTemperature() { int32_t UT, X1, X2, B5; // following ds convention float temp; diff --git a/src/src/PluginStructs/P006_data_struct.h b/src/src/PluginStructs/P006_data_struct.h index 5038458b9..b6132541a 100644 --- a/src/src/PluginStructs/P006_data_struct.h +++ b/src/src/PluginStructs/P006_data_struct.h @@ -8,15 +8,18 @@ # define BMP085_ULTRAHIGHRES 3 struct P006_data_struct : public PluginTaskData_base { + P006_data_struct() = default; + virtual ~P006_data_struct() = default; + bool begin(); - uint16_t readRawTemperature(void); + uint16_t readRawTemperature(); - uint32_t readRawPressure(void); + uint32_t readRawPressure(); - int32_t readPressure(void); + int32_t readPressure(); - float readTemperature(void); + float readTemperature(); uint8_t oversampling = BMP085_ULTRAHIGHRES; int16_t ac1 = 0; diff --git a/src/src/PluginStructs/P008_data_struct.h b/src/src/PluginStructs/P008_data_struct.h index 55bf87d6e..40d86953f 100644 --- a/src/src/PluginStructs/P008_data_struct.h +++ b/src/src/PluginStructs/P008_data_struct.h @@ -20,7 +20,7 @@ public: P008_data_struct(struct EventStruct *event); P008_data_struct() = delete; - ~P008_data_struct(); + virtual ~P008_data_struct(); bool plugin_init(struct EventStruct *event); bool plugin_once_a_second(struct EventStruct *event); diff --git a/src/src/PluginStructs/P012_data_struct.cpp b/src/src/PluginStructs/P012_data_struct.cpp index c5955bc06..0d72e4f67 100644 --- a/src/src/PluginStructs/P012_data_struct.cpp +++ b/src/src/PluginStructs/P012_data_struct.cpp @@ -4,16 +4,17 @@ // Needed also here for PlatformIO's library finder as the .h file // is in a directory which is excluded in the src_filter -#include +# include P012_data_struct::P012_data_struct(uint8_t addr, uint8_t lcd_size, uint8_t mode, - uint8_t timer) : + uint8_t timer) : lcd(addr, 20, 4), Plugin_012_mode(mode), - displayTimer(timer) { + displayTimer(timer) +{ switch (lcd_size) { case 1: @@ -30,8 +31,9 @@ P012_data_struct::P012_data_struct(uint8_t addr, Plugin_012_cols = 16; break; } +} - +void P012_data_struct::init() { // Setup LCD display lcd.init(); // initialize the lcd lcd.backlight(); @@ -81,7 +83,7 @@ void P012_data_struct::lcdWrite(const String& text, uint8_t col, uint8_t row) { else { // Fix Weird (native) lcd display behaviour that split long string into row 1,3,2,4, instead of 1,2,3,4 bool stillProcessing = 1; - uint8_t charCount = 1; + uint8_t charCount = 1; while (stillProcessing) { if (++col > Plugin_012_cols) { // have we printed 20 characters yet (+1 for the logic) @@ -228,41 +230,43 @@ String P012_data_struct::P012_parseTemplate(String& tmpString, uint8_t lineSize) void P012_data_struct::createCustomChars() { # ifdef USES_P012_POLISH_CHARS -/* - static const char LETTER_null[8] PROGMEM = { // spacja - 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000 - }; -*/ - static const char LETTER_a[8] PROGMEM = { // a + + /* + static const char LETTER_null[8] PROGMEM = { // spacja + 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000 + }; + */ + static const char LETTER_a[8] PROGMEM = { // a 0b00000, 0b00000, 0b01110, 0b00001, 0b01111, 0b10001, 0b01111, 0b00010 }; - static const char LETTER_c[8] PROGMEM = { // c + static const char LETTER_c[8] PROGMEM = { // c 0b00010, 0b00100, 0b01110, 0b10000, 0b10000, 0b10001, 0b01110, 0b00000 }; - static const char LETTER_e[8] PROGMEM = { // e + static const char LETTER_e[8] PROGMEM = { // e 0b00000, 0b00000, 0b01110, 0b10001, 0b11111, 0b10000, 0b01110, 0b00010 }; - static const char LETTER_l[8] PROGMEM = { // l + static const char LETTER_l[8] PROGMEM = { // l 0b01100, 0b00100, 0b00101, 0b00110, 0b01100, 0b00100, 0b01110, 0b00000 }; - static const char LETTER_n[8] PROGMEM = { // n + static const char LETTER_n[8] PROGMEM = { // n 0b00010, 0b00100, 0b10110, 0b11001, 0b10001, 0b10001, 0b10001, 0b00000 }; - static const char LETTER_o[8] PROGMEM = { // o + static const char LETTER_o[8] PROGMEM = { // o 0b00010, 0b00100, 0b01110, 0b10001, 0b10001, 0b10001, 0b01110, 0b00000 }; - static const char LETTER_s[8] PROGMEM = { // s + static const char LETTER_s[8] PROGMEM = { // s 0b00010, 0b00100, 0b01110, 0b10000, 0b01110, 0b00001, 0b11110, 0b00000 }; + /* - static const char LETTER_z1[8] PROGMEM = { // z z kreska - 0b00010, 0b00100, 0b11111, 0b00010, 0b00100, 0b01000, 0b11111, 0b00000 - }; - */ - static const char LETTER_z2[8] PROGMEM = { // z z kropka + static const char LETTER_z1[8] PROGMEM = { // z z kreska + 0b00010, 0b00100, 0b11111, 0b00010, 0b00100, 0b01000, 0b11111, 0b00000 + }; + */ + static const char LETTER_z2[8] PROGMEM = { // z z kropka 0b00100, 0b00000, 0b11111, 0b00010, 0b00100, 0b01000, 0b11111, 0b00000 }; - lcd.createChar(0, LETTER_o); // probably defected memory cell + lcd.createChar(0, LETTER_o); // probably defected memory cell lcd.createChar(1, LETTER_l); lcd.createChar(2, LETTER_e); lcd.createChar(3, LETTER_c); diff --git a/src/src/PluginStructs/P012_data_struct.h b/src/src/PluginStructs/P012_data_struct.h index 658e46df2..ef4a77b1a 100644 --- a/src/src/PluginStructs/P012_data_struct.h +++ b/src/src/PluginStructs/P012_data_struct.h @@ -5,32 +5,37 @@ #ifdef USES_P012 -#include +# include struct P012_data_struct : public PluginTaskData_base { P012_data_struct(uint8_t addr, uint8_t lcd_size, uint8_t mode, - uint8_t timer); + uint8_t timer); + P012_data_struct() = delete; + virtual ~P012_data_struct() = default; + + void init(); void setBacklightTimer(uint8_t timer); void checkTimer(); void lcdWrite(const String& text, - uint8_t col, - uint8_t row); + uint8_t col, + uint8_t row); - String P012_parseTemplate(String& tmpString, uint8_t lineSize); + String P012_parseTemplate(String& tmpString, + uint8_t lineSize); - void createCustomChars(); + void createCustomChars(); LiquidCrystal_I2C lcd; int Plugin_012_cols = 16; int Plugin_012_rows = 2; int Plugin_012_mode = 1; - uint8_t displayTimer = 0; + uint8_t displayTimer = 0; }; #endif // ifdef USES_P012 diff --git a/src/src/PluginStructs/P014_data_struct.h b/src/src/PluginStructs/P014_data_struct.h index 43b5529f8..ddb2971fc 100644 --- a/src/src/PluginStructs/P014_data_struct.h +++ b/src/src/PluginStructs/P014_data_struct.h @@ -115,6 +115,8 @@ struct P014_data_struct : public PluginTaskData_base { public: P014_data_struct(); + virtual ~P014_data_struct() = default; + // Only perform the measurements with big interval to prevent the sensor from warming up. //This method runs the FSM step by step on each call bool update(uint8_t i2caddr, uint8_t resolution, uint8_t filter_power); diff --git a/src/src/PluginStructs/P015_data_struct.cpp b/src/src/PluginStructs/P015_data_struct.cpp index ccac2cc15..c0668ad9c 100644 --- a/src/src/PluginStructs/P015_data_struct.cpp +++ b/src/src/PluginStructs/P015_data_struct.cpp @@ -1,8 +1,7 @@ #include "../PluginStructs/P015_data_struct.h" #ifdef USES_P015 -#include "../Helpers/Misc.h" - +# include "../Helpers/Misc.h" # define TSL2561_CMD 0x80 @@ -110,13 +109,6 @@ bool P015_data_struct::performRead(float& luxVal, return success; } -bool P015_data_struct::useAutoGain() const -{ - const bool autoGain = _gain == P015_AUTO_GAIN || _gain == P015_EXT_AUTO_GAIN; - - return autoGain; -} - bool P015_data_struct::begin() { // Wire.begin(); called in ESPEasy framework diff --git a/src/src/PluginStructs/P015_data_struct.h b/src/src/PluginStructs/P015_data_struct.h index 9c1b1493e..927acc83d 100644 --- a/src/src/PluginStructs/P015_data_struct.h +++ b/src/src/PluginStructs/P015_data_struct.h @@ -16,13 +16,20 @@ # define P015_EXT_AUTO_GAIN 3 struct P015_data_struct : public PluginTaskData_base { - P015_data_struct(uint8_t i2caddr, + P015_data_struct(uint8_t i2caddr, unsigned int gain, - uint8_t integration); + uint8_t integration); + + P015_data_struct() = delete; + + virtual ~P015_data_struct() = default; bool begin(); - bool useAutoGain() const; + // Called from the constructor, thus have this simple function in the header file. + bool useAutoGain() const { + return _gain == P015_AUTO_GAIN || _gain == P015_EXT_AUTO_GAIN; + } bool performRead(float& luxVal, float& infraredVal, @@ -125,9 +132,9 @@ struct P015_data_struct : public PluginTaskData_base { unsigned int _gain; // Gain setting, 0 = X1, 1 = X16, 2 = auto, 3 = extended auto; - uint8_t _i2cAddr = 0; - uint8_t _integration = 0; - uint8_t _error = 0; + uint8_t _i2cAddr = 0; + uint8_t _integration = 0; + uint8_t _error = 0; bool _gain16xActive = false; }; diff --git a/src/src/PluginStructs/P016_data_struct.cpp b/src/src/PluginStructs/P016_data_struct.cpp index c730f1fe5..0d7036a5c 100644 --- a/src/src/PluginStructs/P016_data_struct.cpp +++ b/src/src/PluginStructs/P016_data_struct.cpp @@ -66,7 +66,6 @@ tCommandLinesV2::tCommandLinesV2(const tCommandLinesV1& lineV1, uint8_t i) # endif // ifdef P16_SETTINGS_V1 -P016_data_struct::P016_data_struct() {} void P016_data_struct::init(struct EventStruct *event, uint16_t CmdInhibitTime) { # if P016_FEATURE_COMMAND_HANDLING diff --git a/src/src/PluginStructs/P016_data_struct.h b/src/src/PluginStructs/P016_data_struct.h index 43a92ebe0..07d1a62f0 100644 --- a/src/src/PluginStructs/P016_data_struct.h +++ b/src/src/PluginStructs/P016_data_struct.h @@ -76,7 +76,8 @@ struct tCommandLinesV2 { struct P016_data_struct : public PluginTaskData_base { public: - P016_data_struct(); + P016_data_struct() = default; + virtual ~P016_data_struct() = default; void init(struct EventStruct *event, uint16_t CmdInhibitTime); diff --git a/src/src/PluginStructs/P020_data_struct.cpp b/src/src/PluginStructs/P020_data_struct.cpp index 1bede0631..e15a119a3 100644 --- a/src/src/PluginStructs/P020_data_struct.cpp +++ b/src/src/PluginStructs/P020_data_struct.cpp @@ -15,12 +15,18 @@ P020_Task::P020_Task(taskIndex_t taskIndex) : _taskIndex(taskIndex) { - clearBuffer(); + serial_buffer.reserve(P020_DATAGRAM_MAX_SIZE); } P020_Task::~P020_Task() { - stopServer(); - serialEnd(); + if (ser2netServer != nullptr) { + delete ser2netServer; + ser2netServer = nullptr; + } + if (ser2netSerial != nullptr) { + delete ser2netSerial; + ser2netSerial = nullptr; + } } bool P020_Task::serverActive(WiFiServer *server) { diff --git a/src/src/PluginStructs/P020_data_struct.h b/src/src/PluginStructs/P020_data_struct.h index c7f93ab77..51300ba3c 100644 --- a/src/src/PluginStructs/P020_data_struct.h +++ b/src/src/PluginStructs/P020_data_struct.h @@ -15,7 +15,8 @@ # define P020_DATAGRAM_MAX_SIZE 256 struct P020_Task : public PluginTaskData_base { P020_Task(taskIndex_t taskIndex); - ~P020_Task(); + P020_Task() = delete; + virtual ~P020_Task(); inline static bool serverActive(WiFiServer *server); diff --git a/src/src/PluginStructs/P022_data_struct.h b/src/src/PluginStructs/P022_data_struct.h index 3778d124a..4b3d0c291 100644 --- a/src/src/PluginStructs/P022_data_struct.h +++ b/src/src/PluginStructs/P022_data_struct.h @@ -23,6 +23,9 @@ // Administration per address is no longer needed as it may be behind a multiplexer, // so multiple instances using the same address is now allowed. struct P022_data_struct : public PluginTaskData_base { + P022_data_struct() = default; + virtual ~P022_data_struct() = default; + bool p022_is_init(uint8_t address); bool p022_set_init(uint8_t address); diff --git a/src/src/PluginStructs/P023_data_struct.h b/src/src/PluginStructs/P023_data_struct.h index f813ad10b..f0cbf275b 100644 --- a/src/src/PluginStructs/P023_data_struct.h +++ b/src/src/PluginStructs/P023_data_struct.h @@ -28,6 +28,8 @@ struct P023_data_struct : public PluginTaskData_base { Spacing _font_spacing, uint8_t _displayTimer, uint8_t _use_sh1106); + P023_data_struct() = delete; + virtual ~P023_data_struct() = default; void setDisplayTimer(uint8_t _displayTimer); void checkDisplayTimer(); diff --git a/src/src/PluginStructs/P024_data_struct.h b/src/src/PluginStructs/P024_data_struct.h index f1f701c1c..2d1711435 100644 --- a/src/src/PluginStructs/P024_data_struct.h +++ b/src/src/PluginStructs/P024_data_struct.h @@ -9,6 +9,8 @@ struct P024_data_struct : public PluginTaskData_base { public: P024_data_struct(uint8_t i2c_addr); + P024_data_struct() = delete; + virtual ~P024_data_struct() = default; float readTemperature(uint8_t reg); diff --git a/src/src/PluginStructs/P025_data_struct.h b/src/src/PluginStructs/P025_data_struct.h index 496ef23c4..5c36bf0e9 100644 --- a/src/src/PluginStructs/P025_data_struct.h +++ b/src/src/PluginStructs/P025_data_struct.h @@ -10,6 +10,8 @@ public: P025_data_struct(uint8_t i2c_addr, uint8_t _pga, uint8_t _mux); + P025_data_struct() = delete; + virtual ~P025_data_struct() = default; int16_t read(); diff --git a/src/src/PluginStructs/P027_data_struct.h b/src/src/PluginStructs/P027_data_struct.h index dba7b5226..adf514773 100644 --- a/src/src/PluginStructs/P027_data_struct.h +++ b/src/src/PluginStructs/P027_data_struct.h @@ -10,6 +10,9 @@ public: P027_data_struct(uint8_t i2c_addr); + P027_data_struct() = delete; + virtual ~P027_data_struct() = default; + // **************************************************************************/ // Configures to INA219 to be able to measure up to 32V and 2A diff --git a/src/src/PluginStructs/P028_data_struct.h b/src/src/PluginStructs/P028_data_struct.h index 7949bc426..99643a1e2 100644 --- a/src/src/PluginStructs/P028_data_struct.h +++ b/src/src/PluginStructs/P028_data_struct.h @@ -119,6 +119,8 @@ struct P028_data_struct : public PluginTaskData_base { P028_data_struct(uint8_t addr, float tempOffset); + P028_data_struct() = delete; + virtual ~P028_data_struct() = default; private: diff --git a/src/src/PluginStructs/P031_data_struct.h b/src/src/PluginStructs/P031_data_struct.h index ab0752026..ab78b665e 100644 --- a/src/src/PluginStructs/P031_data_struct.h +++ b/src/src/PluginStructs/P031_data_struct.h @@ -30,6 +30,8 @@ public: }; P031_data_struct() = default; + virtual ~P031_data_struct() = default; + uint8_t init(uint8_t data_pin, uint8_t clock_pin, diff --git a/src/src/PluginStructs/P032_data_struct.h b/src/src/PluginStructs/P032_data_struct.h index be058f24e..019443742 100644 --- a/src/src/PluginStructs/P032_data_struct.h +++ b/src/src/PluginStructs/P032_data_struct.h @@ -8,6 +8,9 @@ struct P032_data_struct : public PluginTaskData_base { public: P032_data_struct(uint8_t i2c_addr); + P032_data_struct() = delete; + virtual ~P032_data_struct() = default; + // **************************************************************************/ diff --git a/src/src/PluginStructs/P035_data_struct.h b/src/src/PluginStructs/P035_data_struct.h index 2795a2b79..73e931882 100644 --- a/src/src/PluginStructs/P035_data_struct.h +++ b/src/src/PluginStructs/P035_data_struct.h @@ -29,7 +29,7 @@ public: P035_data_struct(int8_t gpioPin); P035_data_struct() = delete; - ~P035_data_struct(); + virtual ~P035_data_struct(); bool plugin_init(struct EventStruct *event); bool plugin_exit(struct EventStruct *event); diff --git a/src/src/PluginStructs/P036_data_struct.cpp b/src/src/PluginStructs/P036_data_struct.cpp index 7df2db07e..7a9ed74c5 100644 --- a/src/src/PluginStructs/P036_data_struct.cpp +++ b/src/src/PluginStructs/P036_data_struct.cpp @@ -86,10 +86,18 @@ String P036_LineContent::saveDisplayLines(taskIndex_t taskIndex) { return error; } -P036_data_struct::P036_data_struct() : display(nullptr) {} - P036_data_struct::~P036_data_struct() { - reset(); + if (display != nullptr) { + display->displayOff(); + display->end(); + delete display; + display = nullptr; + } + + if (LineContent != nullptr) { + delete LineContent; + LineContent = nullptr; + } } void P036_data_struct::reset() { diff --git a/src/src/PluginStructs/P036_data_struct.h b/src/src/PluginStructs/P036_data_struct.h index af5419542..2dba7326a 100644 --- a/src/src/PluginStructs/P036_data_struct.h +++ b/src/src/PluginStructs/P036_data_struct.h @@ -83,7 +83,7 @@ # define P036_FLAG_SCROLL_WITHOUTWIFI 24 // Bit 24 ScrollWithoutWifi # define P036_FLAG_HIDE_HEADER 25 // Bit 25 Hide header # define P036_FLAG_INPUT_PULLUP 26 // Bit 26 Input PullUp -//# define P036_FLAG_INPUT_PULLDOWN 27 // Bit 27 Input PullDown, 2022-09-04 not longer used +// # define P036_FLAG_INPUT_PULLDOWN 27 // Bit 27 Input PullDown, 2022-09-04 not longer used # define P036_FLAG_SEND_EVENTS 28 // Bit 28 SendEvents # define P036_FLAG_EVENTS_FRAME_LINE 29 // Bit 29 SendEvents also on Frame & Line # define P036_FLAG_HIDE_FOOTER 30 // Bit 30 Hide footer @@ -124,8 +124,8 @@ enum class ePageScrollSpeed { }; enum class eP036pinmode { - ePPM_Input = 0, - ePPM_InputPullUp = 1 + ePPM_Input = 0, + ePPM_InputPullUp = 1 }; typedef struct { @@ -276,7 +276,7 @@ public: }; struct P036_data_struct : public PluginTaskData_base { - P036_data_struct(); + P036_data_struct() = default; virtual ~P036_data_struct(); @@ -326,29 +326,29 @@ struct P036_data_struct : public PluginTaskData_base { ePageScrollSpeed lscrollspeed = ePageScrollSpeed::ePSS_Instant); // Draw scrolling line (1pix/s) - void display_scrolling_lines(); + void display_scrolling_lines(); // Draw Signal Strength Bars, return true when there was an update. - bool display_wifibars(); + bool display_wifibars(); // Perform the actual write to the display. - void update_display(); + void update_display(); // get pixel positions - int16_t GetHeaderHeight(); - int16_t GetIndicatorTop(); - tFontSettings CalculateFontSettings(uint8_t _defaultLines); + int16_t GetHeaderHeight(); + int16_t GetIndicatorTop(); + tFontSettings CalculateFontSettings(uint8_t _defaultLines); - void P036_JumpToPage(struct EventStruct *event, - uint8_t nextFrame); + void P036_JumpToPage(struct EventStruct *event, + uint8_t nextFrame); - void P036_JumpToPageOfLine(struct EventStruct *event, - uint8_t LineNo); - void P036_DisplayPage(struct EventStruct *event); + void P036_JumpToPageOfLine(struct EventStruct *event, + uint8_t LineNo); + void P036_DisplayPage(struct EventStruct *event); // Perform some specific changes for OLED display - String P36_parseTemplate(String& tmpString, - uint8_t lineIdx); + String P36_parseTemplate(String& tmpString, + uint8_t lineIdx); void registerButtonState(uint8_t newButtonState, bool bPin3Invers); @@ -379,11 +379,11 @@ struct P036_data_struct : public PluginTaskData_base { bool bLineScrollEnabled = false; // Display button - bool ButtonState = false; // button not touched - uint8_t ButtonLastState = 0; // Last state checked (debouncing in progress) - uint8_t DebounceCounter = 0; // debounce counter - uint8_t RepeatCounter = 0; // Repeat delay counter when holding button pressed - uint16_t displayTimer = 0; // counter for display OFF + bool ButtonState = false; // button not touched + uint8_t ButtonLastState = 0; // Last state checked (debouncing in progress) + uint8_t DebounceCounter = 0; // debounce counter + uint8_t RepeatCounter = 0; // Repeat delay counter when holding button pressed + uint16_t displayTimer = 0; // counter for display OFF // frame header uint16_t HeaderCount = 0; eHeaderContent HeaderContent = eHeaderContent::eSSID; diff --git a/src/src/PluginStructs/P037_data_struct.cpp b/src/src/PluginStructs/P037_data_struct.cpp index 7fd5885a1..41a35e446 100644 --- a/src/src/PluginStructs/P037_data_struct.cpp +++ b/src/src/PluginStructs/P037_data_struct.cpp @@ -12,11 +12,16 @@ # include "../ESPEasyCore/ESPEasyRules.h" -P037_data_struct::P037_data_struct(taskIndex_t taskIndex) : _taskIndex(taskIndex) { - loadSettings(); -} +P037_data_struct::P037_data_struct(taskIndex_t taskIndex) : _taskIndex(taskIndex) +{} -P037_data_struct::~P037_data_struct() {} +P037_data_struct::~P037_data_struct() { + if (nullptr != root) { + root->clear(); + delete root; + root = nullptr; + } +} /** * Load the settings from file diff --git a/src/src/PluginStructs/P037_data_struct.h b/src/src/PluginStructs/P037_data_struct.h index c09429431..a00c602a9 100644 --- a/src/src/PluginStructs/P037_data_struct.h +++ b/src/src/PluginStructs/P037_data_struct.h @@ -102,7 +102,8 @@ struct P037_data_struct : public PluginTaskData_base { P037_data_struct(taskIndex_t taskIndex); - ~P037_data_struct(); + P037_data_struct() = delete; + virtual ~P037_data_struct(); bool webform_load( # if P037_MAPPING_SUPPORT diff --git a/src/src/PluginStructs/P038_data_struct.cpp b/src/src/PluginStructs/P038_data_struct.cpp index 72221363c..abf783639 100644 --- a/src/src/PluginStructs/P038_data_struct.cpp +++ b/src/src/PluginStructs/P038_data_struct.cpp @@ -16,7 +16,7 @@ P038_data_struct::P038_data_struct(int8_t gpioPin, // Destructor // **************************************************************************/ P038_data_struct::~P038_data_struct() { - if (isInitialized()) { + if (Plugin_038_pixels != nullptr) { delete Plugin_038_pixels; Plugin_038_pixels = nullptr; } diff --git a/src/src/PluginStructs/P038_data_struct.h b/src/src/PluginStructs/P038_data_struct.h index 5ca60d01e..84f07ecb0 100644 --- a/src/src/PluginStructs/P038_data_struct.h +++ b/src/src/PluginStructs/P038_data_struct.h @@ -26,7 +26,7 @@ public: uint8_t maxbright); P038_data_struct() = delete; - ~P038_data_struct(); + virtual ~P038_data_struct(); bool plugin_init(struct EventStruct *event); bool plugin_exit(struct EventStruct *event); diff --git a/src/src/PluginStructs/P039_data_struct.cpp b/src/src/PluginStructs/P039_data_struct.cpp index dde856e54..db813365a 100644 --- a/src/src/PluginStructs/P039_data_struct.cpp +++ b/src/src/PluginStructs/P039_data_struct.cpp @@ -2,6 +2,7 @@ #ifdef USES_P039 +/* P039_data_struct::P039_data_struct( uint16_t l_conversionResult, uint8_t l_devicefaults, @@ -9,6 +10,7 @@ P039_data_struct::P039_data_struct( bool l_sensorFault, bool l_convReady) : conversionResult(l_conversionResult), deviceFaults(l_devicefaults), timer(l_timer), sensorFault(l_sensorFault), convReady(l_convReady) {} +*/ bool P039_data_struct::begin() { diff --git a/src/src/PluginStructs/P039_data_struct.h b/src/src/PluginStructs/P039_data_struct.h index 0c9a06913..db08ca08c 100644 --- a/src/src/PluginStructs/P039_data_struct.h +++ b/src/src/PluginStructs/P039_data_struct.h @@ -9,13 +9,16 @@ struct P039_data_struct : public PluginTaskData_base { public: +/* P039_data_struct(uint16_t conversionResult, uint8_t deviceFaults, unsigned long timer, bool sensorFault, bool convReady); +*/ P039_data_struct() = default; + virtual ~P039_data_struct() = default; bool begin(); diff --git a/src/src/PluginStructs/P044_data_struct.cpp b/src/src/PluginStructs/P044_data_struct.cpp index 76886aa2f..dc7d1273b 100644 --- a/src/src/PluginStructs/P044_data_struct.cpp +++ b/src/src/PluginStructs/P044_data_struct.cpp @@ -13,13 +13,15 @@ #define P044_RX_WAIT PCONFIG(0) -P044_Task::P044_Task() { - clearBuffer(); -} - P044_Task::~P044_Task() { - stopServer(); - serialEnd(); + if (P1GatewayServer != nullptr) { + delete P1GatewayServer; + P1GatewayServer = nullptr; + } + if (P1EasySerial != nullptr) { + delete P1EasySerial; + P1EasySerial = nullptr; + } } bool P044_Task::serverActive(WiFiServer *server) { diff --git a/src/src/PluginStructs/P044_data_struct.h b/src/src/PluginStructs/P044_data_struct.h index 62469d5c8..7b523ab72 100644 --- a/src/src/PluginStructs/P044_data_struct.h +++ b/src/src/PluginStructs/P044_data_struct.h @@ -23,9 +23,9 @@ struct P044_Task : public PluginTaskData_base { CHECKSUM }; - P044_Task(); + P044_Task() = default; - ~P044_Task(); + virtual ~P044_Task(); inline static bool serverActive(WiFiServer *server); diff --git a/src/src/PluginStructs/P045_data_struct.cpp b/src/src/PluginStructs/P045_data_struct.cpp index c8f48535b..89b576ad7 100644 --- a/src/src/PluginStructs/P045_data_struct.cpp +++ b/src/src/PluginStructs/P045_data_struct.cpp @@ -17,7 +17,9 @@ # define MPU6050_PWR1_CLKSEL_BIT 2 # define MPU6050_PWR1_CLKSEL_LENGTH 3 -P045_data_struct::P045_data_struct(uint8_t i2c_addr) : i2cAddress(i2c_addr) +P045_data_struct::P045_data_struct(uint8_t i2c_addr) : i2cAddress(i2c_addr) {} + +void P045_data_struct::init() { // Initialize the MPU6050, for details look at the MPU6050 library: MPU6050::Initialize writeBits(MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CLKSEL_BIT, MPU6050_PWR1_CLKSEL_LENGTH, MPU6050_CLOCK_PLL_XGYRO); diff --git a/src/src/PluginStructs/P045_data_struct.h b/src/src/PluginStructs/P045_data_struct.h index e3907c5b4..c776e132d 100644 --- a/src/src/PluginStructs/P045_data_struct.h +++ b/src/src/PluginStructs/P045_data_struct.h @@ -8,6 +8,10 @@ struct P045_data_struct : public PluginTaskData_base { public: P045_data_struct(uint8_t i2c_addr); + P045_data_struct() = delete; + virtual ~P045_data_struct() = default; + + void init(); void loop(); diff --git a/src/src/PluginStructs/P049_data_struct.cpp b/src/src/PluginStructs/P049_data_struct.cpp index 25644d659..be070c3ad 100644 --- a/src/src/PluginStructs/P049_data_struct.cpp +++ b/src/src/PluginStructs/P049_data_struct.cpp @@ -50,13 +50,12 @@ const PROGMEM uint8_t mhzCmdData[][3] = { }; -P049_data_struct::P049_data_struct() { - reset(); - sensorResets = 0; -} P049_data_struct::~P049_data_struct() { - reset(); + if (easySerial != nullptr) { + delete easySerial; + easySerial = nullptr; + } } void P049_data_struct::reset() { diff --git a/src/src/PluginStructs/P049_data_struct.h b/src/src/PluginStructs/P049_data_struct.h index 50257ff4d..cc090d437 100644 --- a/src/src/PluginStructs/P049_data_struct.h +++ b/src/src/PluginStructs/P049_data_struct.h @@ -42,9 +42,9 @@ enum mhzCommands : uint8_t { mhzCmdReadPPM, struct P049_data_struct : public PluginTaskData_base { - P049_data_struct(); + P049_data_struct() = default; - ~P049_data_struct(); + virtual ~P049_data_struct(); void reset(); diff --git a/src/src/PluginStructs/P050_data_struct.h b/src/src/PluginStructs/P050_data_struct.h index c3be6f7db..86370ffae 100644 --- a/src/src/PluginStructs/P050_data_struct.h +++ b/src/src/PluginStructs/P050_data_struct.h @@ -15,6 +15,8 @@ struct P050_data_struct : public PluginTaskData_base { public: P050_data_struct(uint16_t integrationSetting, uint16_t gainSetting); + P050_data_struct() = delete; + virtual ~P050_data_struct() = default; bool loadSettings(taskIndex_t taskIndex); bool saveSettings(taskIndex_t taskIndex); diff --git a/src/src/PluginStructs/P052_data_struct.cpp b/src/src/PluginStructs/P052_data_struct.cpp index cc21a4c99..5d78bcebb 100644 --- a/src/src/PluginStructs/P052_data_struct.cpp +++ b/src/src/PluginStructs/P052_data_struct.cpp @@ -3,7 +3,7 @@ #ifdef USES_P052 P052_data_struct::~P052_data_struct() { - reset(); + modbus.reset(); } void P052_data_struct::reset() { diff --git a/src/src/PluginStructs/P052_data_struct.h b/src/src/PluginStructs/P052_data_struct.h index da5cdf95c..e1654b6e3 100644 --- a/src/src/PluginStructs/P052_data_struct.h +++ b/src/src/PluginStructs/P052_data_struct.h @@ -81,7 +81,7 @@ struct P052_data_struct : public PluginTaskData_base { P052_data_struct() = default; - ~P052_data_struct(); + virtual ~P052_data_struct(); void reset(); diff --git a/src/src/PluginStructs/P053_data_struct.cpp b/src/src/PluginStructs/P053_data_struct.cpp index 9ecd74d19..73b6262ea 100644 --- a/src/src/PluginStructs/P053_data_struct.cpp +++ b/src/src/PluginStructs/P053_data_struct.cpp @@ -52,6 +52,9 @@ P053_data_struct::P053_data_struct( # endif // ifdef PLUGIN_053_ENABLE_EXTRA_SENSORS ) : _taskIndex(TaskIndex), + _rxPin(rxPin), + _txPin(txPin), + _port(port), _sensortype(sensortype), # ifdef PLUGIN_053_ENABLE_EXTRA_SENSORS _oversample(oversample), @@ -59,16 +62,18 @@ P053_data_struct::P053_data_struct( # endif // ifdef PLUGIN_053_ENABLE_EXTRA_SENSORS _delay_read_after_wakeup_ms(delay_read_after_wakeup_ms), _resetPin(resetPin), _pwrPin(pwrPin) -{ +{} + +bool P053_data_struct::init() { # ifndef BUILD_NO_DEBUG if (loglevelActiveFor(LOG_LEVEL_DEBUG)) { String log; log.reserve(25); log = F("PMSx003 : config "); - log += rxPin; + log += _rxPin; log += ' '; - log += txPin; + log += _txPin; log += ' '; log += _resetPin; log += ' '; @@ -77,12 +82,12 @@ P053_data_struct::P053_data_struct( } # endif // ifndef BUILD_NO_DEBUG - if (port == ESPEasySerialPort::software) { + if (_port == ESPEasySerialPort::software) { addLog(LOG_LEVEL_INFO, F("PMSx003 : using software serial")); } else { addLog(LOG_LEVEL_INFO, F("PMSx003 : using hardware serial")); } - _easySerial = new (std::nothrow) ESPeasySerial(port, rxPin, txPin, false, 96); // 96 Bytes buffer, enough for up to 3 packets. + _easySerial = new (std::nothrow) ESPeasySerial(_port, _rxPin, _txPin, false, 96); // 96 Bytes buffer, enough for up to 3 packets. if (_easySerial != nullptr) { _easySerial->begin(9600); @@ -97,6 +102,7 @@ P053_data_struct::P053_data_struct( setActiveReadingMode(); } clearReceivedData(); + return initialized(); } P053_data_struct::~P053_data_struct() { diff --git a/src/src/PluginStructs/P053_data_struct.h b/src/src/PluginStructs/P053_data_struct.h index 38ba7eb31..173bdca3b 100644 --- a/src/src/PluginStructs/P053_data_struct.h +++ b/src/src/PluginStructs/P053_data_struct.h @@ -139,7 +139,9 @@ public: P053_data_struct() = delete; - ~P053_data_struct(); + virtual ~P053_data_struct(); + + bool init(); bool initialized() const; @@ -217,6 +219,9 @@ private: uint8_t _packet[PMSx003_PACKET_BUFFER_SIZE] = { 0 }; uint8_t _packetPos = 0; const taskIndex_t _taskIndex = INVALID_TASK_INDEX; + const int8_t _rxPin = -1; + const int8_t _txPin = -1; + const ESPEasySerialPort _port = ESPEasySerialPort::not_set; const PMSx003_type _sensortype; # ifdef PLUGIN_053_ENABLE_EXTRA_SENSORS const bool _oversample = false; @@ -230,6 +235,7 @@ private: uint16_t _last_checksum = 0; // To detect duplicate messages const int8_t _resetPin = -1; const int8_t _pwrPin = -1; + bool _activeReadingModeEnabled = true; }; diff --git a/src/src/PluginStructs/P057_data_struct.h b/src/src/PluginStructs/P057_data_struct.h index 909a798e8..1083b4a09 100644 --- a/src/src/PluginStructs/P057_data_struct.h +++ b/src/src/PluginStructs/P057_data_struct.h @@ -11,6 +11,8 @@ struct P057_data_struct : public PluginTaskData_base { public: P057_data_struct(uint8_t i2c_addr); + P057_data_struct() = delete; + virtual ~P057_data_struct() = default; CHT16K33 ledMatrix; uint8_t i2cAddress; diff --git a/src/src/PluginStructs/P058_data_struct.h b/src/src/PluginStructs/P058_data_struct.h index 7b3216ddc..b96e67853 100644 --- a/src/src/PluginStructs/P058_data_struct.h +++ b/src/src/PluginStructs/P058_data_struct.h @@ -11,6 +11,8 @@ struct P058_data_struct : public PluginTaskData_base { public: P058_data_struct(uint8_t i2c_addr); + P058_data_struct() = delete; + virtual ~P058_data_struct() = default; // Read key // @retval True when key has changed since last check. diff --git a/src/src/PluginStructs/P060_data_struct.h b/src/src/PluginStructs/P060_data_struct.h index a6dad3d0c..7b48dd6ab 100644 --- a/src/src/PluginStructs/P060_data_struct.h +++ b/src/src/PluginStructs/P060_data_struct.h @@ -8,6 +8,8 @@ struct P060_data_struct : public PluginTaskData_base { public: P060_data_struct(uint8_t i2c_addr); + P060_data_struct() = delete; + virtual ~P060_data_struct() = default; void overSampleRead(); diff --git a/src/src/PluginStructs/P061_data_struct.h b/src/src/PluginStructs/P061_data_struct.h index 9e06c115e..6afe5bf0f 100644 --- a/src/src/PluginStructs/P061_data_struct.h +++ b/src/src/PluginStructs/P061_data_struct.h @@ -48,6 +48,8 @@ public: P061_data_struct(uint8_t i2c_addr, uint8_t keypadType) : _i2c_addr(i2c_addr), _keypadType(keypadType) {} + P061_data_struct() = delete; + virtual ~P061_data_struct() = default; bool plugin_init(struct EventStruct *event); bool plugin_fifty_per_second(struct EventStruct *event); diff --git a/src/src/PluginStructs/P062_data_struct.h b/src/src/PluginStructs/P062_data_struct.h index b04c64036..93a88caf1 100644 --- a/src/src/PluginStructs/P062_data_struct.h +++ b/src/src/PluginStructs/P062_data_struct.h @@ -14,7 +14,8 @@ struct P062_data_struct : public PluginTaskData_base { public: P062_data_struct(); - ~P062_data_struct(); + virtual ~P062_data_struct(); + bool init(taskIndex_t taskIndex, uint8_t i2c_addr, bool scancode, diff --git a/src/src/PluginStructs/P064_data_struct.h b/src/src/PluginStructs/P064_data_struct.h index f917fdf7c..c280917ae 100644 --- a/src/src/PluginStructs/P064_data_struct.h +++ b/src/src/PluginStructs/P064_data_struct.h @@ -11,6 +11,7 @@ struct P064_data_struct : public PluginTaskData_base { public: P064_data_struct(); + virtual ~P064_data_struct() = default; SparkFun_APDS9960 sensor; }; diff --git a/src/src/PluginStructs/P068_data_struct.h b/src/src/PluginStructs/P068_data_struct.h index 3ba40dfdb..221f2cb1f 100644 --- a/src/src/PluginStructs/P068_data_struct.h +++ b/src/src/PluginStructs/P068_data_struct.h @@ -12,6 +12,8 @@ class P068_SHT3X : public PluginTaskData_base { public: P068_SHT3X(uint8_t addr); + P068_SHT3X() = delete; + virtual ~P068_SHT3X() = default; void readFromSensor(void); static bool CRC8(uint8_t MSB, diff --git a/src/src/PluginStructs/P069_data_struct.h b/src/src/PluginStructs/P069_data_struct.h index 547ccd3f0..1ce149a2f 100644 --- a/src/src/PluginStructs/P069_data_struct.h +++ b/src/src/PluginStructs/P069_data_struct.h @@ -14,6 +14,9 @@ public: P069_data_struct(uint8_t addr); + P069_data_struct() = delete; + virtual ~P069_data_struct() = default; + void setAddress(uint8_t addr); float getTemperatureInDegrees() const; diff --git a/src/src/PluginStructs/P070_data_struct.cpp b/src/src/PluginStructs/P070_data_struct.cpp index b4f0a8bf2..1bc5c81bf 100644 --- a/src/src/PluginStructs/P070_data_struct.cpp +++ b/src/src/PluginStructs/P070_data_struct.cpp @@ -4,7 +4,10 @@ P070_data_struct::~P070_data_struct() { - reset(); + if (Plugin_070_pixels != nullptr) { + delete Plugin_070_pixels; + Plugin_070_pixels = nullptr; + } } void P070_data_struct::reset() { diff --git a/src/src/PluginStructs/P070_data_struct.h b/src/src/PluginStructs/P070_data_struct.h index e4f6e56a7..4d3cd34c6 100644 --- a/src/src/PluginStructs/P070_data_struct.h +++ b/src/src/PluginStructs/P070_data_struct.h @@ -13,7 +13,7 @@ struct P070_data_struct : public PluginTaskData_base { P070_data_struct() = default; - ~P070_data_struct(); + virtual ~P070_data_struct(); void reset(); diff --git a/src/src/PluginStructs/P073_data_struct.cpp b/src/src/PluginStructs/P073_data_struct.cpp index b7730bdcb..38d50efe4 100644 --- a/src/src/PluginStructs/P073_data_struct.cpp +++ b/src/src/PluginStructs/P073_data_struct.cpp @@ -2,26 +2,34 @@ #ifdef USES_P073 -P073_data_struct::P073_data_struct() - : dotpos(-1), pin1(-1), pin2(-1), pin3(-1), displayModel(0), output(0), - brightness(0), timesep(false), shift(false), periods(false), hideDegree(false), - rightAlignTempMAX7219(false), fontset(0) - # ifdef P073_7DBIN_COMMAND - , binaryData(false) - # endif // P073_7DBIN_COMMAND - # ifdef P073_SCROLL_TEXT - , txtScrolling(false), scrollCount(0), scrollPos(0), scrollFull(false) - , _scrollSpeed(0) - # endif // P073_SCROLL_TEXT +void P073_data_struct::init(struct EventStruct *event) { ClearBuffer(); + pin1 = CONFIG_PIN1; + pin2 = CONFIG_PIN2; + pin3 = CONFIG_PIN3; + displayModel = PCONFIG(0); + output = PCONFIG(1); + brightness = PCONFIG(2); + periods = bitRead(PCONFIG_LONG(0), P073_OPTION_PERIOD); + hideDegree = bitRead(PCONFIG_LONG(0), P073_OPTION_HIDEDEGREE); + # ifdef P073_SCROLL_TEXT + txtScrolling = bitRead(PCONFIG_LONG(0), P073_OPTION_SCROLLTEXT); + scrollFull = bitRead(PCONFIG_LONG(0), P073_OPTION_SCROLLFULL); + setScrollSpeed(PCONFIG(3)); + # endif // P073_SCROLL_TEXT + rightAlignTempMAX7219 = bitRead(PCONFIG_LONG(0), P073_OPTION_RIGHTALIGN); + timesep = true; + # ifdef P073_EXTRA_FONTS + fontset = PCONFIG(4); + # endif // P073_EXTRA_FONTS } -void P073_data_struct::FillBufferWithTime(boolean sevendgt_now, +void P073_data_struct::FillBufferWithTime(bool sevendgt_now, uint8_t sevendgt_hours, uint8_t sevendgt_minutes, uint8_t sevendgt_seconds, - boolean flag12h) { + bool flag12h) { ClearBuffer(); if (sevendgt_now) { @@ -45,7 +53,7 @@ void P073_data_struct::FillBufferWithTime(boolean sevendgt_now, showbuffer[5] = sevendgt_seconds % 10; } -void P073_data_struct::FillBufferWithDate(boolean sevendgt_now, +void P073_data_struct::FillBufferWithDate(bool sevendgt_now, uint8_t sevendgt_day, uint8_t sevendgt_month, int sevendgt_year) { diff --git a/src/src/PluginStructs/P073_data_struct.h b/src/src/PluginStructs/P073_data_struct.h index c9ff60064..aab083871 100644 --- a/src/src/PluginStructs/P073_data_struct.h +++ b/src/src/PluginStructs/P073_data_struct.h @@ -140,14 +140,17 @@ static const uint8_t Dseg7CharTable[42] PROGMEM = { struct P073_data_struct : public PluginTaskData_base { public: - P073_data_struct(); + P073_data_struct() = default; + virtual ~P073_data_struct() = default; - void FillBufferWithTime(boolean sevendgt_now, + void init(struct EventStruct *event); + + void FillBufferWithTime(bool sevendgt_now, uint8_t sevendgt_hours, uint8_t sevendgt_minutes, uint8_t sevendgt_seconds, - boolean flag12h); - void FillBufferWithDate(boolean sevendgt_now, + bool flag12h); + void FillBufferWithDate(bool sevendgt_now, uint8_t sevendgt_day, uint8_t sevendgt_month, int sevendgt_year); @@ -178,37 +181,39 @@ public: void ClearBuffer(); uint8_t mapCharToFontPosition(char character, - uint8_t fontset); + uint8_t fontset); uint8_t mapMAX7219FontToTM1673Font(uint8_t character); uint8_t tm1637_getFontChar(uint8_t index, uint8_t fontset); - int dotpos = 0; - uint8_t showbuffer[8] = { 0 }; - bool showperiods[8]; - uint8_t spidata[2] = { 0 }; - uint8_t pin1, pin2, pin3; - uint8_t displayModel; - uint8_t output; - uint8_t brightness; - bool timesep; - bool shift; - bool periods; - bool hideDegree; - bool rightAlignTempMAX7219; - uint8_t fontset; + int dotpos = -1; + uint8_t showbuffer[8] = { 0 }; + bool showperiods[8] = { 0 }; + uint8_t spidata[2] = { 0 }; + int8_t pin1 = -1; + int8_t pin2 = -1; + int8_t pin3 = -1; + uint8_t displayModel = 0; + uint8_t output = 0; + uint8_t brightness = 0; + bool timesep = false; + bool shift = false; + bool periods = false; + bool hideDegree = false; + bool rightAlignTempMAX7219 = false; + uint8_t fontset = 0; # ifdef P073_7DBIN_COMMAND - bool binaryData; + bool binaryData = false; # endif // P073_7DBIN_COMMAND # ifdef P073_SCROLL_TEXT - bool txtScrolling; - uint16_t scrollCount; - uint16_t scrollPos; - bool scrollFull; + bool txtScrolling = false; + uint16_t scrollCount = 0; + uint16_t scrollPos = 0; + bool scrollFull = false; private: - uint16_t _scrollSpeed; + uint16_t _scrollSpeed = 0; # endif // P073_SCROLL_TEXT # if defined(P073_SCROLL_TEXT) || defined(P073_7DBIN_COMMAND) String _textToScroll; diff --git a/src/src/PluginStructs/P074_data_struct.h b/src/src/PluginStructs/P074_data_struct.h index 014b0e20e..f572ecbdd 100644 --- a/src/src/PluginStructs/P074_data_struct.h +++ b/src/src/PluginStructs/P074_data_struct.h @@ -11,6 +11,7 @@ struct P074_data_struct : public PluginTaskData_base { P074_data_struct(); + virtual ~P074_data_struct() = default; // Changing the integration time gives you a longer time over which to sense // light diff --git a/src/src/PluginStructs/P075_data_struct.h b/src/src/PluginStructs/P075_data_struct.h index a97890ed8..c409a74bd 100644 --- a/src/src/PluginStructs/P075_data_struct.h +++ b/src/src/PluginStructs/P075_data_struct.h @@ -34,7 +34,8 @@ struct P075_data_struct : public PluginTaskData_base { int rx, int tx, uint32_t baud); - ~P075_data_struct(); + P075_data_struct() = delete; + virtual ~P075_data_struct(); void loadDisplayLines(taskIndex_t taskIndex); diff --git a/src/src/PluginStructs/P077_data_struct.h b/src/src/PluginStructs/P077_data_struct.h index 4dcb8118b..6064c7993 100644 --- a/src/src/PluginStructs/P077_data_struct.h +++ b/src/src/PluginStructs/P077_data_struct.h @@ -20,6 +20,9 @@ */ struct P077_data_struct : public PluginTaskData_base { + P077_data_struct() = default; + virtual ~P077_data_struct() = default; + bool processCseReceived(struct EventStruct *event); bool processSerialData(); diff --git a/src/src/PluginStructs/P079_data_struct.cpp b/src/src/PluginStructs/P079_data_struct.cpp index 747948e1e..81c4f233b 100644 --- a/src/src/PluginStructs/P079_data_struct.cpp +++ b/src/src/PluginStructs/P079_data_struct.cpp @@ -5,37 +5,33 @@ WemosMotor::WemosMotor(uint8_t address, uint8_t motor, uint32_t freq) - : _address(address) + : _address(address), _freq(freq), _use_STBY_IO(false) { - _use_STBY_IO = false; - if (motor == P079_MOTOR_A) { _motor = P079_MOTOR_A; } else { _motor = P079_MOTOR_B; } - - setfreq(freq); } WemosMotor::WemosMotor(uint8_t address, uint8_t motor, uint32_t freq, uint8_t STBY_IO) - : _address(address) + : _address(address), _freq(freq), _use_STBY_IO(true), _STBY_IO(STBY_IO) { - _use_STBY_IO = true; - _STBY_IO = STBY_IO; - if (motor == P079_MOTOR_A) { _motor = P079_MOTOR_A; } else { _motor = P079_MOTOR_B; } +} - setfreq(freq); - - pinMode(_STBY_IO, OUTPUT); - digitalWrite(_STBY_IO, LOW); +void WemosMotor::init() { + setfreq(_freq); + if (_use_STBY_IO) { + pinMode(_STBY_IO, OUTPUT); + digitalWrite(_STBY_IO, LOW); + } } /* setfreq() -- set PWM's frequency diff --git a/src/src/PluginStructs/P079_data_struct.h b/src/src/PluginStructs/P079_data_struct.h index e00c2566e..b0bd05313 100644 --- a/src/src/PluginStructs/P079_data_struct.h +++ b/src/src/PluginStructs/P079_data_struct.h @@ -78,6 +78,9 @@ public: uint8_t motor, uint32_t freq, uint8_t STBY_IO); + WemosMotor() = delete; + + void init(); void setfreq(uint32_t freq); void setmotor(uint8_t dir, float pwm_val); @@ -85,10 +88,11 @@ public: private: - uint8_t _address; + const uint8_t _address; uint8_t _motor; - bool _use_STBY_IO = false; - uint8_t _STBY_IO = 0; + const uint32_t _freq; + const bool _use_STBY_IO = false; + const uint8_t _STBY_IO = 0; }; @@ -96,6 +100,7 @@ class LOLIN_I2C_MOTOR { public: LOLIN_I2C_MOTOR(unsigned char address); + LOLIN_I2C_MOTOR() = delete; unsigned char reset(void); unsigned char getInfo(void); unsigned char changeStatus(unsigned char ch, diff --git a/src/src/PluginStructs/P081_data_struct.h b/src/src/PluginStructs/P081_data_struct.h index 5f4d82a33..6334aa00e 100644 --- a/src/src/PluginStructs/P081_data_struct.h +++ b/src/src/PluginStructs/P081_data_struct.h @@ -25,6 +25,7 @@ extern "C" struct P081_data_struct : public PluginTaskData_base { P081_data_struct() = delete; explicit P081_data_struct(const String& expression); + virtual ~P081_data_struct() = default; bool isInitialized() const { return _initialized; diff --git a/src/src/PluginStructs/P082_data_struct.cpp b/src/src/PluginStructs/P082_data_struct.cpp index 9b5c0ae65..edcea68ee 100644 --- a/src/src/PluginStructs/P082_data_struct.cpp +++ b/src/src/PluginStructs/P082_data_struct.cpp @@ -63,14 +63,13 @@ const __FlashStringHelper* toString(P082_DynamicModel model) { return F(""); } -P082_data_struct::P082_data_struct() : gps(nullptr), easySerial(nullptr) {} - -P082_data_struct::~P082_data_struct() { - powerDown(); - reset(); +P082_data_struct::P082_data_struct() : gps(nullptr), easySerial(nullptr) { + for (size_t i = 0; i < static_cast(P082_query::P082_NR_OUTPUT_OPTIONS); ++i) { + _cache[i] = 0.0f; + } } -void P082_data_struct::reset() { +P082_data_struct::~P082_data_struct() { if (gps != nullptr) { delete gps; gps = nullptr; @@ -82,11 +81,34 @@ void P082_data_struct::reset() { } } +/* +void P082_data_struct::reset() { + if (gps != nullptr) { + delete gps; + gps = nullptr; + } + + if (easySerial != nullptr) { + delete easySerial; + easySerial = nullptr; + } +} +*/ + bool P082_data_struct::init(ESPEasySerialPort port, const int16_t serial_rx, const int16_t serial_tx) { if (serial_rx < 0) { return false; } - reset(); + if (gps != nullptr) { + delete gps; + gps = nullptr; + } + + if (easySerial != nullptr) { + delete easySerial; + easySerial = nullptr; + } + gps = new (std::nothrow) TinyGPSPlus(); easySerial = new (std::nothrow) ESPeasySerial(port, serial_rx, serial_tx); diff --git a/src/src/PluginStructs/P082_data_struct.h b/src/src/PluginStructs/P082_data_struct.h index 6af6fab8a..60bb74060 100644 --- a/src/src/PluginStructs/P082_data_struct.h +++ b/src/src/PluginStructs/P082_data_struct.h @@ -68,9 +68,9 @@ struct P082_data_struct : public PluginTaskData_base { P082_data_struct(); - ~P082_data_struct(); + virtual ~P082_data_struct(); - void reset(); +// void reset(); bool init(ESPEasySerialPort port, const int16_t serial_rx, @@ -151,7 +151,7 @@ public: String _currentSentence; # endif // ifdef P082_SEND_GPS_TO_LOG - float _cache[static_cast(P082_query::P082_NR_OUTPUT_OPTIONS)] = { 0 }; + float _cache[static_cast(P082_query::P082_NR_OUTPUT_OPTIONS)]; }; #endif // ifdef USES_P082 diff --git a/src/src/PluginStructs/P083_data_struct.h b/src/src/PluginStructs/P083_data_struct.h index 397f6d007..c1bd329fc 100644 --- a/src/src/PluginStructs/P083_data_struct.h +++ b/src/src/PluginStructs/P083_data_struct.h @@ -10,6 +10,7 @@ struct P083_data_struct : public PluginTaskData_base { public: P083_data_struct(); + virtual ~P083_data_struct() = default; Adafruit_SGP30 sgp; unsigned long init_time = 0; diff --git a/src/src/PluginStructs/P085_data_struct.cpp b/src/src/PluginStructs/P085_data_struct.cpp index ca4b9c739..4654518a7 100644 --- a/src/src/PluginStructs/P085_data_struct.cpp +++ b/src/src/PluginStructs/P085_data_struct.cpp @@ -3,7 +3,7 @@ #ifdef USES_P085 P085_data_struct::~P085_data_struct() { - reset(); + modbus.reset(); } void P085_data_struct::reset() { diff --git a/src/src/PluginStructs/P085_data_struct.h b/src/src/PluginStructs/P085_data_struct.h index 1b7c207a3..d9a329fdc 100644 --- a/src/src/PluginStructs/P085_data_struct.h +++ b/src/src/PluginStructs/P085_data_struct.h @@ -46,9 +46,9 @@ # include "src/DataStructs/ESPEasy_packed_raw_data.h" struct P085_data_struct : public PluginTaskData_base { - P085_data_struct() {} + P085_data_struct() = default; - ~P085_data_struct(); + virtual ~P085_data_struct(); void reset(); diff --git a/src/src/PluginStructs/P087_data_struct.cpp b/src/src/PluginStructs/P087_data_struct.cpp index 386cb794f..0231b67ef 100644 --- a/src/src/PluginStructs/P087_data_struct.cpp +++ b/src/src/PluginStructs/P087_data_struct.cpp @@ -11,10 +11,12 @@ #include -P087_data_struct::P087_data_struct() : easySerial(nullptr) {} P087_data_struct::~P087_data_struct() { - reset(); + if (easySerial != nullptr) { + delete easySerial; + easySerial = nullptr; + } } void P087_data_struct::reset() { diff --git a/src/src/PluginStructs/P087_data_struct.h b/src/src/PluginStructs/P087_data_struct.h index 7c6639feb..64a27778d 100644 --- a/src/src/PluginStructs/P087_data_struct.h +++ b/src/src/PluginStructs/P087_data_struct.h @@ -40,9 +40,9 @@ enum P087_Match_Type { struct P087_data_struct : public PluginTaskData_base { public: - P087_data_struct(); + P087_data_struct() = default; - ~P087_data_struct(); + virtual ~P087_data_struct(); void reset(); diff --git a/src/src/PluginStructs/P089_data_struct.h b/src/src/PluginStructs/P089_data_struct.h index d66ab9778..8e8cefa23 100644 --- a/src/src/PluginStructs/P089_data_struct.h +++ b/src/src/PluginStructs/P089_data_struct.h @@ -35,7 +35,7 @@ public: P089_data_struct(); - ~P089_data_struct(); + virtual ~P089_data_struct(); bool send_ping(struct EventStruct *event); diff --git a/src/src/PluginStructs/P090_data_struct.h b/src/src/PluginStructs/P090_data_struct.h index e96fddb9f..44051026a 100644 --- a/src/src/PluginStructs/P090_data_struct.h +++ b/src/src/PluginStructs/P090_data_struct.h @@ -27,6 +27,7 @@ public: } status; CCS811Core(uint8_t); + CCS811Core() = delete; virtual ~CCS811Core() = default; status beginCore(void); @@ -64,6 +65,8 @@ class CCS811 : public CCS811Core { public: CCS811(uint8_t); + CCS811() = delete; + virtual ~CCS811() = default; // Call to check for errors, start app, and set default mode 1 status begin(void); @@ -105,6 +108,8 @@ struct P090_data_struct : public PluginTaskData_base { public: P090_data_struct(uint8_t i2cAddr); + P090_data_struct() = delete; + virtual ~P090_data_struct() = default; CCS811 myCCS811; bool compensation_set = false; diff --git a/src/src/PluginStructs/P092_data_struct.cpp b/src/src/PluginStructs/P092_data_struct.cpp index 911cb8288..8a656351a 100644 --- a/src/src/PluginStructs/P092_data_struct.cpp +++ b/src/src/PluginStructs/P092_data_struct.cpp @@ -468,8 +468,6 @@ boolean DLBus::CheckCRC(uint8_t IdxCRC) { # define DLbus_RSM_STANDBY 0b11 -P092_data_struct::P092_data_struct() {} - P092_data_struct::~P092_data_struct() { if (DLbus_Data != nullptr) { if (DLbus_Data->ISR_DLB_Pin != 0xFF) { diff --git a/src/src/PluginStructs/P092_data_struct.h b/src/src/PluginStructs/P092_data_struct.h index d18b7ff0f..371bf50a0 100644 --- a/src/src/PluginStructs/P092_data_struct.h +++ b/src/src/PluginStructs/P092_data_struct.h @@ -125,8 +125,8 @@ private: struct P092_data_struct : public PluginTaskData_base { public: - P092_data_struct(); - ~P092_data_struct(); + P092_data_struct() = default; + virtual ~P092_data_struct(); bool init(int8_t pin1, int P092DeviceIndex, eP092pinmode P092pinmode); diff --git a/src/src/PluginStructs/P093_data_struct.cpp b/src/src/PluginStructs/P093_data_struct.cpp index 6c78b03fe..39d87e93c 100644 --- a/src/src/PluginStructs/P093_data_struct.cpp +++ b/src/src/PluginStructs/P093_data_struct.cpp @@ -24,7 +24,9 @@ P093_data_struct::P093_data_struct(const ESPEasySerialPort port, const int16_t s _tempMode(false), _wideVaneAdj(false), _valuesInitialized(false), - _includeStatus(includeStatus) { + _includeStatus(includeStatus) {} + +void P093_data_struct::init() { setState(Connecting); } diff --git a/src/src/PluginStructs/P093_data_struct.h b/src/src/PluginStructs/P093_data_struct.h index 58473c136..b03cd09cf 100644 --- a/src/src/PluginStructs/P093_data_struct.h +++ b/src/src/PluginStructs/P093_data_struct.h @@ -36,6 +36,11 @@ struct P093_data_struct : public PluginTaskData_base { const int16_t serialTx, bool includeStatus); + P093_data_struct() = delete; + virtual ~P093_data_struct() = default; + + void init(); + bool sync(); bool read(String& result) const; diff --git a/src/src/PluginStructs/P094_data_struct.cpp b/src/src/PluginStructs/P094_data_struct.cpp index 673133a46..30a8449a7 100644 --- a/src/src/PluginStructs/P094_data_struct.cpp +++ b/src/src/PluginStructs/P094_data_struct.cpp @@ -20,7 +20,10 @@ P094_data_struct::P094_data_struct() : easySerial(nullptr) { } P094_data_struct::~P094_data_struct() { - reset(); + if (easySerial != nullptr) { + delete easySerial; + easySerial = nullptr; + } } void P094_data_struct::reset() { diff --git a/src/src/PluginStructs/P094_data_struct.h b/src/src/PluginStructs/P094_data_struct.h index 7a50e1355..9fdcd9db2 100644 --- a/src/src/PluginStructs/P094_data_struct.h +++ b/src/src/PluginStructs/P094_data_struct.h @@ -58,7 +58,7 @@ public: P094_data_struct(); - ~P094_data_struct(); + virtual ~P094_data_struct(); void reset(); diff --git a/src/src/PluginStructs/P095_data_struct.cpp b/src/src/PluginStructs/P095_data_struct.cpp index 64c2eb440..010e6b3ea 100644 --- a/src/src/PluginStructs/P095_data_struct.cpp +++ b/src/src/PluginStructs/P095_data_struct.cpp @@ -100,11 +100,6 @@ P095_data_struct::P095_data_struct(ILI9xxx_type_e displayType, _displayTimeout(displayTimer), _commandTrigger(commandTrigger), _fgcolor(fgcolor), _bgcolor(bgcolor), _textBackFill(textBackFill) { - _xpix = 240; - _ypix = 320; - ILI9xxx_type_toResolution(_displayType, _xpix, _ypix); - - updateFontMetrics(); _commandTrigger.toLowerCase(); _commandTriggerCmd = _commandTrigger; _commandTriggerCmd += F("cmd"); @@ -118,10 +113,19 @@ P095_data_struct::~P095_data_struct() { delete tft; } +void P095_data_struct::init() { + _xpix = 240; + _ypix = 320; + ILI9xxx_type_toResolution(_displayType, _xpix, _ypix); + + updateFontMetrics(); +} + /**************************************************************************** * plugin_init: Initialize display ***************************************************************************/ bool P095_data_struct::plugin_init(struct EventStruct *event) { + init(); bool success = false; if (nullptr == tft) { diff --git a/src/src/PluginStructs/P095_data_struct.h b/src/src/PluginStructs/P095_data_struct.h index 544f37af6..c1dcc7f68 100644 --- a/src/src/PluginStructs/P095_data_struct.h +++ b/src/src/PluginStructs/P095_data_struct.h @@ -123,7 +123,10 @@ public: uint16_t fgcolor = ADAGFX_WHITE, uint16_t bgcolor = ADAGFX_BLACK, bool textBackFill = true); - ~P095_data_struct(); + P095_data_struct() = delete; + virtual ~P095_data_struct(); + + void init(); bool plugin_init(struct EventStruct *event); bool plugin_exit(struct EventStruct *event); diff --git a/src/src/PluginStructs/P096_data_struct.cpp b/src/src/PluginStructs/P096_data_struct.cpp index e8705c703..e8e830e86 100644 --- a/src/src/PluginStructs/P096_data_struct.cpp +++ b/src/src/PluginStructs/P096_data_struct.cpp @@ -87,12 +87,6 @@ P096_data_struct::P096_data_struct(EPD_type_e display, _rotation(rotation), _fontscaling(fontscaling), _textmode(textmode), _commandTrigger(commandTrigger), _fgcolor(fgcolor), _bgcolor(bgcolor), _colorDepth(colorDepth), _textBackFill(textBackFill) { - # if P096_USE_EXTENDED_SETTINGS - - EPD_type_toResolution(_display, _xpix, _ypix); - # endif // if P096_USE_EXTENDED_SETTINGS - - updateFontMetrics(); _commandTrigger.toLowerCase(); _commandTriggerCmd = _commandTrigger; _commandTriggerCmd += F("cmd"); @@ -117,6 +111,13 @@ P096_data_struct::~P096_data_struct() { * plugin_init: Initialize display ***************************************************************************/ bool P096_data_struct::plugin_init(struct EventStruct *event) { + # if P096_USE_EXTENDED_SETTINGS + + EPD_type_toResolution(_display, _xpix, _ypix); + # endif // if P096_USE_EXTENDED_SETTINGS + + updateFontMetrics(); + bool success = false; if (nullptr == eInkScreen) { diff --git a/src/src/PluginStructs/P096_data_struct.h b/src/src/PluginStructs/P096_data_struct.h index 6858437d4..8c52a7c6c 100644 --- a/src/src/PluginStructs/P096_data_struct.h +++ b/src/src/PluginStructs/P096_data_struct.h @@ -113,7 +113,8 @@ public: uint16_t bgcolor = ADAGFX_BLACK, AdaGFXColorDepth colorDepth = AdaGFXColorDepth::Monochrome, bool textBackFill = true); - ~P096_data_struct(); + P096_data_struct() = delete; + virtual ~P096_data_struct(); bool plugin_init(struct EventStruct *event); bool plugin_exit(struct EventStruct *event); diff --git a/src/src/PluginStructs/P098_data_struct.h b/src/src/PluginStructs/P098_data_struct.h index ffd452e84..8f1502131 100644 --- a/src/src/PluginStructs/P098_data_struct.h +++ b/src/src/PluginStructs/P098_data_struct.h @@ -89,7 +89,8 @@ struct P098_data_struct : public PluginTaskData_base { }; P098_data_struct(const P098_config_struct& config); - ~P098_data_struct(); + P098_data_struct() = delete; + virtual ~P098_data_struct(); bool begin(int pos, int limitApos, diff --git a/src/src/PluginStructs/P099_data_struct.cpp b/src/src/PluginStructs/P099_data_struct.cpp index 1c62647c0..85442380c 100644 --- a/src/src/PluginStructs/P099_data_struct.cpp +++ b/src/src/PluginStructs/P099_data_struct.cpp @@ -11,10 +11,11 @@ #include -P099_data_struct::P099_data_struct() : touchscreen(nullptr) {} - P099_data_struct::~P099_data_struct() { - reset(); + if (touchscreen != nullptr) { + delete touchscreen; + touchscreen = nullptr; + } } /** diff --git a/src/src/PluginStructs/P099_data_struct.h b/src/src/PluginStructs/P099_data_struct.h index 12e37dbb2..69ec8ea03 100644 --- a/src/src/PluginStructs/P099_data_struct.h +++ b/src/src/PluginStructs/P099_data_struct.h @@ -26,10 +26,10 @@ // Data structure struct P099_data_struct : public PluginTaskData_base { - P099_data_struct(); - ~P099_data_struct(); + P099_data_struct() = default; + virtual ~P099_data_struct(); - void reset(); + void reset(); bool init(taskIndex_t taskIndex, uint8_t cs, uint8_t rotation, diff --git a/src/src/PluginStructs/P104_data_struct.h b/src/src/PluginStructs/P104_data_struct.h index 581fa293e..6690483e5 100644 --- a/src/src/PluginStructs/P104_data_struct.h +++ b/src/src/PluginStructs/P104_data_struct.h @@ -354,7 +354,7 @@ struct P104_data_struct : public PluginTaskData_base { int8_t _cs_pin, uint8_t _modules, uint8_t _zonesCount); - ~P104_data_struct(); + virtual ~P104_data_struct(); bool begin(); void loadSettings(); diff --git a/src/src/PluginStructs/P105_data_struct.h b/src/src/PluginStructs/P105_data_struct.h index 6b8aff6f0..319c07b6d 100644 --- a/src/src/PluginStructs/P105_data_struct.h +++ b/src/src/PluginStructs/P105_data_struct.h @@ -24,6 +24,7 @@ public: AHTx_Device(uint8_t addr, AHTx_device_type type); + AHTx_Device() = delete; const __FlashStringHelper* getDeviceName() const; @@ -45,13 +46,15 @@ protected: const uint8_t i2cAddress; const AHTx_device_type device_type; - float last_hum_val; - float last_temp_val; + float last_hum_val = 0.0f; + float last_temp_val = 0.0f; }; struct P105_data_struct : public PluginTaskData_base { P105_data_struct(uint8_t addr, AHTx_device_type dev); + P105_data_struct() = delete; + virtual ~P105_data_struct() = default; inline String getDeviceName() const { return device.getDeviceName(); diff --git a/src/src/PluginStructs/P106_data_struct.h b/src/src/PluginStructs/P106_data_struct.h index 347607a3e..db0bef7da 100644 --- a/src/src/PluginStructs/P106_data_struct.h +++ b/src/src/PluginStructs/P106_data_struct.h @@ -9,6 +9,10 @@ # include struct P106_data_struct : public PluginTaskData_base { + P106_data_struct() = default; + virtual ~P106_data_struct() = default; + + bool begin(uint8_t addr, bool initSettings = true); diff --git a/src/src/PluginStructs/P107_data_struct.h b/src/src/PluginStructs/P107_data_struct.h index ae54594ef..506ffe3a2 100644 --- a/src/src/PluginStructs/P107_data_struct.h +++ b/src/src/PluginStructs/P107_data_struct.h @@ -8,6 +8,10 @@ struct P107_data_struct : public PluginTaskData_base { + P107_data_struct() = default; + + virtual ~P107_data_struct() = default; + bool begin(); Adafruit_SI1145 uv; diff --git a/src/src/PluginStructs/P108_data_struct.cpp b/src/src/PluginStructs/P108_data_struct.cpp index dae6df521..ff3b23b03 100644 --- a/src/src/PluginStructs/P108_data_struct.cpp +++ b/src/src/PluginStructs/P108_data_struct.cpp @@ -4,7 +4,7 @@ P108_data_struct::~P108_data_struct() { - reset(); + modbus.reset(); } void P108_data_struct::reset() { diff --git a/src/src/PluginStructs/P108_data_struct.h b/src/src/PluginStructs/P108_data_struct.h index 64e9b33e2..ce415a375 100644 --- a/src/src/PluginStructs/P108_data_struct.h +++ b/src/src/PluginStructs/P108_data_struct.h @@ -49,7 +49,7 @@ struct P108_data_struct : public PluginTaskData_base { P108_data_struct() = default; - ~P108_data_struct(); + virtual ~P108_data_struct(); void reset(); diff --git a/src/src/PluginStructs/P109_data_struct.h b/src/src/PluginStructs/P109_data_struct.h index 9de11a1da..dd04110b7 100644 --- a/src/src/PluginStructs/P109_data_struct.h +++ b/src/src/PluginStructs/P109_data_struct.h @@ -60,7 +60,7 @@ const char flameimg[] PROGMEM = { struct P109_data_struct : public PluginTaskData_base { P109_data_struct(); - ~P109_data_struct(); + virtual ~P109_data_struct(); bool plugin_init(struct EventStruct *event); bool plugin_exit(struct EventStruct *event); diff --git a/src/src/PluginStructs/P110_data_struct.h b/src/src/PluginStructs/P110_data_struct.h index aa6976104..84cc1dc57 100644 --- a/src/src/PluginStructs/P110_data_struct.h +++ b/src/src/PluginStructs/P110_data_struct.h @@ -32,6 +32,8 @@ public: P110_data_struct(uint8_t i2c_addr, int timing, bool range); + P110_data_struct() = delete; + virtual ~P110_data_struct() = default; bool begin(); long readDistance(); diff --git a/src/src/PluginStructs/P111_data_struct.h b/src/src/PluginStructs/P111_data_struct.h index 9027eae3d..219af16fb 100644 --- a/src/src/PluginStructs/P111_data_struct.h +++ b/src/src/PluginStructs/P111_data_struct.h @@ -32,7 +32,8 @@ enum class P111_initPhases : uint8_t { struct P111_data_struct : public PluginTaskData_base { P111_data_struct(int8_t csPin, int8_t rstPin); - ~P111_data_struct(); + P111_data_struct() = delete; + virtual ~P111_data_struct(); void init(); bool plugin_ten_per_second(struct EventStruct *event); diff --git a/src/src/PluginStructs/P112_data_struct.h b/src/src/PluginStructs/P112_data_struct.h index e1a71a606..f19aef9d6 100644 --- a/src/src/PluginStructs/P112_data_struct.h +++ b/src/src/PluginStructs/P112_data_struct.h @@ -19,6 +19,9 @@ #include struct P112_data_struct : public PluginTaskData_base { + P112_data_struct() = default; + virtual ~P112_data_struct() = default; + bool begin(); AS7265X sensor; bool initialized = false; diff --git a/src/src/PluginStructs/P113_data_struct.h b/src/src/PluginStructs/P113_data_struct.h index 406151206..fb0aaa0a3 100644 --- a/src/src/PluginStructs/P113_data_struct.h +++ b/src/src/PluginStructs/P113_data_struct.h @@ -25,6 +25,7 @@ public: int timing, bool range); P113_data_struct() = delete; + virtual ~P113_data_struct() = default; bool begin(); bool startRead(); @@ -37,10 +38,10 @@ private: SFEVL53L1X sensor; - uint8_t i2cAddress; + const uint8_t i2cAddress; bool initState = false; - int timing; - bool range; + const int timing; + const bool range; bool success = false; bool readActive = false; uint16_t distance = 0u; diff --git a/src/src/PluginStructs/P114_data_struct.h b/src/src/PluginStructs/P114_data_struct.h index 5e46e1eb7..aa339795b 100644 --- a/src/src/PluginStructs/P114_data_struct.h +++ b/src/src/PluginStructs/P114_data_struct.h @@ -40,6 +40,7 @@ public: bool highDensity); P114_data_struct() = delete; + virtual ~P114_data_struct() = default; bool read_sensor(float& _UVA, float& _UVB, @@ -49,11 +50,11 @@ private: bool init_sensor(); - uint8_t i2cAddress; + const uint8_t i2cAddress; // Specify VEML6075 Integration time - uint8_t IT; - bool HD; + const uint8_t IT; + const bool HD; uint16_t UVData[5] = { 0, 0, 0, 0, 0 }; // UVA, Dummy, UVB, UVComp1, UVComp2 float UVAComp = 0.0f; diff --git a/src/src/PluginStructs/P115_data_struct.h b/src/src/PluginStructs/P115_data_struct.h index d62ecc300..a79b85c45 100644 --- a/src/src/PluginStructs/P115_data_struct.h +++ b/src/src/PluginStructs/P115_data_struct.h @@ -14,6 +14,8 @@ public: P115_data_struct(uint8_t i2c_addr, sfe_max1704x_devices_e device, int threshold); + P115_data_struct() = delete; + virtual ~P115_data_struct() = default; bool begin(); diff --git a/src/src/PluginStructs/P116_data_struct.cpp b/src/src/PluginStructs/P116_data_struct.cpp index d8e0c1500..e439cdcaa 100644 --- a/src/src/PluginStructs/P116_data_struct.cpp +++ b/src/src/PluginStructs/P116_data_struct.cpp @@ -99,9 +99,6 @@ P116_data_struct::P116_data_struct(ST77xx_type_e device, _backlightPercentage(backlightPercentage), _displayTimer(displayTimer), _displayTimeout(displayTimer), _commandTrigger(commandTrigger), _fgcolor(fgcolor), _bgcolor(bgcolor), _textBackFill(textBackFill) { - ST77xx_type_toResolution(_device, _xpix, _ypix); - - updateFontMetrics(); _commandTrigger.toLowerCase(); _commandTriggerCmd = _commandTrigger; _commandTriggerCmd += F("cmd"); @@ -118,6 +115,10 @@ P116_data_struct::~P116_data_struct() { * plugin_init: Initialize display ***************************************************************************/ bool P116_data_struct::plugin_init(struct EventStruct *event) { + ST77xx_type_toResolution(_device, _xpix, _ypix); + + updateFontMetrics(); + bool success = false; ButtonState = false; // button not touched diff --git a/src/src/PluginStructs/P116_data_struct.h b/src/src/PluginStructs/P116_data_struct.h index 758663f40..7b7c11d4f 100644 --- a/src/src/PluginStructs/P116_data_struct.h +++ b/src/src/PluginStructs/P116_data_struct.h @@ -106,7 +106,8 @@ public: uint16_t fgcolor = ADAGFX_WHITE, uint16_t bgcolor = ADAGFX_BLACK, bool textBackFill = true); - ~P116_data_struct(); + P116_data_struct() = delete; + virtual ~P116_data_struct(); bool plugin_init(struct EventStruct *event); bool plugin_exit(struct EventStruct *event); diff --git a/src/src/PluginStructs/P117_data_struct.h b/src/src/PluginStructs/P117_data_struct.h index 9675262a4..7400ac00e 100644 --- a/src/src/PluginStructs/P117_data_struct.h +++ b/src/src/PluginStructs/P117_data_struct.h @@ -19,6 +19,7 @@ public: uint16_t interval); P117_data_struct() = delete; + virtual ~P117_data_struct() = default; uint32_t read_sensor(uint16_t *scd30_CO2, uint16_t *scd30_CO2EAvg, @@ -59,8 +60,8 @@ private: bool init_sensor(); - uint16_t _altitude; - float _temperatureOffset; + const uint16_t _altitude; + const float _temperatureOffset; bool _autoCalibration; uint16_t _interval; diff --git a/src/src/PluginStructs/P118_data_struct.h b/src/src/PluginStructs/P118_data_struct.h index 2197ed0e1..6bf1da730 100644 --- a/src/src/PluginStructs/P118_data_struct.h +++ b/src/src/PluginStructs/P118_data_struct.h @@ -64,7 +64,7 @@ public: bool rfLog); P118_data_struct() = delete; - ~P118_data_struct(); + virtual ~P118_data_struct(); bool plugin_init(struct EventStruct *event); bool plugin_exit(struct EventStruct *event); diff --git a/src/src/PluginStructs/P119_data_struct.h b/src/src/PluginStructs/P119_data_struct.h index 4d1d45500..ff5661a1a 100644 --- a/src/src/PluginStructs/P119_data_struct.h +++ b/src/src/PluginStructs/P119_data_struct.h @@ -19,7 +19,7 @@ public: P119_data_struct() = delete; - ~P119_data_struct(); + virtual ~P119_data_struct(); bool read_sensor(); diff --git a/src/src/PluginStructs/P120_data_struct.cpp b/src/src/PluginStructs/P120_data_struct.cpp index f9bf64463..54091a796 100644 --- a/src/src/PluginStructs/P120_data_struct.cpp +++ b/src/src/PluginStructs/P120_data_struct.cpp @@ -5,34 +5,9 @@ # define P120_RAD_TO_DEG 57.295779f // 180.0/M_PI -// **************************************************************************/ -// Constructor I2C -// **************************************************************************/ -P120_data_struct::P120_data_struct( - uint8_t i2c_addr, - uint8_t aSize) - : _i2c_addr(i2c_addr), _aSize(aSize) +P120_data_struct::P120_data_struct(uint8_t aSize) + : _aSize(aSize) { - i2c_mode = true; - initialization(); -} - -// **************************************************************************/ -// Constructor SPI -// **************************************************************************/ -P120_data_struct::P120_data_struct( - int cs_pin, - uint8_t aSize) - : _cs_pin(cs_pin), _aSize(aSize) -{ - i2c_mode = false; - initialization(); -} - -// **************************************************************************/ -// Common initialization -// **************************************************************************/ -void P120_data_struct::initialization() { if (_aSize == 0) { _aSize = 1; } _XA.resize(_aSize, 0); _YA.resize(_aSize, 0); @@ -41,16 +16,30 @@ void P120_data_struct::initialization() { _aMax = 0; } + // **************************************************************************/ // Destructor // **************************************************************************/ P120_data_struct::~P120_data_struct() { - if (initialized()) { + if (adxl345 != nullptr) { delete adxl345; adxl345 = nullptr; } } +void P120_data_struct::setI2Caddress(uint8_t i2c_addr) +{ + _i2c_addr = i2c_addr; + i2c_mode = true; +} + +void P120_data_struct::setSPI_CSpin(int cs_pin) +{ + _cs_pin = cs_pin; + i2c_mode = false; +} + + // **************************************************************************/ // Initialize sensor and read data from ADXL345 // **************************************************************************/ diff --git a/src/src/PluginStructs/P120_data_struct.h b/src/src/PluginStructs/P120_data_struct.h index 9efb16946..4991c53fd 100644 --- a/src/src/PluginStructs/P120_data_struct.h +++ b/src/src/PluginStructs/P120_data_struct.h @@ -96,11 +96,12 @@ public: static bool isXYZ(valueType vtype); - P120_data_struct(uint8_t i2c_addr, - uint8_t aSize); - P120_data_struct(int cs_pin, - uint8_t aSize); - ~P120_data_struct(); + P120_data_struct(uint8_t aSize); + P120_data_struct() = delete; + virtual ~P120_data_struct(); + + void setI2Caddress(uint8_t i2c_addr); + void setSPI_CSpin(int cs_pin); bool read_sensor(struct EventStruct *event); @@ -136,7 +137,6 @@ public: private: - void initialization(); bool init_sensor(struct EventStruct *event); void sensor_check_interrupt(struct EventStruct *event); void appendPayloadXYZ(struct EventStruct *event, @@ -151,7 +151,7 @@ private: uint8_t _i2c_addr = 0; int _cs_pin = -1; - uint8_t _aSize; + uint8_t _aSize = 0; std::vector_XA; std::vector_YA; diff --git a/src/src/PluginStructs/P121_data_struct.h b/src/src/PluginStructs/P121_data_struct.h index da5979bc7..f965cbb64 100644 --- a/src/src/PluginStructs/P121_data_struct.h +++ b/src/src/PluginStructs/P121_data_struct.h @@ -9,6 +9,9 @@ struct P121_data_struct : public PluginTaskData_base { + P121_data_struct() = default; + virtual ~P121_data_struct() = default; + bool begin(int taskid); Adafruit_HMC5883_Unified mag; diff --git a/src/src/PluginStructs/P124_data_struct.cpp b/src/src/PluginStructs/P124_data_struct.cpp index 29c60df45..f7f73c852 100644 --- a/src/src/PluginStructs/P124_data_struct.cpp +++ b/src/src/PluginStructs/P124_data_struct.cpp @@ -8,13 +8,26 @@ P124_data_struct::P124_data_struct(int8_t i2c_address, uint8_t relayCount, bool changeAddress) - : _i2c_address(i2c_address), _relayCount(relayCount) { + : _i2c_address(i2c_address), _relayCount(relayCount), _changeAddress(changeAddress) +{} + +// **************************************************************************/ +// Destructor +// **************************************************************************/ +P124_data_struct::~P124_data_struct() { + if (isInitialized()) { + delete relay; + relay = nullptr; + } +} + +bool P124_data_struct::init() { relay = new (std::nothrow) Multi_Channel_Relay(); if (isInitialized()) { relay->begin(_i2c_address); - if (changeAddress) { + if (_changeAddress) { // This increment shpould match with the range of addresses in _P124_MultiRelay.ino PLUGIN_I2C_HAS_ADDRESS uint8_t _new_address = _i2c_address == 0x18 ? 0x11 : _i2c_address + 1; // Set to next address relay->changeI2CAddress(_new_address, _i2c_address); @@ -29,16 +42,7 @@ P124_data_struct::P124_data_struct(int8_t i2c_address, # endif // ifndef BUILD_NO_DEBUG } } -} - -// **************************************************************************/ -// Destructor -// **************************************************************************/ -P124_data_struct::~P124_data_struct() { - if (isInitialized()) { - delete relay; - relay = nullptr; - } + return isInitialized(); } uint8_t P124_data_struct::getChannelState() { diff --git a/src/src/PluginStructs/P124_data_struct.h b/src/src/PluginStructs/P124_data_struct.h index b55e3ce38..68b8076f7 100644 --- a/src/src/PluginStructs/P124_data_struct.h +++ b/src/src/PluginStructs/P124_data_struct.h @@ -27,7 +27,9 @@ public: bool changeAddress = false); P124_data_struct() = delete; - ~P124_data_struct(); + virtual ~P124_data_struct(); + + bool init(); bool isInitialized() { return relay != nullptr; @@ -55,8 +57,9 @@ private: Multi_Channel_Relay *relay = nullptr; - int8_t _i2c_address; - uint8_t _relayCount; + const int8_t _i2c_address; + const uint8_t _relayCount; + const bool _changeAddress; uint8_t _getLoop = 0; bool _loopEnabled = false; }; diff --git a/src/src/PluginStructs/P126_data_struct.h b/src/src/PluginStructs/P126_data_struct.h index eda795d5c..dacc8e7c8 100644 --- a/src/src/PluginStructs/P126_data_struct.h +++ b/src/src/PluginStructs/P126_data_struct.h @@ -56,7 +56,7 @@ public: uint8_t chipCount); P126_data_struct() = delete; - ~P126_data_struct(); + virtual ~P126_data_struct(); const bool isInitialized() const { return nullptr != shift; diff --git a/src/src/PluginStructs/P127_data_struct.h b/src/src/PluginStructs/P127_data_struct.h index ffece8f7d..79f55bc98 100644 --- a/src/src/PluginStructs/P127_data_struct.h +++ b/src/src/PluginStructs/P127_data_struct.h @@ -41,6 +41,8 @@ enum class P127_initPhases : uint8_t { struct P127_data_struct : public PluginTaskData_base { P127_data_struct(const int8_t i2caddr, const uint16_t alt); + P127_data_struct() = delete; + virtual ~P127_data_struct() = default; bool init(); bool checkData(); uint16_t readData(); @@ -65,9 +67,9 @@ private: int32_t timeToWait = 0; P127_initPhases initPhase = P127_initPhases::Undefined; - int8_t _i2cAddress; + const int8_t _i2cAddress; uint16_t _alt; - uint16_t _co2; + uint16_t _co2 = 0; }; #endif // ifdef USES_P127 diff --git a/src/src/PluginStructs/P128_data_struct.cpp b/src/src/PluginStructs/P128_data_struct.cpp index 832b2e860..bc604a807 100644 --- a/src/src/PluginStructs/P128_data_struct.cpp +++ b/src/src/PluginStructs/P128_data_struct.cpp @@ -9,20 +9,19 @@ P128_data_struct::P128_data_struct(int8_t _gpioPin, uint16_t _pixelCount, uint8_t _maxBright) - : gpioPin(_gpioPin), pixelCount(_pixelCount), maxBright(_maxBright) { - if (!Plugin_128_pixels) { - # ifdef ESP8266 - Plugin_128_pixels = new (std::nothrow) NEOPIXEL_LIB(min(pixelCount, static_cast(ARRAYSIZE))); - # endif // ifdef ESP8266 - # ifdef ESP32 - Plugin_128_pixels = new (std::nothrow) NEOPIXEL_LIB(min(pixelCount, static_cast(ARRAYSIZE)), - _gpioPin); - # endif // ifdef ESP32 + : gpioPin(_gpioPin), pixelCount(_pixelCount), maxBright(_maxBright) +{ + # ifdef ESP8266 + Plugin_128_pixels = new (std::nothrow) NEOPIXEL_LIB(min(pixelCount, static_cast(ARRAYSIZE))); + # endif // ifdef ESP8266 + # ifdef ESP32 + Plugin_128_pixels = new (std::nothrow) NEOPIXEL_LIB(min(pixelCount, static_cast(ARRAYSIZE)), + _gpioPin); + # endif // ifdef ESP32 - if (nullptr != Plugin_128_pixels) { - Plugin_128_pixels->Begin(); // This initializes the NeoPixelBus library. - Plugin_128_pixels->SetBrightness(maxBright); - } + if (nullptr != Plugin_128_pixels) { + Plugin_128_pixels->Begin(); // This initializes the NeoPixelBus library. + Plugin_128_pixels->SetBrightness(maxBright); } } diff --git a/src/src/PluginStructs/P128_data_struct.h b/src/src/PluginStructs/P128_data_struct.h index e88fe62f1..e9c46f12a 100644 --- a/src/src/PluginStructs/P128_data_struct.h +++ b/src/src/PluginStructs/P128_data_struct.h @@ -2290,7 +2290,7 @@ public: uint8_t _maxBright); P128_data_struct() = delete; - ~P128_data_struct(); + virtual ~P128_data_struct(); bool plugin_fifty_per_second(struct EventStruct *event); bool plugin_read(struct EventStruct *event); @@ -2330,9 +2330,9 @@ private: rgb_s = HtmlColor(0xFF0000); # endif // if defined(RGBW) || defined(GRBW) - int8_t gpioPin; - uint16_t pixelCount; - uint8_t maxBright; + const int8_t gpioPin = -1; + const uint16_t pixelCount = 0; + const uint8_t maxBright = 0; int16_t fadedelay = 20; diff --git a/src/src/PluginStructs/P129_data_struct.cpp b/src/src/PluginStructs/P129_data_struct.cpp index d6f650cd9..713da1a03 100644 --- a/src/src/PluginStructs/P129_data_struct.cpp +++ b/src/src/PluginStructs/P129_data_struct.cpp @@ -12,10 +12,6 @@ P129_data_struct::P129_data_struct(int8_t dataPin, uint8_t chipCount) : _dataPin(dataPin), _clockPin(clockPin), _enablePin(enablePin), _loadPin(loadPin), _chipCount(chipCount) {} -// **************************************************************************/ -// Destructor -// **************************************************************************/ -P129_data_struct::~P129_data_struct() {} bool P129_data_struct::plugin_init(struct EventStruct *event) { if (isInitialized()) { diff --git a/src/src/PluginStructs/P129_data_struct.h b/src/src/PluginStructs/P129_data_struct.h index 7f3dc071f..e2eda3501 100644 --- a/src/src/PluginStructs/P129_data_struct.h +++ b/src/src/PluginStructs/P129_data_struct.h @@ -61,7 +61,7 @@ public: uint8_t chipCount); P129_data_struct() = delete; - ~P129_data_struct(); + virtual ~P129_data_struct() = default; const bool isInitialized() const { // All GPIO's defined return _dataPin != -1 && @@ -91,10 +91,10 @@ private: uint8_t state); - int8_t _dataPin; - int8_t _clockPin; - int8_t _enablePin; - int8_t _loadPin; + const int8_t _dataPin; + const int8_t _clockPin; + const int8_t _enablePin; + const int8_t _loadPin; uint8_t _chipCount; uint8_t readBuffer[P129_MAX_CHIP_COUNT] = { 0 }; diff --git a/src/src/PluginStructs/P131_data_struct.cpp b/src/src/PluginStructs/P131_data_struct.cpp index 8f2bcd4c7..dde31860c 100644 --- a/src/src/PluginStructs/P131_data_struct.cpp +++ b/src/src/PluginStructs/P131_data_struct.cpp @@ -36,8 +36,6 @@ P131_data_struct::P131_data_struct(uint8_t matrixWidth, : _matrixWidth(matrixWidth), _matrixHeight(matrixHeight), _tileWidth(tileWidth), _tileHeight(tileHeight), _pin(pin), _matrixType(matrixType), _ledType(ledType), _rotation(rotation), _fontscaling(fontscaling), _textmode(textmode), _commandTrigger(commandTrigger), _brightness(brightness), _maxbright(maxbright), _fgcolor(fgcolor), _bgcolor(bgcolor) { - updateFontMetrics(); - _commandTrigger.toLowerCase(); _commandTriggerCmd = _commandTrigger; _commandTriggerCmd += F("cmd"); @@ -57,6 +55,8 @@ P131_data_struct::~P131_data_struct() { * plugin_init: Initialize display ***************************************************************************/ bool P131_data_struct::plugin_init(struct EventStruct *event) { + updateFontMetrics(); + bool success = false; if (!isInitialized()) { diff --git a/src/src/PluginStructs/P131_data_struct.h b/src/src/PluginStructs/P131_data_struct.h index 83b108e87..3dc7302f6 100644 --- a/src/src/PluginStructs/P131_data_struct.h +++ b/src/src/PluginStructs/P131_data_struct.h @@ -111,7 +111,7 @@ public: uint16_t bgcolor = ADAGFX_BLACK); P131_data_struct() = delete; - ~P131_data_struct(); + virtual ~P131_data_struct(); bool plugin_init(struct EventStruct *event); bool plugin_exit(struct EventStruct *event); diff --git a/src/src/PluginStructs/P132_data_struct.cpp b/src/src/PluginStructs/P132_data_struct.cpp index ef41a4256..1882e5b94 100644 --- a/src/src/PluginStructs/P132_data_struct.cpp +++ b/src/src/PluginStructs/P132_data_struct.cpp @@ -10,11 +10,6 @@ P132_data_struct::P132_data_struct(struct EventStruct *event) { setCalibration_INA3221(event); } -// **************************************************************************/ -// Destructor -// **************************************************************************/ -P132_data_struct::~P132_data_struct() {} - // **************************************************************************/ // Gets the raw bus voltage (7FF8 / 32760) LSB 8mV // **************************************************************************/ diff --git a/src/src/PluginStructs/P132_data_struct.h b/src/src/PluginStructs/P132_data_struct.h index 837ce44fe..4f7bb4c69 100644 --- a/src/src/PluginStructs/P132_data_struct.h +++ b/src/src/PluginStructs/P132_data_struct.h @@ -33,14 +33,14 @@ public: P132_data_struct(struct EventStruct *event); P132_data_struct() = delete; - ~P132_data_struct(); + virtual ~P132_data_struct() = default; float getShuntVoltage_mV(byte reg); float getBusVoltage_V(byte reg); -private: + void setCalibration_INA3221(struct EventStruct *event); - void setCalibration_INA3221(struct EventStruct *event); +private: int16_t getBusVoltage_raw(byte reg); int16_t getShuntVoltage_raw(byte reg); diff --git a/src/src/PluginStructs/P133_data_struct.h b/src/src/PluginStructs/P133_data_struct.h index 6622db4bf..e93b9e160 100644 --- a/src/src/PluginStructs/P133_data_struct.h +++ b/src/src/PluginStructs/P133_data_struct.h @@ -33,7 +33,7 @@ public: bool initReset); P133_data_struct() = delete; - ~P133_data_struct(); + virtual ~P133_data_struct(); bool plugin_init(struct EventStruct *event); bool plugin_read(struct EventStruct *event); @@ -55,12 +55,12 @@ private: ltr390_mode_t mode = LTR390_MODE_UVS; - P133_selectMode_e _selectMode; - ltr390_gain_t _uvGain; - ltr390_resolution_t _uvResolution; - ltr390_gain_t _alsGain; - ltr390_resolution_t _alsResolution; - bool _initReset; + const P133_selectMode_e _selectMode; + const ltr390_gain_t _uvGain; + const ltr390_resolution_t _uvResolution; + const ltr390_gain_t _alsGain; + const ltr390_resolution_t _alsResolution; + const bool _initReset; }; #endif // ifdef USES_P133 diff --git a/src/src/PluginStructs/P134_data_struct.cpp b/src/src/PluginStructs/P134_data_struct.cpp index fd0e7abe2..2b3480298 100644 --- a/src/src/PluginStructs/P134_data_struct.cpp +++ b/src/src/PluginStructs/P134_data_struct.cpp @@ -32,7 +32,6 @@ P134_data_struct::P134_data_struct(uint8_t config_port, P134_Serial->begin(P134_SERIAL_BAUD_RATE); P134_Serial->flush(); addLog(LOG_LEVEL_INFO, F("A02YYUW: Initialization OK")); - initialised = true; } else { addLog(LOG_LEVEL_ERROR, F("A02YYUW: Initialization FAILED")); } @@ -52,7 +51,7 @@ P134_data_struct::~P134_data_struct() { bool P134_data_struct::plugin_read(struct EventStruct *event) { bool success = false; - if (initialised) { + if (isInitialized()) { uint8_t data[P134_DISTANCE_DATA_SIZE] = { 0 }; int16_t i = 0; uint16_t measuredDistance = P134_MIN_DISTANCE; @@ -61,11 +60,15 @@ bool P134_data_struct::plugin_read(struct EventStruct *event) { while (!P134_Serial->available() && i < P134_SERIAL_AVAILABLE_CHECK_CYCLES) { i++; + // FIXME TD-er: Why making such a lousy check for data holding up everything running on the ESP node. + // Repeat after me: "Thou shall not use delay()!" delay(P134_SERIAL_AVAILABLE_CHECK_DELAY); } i = 0; while (P134_Serial->available() && i < P134_DISTANCE_DATA_SIZE) { + // FIXME TD-er: This does not have a timeout => Will crash the node when only data is received != P134_SERIAL_HEAD_DATA + // Reading bytes should be done from the PLUGIN_TEN_PER_SECOND or something similar. data[i] = P134_Serial->read(); i++; diff --git a/src/src/PluginStructs/P134_data_struct.h b/src/src/PluginStructs/P134_data_struct.h index 0c04d534c..fc0f8a746 100644 --- a/src/src/PluginStructs/P134_data_struct.h +++ b/src/src/PluginStructs/P134_data_struct.h @@ -37,21 +37,20 @@ public: int8_t config_pin2); P134_data_struct() = delete; - ~P134_data_struct(); + virtual ~P134_data_struct(); bool plugin_read(struct EventStruct *event); - bool isInitialized() { - return initialised; + bool isInitialized() const { + return P134_Serial != nullptr; } private: ESPeasySerial *P134_Serial = nullptr; - uint8_t _config_port; - int8_t _config_pin1; - int8_t _config_pin2; - bool initialised = false; + const uint8_t _config_port; + const int8_t _config_pin1; + const int8_t _config_pin2; }; #endif // ifdef USES_P134 diff --git a/src/src/PluginStructs/P135_data_struct.cpp b/src/src/PluginStructs/P135_data_struct.cpp index 8e6cabad3..ee497f804 100644 --- a/src/src/PluginStructs/P135_data_struct.cpp +++ b/src/src/PluginStructs/P135_data_struct.cpp @@ -13,7 +13,10 @@ P135_data_struct::P135_data_struct(taskIndex_t taskIndex, bool lowPowerMeasurement, bool useSingleShot) : _sensorType(sensorType), _altitude(altitude), _tempOffset(tempOffset), _autoCalibrate(autoCalibrate), - _lowPowerMeasurement(lowPowerMeasurement), _useSingleShot(useSingleShot), initialized(false) { + _lowPowerMeasurement(lowPowerMeasurement), _useSingleShot(useSingleShot), initialized(false) + {} + +bool P135_data_struct::init() { scd4x = new (std::nothrow) SCD4x(static_cast(_sensorType)); // Don't start measurement, we want to set arguments if (scd4x != nullptr) { @@ -57,6 +60,7 @@ P135_data_struct::P135_data_struct(taskIndex_t taskIndex, addLog(LOG_LEVEL_ERROR, F("SDC4x: Sensor not detected.")); } } + return isInitialized(); } /***************************************************** diff --git a/src/src/PluginStructs/P135_data_struct.h b/src/src/PluginStructs/P135_data_struct.h index 14f0ecead..7bc2e50cd 100644 --- a/src/src/PluginStructs/P135_data_struct.h +++ b/src/src/PluginStructs/P135_data_struct.h @@ -52,14 +52,16 @@ public: bool useSingleShot); P135_data_struct() = delete; - ~P135_data_struct(); + virtual ~P135_data_struct(); + + bool init(); bool plugin_read(struct EventStruct *event); bool plugin_write(struct EventStruct *event, String & string); bool plugin_get_config_value(struct EventStruct *event, String & string); - bool isInitialized() { + bool isInitialized() const { return initialized; } diff --git a/src/src/PluginStructs/P141_data_struct.cpp b/src/src/PluginStructs/P141_data_struct.cpp index 718999c36..6b7b0b297 100644 --- a/src/src/PluginStructs/P141_data_struct.cpp +++ b/src/src/PluginStructs/P141_data_struct.cpp @@ -35,7 +35,6 @@ P141_data_struct::P141_data_struct(uint8_t rotation, _displayTimeout(displayTimer), _commandTrigger(commandTrigger), _fgcolor(fgcolor), _bgcolor(bgcolor), _textBackFill(textBackFill), _displayInverted(displayInverted) { - updateFontMetrics(); _commandTrigger.toLowerCase(); _commandTriggerCmd = concat(_commandTrigger, F("cmd")); } @@ -51,6 +50,7 @@ P141_data_struct::~P141_data_struct() { * plugin_init: Initialize display ***************************************************************************/ bool P141_data_struct::plugin_init(struct EventStruct *event) { + updateFontMetrics(); bool success = false; ButtonState = false; // button not touched diff --git a/src/src/PluginStructs/P141_data_struct.h b/src/src/PluginStructs/P141_data_struct.h index bcf97a92b..83cf904ab 100644 --- a/src/src/PluginStructs/P141_data_struct.h +++ b/src/src/PluginStructs/P141_data_struct.h @@ -88,7 +88,8 @@ public: uint16_t bgcolor = ADAGFX_BLACK, bool textBackFill = true, bool displayInverted = false); - ~P141_data_struct(); + P141_data_struct() = delete; + virtual ~P141_data_struct(); bool plugin_init(struct EventStruct *event); bool plugin_exit(struct EventStruct *event);