From 1eeeff22ca8fd14686e47f1553a8bd866506ca15 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Sat, 31 Aug 2024 14:43:21 +0200 Subject: [PATCH 1/2] [DeviceStruct] Add PinDirection flag for PIN1..PIN3 --- src/src/DataStructs/DeviceStruct.cpp | 33 +++++++++++++++++++++++- src/src/DataStructs/DeviceStruct.h | 10 +++++++ src/src/Helpers/ESPEasy_checks.cpp | 2 +- src/src/Helpers/StringGenerator_GPIO.cpp | 1 + src/src/Helpers/StringGenerator_GPIO.h | 3 ++- src/src/WebServer/DevicesPage.cpp | 6 ++--- 6 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/src/DataStructs/DeviceStruct.cpp b/src/src/DataStructs/DeviceStruct.cpp index d58f798feb..569f88f796 100644 --- a/src/src/DataStructs/DeviceStruct.cpp +++ b/src/src/DataStructs/DeviceStruct.cpp @@ -11,7 +11,8 @@ DeviceStruct::DeviceStruct() : DuplicateDetection(false), ExitTaskBeforeSave(true), ErrorStateValues(false), PluginStats(false), PluginLogsPeaks(false), PowerManager(false), TaskLogsOwnPeaks(false), I2CNoDeviceCheck(false), - I2CMax100kHz(false), HasFormatUserVar(false) {} + I2CMax100kHz(false), HasFormatUserVar(false), Pin1Direction(gpio_direction::gpio_direction_MAX), + Pin2Direction(gpio_direction::gpio_direction_MAX), Pin3Direction(gpio_direction::gpio_direction_MAX) {} bool DeviceStruct::connectedToGPIOpins() const { switch(Type) { @@ -68,3 +69,33 @@ bool DeviceStruct::isCustom() const { (Type == DEVICE_TYPE_CUSTOM3); } +gpio_direction DeviceStruct::getPinDirection(int pin) const { + switch (pin) { + case 1: + return Pin1Direction; + case 2: + return Pin2Direction; + case 3: + return Pin3Direction; + } + return gpio_direction::gpio_direction_MAX; +} + +PinSelectPurpose DeviceStruct::pinDirectionToPurpose(gpio_direction direction) const { + switch (direction) { + case gpio_direction::gpio_input: + return PinSelectPurpose::Generic_input; + case gpio_direction::gpio_output: + return PinSelectPurpose::Generic_output; + case gpio_direction::gpio_bidirectional: + return PinSelectPurpose::Generic_bidir; + case gpio_direction::gpio_direction_MAX: + break; + } + return PinSelectPurpose::Generic; +} + + +PinSelectPurpose DeviceStruct::getPinSelectPurpose(int pin) const { + return pinDirectionToPurpose(getPinDirection(pin)); +} diff --git a/src/src/DataStructs/DeviceStruct.h b/src/src/DataStructs/DeviceStruct.h index 6d0d1da66e..f5dccc73ba 100644 --- a/src/src/DataStructs/DeviceStruct.h +++ b/src/src/DataStructs/DeviceStruct.h @@ -10,6 +10,8 @@ #include "../DataTypes/PluginID.h" #include "../DataTypes/SensorVType.h" +#include "../Helpers/StringGenerator_GPIO.h" + #define DEVICE_TYPE_SINGLE 1 // connected through 1 datapin #define DEVICE_TYPE_DUAL 2 // connected through 2 datapins @@ -67,6 +69,10 @@ struct __attribute__((__packed__)) DeviceStruct return pluginID_t::toPluginID(Number); } + gpio_direction getPinDirection(int pin) const; + PinSelectPurpose pinDirectionToPurpose(gpio_direction direction) const; + PinSelectPurpose getPinSelectPurpose(int pin) const; + uint8_t Number; // Plugin ID number. (PLUGIN_ID_xxx) uint8_t Type; // How the device is connected. e.g. DEVICE_TYPE_SINGLE => connected through 1 datapin @@ -74,6 +80,10 @@ struct __attribute__((__packed__)) DeviceStruct uint8_t Ports; // Port to use when device has multiple I/O pins (N.B. not used much) uint8_t ValueCount; // The number of output values of a plugin. The value should match the number of keys PLUGIN_VALUENAME1_xxx Output_Data_type_t OutputDataType; // Subset of selectable output data types (Default = no selection) + + gpio_direction Pin1Direction : NR_BITS(static_cast(gpio_direction::gpio_direction_MAX)); + gpio_direction Pin2Direction : NR_BITS(static_cast(gpio_direction::gpio_direction_MAX)); + gpio_direction Pin3Direction : NR_BITS(static_cast(gpio_direction::gpio_direction_MAX)); bool PullUpOption : 1; // Allow to set internal pull-up resistors. bool InverseLogicOption : 1; // Allow to invert the boolean state (e.g. a switch) diff --git a/src/src/Helpers/ESPEasy_checks.cpp b/src/src/Helpers/ESPEasy_checks.cpp index b56db5c670..87a0986450 100644 --- a/src/src/Helpers/ESPEasy_checks.cpp +++ b/src/src/Helpers/ESPEasy_checks.cpp @@ -108,7 +108,7 @@ void run_compiletime_checks() { const unsigned int LogStructSize = ((13u + 20 * LOG_STRUCT_MESSAGE_LINES) + 3) & ~3; #endif check_size(); // Is not stored - check_size(); // Is not stored + check_size(); // Is not stored check_size(); #if FEATURE_NOTIFIER check_size(); diff --git a/src/src/Helpers/StringGenerator_GPIO.cpp b/src/src/Helpers/StringGenerator_GPIO.cpp index 3c0450930d..a5a6fc9f5a 100644 --- a/src/src/Helpers/StringGenerator_GPIO.cpp +++ b/src/src/Helpers/StringGenerator_GPIO.cpp @@ -14,6 +14,7 @@ const __FlashStringHelper* formatGpioDirection(gpio_direction direction) { case gpio_direction::gpio_input: return F("← "); case gpio_direction::gpio_output: return F("→ "); case gpio_direction::gpio_bidirectional: return F("⇄ "); + case gpio_direction::gpio_direction_MAX: break; } return F(""); } diff --git a/src/src/Helpers/StringGenerator_GPIO.h b/src/src/Helpers/StringGenerator_GPIO.h index 2b9271ff14..6ead026e51 100644 --- a/src/src/Helpers/StringGenerator_GPIO.h +++ b/src/src/Helpers/StringGenerator_GPIO.h @@ -13,7 +13,8 @@ enum class gpio_direction : uint8_t { gpio_input, gpio_output, - gpio_bidirectional + gpio_bidirectional, + gpio_direction_MAX // Keep last, used as bit-size value and dummy-default value }; enum class PinSelectPurpose : uint8_t { diff --git a/src/src/WebServer/DevicesPage.cpp b/src/src/WebServer/DevicesPage.cpp index 3e24c13b41..cfece1703c 100644 --- a/src/src/WebServer/DevicesPage.cpp +++ b/src/src/WebServer/DevicesPage.cpp @@ -1107,7 +1107,7 @@ void devicePage_show_pin_config(taskIndex_t taskIndex, deviceIndex_t DeviceIndex PluginCall(PLUGIN_GET_DEVICEGPIONAMES, &TempEvent, dummy); if (device.usesTaskDevicePin(1)) { - PinSelectPurpose purpose = PinSelectPurpose::Generic; + PinSelectPurpose purpose = device.getPinSelectPurpose(1); // PinSelectPurpose::Generic; if (device.isSerial()) { @@ -1123,7 +1123,7 @@ void devicePage_show_pin_config(taskIndex_t taskIndex, deviceIndex_t DeviceIndex } if (device.usesTaskDevicePin(2)) { - PinSelectPurpose purpose = PinSelectPurpose::Generic; + PinSelectPurpose purpose = device.getPinSelectPurpose(2); // PinSelectPurpose::Generic; if (device.isSerial()) { @@ -1139,7 +1139,7 @@ void devicePage_show_pin_config(taskIndex_t taskIndex, deviceIndex_t DeviceIndex } if (device.usesTaskDevicePin(3)) { - PinSelectPurpose purpose = PinSelectPurpose::Generic; + PinSelectPurpose purpose = device.getPinSelectPurpose(3); // PinSelectPurpose::Generic; if (device.isSPI()) { From 09e5b1e5ffb8a6449d49fb5efb2bf9836c0f77e8 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Sat, 31 Aug 2024 23:16:44 +0200 Subject: [PATCH 2/2] [DeviceStruct] Apply PinXDirection flags for all plugins where appropriate, cleanup unneeded Device flags, reformatted some plugin sources --- src/_P004_Dallas.ino | 25 +- src/_P013_HCSR04.ino | 1 + src/_P018_Dust.ino | 3 +- src/_P021_Level.ino | 21 +- src/_P029_Output.ino | 5 +- src/_P031_SHT1X.ino | 23 +- src/_P035_IRTX.ino | 1 + src/_P038_NeoPixel.ino | 7 +- src/_P041_NeoClock.ino | 15 +- src/_P042_Candle.ino | 19 +- src/_P043_ClkOutput.ino | 18 +- src/_P054_DMX512.ino | 325 ++++++++++---------- src/_P055_Chiming.ino | 562 ++++++++++++++++++---------------- src/_P063_TTP229_KeyPad.ino | 255 +++++++-------- src/_P067_HX711_Load_Cell.ino | 23 +- src/_P070_NeoPixel_Clock.ino | 17 +- src/_P073_7DGT.ino | 36 +-- src/_P076_HLW8012.ino | 22 +- src/_P088_HeatpumpIR.ino | 327 ++++++++++---------- src/_P126_74HC595.ino | 23 +- src/_P128_NeoPixelBusFX.ino | 23 +- src/_P129_74HC165.ino | 22 +- src/_P131_NeoPixelMatrix.ino | 19 +- 23 files changed, 916 insertions(+), 876 deletions(-) diff --git a/src/_P004_Dallas.ino b/src/_P004_Dallas.ino index f5c2853e02..60e2e89f81 100644 --- a/src/_P004_Dallas.ino +++ b/src/_P004_Dallas.ino @@ -51,19 +51,18 @@ boolean Plugin_004(uint8_t function, struct EventStruct *event, String& string) { case PLUGIN_DEVICE_ADD: { - Device[++deviceCount].Number = PLUGIN_ID_004; - Device[deviceCount].Type = DEVICE_TYPE_DUAL; - Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SINGLE; - Device[deviceCount].Ports = 0; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = true; - Device[deviceCount].ValueCount = 1; - Device[deviceCount].SendDataOption = true; - Device[deviceCount].TimerOption = true; - Device[deviceCount].GlobalSyncOption = true; - Device[deviceCount].OutputDataType = Output_Data_type_t::Simple; - Device[deviceCount].PluginStats = true; + Device[++deviceCount].Number = PLUGIN_ID_004; + Device[deviceCount].Type = DEVICE_TYPE_DUAL; + Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SINGLE; + Device[deviceCount].Ports = 0; + Device[deviceCount].FormulaOption = true; + Device[deviceCount].ValueCount = 1; + Device[deviceCount].SendDataOption = true; + Device[deviceCount].TimerOption = true; + Device[deviceCount].GlobalSyncOption = true; + Device[deviceCount].OutputDataType = Output_Data_type_t::Simple; + Device[deviceCount].PluginStats = true; + Device[deviceCount].Pin2Direction = gpio_direction::gpio_output; break; } diff --git a/src/_P013_HCSR04.ino b/src/_P013_HCSR04.ino index 6b9e032799..0c56c9bf9d 100644 --- a/src/_P013_HCSR04.ino +++ b/src/_P013_HCSR04.ino @@ -58,6 +58,7 @@ boolean Plugin_013(uint8_t function, struct EventStruct *even Device[deviceCount].TimerOptional = true; Device[deviceCount].GlobalSyncOption = true; Device[deviceCount].PluginStats = true; + Device[deviceCount].Pin1Direction = gpio_direction::gpio_output; break; } diff --git a/src/_P018_Dust.ino b/src/_P018_Dust.ino index 390fa18a49..12b1a611f6 100644 --- a/src/_P018_Dust.ino +++ b/src/_P018_Dust.ino @@ -27,14 +27,13 @@ boolean Plugin_018(uint8_t function, struct EventStruct *event, String& string) Device[deviceCount].Type = DEVICE_TYPE_SINGLE; Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SINGLE; Device[deviceCount].Ports = 0; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; Device[deviceCount].FormulaOption = true; Device[deviceCount].ValueCount = 1; Device[deviceCount].SendDataOption = true; Device[deviceCount].TimerOption = true; Device[deviceCount].GlobalSyncOption = true; Device[deviceCount].PluginStats = true; + Device[deviceCount].Pin1Direction = gpio_direction::gpio_output; break; } diff --git a/src/_P021_Level.ino b/src/_P021_Level.ino index 92801bc6fd..07942aaded 100644 --- a/src/_P021_Level.ino +++ b/src/_P021_Level.ino @@ -41,16 +41,13 @@ boolean Plugin_021(uint8_t function, struct EventStruct *event, String& string) { case PLUGIN_DEVICE_ADD: { - Device[++deviceCount].Number = PLUGIN_ID_021; - Device[deviceCount].Type = DEVICE_TYPE_SINGLE; - Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SWITCH; - Device[deviceCount].Ports = 0; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = false; - Device[deviceCount].ValueCount = 1; - Device[deviceCount].SendDataOption = true; - Device[deviceCount].TimerOption = false; + Device[++deviceCount].Number = PLUGIN_ID_021; + Device[deviceCount].Type = DEVICE_TYPE_SINGLE; + Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SWITCH; + Device[deviceCount].Ports = 0; + Device[deviceCount].ValueCount = 1; + Device[deviceCount].SendDataOption = true; + Device[deviceCount].Pin1Direction = gpio_direction::gpio_output; break; } @@ -100,14 +97,18 @@ boolean Plugin_021(uint8_t function, struct EventStruct *event, String& string) addFormCheckBox(F("Save 'Set Level'/'Hysteresis' after change via
config
command"), F("psave_always"), P021_DONT_ALWAYS_SAVE == 0); + // # ifndef BUILD_NO_DEBUG addFormNote(F("Saving settings too often can wear out the flash chip on your ESP!")); + // # endif // ifndef BUILD_NO_DEBUG addFormNumericBox(F("Auto-save interval"), F("pautosave"), P021_AUTOSAVE_TIMER / 60, 0, 1440); // Present in minutes addUnit(F("minutes")); + // # ifndef BUILD_NO_DEBUG addFormNote(F("Interval to check if settings are changed via
config
command and saves that. Max. 24h, 0 = Off")); + // # endif // ifndef BUILD_NO_DEBUG success = true; diff --git a/src/_P029_Output.ino b/src/_P029_Output.ino index 1acbbc552f..423597a2a8 100644 --- a/src/_P029_Output.ino +++ b/src/_P029_Output.ino @@ -29,11 +29,8 @@ boolean Plugin_029(uint8_t function, struct EventStruct *event, String& string) Device[deviceCount].Type = DEVICE_TYPE_SINGLE; Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SWITCH; Device[deviceCount].Ports = 0; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = false; Device[deviceCount].ValueCount = 1; - Device[deviceCount].SendDataOption = false; + Device[deviceCount].Pin1Direction = gpio_direction::gpio_output; break; } diff --git a/src/_P031_SHT1X.ino b/src/_P031_SHT1X.ino index b8cfdf7f34..eff2e58f28 100644 --- a/src/_P031_SHT1X.ino +++ b/src/_P031_SHT1X.ino @@ -22,18 +22,17 @@ boolean Plugin_031(uint8_t function, struct EventStruct *event, String& string) { case PLUGIN_DEVICE_ADD: { - Device[++deviceCount].Number = PLUGIN_ID_031; - Device[deviceCount].Type = DEVICE_TYPE_DUAL; - Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_TEMP_HUM; - Device[deviceCount].Ports = 0; - Device[deviceCount].PullUpOption = true; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = true; - Device[deviceCount].ValueCount = 2; - Device[deviceCount].SendDataOption = true; - Device[deviceCount].TimerOption = true; - Device[deviceCount].GlobalSyncOption = true; - Device[deviceCount].PluginStats = true; + Device[++deviceCount].Number = PLUGIN_ID_031; + Device[deviceCount].Type = DEVICE_TYPE_DUAL; + Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_TEMP_HUM; + Device[deviceCount].Ports = 0; + Device[deviceCount].PullUpOption = true; + Device[deviceCount].FormulaOption = true; + Device[deviceCount].ValueCount = 2; + Device[deviceCount].SendDataOption = true; + Device[deviceCount].TimerOption = true; + Device[deviceCount].PluginStats = true; + Device[deviceCount].Pin2Direction = gpio_direction::gpio_output; break; } diff --git a/src/_P035_IRTX.ino b/src/_P035_IRTX.ino index a7fc751b3c..7b6215de53 100644 --- a/src/_P035_IRTX.ino +++ b/src/_P035_IRTX.ino @@ -62,6 +62,7 @@ boolean Plugin_035(uint8_t function, struct EventStruct *event, String& string) Device[++deviceCount].Number = PLUGIN_ID_035; Device[deviceCount].Type = DEVICE_TYPE_SINGLE; Device[deviceCount].SendDataOption = false; + Device[deviceCount].Pin1Direction = gpio_direction::gpio_output; break; } diff --git a/src/_P038_NeoPixel.ino b/src/_P038_NeoPixel.ino index 34b79badcf..b1b3b96f98 100644 --- a/src/_P038_NeoPixel.ino +++ b/src/_P038_NeoPixel.ino @@ -57,9 +57,10 @@ boolean Plugin_038(uint8_t function, struct EventStruct *event, String& string) { case PLUGIN_DEVICE_ADD: { - Device[++deviceCount].Number = PLUGIN_ID_038; - Device[deviceCount].Type = DEVICE_TYPE_SINGLE; - Device[deviceCount].TimerOption = false; + Device[++deviceCount].Number = PLUGIN_ID_038; + Device[deviceCount].Type = DEVICE_TYPE_SINGLE; + Device[deviceCount].TimerOption = false; + Device[deviceCount].Pin1Direction = gpio_direction::gpio_output; break; } diff --git a/src/_P041_NeoClock.ino b/src/_P041_NeoClock.ino index 85a4ed5d5e..273f72fa86 100644 --- a/src/_P041_NeoClock.ino +++ b/src/_P041_NeoClock.ino @@ -36,15 +36,12 @@ boolean Plugin_041(uint8_t function, struct EventStruct *event, String& string) { case PLUGIN_DEVICE_ADD: { - Device[++deviceCount].Number = PLUGIN_ID_041; - Device[deviceCount].Type = DEVICE_TYPE_SINGLE; - Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_NONE; - Device[deviceCount].Ports = 0; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = false; - Device[deviceCount].ValueCount = 0; - Device[deviceCount].SendDataOption = false; + Device[++deviceCount].Number = PLUGIN_ID_041; + Device[deviceCount].Type = DEVICE_TYPE_SINGLE; + Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_NONE; + Device[deviceCount].Ports = 0; + Device[deviceCount].ValueCount = 0; + Device[deviceCount].Pin1Direction = gpio_direction::gpio_output; break; } diff --git a/src/_P042_Candle.ino b/src/_P042_Candle.ino index 3334ca0ee8..c9e0f0bb6f 100644 --- a/src/_P042_Candle.ino +++ b/src/_P042_Candle.ino @@ -92,17 +92,14 @@ boolean Plugin_042(uint8_t function, struct EventStruct *event, String& string) { case PLUGIN_DEVICE_ADD: { - Device[++deviceCount].Number = PLUGIN_ID_042; - Device[deviceCount].Type = DEVICE_TYPE_SINGLE; - Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_TRIPLE; - Device[deviceCount].Ports = 0; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = false; - Device[deviceCount].ValueCount = 3; - Device[deviceCount].SendDataOption = true; - Device[deviceCount].TimerOption = true; - Device[deviceCount].GlobalSyncOption = false; + Device[++deviceCount].Number = PLUGIN_ID_042; + Device[deviceCount].Type = DEVICE_TYPE_SINGLE; + Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_TRIPLE; + Device[deviceCount].Ports = 0; + Device[deviceCount].ValueCount = 3; + Device[deviceCount].SendDataOption = true; + Device[deviceCount].TimerOption = true; + Device[deviceCount].Pin1Direction = gpio_direction::gpio_output; break; } diff --git a/src/_P043_ClkOutput.ino b/src/_P043_ClkOutput.ino index 352108d294..f0138baff8 100644 --- a/src/_P043_ClkOutput.ino +++ b/src/_P043_ClkOutput.ino @@ -68,16 +68,14 @@ boolean Plugin_043(uint8_t function, struct EventStruct *event, String& string) { case PLUGIN_DEVICE_ADD: { - Device[++deviceCount].Number = PLUGIN_ID_043; - Device[deviceCount].Type = DEVICE_TYPE_SINGLE; - Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SWITCH; - Device[deviceCount].Ports = 0; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = false; - Device[deviceCount].ValueCount = 2; - Device[deviceCount].SendDataOption = true; - Device[deviceCount].OutputDataType = Output_Data_type_t::Simple; + Device[++deviceCount].Number = PLUGIN_ID_043; + Device[deviceCount].Type = DEVICE_TYPE_SINGLE; + Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SWITCH; + Device[deviceCount].Ports = 0; + Device[deviceCount].ValueCount = 2; + Device[deviceCount].SendDataOption = true; + Device[deviceCount].OutputDataType = Output_Data_type_t::Simple; + Device[deviceCount].Pin1Direction = gpio_direction::gpio_output; break; } diff --git a/src/_P054_DMX512.ino b/src/_P054_DMX512.ino index 914acfea89..715cdf10b6 100644 --- a/src/_P054_DMX512.ino +++ b/src/_P054_DMX512.ino @@ -1,8 +1,9 @@ #include "_Plugin_Helper.h" #ifdef USES_P054 -//####################################################################################################### -//######################################## Plugin 054: DMX512 TX ######################################## -//####################################################################################################### + +// ####################################################################################################### +// ######################################## Plugin 054: DMX512 TX ######################################## +// ####################################################################################################### // ESPEasy Plugin to control DMX-512 Devices (DMX 512/1990; DIN 56930-2) like Dimmer-Packs, LED-Bars, Moving-Heads, Event-Lighting // written by Jochen Krapf (jk@nerd2nerd.org) @@ -49,25 +50,27 @@ // Note: The ESP serial FIFO has size of 128 uint8_t. Therefore it is rcommented to use DMX buffer sizes below 128 -//#include <*.h> //no lib needed +// #include <*.h> //no lib needed -#define PLUGIN_054 -#define PLUGIN_ID_054 54 -#define PLUGIN_NAME_054 "Communication - DMX512 TX" +# define PLUGIN_054 +# define PLUGIN_ID_054 54 +# define PLUGIN_NAME_054 "Communication - DMX512 TX" -uint8_t* Plugin_054_DMXBuffer = 0; -int16_t Plugin_054_DMXSize = 32; +uint8_t *Plugin_054_DMXBuffer = 0; +int16_t Plugin_054_DMXSize = 32; static inline void PLUGIN_054_Limit(int16_t& value, int16_t min, int16_t max) { - if (value < min) + if (value < min) { value = min; - if (value > max) + } + + if (value > max) { value = max; + } } - boolean Plugin_054(uint8_t function, struct EventStruct *event, String& string) { boolean success = false; @@ -75,198 +78,200 @@ boolean Plugin_054(uint8_t function, struct EventStruct *event, String& string) switch (function) { case PLUGIN_DEVICE_ADD: - { - Device[++deviceCount].Number = PLUGIN_ID_054; - Device[deviceCount].Type = DEVICE_TYPE_SINGLE; - Device[deviceCount].Ports = 0; - Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_NONE; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = false; - Device[deviceCount].ValueCount = 0; - Device[deviceCount].SendDataOption = false; - Device[deviceCount].TimerOption = false; - Device[deviceCount].TimerOptional = false; - Device[deviceCount].GlobalSyncOption = true; - break; - } + { + Device[++deviceCount].Number = PLUGIN_ID_054; + Device[deviceCount].Type = DEVICE_TYPE_SINGLE; + Device[deviceCount].Ports = 0; + Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_NONE; + Device[deviceCount].ValueCount = 0; + Device[deviceCount].Pin1Direction = gpio_direction::gpio_output; + break; + } case PLUGIN_GET_DEVICENAME: - { - string = F(PLUGIN_NAME_054); - break; - } + { + string = F(PLUGIN_NAME_054); + break; + } case PLUGIN_WEBFORM_LOAD: - { - CONFIG_PIN1 = 2; - PCONFIG(0) = Plugin_054_DMXSize; - addFormNote(F("Only GPIO-2 (D4) can be used as TX1!")); - addFormNumericBox(F("Channels"), F("channels"), Plugin_054_DMXSize, 1, 512); - success = true; - break; - } + { + CONFIG_PIN1 = 2; + PCONFIG(0) = Plugin_054_DMXSize; + addFormNote(F("Only GPIO-2 (D4) can be used as TX1!")); + addFormNumericBox(F("Channels"), F("channels"), Plugin_054_DMXSize, 1, 512); + success = true; + break; + } case PLUGIN_WEBFORM_SAVE: - { - CONFIG_PIN1 = 2; - if (Settings.Pin_status_led == 2) //Status LED assigned to TX1? - Settings.Pin_status_led = -1; - Plugin_054_DMXSize = getFormItemInt(F("channels")); - PLUGIN_054_Limit (Plugin_054_DMXSize, 1, 512); - PCONFIG(0) = Plugin_054_DMXSize; - success = true; - break; + { + CONFIG_PIN1 = 2; + + if (Settings.Pin_status_led == 2) { // Status LED assigned to TX1? + Settings.Pin_status_led = -1; } + Plugin_054_DMXSize = getFormItemInt(F("channels")); + PLUGIN_054_Limit(Plugin_054_DMXSize, 1, 512); + PCONFIG(0) = Plugin_054_DMXSize; + success = true; + break; + } case PLUGIN_INIT: - { - CONFIG_PIN1 = 2; //TX1 fix to GPIO2 (D4) == onboard LED - Plugin_054_DMXSize = PCONFIG(0); + { + CONFIG_PIN1 = 2; // TX1 fix to GPIO2 (D4) == onboard LED + Plugin_054_DMXSize = PCONFIG(0); - if (Plugin_054_DMXBuffer) { - delete [] Plugin_054_DMXBuffer; - } - Plugin_054_DMXBuffer = new (std::nothrow) uint8_t[Plugin_054_DMXSize]; - if (Plugin_054_DMXBuffer != nullptr) { - memset(Plugin_054_DMXBuffer, 0, Plugin_054_DMXSize); - } + if (Plugin_054_DMXBuffer) { + delete[] Plugin_054_DMXBuffer; + } + Plugin_054_DMXBuffer = new (std::nothrow) uint8_t[Plugin_054_DMXSize]; - success = Plugin_054_DMXBuffer != nullptr; - break; + if (Plugin_054_DMXBuffer != nullptr) { + memset(Plugin_054_DMXBuffer, 0, Plugin_054_DMXSize); } + success = Plugin_054_DMXBuffer != nullptr; + break; + } + case PLUGIN_EXIT: - { - if (Plugin_054_DMXBuffer) { - delete [] Plugin_054_DMXBuffer; - } - break; + { + if (Plugin_054_DMXBuffer) { + delete[] Plugin_054_DMXBuffer; } + break; + } case PLUGIN_WRITE: + { + String lowerString = string; + lowerString.toLowerCase(); + String command = parseString(lowerString, 1); + + if (equals(command, F("dmx"))) { - String lowerString=string; - lowerString.toLowerCase(); - String command = parseString(lowerString, 1); + String param; + String paramKey; + String paramVal; + uint8_t paramIdx = 2; + int16_t channel = 1; + int16_t value = 0; + + // FIXME TD-er: Same code in _P057 + lowerString.replace(F(" "), " "); + lowerString.replace(F(" ="), "="); + lowerString.replace(F("= "), "="); - if (equals(command, F("dmx"))) + param = parseString(lowerString, paramIdx++); + + if (param.length()) { - String param; - String paramKey; - String paramVal; - uint8_t paramIdx = 2; - int16_t channel = 1; - int16_t value = 0; - //FIXME TD-er: Same code in _P057 - lowerString.replace(F(" "), " "); - lowerString.replace(F(" ="), "="); - lowerString.replace(F("= "), "="); - - param = parseString(lowerString, paramIdx++); - if (param.length()) + while (param.length()) { - while (param.length()) + # ifndef BUILD_NO_DEBUG + addLog(LOG_LEVEL_DEBUG_MORE, param); + # endif // ifndef BUILD_NO_DEBUG + + if (equals(param, F("log"))) { - #ifndef BUILD_NO_DEBUG - addLog(LOG_LEVEL_DEBUG_MORE, param); - #endif + if (loglevelActiveFor(LOG_LEVEL_INFO)) { + String log = F("DMX : "); - if (equals(param, F("log"))) - { - if (loglevelActiveFor(LOG_LEVEL_INFO)) { - String log = F("DMX : "); - for (int16_t i = 0; i < Plugin_054_DMXSize; i++) - { - log += Plugin_054_DMXBuffer[i]; - log += F(", "); - } - addLogMove(LOG_LEVEL_INFO, log); + for (int16_t i = 0; i < Plugin_054_DMXSize; i++) + { + log += Plugin_054_DMXBuffer[i]; + log += F(", "); } - success = true; + addLogMove(LOG_LEVEL_INFO, log); } + success = true; + } - else if (equals(param, F("test"))) - { - for (int16_t i = 0; i < Plugin_054_DMXSize; i++) - //Plugin_054_DMXBuffer[i] = i+1; - Plugin_054_DMXBuffer[i] = rand()&255; - success = true; + else if (equals(param, F("test"))) + { + for (int16_t i = 0; i < Plugin_054_DMXSize; i++) { + // Plugin_054_DMXBuffer[i] = i+1; + Plugin_054_DMXBuffer[i] = rand() & 255; } + success = true; + } - else if (equals(param, F("on"))) - { - memset(Plugin_054_DMXBuffer, 255, Plugin_054_DMXSize); - success = true; - } + else if (equals(param, F("on"))) + { + memset(Plugin_054_DMXBuffer, 255, Plugin_054_DMXSize); + success = true; + } - else if (equals(param, F("off"))) + else if (equals(param, F("off"))) + { + memset(Plugin_054_DMXBuffer, 0, Plugin_054_DMXSize); + success = true; + } + + else + { + int16_t index = param.indexOf('='); + + if (index > 0) // syntax: "=" { - memset(Plugin_054_DMXBuffer, 0, Plugin_054_DMXSize); - success = true; + paramKey = param.substring(0, index); + paramVal = param.substring(index + 1); + channel = paramKey.toInt(); } - - else + else // syntax: "" { - int16_t index = param.indexOf('='); - if (index > 0) //syntax: "=" - { - paramKey = param.substring(0, index); - paramVal = param.substring(index+1); - channel = paramKey.toInt(); - } - else //syntax: "" - { - paramVal = param; - } + paramVal = param; + } - value = paramVal.toInt(); - PLUGIN_054_Limit (value, 0, 255); + value = paramVal.toInt(); + PLUGIN_054_Limit(value, 0, 255); - if (channel > 0 && channel <= Plugin_054_DMXSize) - Plugin_054_DMXBuffer[channel-1] = value; - channel++; + if ((channel > 0) && (channel <= Plugin_054_DMXSize)) { + Plugin_054_DMXBuffer[channel - 1] = value; } - - param = parseString(lowerString, paramIdx++); + channel++; } - } - else - { - //??? no params - } - success = true; + param = parseString(lowerString, paramIdx++); + } + } + else + { + // ??? no params } - break; + success = true; } + break; + } + case PLUGIN_TEN_PER_SECOND: + { + if (Plugin_054_DMXBuffer) { - if (Plugin_054_DMXBuffer) - { - int16_t sendPin = 2; //TX1 fix to GPIO2 (D4) == onboard LED - - //empty serial from prev. transmit - Serial1.flush(); - - //send break - Serial1.end(); - pinMode(sendPin, OUTPUT); - digitalWrite(sendPin, LOW); - delayMicroseconds(120); //88µs ... inf - digitalWrite(sendPin, HIGH); - delayMicroseconds(12); //8µs ... 1s - - //send DMX data - Serial1.begin(250000, SERIAL_8N2); - Serial1.write(0); //start uint8_t - Serial1.write(Plugin_054_DMXBuffer, Plugin_054_DMXSize); - } - break; + int16_t sendPin = 2; // TX1 fix to GPIO2 (D4) == onboard LED + + // empty serial from prev. transmit + Serial1.flush(); + + // send break + Serial1.end(); + pinMode(sendPin, OUTPUT); + digitalWrite(sendPin, LOW); + delayMicroseconds(120); // 88µs ... inf + digitalWrite(sendPin, HIGH); + delayMicroseconds(12); // 8µs ... 1s + + // send DMX data + Serial1.begin(250000, SERIAL_8N2); + Serial1.write(0); // start uint8_t + Serial1.write(Plugin_054_DMXBuffer, Plugin_054_DMXSize); } - + break; + } } return success; } diff --git a/src/_P055_Chiming.ino b/src/_P055_Chiming.ino index db2b3eb27f..828fe03dda 100644 --- a/src/_P055_Chiming.ino +++ b/src/_P055_Chiming.ino @@ -1,8 +1,9 @@ #include "_Plugin_Helper.h" #ifdef USES_P055 -//####################################################################################################### -//#################################### Plugin 055: Chiming Mechanism #################################### -//####################################################################################################### + +// ####################################################################################################### +// #################################### Plugin 055: Chiming Mechanism #################################### +// ####################################################################################################### // ESPEasy plugin to strike up to 4 physical bells and gongs with chiming sequences. // You also can use an antique door bell as a single strikes (not ringing) notification. @@ -15,7 +16,8 @@ // (3) CHIMEPLAY, Play saved tokens given name out of FFS // List of tokens: -// (a) '1'...'9', 'A'...'F' Bell number - 1=1st bell, 2=2nd bell, 4=3rd bell, 8=4th bell, numbers can be added to strike simultaniouly, F=all bells +// (a) '1'...'9', 'A'...'F' Bell number - 1=1st bell, 2=2nd bell, 4=3rd bell, 8=4th bell, numbers can be added to strike +// simultaniouly, F=all bells // (b) '!' Double strike prev. token // (c) '-' or ' ' Normal Pause // (d) '=' Long Pause (3 times normal) @@ -25,12 +27,14 @@ // Note: If no pause is specified, a normal pause will be inserted "111" -> "1-1-1" // Usage as Hourly Chime Clock: -// save twelve comma separated tokens with name "hours", enable checkbox "Hourly Chiming Clock Strike" in plugin web interface and enable NTP (advanced settings) +// save twelve comma separated tokens with name "hours", enable checkbox "Hourly Chiming Clock Strike" in plugin web interface and enable +// NTP (advanced settings) // // examples: // Historical coded with 1 bell: "1,11,111,1111,11111,111111,1111111,11111111,111111111,1111111111,11111111111,111111111111" // Binary coded with 2 bells (2nd bell=1): "1112,1121,1122,1211,1212,1221,1222,2111,2112,2121,2122,2211" -// Binary coded with 1 bell (short pause=1): "1_1_1_11,1_1_11_1,1_1_111,1_11_1_1,1_11_11,1_111_1,1_1111,11_1_1_1,11_1_11,11_11_1,11_111,111_1_1" +// Binary coded with 1 bell (short pause=1): +// "1_1_1_11,1_1_11_1,1_1_111,1_11_1_1,1_11_11,1_111_1,1_1111,11_1_1_1,11_1_11,11_11_1,11_111,111_1_1" // Binary coded with 1 bell (double strike=1):"1111!,111!1,111!1!,11!11,11!11!,11!1!1,11!1!1!,1!111,1!111!,1!11!1,1!11!1!,1!1!11" // // CHIMESAVE,hours,1111!,111!1,111!1!,11!11,11!11!,11!1!1,11!1!1!,1!111,1!111!,1!11!1,1!11!1!,1!1!11 @@ -47,35 +51,34 @@ // Use a power-FET or an ULN2003 to switch on the bells coil with 12 or 24 volts +// #include <*.h> - no external lib required -//#include <*.h> - no external lib required - -#include "src/WebServer/Markup_Buttons.h" +# include "src/WebServer/Markup_Buttons.h" -#define PLUGIN_055 -#define PLUGIN_ID_055 55 -#define PLUGIN_NAME_055 "Notify - Chiming" +# define PLUGIN_055 +# define PLUGIN_ID_055 55 +# define PLUGIN_NAME_055 "Notify - Chiming" -#define PLUGIN_055_FIFO_SIZE 64 // must be power of 2 -#define PLUGIN_055_FIFO_MASK (PLUGIN_055_FIFO_SIZE-1) +# define PLUGIN_055_FIFO_SIZE 64 // must be power of 2 +# define PLUGIN_055_FIFO_MASK (PLUGIN_055_FIFO_SIZE - 1) -class CPlugin_055_Data -{ +class CPlugin_055_Data { public: - long millisStateEnd = 0; + + long millisStateEnd = 0; long millisChimeTime = 60; long millisPauseTime = 400; - int pin[4] = {0}; - uint8_t lowActive = false; + int pin[4] = { 0 }; + uint8_t lowActive = false; uint8_t chimeClock = true; - char FIFO[PLUGIN_055_FIFO_SIZE] = {0}; - uint8_t FIFO_IndexR = 0; - uint8_t FIFO_IndexW = 0; + char FIFO[PLUGIN_055_FIFO_SIZE] = { 0 }; + uint8_t FIFO_IndexR = 0; + uint8_t FIFO_IndexW = 0; }; -static CPlugin_055_Data* Plugin_055_Data = nullptr; +static CPlugin_055_Data *Plugin_055_Data = nullptr; boolean Plugin_055(uint8_t function, struct EventStruct *event, String& string) @@ -85,35 +88,33 @@ boolean Plugin_055(uint8_t function, struct EventStruct *event, String& string) switch (function) { case PLUGIN_DEVICE_ADD: - { - Device[++deviceCount].Number = PLUGIN_ID_055; - Device[deviceCount].Type = DEVICE_TYPE_TRIPLE; - Device[deviceCount].Ports = 0; - Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_NONE; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = true; - Device[deviceCount].FormulaOption = false; - Device[deviceCount].ValueCount = 0; - Device[deviceCount].SendDataOption = false; - Device[deviceCount].TimerOption = false; - Device[deviceCount].TimerOptional = false; - Device[deviceCount].GlobalSyncOption = true; - break; - } + { + Device[++deviceCount].Number = PLUGIN_ID_055; + Device[deviceCount].Type = DEVICE_TYPE_TRIPLE; + Device[deviceCount].Ports = 0; + Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_NONE; + Device[deviceCount].InverseLogicOption = true; + Device[deviceCount].ValueCount = 0; + Device[deviceCount].GlobalSyncOption = true; + Device[deviceCount].Pin1Direction = gpio_direction::gpio_output; + Device[deviceCount].Pin2Direction = gpio_direction::gpio_output; + Device[deviceCount].Pin3Direction = gpio_direction::gpio_output; + break; + } case PLUGIN_GET_DEVICENAME: - { - string = F(PLUGIN_NAME_055); - break; - } + { + string = F(PLUGIN_NAME_055); + break; + } case PLUGIN_GET_DEVICEGPIONAMES: - { - event->String1 = formatGpioName_output(F("Driver#1")); - event->String2 = formatGpioName_output(F("Driver#2")); - event->String3 = formatGpioName_output(F("Driver#4")); - break; - } + { + event->String1 = formatGpioName_output(F("Driver#1")); + event->String2 = formatGpioName_output(F("Driver#2")); + event->String3 = formatGpioName_output(F("Driver#4")); + break; + } case PLUGIN_WEBFORM_SHOW_GPIO_DESCR: { @@ -123,266 +124,295 @@ boolean Plugin_055(uint8_t function, struct EventStruct *event, String& string) } case PLUGIN_WEBFORM_LOAD: - { - //default values - if (PCONFIG(0) <= 0) //Plugin_055_millisChimeTime - PCONFIG(0) = 60; - if (PCONFIG(1) <= 0) //Plugin_055_millisPauseTime - PCONFIG(1) = 400; + { + // default values + if (PCONFIG(0) <= 0) { // Plugin_055_millisChimeTime + PCONFIG(0) = 60; + } - // FIXME TD-er: Should we add support for 4 pin definitions? - addFormPinSelect(PinSelectPurpose::Generic_output, formatGpioName_output(F("Driver#8")), F("TDP4"), static_cast(Settings.TaskDevicePin[3][event->TaskIndex])); + if (PCONFIG(1) <= 0) { // Plugin_055_millisPauseTime + PCONFIG(1) = 400; + } - addFormSubHeader(F("Timing")); + // FIXME TD-er: Should we add support for 4 pin definitions? + addFormPinSelect(PinSelectPurpose::Generic_output, formatGpioName_output(F("Driver#8")), F("TDP4"), + static_cast(Settings.TaskDevicePin[3][event->TaskIndex])); - addFormNumericBox(F("Chiming/Strike Time (ct)"), F("chimetime"), PCONFIG(0)); - addUnit(F("ms")); + addFormSubHeader(F("Timing")); - addFormNumericBox(F("Normal Pause Time (t)"), F("pausetime"), PCONFIG(1)); - addUnit(F("ms")); + addFormNumericBox(F("Chiming/Strike Time (ct)"), F("chimetime"), PCONFIG(0)); + addUnit(F("ms")); - addFormNote(F("'1=1'⇒3t, '1-1' or '11'⇒1t, '1.1'⇒⅓t, '1|1'⇒½ct")); + addFormNumericBox(F("Normal Pause Time (t)"), F("pausetime"), PCONFIG(1)); + addUnit(F("ms")); + addFormNote(F("'1=1'⇒3t, '1-1' or '11'⇒1t, '1.1'⇒⅓t, '1|1'⇒½ct")); - addFormSubHeader(F("Chiming Clock")); - addFormCheckBox(F("Hourly Chiming Clock Strike"), F("chimeclock"), PCONFIG(2)); - //addHtml(F("")); - addButton(F("'control?cmd=chimeplay,hours'"), F("Test 1…12")); + addFormSubHeader(F("Chiming Clock")); - if (PCONFIG(2) && !(Settings.UseNTP())) - addFormNote(F("Enable and configure NTP!")); + addFormCheckBox(F("Hourly Chiming Clock Strike"), F("chimeclock"), PCONFIG(2)); - success = true; - break; + // addHtml(F("")); + addButton(F("'control?cmd=chimeplay,hours'"), F("Test 1…12")); + + if (PCONFIG(2) && !(Settings.UseNTP())) { + addFormNote(F("Enable and configure NTP!")); } + success = true; + break; + } + case PLUGIN_WEBFORM_SAVE: - { - Settings.TaskDevicePin[3][event->TaskIndex] = (int8_t)getFormItemInt(F("TDP4")); + { + Settings.TaskDevicePin[3][event->TaskIndex] = (int8_t)getFormItemInt(F("TDP4")); - PCONFIG(0) = getFormItemInt(F("chimetime")); - PCONFIG(1) = getFormItemInt(F("pausetime")); - PCONFIG(2) = isFormItemChecked(F("chimeclock")); + PCONFIG(0) = getFormItemInt(F("chimetime")); + PCONFIG(1) = getFormItemInt(F("pausetime")); + PCONFIG(2) = isFormItemChecked(F("chimeclock")); - success = true; - break; - } + success = true; + break; + } case PLUGIN_INIT: - { - if (!Plugin_055_Data) - Plugin_055_Data = new (std::nothrow) CPlugin_055_Data(); + { + if (!Plugin_055_Data) { + Plugin_055_Data = new (std::nothrow) CPlugin_055_Data(); + } - if (Plugin_055_Data != nullptr) { - Plugin_055_Data->lowActive = Settings.TaskDevicePin1Inversed[event->TaskIndex]; - Plugin_055_Data->millisChimeTime = PCONFIG(0); - Plugin_055_Data->millisPauseTime = PCONFIG(1); - Plugin_055_Data->chimeClock = PCONFIG(2); + if (Plugin_055_Data != nullptr) { + Plugin_055_Data->lowActive = Settings.TaskDevicePin1Inversed[event->TaskIndex]; + Plugin_055_Data->millisChimeTime = PCONFIG(0); + Plugin_055_Data->millisPauseTime = PCONFIG(1); + Plugin_055_Data->chimeClock = PCONFIG(2); - String log = F("Chime: GPIO: "); - for (uint8_t i = 0; i < 4; ++i) + String log = F("Chime: GPIO: "); + + for (uint8_t i = 0; i < 4; ++i) + { + int pin = Settings.TaskDevicePin[i][event->TaskIndex]; + Plugin_055_Data->pin[i] = pin; + + if (pin >= 0) { - int pin = Settings.TaskDevicePin[i][event->TaskIndex]; - Plugin_055_Data->pin[i] = pin; - if (pin >= 0) - { - pinMode(pin, OUTPUT); - digitalWrite(pin, Plugin_055_Data->lowActive); - } - log += pin; - log += ' '; + pinMode(pin, OUTPUT); + digitalWrite(pin, Plugin_055_Data->lowActive); } - if (Plugin_055_Data->lowActive) - log += F("!"); - addLogMove(LOG_LEVEL_INFO, log); - success = true; + log += pin; + log += ' '; } - break; + if (Plugin_055_Data->lowActive) { + log += F("!"); + } + addLogMove(LOG_LEVEL_INFO, log); + success = true; } + break; + } + case PLUGIN_EXIT: - { - if (Plugin_055_Data != nullptr) { - delete Plugin_055_Data; - Plugin_055_Data = nullptr; - } - break; + { + if (Plugin_055_Data != nullptr) { + delete Plugin_055_Data; + Plugin_055_Data = nullptr; } + break; + } case PLUGIN_WRITE: - { - if (!Plugin_055_Data) - break; + { + if (!Plugin_055_Data) { + break; + } - String command = parseString(string, 1); + String command = parseString(string, 1); - if (equals(command, F("chime"))) - { - String param = parseStringToEndKeepCase(string, 2); - if (param.length() > 0) { - Plugin_055_AddStringFIFO(param); - } - success = true; + if (equals(command, F("chime"))) + { + String param = parseStringToEndKeepCase(string, 2); + + if (param.length() > 0) { + Plugin_055_AddStringFIFO(param); } - if (equals(command, F("chimeplay"))) - { - String name = parseString(string, 2); - if (name.length() > 0) { - String param; - Plugin_055_ReadChime(name, param); - Plugin_055_AddStringFIFO(param); - } - success = true; + success = true; + } + + if (equals(command, F("chimeplay"))) + { + String name = parseString(string, 2); + + if (name.length() > 0) { + String param; + Plugin_055_ReadChime(name, param); + Plugin_055_AddStringFIFO(param); } - if (equals(command, F("chimesave"))) - { - String name = parseString(string, 2); - String param = parseStringToEndKeepCase(string, 3); - if (name.length() > 0 && param.length() > 0) { - Plugin_055_WriteChime(name, param); - Plugin_055_AddStringFIFO("1"); - } - success = true; + success = true; + } + + if (equals(command, F("chimesave"))) + { + String name = parseString(string, 2); + String param = parseStringToEndKeepCase(string, 3); + + if ((name.length() > 0) && (param.length() > 0)) { + Plugin_055_WriteChime(name, param); + Plugin_055_AddStringFIFO("1"); } + success = true; + } + break; + } + + case PLUGIN_CLOCK_IN: + { + if (!Plugin_055_Data) { break; } - case PLUGIN_CLOCK_IN: - { - if (!Plugin_055_Data) - break; + String tokens; + uint8_t hours = node_time.hour(); + const uint8_t minutes = node_time.minute(); - String tokens; - uint8_t hours = node_time.hour(); - const uint8_t minutes = node_time.minute(); + if (Plugin_055_Data->chimeClock) + { + const String tmpString = strformat(F("%02d%02d"), hours, minutes); - if (Plugin_055_Data->chimeClock) - { - const String tmpString = strformat(F("%02d%02d"), hours, minutes); - if (Plugin_055_ReadChime(tmpString, tokens)) - Plugin_055_AddStringFIFO(tokens); + if (Plugin_055_ReadChime(tmpString, tokens)) { + Plugin_055_AddStringFIFO(tokens); + } - if (minutes == 0) - { - if (Plugin_055_ReadChime("hours", tokens) == 0) - tokens = F("1111!,111!1,111!1!,11!11,11!11!,11!1!1,11!1!1!,1!111,1!111!,1!11!1,1!11!1!,1!1!11"); //1..12 + if (minutes == 0) + { + if (Plugin_055_ReadChime("hours", tokens) == 0) { + tokens = F("1111!,111!1,111!1!,11!11,11!11!,11!1!1,11!1!1!,1!111,1!111!,1!11!1,1!11!1!,1!1!11"); // 1..12 + } - // hours 0..23 -> 1..12 - hours = hours % 12; - if (hours == 0) - hours = 12; + // hours 0..23 -> 1..12 + hours = hours % 12; - tokens = parseString(tokens, hours); - Plugin_055_AddStringFIFO(tokens); - } + if (hours == 0) { + hours = 12; } - success = true; - break; + tokens = parseString(tokens, hours); + Plugin_055_AddStringFIFO(tokens); } + } + + success = true; + break; + } case PLUGIN_FIFTY_PER_SECOND: - //case PLUGIN_TEN_PER_SECOND: - { - if (!Plugin_055_Data) - break; + // case PLUGIN_TEN_PER_SECOND: + { + if (!Plugin_055_Data) { + break; + } - long millisAct = millis(); + long millisAct = millis(); - if (Plugin_055_Data->millisStateEnd > 0) // just striking? + if (Plugin_055_Data->millisStateEnd > 0) // just striking? + { + if (timeDiff(millisAct, Plugin_055_Data->millisStateEnd) <= 0) // end reached? { - if (timeDiff(millisAct, Plugin_055_Data->millisStateEnd) <= 0) // end reached? + for (uint8_t i = 0; i < 4; ++i) { - for (uint8_t i = 0; i < 4; ++i) - { - if (Plugin_055_Data->pin[i] >= 0) - digitalWrite(Plugin_055_Data->pin[i], Plugin_055_Data->lowActive); + if (Plugin_055_Data->pin[i] >= 0) { + digitalWrite(Plugin_055_Data->pin[i], Plugin_055_Data->lowActive); } - Plugin_055_Data->millisStateEnd = 0; } + Plugin_055_Data->millisStateEnd = 0; } + } - if (Plugin_055_Data->millisStateEnd == 0) // just finished? + if (Plugin_055_Data->millisStateEnd == 0) // just finished? + { + if (!Plugin_055_IsEmptyFIFO()) { - if (! Plugin_055_IsEmptyFIFO()) - { - char c = Plugin_055_ReadFIFO(); + char c = Plugin_055_ReadFIFO(); # ifndef BUILD_NO_DEBUG - if (loglevelActiveFor(LOG_LEVEL_DEBUG)) { - addLog(LOG_LEVEL_DEBUG, strformat(F("Chime: Process '%c'"), c)); - } - #endif - switch (c) + if (loglevelActiveFor(LOG_LEVEL_DEBUG)) { + addLog(LOG_LEVEL_DEBUG, strformat(F("Chime: Process '%c'"), c)); + } + # endif // ifndef BUILD_NO_DEBUG + + switch (c) + { + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + c -= 'A' - '0' - 10; + + // vvv + + case '0': // strikes 1=1st bell, 2=2nd bell, 4=3rd bell, 8=4rd bell + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': { - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - c -= 'A' - '0' - 10; - //vvv - - case '0': //strikes 1=1st bell, 2=2nd bell, 4=3rd bell, 8=4rd bell - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': + uint8_t mask = 1; + + for (uint8_t i = 0; i < 4; ++i) { - uint8_t mask = 1; - for (uint8_t i = 0; i < 4; ++i) - { - if (Plugin_055_Data->pin[i] >= 0) - if (c & mask) - digitalWrite(Plugin_055_Data->pin[i], !Plugin_055_Data->lowActive); - mask <<= 1; + if (Plugin_055_Data->pin[i] >= 0) { + if (c & mask) { + digitalWrite(Plugin_055_Data->pin[i], !Plugin_055_Data->lowActive); + } } - Plugin_055_Data->millisStateEnd = millisAct + Plugin_055_Data->millisChimeTime; - break; + mask <<= 1; } - case '=': //long pause - case ' ': - case ',': - Plugin_055_Data->millisStateEnd = millisAct + Plugin_055_Data->millisPauseTime*3; - break; - case '-': //single pause - Plugin_055_Data->millisStateEnd = millisAct + Plugin_055_Data->millisPauseTime; - break; - case '.': //short pause - Plugin_055_Data->millisStateEnd = millisAct + Plugin_055_Data->millisPauseTime/3; - break; - case '|': //shortest pause - Plugin_055_Data->millisStateEnd = millisAct + Plugin_055_Data->millisChimeTime/2; - break; - case '#': //comment -> eat till FIFO is empty - while (Plugin_055_ReadFIFO()); - break; - default: //unknown char -> do nothing - break; + Plugin_055_Data->millisStateEnd = millisAct + Plugin_055_Data->millisChimeTime; + break; } + case '=': // long pause + case ' ': + case ',': + Plugin_055_Data->millisStateEnd = millisAct + Plugin_055_Data->millisPauseTime * 3; + break; + case '-': // single pause + Plugin_055_Data->millisStateEnd = millisAct + Plugin_055_Data->millisPauseTime; + break; + case '.': // short pause + Plugin_055_Data->millisStateEnd = millisAct + Plugin_055_Data->millisPauseTime / 3; + break; + case '|': // shortest pause + Plugin_055_Data->millisStateEnd = millisAct + Plugin_055_Data->millisChimeTime / 2; + break; + case '#': // comment -> eat till FIFO is empty + + while (Plugin_055_ReadFIFO()) {} + break; + default: // unknown char -> do nothing + break; } - } - success = true; - break; } - + success = true; + break; + } } return success; } @@ -391,8 +421,9 @@ boolean Plugin_055(uint8_t function, struct EventStruct *event, String& string) void Plugin_055_WriteFIFO(char c) { - if (Plugin_055_Data->FIFO_IndexR == ((Plugin_055_Data->FIFO_IndexW+1) & PLUGIN_055_FIFO_MASK)) // FIFO full? + if (Plugin_055_Data->FIFO_IndexR == ((Plugin_055_Data->FIFO_IndexW + 1) & PLUGIN_055_FIFO_MASK)) { // FIFO full? return; + } Plugin_055_Data->FIFO[Plugin_055_Data->FIFO_IndexW] = c; Plugin_055_Data->FIFO_IndexW++; @@ -401,10 +432,12 @@ void Plugin_055_WriteFIFO(char c) char Plugin_055_ReadFIFO() { - if (Plugin_055_IsEmptyFIFO()) + if (Plugin_055_IsEmptyFIFO()) { return '\0'; + } char c = Plugin_055_Data->FIFO[Plugin_055_Data->FIFO_IndexR]; + Plugin_055_Data->FIFO_IndexR++; Plugin_055_Data->FIFO_IndexR &= PLUGIN_055_FIFO_MASK; @@ -413,31 +446,35 @@ char Plugin_055_ReadFIFO() char Plugin_055_PeekFIFO() { - if (Plugin_055_IsEmptyFIFO()) + if (Plugin_055_IsEmptyFIFO()) { return '\0'; + } return Plugin_055_Data->FIFO[Plugin_055_Data->FIFO_IndexR]; } boolean Plugin_055_IsEmptyFIFO() { - return (Plugin_055_Data->FIFO_IndexR == Plugin_055_Data->FIFO_IndexW); + return Plugin_055_Data->FIFO_IndexR == Plugin_055_Data->FIFO_IndexW; } void Plugin_055_AddStringFIFO(const String& param) { - if (param.isEmpty()) + if (param.isEmpty()) { return; + } - uint8_t i = 0; - char c = param[i]; - char c_last = '\0'; + uint8_t i = 0; + char c = param[i]; + char c_last = '\0'; while (c != 0) { - if (isDigit(c) && isDigit(c_last)) // "11" is shortcut for "1-1" -> add pause + if (isDigit(c) && isDigit(c_last)) { // "11" is shortcut for "1-1" -> add pause Plugin_055_WriteFIFO('-'); - if (c == '!') //double strike -> add shortest pause and repeat last strike + } + + if (c == '!') // double strike -> add shortest pause and repeat last strike { Plugin_055_WriteFIFO('|'); c = c_last; @@ -451,24 +488,29 @@ void Plugin_055_AddStringFIFO(const String& param) Plugin_055_WriteFIFO('='); } -//File I/O functions +// File I/O functions void Plugin_055_WriteChime(const String& name, const String& tokens) { const String fileName = strformat(F("chime_%s.txt"), name.c_str()); String log; - if (loglevelActiveFor(LOG_LEVEL_INFO)) + + if (loglevelActiveFor(LOG_LEVEL_INFO)) { log = strformat(F("Chime: write %s "), fileName.c_str()); + } fs::File f = tryOpenFile(fileName, "w"); + if (f) { f.print(tokens); f.close(); - //flashCount(); - if (loglevelActiveFor(LOG_LEVEL_INFO)) + + // flashCount(); + if (loglevelActiveFor(LOG_LEVEL_INFO)) { log += tokens; + } } addLogMove(LOG_LEVEL_INFO, log); @@ -479,23 +521,29 @@ uint8_t Plugin_055_ReadChime(const String& name, String& tokens) const String fileName = strformat(F("chime_%s.txt"), name.c_str()); String log; - if (loglevelActiveFor(LOG_LEVEL_INFO)) + + if (loglevelActiveFor(LOG_LEVEL_INFO)) { log = strformat(F("Chime: read %s "), fileName.c_str()); + } tokens = String(); fs::File f = tryOpenFile(fileName, "r"); + if (f) { tokens.reserve(f.size()); char c; + while (f.available()) { - c = f.read(); + c = f.read(); tokens += c; } f.close(); - if (loglevelActiveFor(LOG_LEVEL_INFO)) + + if (loglevelActiveFor(LOG_LEVEL_INFO)) { log += tokens; + } } addLogMove(LOG_LEVEL_INFO, log); diff --git a/src/_P063_TTP229_KeyPad.ino b/src/_P063_TTP229_KeyPad.ino index 9d5f1a2523..b33599a3ab 100644 --- a/src/_P063_TTP229_KeyPad.ino +++ b/src/_P063_TTP229_KeyPad.ino @@ -1,14 +1,17 @@ #include "_Plugin_Helper.h" #ifdef USES_P063 -//####################################################################################################### -//#################################### Plugin 063: TTP229 KeyPad ######################################## -//####################################################################################################### + +// ####################################################################################################### +// #################################### Plugin 063: TTP229 KeyPad ######################################## +// ####################################################################################################### // ESPEasy Plugin to scan a 16 key touch pad chip TTP229 // written by Jochen Krapf (jk@nerd2nerd.org) -// Important: There are several types of TTP299 chips with different features available. They are named all TTP229 but differ in the letter(s) followed. -// On the china boards (found on eBay and AliExpress) the TTP229-B is used which has NO! I2C-interface. It uses a proprietary serial protocol with clock (SCL) and bidirectional data (SDO) +// Important: There are several types of TTP299 chips with different features available. They are named all TTP229 but differ in the +// letter(s) followed. +// On the china boards (found on eBay and AliExpress) the TTP229-B is used which has NO! I2C-interface. It uses a proprietary serial +// protocol with clock (SCL) and bidirectional data (SDO) // ScanCode; // Value 1...16 for the key number @@ -24,17 +27,16 @@ // Schematics: https://www.openimpulse.com/blog/wp-content/uploads/wpsc/downloadables/TTP229B-Schematic-Diagram.pdf // Datasheet: http://www.datasheet4u.com/download_new.php?id=996751 -#define PLUGIN_063 -#define PLUGIN_ID_063 63 -#define PLUGIN_NAME_063 "Keypad - TTP229 Touch" -#define PLUGIN_VALUENAME1_063 "ScanCode" - +# define PLUGIN_063 +# define PLUGIN_ID_063 63 +# define PLUGIN_NAME_063 "Keypad - TTP229 Touch" +# define PLUGIN_VALUENAME1_063 "ScanCode" uint16_t readTTP229(int16_t pinSCL, int16_t pinSDO) { uint16_t value = 0; - uint16_t mask = 1; + uint16_t mask = 1; pinMode(pinSDO, OUTPUT); digitalWrite(pinSDO, HIGH); @@ -44,11 +46,13 @@ uint16_t readTTP229(int16_t pinSCL, int16_t pinSDO) delayMicroseconds(10); pinMode(pinSDO, INPUT); + for (uint8_t i = 0; i < 16; ++i) { digitalWrite(pinSCL, HIGH); delayMicroseconds(1); digitalWrite(pinSCL, LOW); + if (!digitalRead(pinSDO)) { value |= mask; } @@ -59,7 +63,6 @@ uint16_t readTTP229(int16_t pinSCL, int16_t pinSDO) return value; } - boolean Plugin_063(uint8_t function, struct EventStruct *event, String& string) { boolean success = false; @@ -67,153 +70,159 @@ boolean Plugin_063(uint8_t function, struct EventStruct *event, String& string) switch (function) { case PLUGIN_DEVICE_ADD: - { - Device[++deviceCount].Number = PLUGIN_ID_063; - Device[deviceCount].Type = DEVICE_TYPE_DUAL; - Device[deviceCount].Ports = 0; - Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SWITCH; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = false; - Device[deviceCount].ValueCount = 1; - Device[deviceCount].SendDataOption = true; - Device[deviceCount].TimerOption = true; - Device[deviceCount].TimerOptional = true; - Device[deviceCount].GlobalSyncOption = true; - break; - } + { + Device[++deviceCount].Number = PLUGIN_ID_063; + Device[deviceCount].Type = DEVICE_TYPE_DUAL; + Device[deviceCount].Ports = 0; + Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SWITCH; + Device[deviceCount].ValueCount = 1; + Device[deviceCount].SendDataOption = true; + Device[deviceCount].TimerOption = true; + Device[deviceCount].TimerOptional = true; + Device[deviceCount].GlobalSyncOption = true; + Device[deviceCount].Pin1Direction = gpio_direction::gpio_output; + break; + } case PLUGIN_GET_DEVICENAME: - { - string = F(PLUGIN_NAME_063); - break; - } + { + string = F(PLUGIN_NAME_063); + break; + } case PLUGIN_GET_DEVICEVALUENAMES: - { - strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_063)); - break; - } + { + strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_063)); + break; + } case PLUGIN_GET_DEVICEGPIONAMES: - { - event->String1 = formatGpioName_output(F("SCL")); - event->String2 = formatGpioName_bidirectional(F("SDO")); - break; - } + { + event->String1 = formatGpioName_output(F("SCL")); + event->String2 = formatGpioName_bidirectional(F("SDO")); + break; + } case PLUGIN_WEBFORM_LOAD: - { - addFormCheckBox(F("ScanCode"), F("scancode"), PCONFIG(1)); + { + addFormCheckBox(F("ScanCode"), F("scancode"), PCONFIG(1)); - success = true; - break; - } + success = true; + break; + } case PLUGIN_WEBFORM_SAVE: - { - PCONFIG(1) = isFormItemChecked(F("scancode")); + { + PCONFIG(1) = isFormItemChecked(F("scancode")); - success = true; - break; - } + success = true; + break; + } case PLUGIN_INIT: + { + portStatusStruct newStatus; + + int16_t pinSCL = CONFIG_PIN1; + int16_t pinSDO = CONFIG_PIN2; + + if (loglevelActiveFor(LOG_LEVEL_INFO)) { + addLog(LOG_LEVEL_INFO, strformat(F("Tkey : GPIO: %d %d"), pinSCL, pinSDO)); + } + + if (validGpio(pinSCL) && validGpio(pinSDO)) { - portStatusStruct newStatus; + pinMode(pinSCL, OUTPUT); + digitalWrite(pinSCL, LOW); - int16_t pinSCL = CONFIG_PIN1; - int16_t pinSDO = CONFIG_PIN2; + constexpr pluginID_t P063_PLUGIN_ID{ PLUGIN_ID_063 }; - if (loglevelActiveFor(LOG_LEVEL_INFO)) { - addLog(LOG_LEVEL_INFO, strformat(F("Tkey : GPIO: %d %d"), pinSCL, pinSDO)); - } + uint32_t key = createKey(P063_PLUGIN_ID, pinSCL); - if (validGpio(pinSCL) && validGpio(pinSDO)) - { - pinMode(pinSCL, OUTPUT); - digitalWrite(pinSCL, LOW); - - constexpr pluginID_t P063_PLUGIN_ID{PLUGIN_ID_063}; - - uint32_t key = createKey(P063_PLUGIN_ID, pinSCL); - // WARNING: operator [] creates an entry in the map if key does not exist - newStatus = globalMapPortStatus[key]; - newStatus.task++; // add this GPIO/port as a task - newStatus.mode = PIN_MODE_OUTPUT; - newStatus.state = 0; - savePortStatus(key,newStatus); - //setPinState(PLUGIN_ID_063, pinSCL, PIN_MODE_OUTPUT, 0); - - pinMode(pinSDO, OUTPUT); - digitalWrite(pinSDO, LOW); - key = createKey(P063_PLUGIN_ID, pinSDO); - // WARNING: operator [] creates an entry in the map if key does not exist - newStatus = globalMapPortStatus[key]; - newStatus.task++; // add this GPIO/port as a task - newStatus.mode = PIN_MODE_INPUT; - newStatus.state = 0; - savePortStatus(key,newStatus); - //setPinState(PLUGIN_ID_063, pinSDO, PIN_MODE_INPUT, 0); - success = true; - } + // WARNING: operator [] creates an entry in the map if key does not exist + newStatus = globalMapPortStatus[key]; + newStatus.task++; // add this GPIO/port as a task + newStatus.mode = PIN_MODE_OUTPUT; + newStatus.state = 0; + savePortStatus(key, newStatus); + + // setPinState(PLUGIN_ID_063, pinSCL, PIN_MODE_OUTPUT, 0); - break; + pinMode(pinSDO, OUTPUT); + digitalWrite(pinSDO, LOW); + key = createKey(P063_PLUGIN_ID, pinSDO); + + // WARNING: operator [] creates an entry in the map if key does not exist + newStatus = globalMapPortStatus[key]; + newStatus.task++; // add this GPIO/port as a task + newStatus.mode = PIN_MODE_INPUT; + newStatus.state = 0; + savePortStatus(key, newStatus); + + // setPinState(PLUGIN_ID_063, pinSDO, PIN_MODE_INPUT, 0); + success = true; } + break; + } + case PLUGIN_TEN_PER_SECOND: - { - static uint16_t keyLast = 0; - int16_t pinSCL = CONFIG_PIN1; - int16_t pinSDO = CONFIG_PIN2; + { + static uint16_t keyLast = 0; + int16_t pinSCL = CONFIG_PIN1; + int16_t pinSDO = CONFIG_PIN2; - uint16_t key = readTTP229(pinSCL, pinSDO); + uint16_t key = readTTP229(pinSCL, pinSDO); + + if (key && PCONFIG(1)) + { + uint16_t colMask = 0x01; - if (key && PCONFIG(1)) + for (uint8_t col = 1; col <= 16; ++col) { - uint16_t colMask = 0x01; - for (uint8_t col = 1; col <= 16; ++col) + if (key & colMask) // this key pressed? { - if (key & colMask) // this key pressed? - { - key = col; - break; - } - colMask <<= 1; + key = col; + break; } + colMask <<= 1; } + } - if (keyLast != key) - { - keyLast = key; - UserVar.setFloat(event->TaskIndex, 0, key); - event->sensorType = Sensor_VType::SENSOR_TYPE_SWITCH; - - if (loglevelActiveFor(LOG_LEVEL_INFO)) { - String log = F("Tkey : "); - if (PCONFIG(1)) - log = F("ScanCode="); - else - log = F("KeyMap="); - log += formatToHex(key); - addLogMove(LOG_LEVEL_INFO, log); - } + if (keyLast != key) + { + keyLast = key; + UserVar.setFloat(event->TaskIndex, 0, key); + event->sensorType = Sensor_VType::SENSOR_TYPE_SWITCH; + + if (loglevelActiveFor(LOG_LEVEL_INFO)) { + String log = F("Tkey : "); - sendData(event); + if (PCONFIG(1)) { + log = F("ScanCode="); + } + else { + log = F("KeyMap="); + } + log += formatToHex(key); + addLogMove(LOG_LEVEL_INFO, log); } - success = true; - break; + sendData(event); } - case PLUGIN_READ: - { - // work is done in PLUGIN_TEN_PER_SECOND - success = true; - break; - } + success = true; + break; + } + case PLUGIN_READ: + { + // work is done in PLUGIN_TEN_PER_SECOND + success = true; + break; + } } return success; } + #endif // USES_P063 diff --git a/src/_P067_HX711_Load_Cell.ino b/src/_P067_HX711_Load_Cell.ino index af4fa2c52b..9452f1efdd 100644 --- a/src/_P067_HX711_Load_Cell.ino +++ b/src/_P067_HX711_Load_Cell.ino @@ -42,19 +42,16 @@ boolean Plugin_067(uint8_t function, struct EventStruct *event, String& string) { case PLUGIN_DEVICE_ADD: { - Device[++deviceCount].Number = PLUGIN_ID_067; - Device[deviceCount].Type = DEVICE_TYPE_DUAL; - Device[deviceCount].Ports = 0; - Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_DUAL; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = true; - Device[deviceCount].ValueCount = 2; - Device[deviceCount].SendDataOption = true; - Device[deviceCount].TimerOption = true; - Device[deviceCount].TimerOptional = false; - Device[deviceCount].GlobalSyncOption = true; - Device[deviceCount].PluginStats = true; + Device[++deviceCount].Number = PLUGIN_ID_067; + Device[deviceCount].Type = DEVICE_TYPE_DUAL; + Device[deviceCount].Ports = 0; + Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_DUAL; + Device[deviceCount].FormulaOption = true; + Device[deviceCount].ValueCount = 2; + Device[deviceCount].SendDataOption = true; + Device[deviceCount].TimerOption = true; + Device[deviceCount].PluginStats = true; + Device[deviceCount].Pin1Direction = gpio_direction::gpio_output; break; } diff --git a/src/_P070_NeoPixel_Clock.ino b/src/_P070_NeoPixel_Clock.ino index 1c1a8381f8..2de1610378 100644 --- a/src/_P070_NeoPixel_Clock.ino +++ b/src/_P070_NeoPixel_Clock.ino @@ -36,17 +36,12 @@ boolean Plugin_070(uint8_t function, struct EventStruct *event, String& string) { case PLUGIN_DEVICE_ADD: { - Device[++deviceCount].Number = PLUGIN_ID_070; - Device[deviceCount].Type = DEVICE_TYPE_SINGLE; - Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_TRIPLE; - Device[deviceCount].Ports = 0; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = false; - Device[deviceCount].ValueCount = 3; - Device[deviceCount].SendDataOption = false; - Device[deviceCount].TimerOption = false; - Device[deviceCount].GlobalSyncOption = false; + Device[++deviceCount].Number = PLUGIN_ID_070; + Device[deviceCount].Type = DEVICE_TYPE_SINGLE; + Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_TRIPLE; + Device[deviceCount].Ports = 0; + Device[deviceCount].ValueCount = 3; + Device[deviceCount].Pin1Direction = gpio_direction::gpio_output; // FIXME TD-er: Not sure if access to any existing task data is needed when saving Device[deviceCount].ExitTaskBeforeSave = false; diff --git a/src/_P073_7DGT.ino b/src/_P073_7DGT.ino index 1e3102f1b7..d0f07b42de 100644 --- a/src/_P073_7DGT.ino +++ b/src/_P073_7DGT.ino @@ -87,18 +87,14 @@ boolean Plugin_073(uint8_t function, struct EventStruct *event, String& string) switch (function) { case PLUGIN_DEVICE_ADD: { - Device[++deviceCount].Number = PLUGIN_ID_073; - Device[deviceCount].Type = DEVICE_TYPE_TRIPLE; - Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_NONE; - Device[deviceCount].Ports = 0; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = false; - Device[deviceCount].ValueCount = 0; - Device[deviceCount].SendDataOption = false; - Device[deviceCount].TimerOption = false; - Device[deviceCount].TimerOptional = false; - Device[deviceCount].GlobalSyncOption = true; + Device[++deviceCount].Number = PLUGIN_ID_073; + Device[deviceCount].Type = DEVICE_TYPE_TRIPLE; + Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_NONE; + Device[deviceCount].Ports = 0; + Device[deviceCount].ValueCount = 0; + Device[deviceCount].Pin1Direction = gpio_direction::gpio_output; + Device[deviceCount].Pin2Direction = gpio_direction::gpio_output; + Device[deviceCount].Pin3Direction = gpio_direction::gpio_output; break; } @@ -868,7 +864,7 @@ bool p073_plugin_write_7dfont(struct EventStruct *event, } if (!text.isEmpty()) { - String fontArg = parseString(text, 1); + String fontArg = parseString(text, 1); int32_t fontNr = -1; if ((equals(fontArg, F("default"))) || (equals(fontArg, F("7dgt")))) { @@ -912,10 +908,10 @@ bool p073_plugin_write_7dbin(struct EventStruct *event, } if (!text.isEmpty()) { - String data; + String data; int32_t byteValue{}; - int arg = 1; - String argValue = parseString(text, arg); + int arg = 1; + String argValue = parseString(text, arg); while (!argValue.isEmpty()) { if (validIntFromString(argValue, byteValue) && (byteValue < 256) && (byteValue > -1)) { @@ -1297,10 +1293,10 @@ void tm1637_ShowBuffer(struct EventStruct *event, # define OP_SHUTDOWN 12 # define OP_DISPLAYTEST 15 -void max7219_spiTransfer(struct EventStruct *event, - uint8_t din_pin, - uint8_t clk_pin, - uint8_t cs_pin, +void max7219_spiTransfer(struct EventStruct *event, + uint8_t din_pin, + uint8_t clk_pin, + uint8_t cs_pin, ESPEASY_VOLATILE(uint8_t) opcode, ESPEASY_VOLATILE(uint8_t) data) { P073_data_struct *P073_data = diff --git a/src/_P076_HLW8012.ino b/src/_P076_HLW8012.ino index 041dcd285e..58c90e0c55 100644 --- a/src/_P076_HLW8012.ino +++ b/src/_P076_HLW8012.ino @@ -109,18 +109,16 @@ boolean Plugin_076(uint8_t function, struct EventStruct *event, String& string) switch (function) { case PLUGIN_DEVICE_ADD: { - Device[++deviceCount].Number = PLUGIN_ID_076; - Device[deviceCount].Type = DEVICE_TYPE_TRIPLE; - Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_QUAD; - Device[deviceCount].Ports = 0; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = true; - Device[deviceCount].ValueCount = 4; - Device[deviceCount].SendDataOption = true; - Device[deviceCount].TimerOption = true; - Device[deviceCount].GlobalSyncOption = false; - Device[deviceCount].PluginStats = true; + Device[++deviceCount].Number = PLUGIN_ID_076; + Device[deviceCount].Type = DEVICE_TYPE_TRIPLE; + Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_QUAD; + Device[deviceCount].Ports = 0; + Device[deviceCount].FormulaOption = true; + Device[deviceCount].ValueCount = 4; + Device[deviceCount].SendDataOption = true; + Device[deviceCount].TimerOption = true; + Device[deviceCount].PluginStats = true; + Device[deviceCount].Pin1Direction = gpio_direction::gpio_output; break; } diff --git a/src/_P088_HeatpumpIR.ino b/src/_P088_HeatpumpIR.ino index 66155b16f8..0696c9cef9 100644 --- a/src/_P088_HeatpumpIR.ino +++ b/src/_P088_HeatpumpIR.ino @@ -1,12 +1,13 @@ #include "_Plugin_Helper.h" #ifdef USES_P088 -//####################################################################################################### -//#################################### Plugin 088: Heatpump IR ########################################## -//####################################################################################################### -#define PLUGIN_088 -#define PLUGIN_ID_088 88 -#define PLUGIN_NAME_088 "Energy (Heat) - Heatpump IR transmitter" +// ####################################################################################################### +// #################################### Plugin 088: Heatpump IR ########################################## +// ####################################################################################################### + +# define PLUGIN_088 +# define PLUGIN_ID_088 88 +# define PLUGIN_NAME_088 "Energy (Heat) - Heatpump IR transmitter" /* @@ -32,7 +33,8 @@ * Take a look at https://github.com/ToniA/cabin-village-project/blob/eventscripts/script_device_hp.lua for Domoticz event examples * * The parameters are (in this order) - * * The type of the heatpump as a string, see the implementations of different models, like https://github.com/ToniA/arduino-heatpumpir/blob/master/MitsubishiHeatpumpIR.cpp + * * The type of the heatpump as a string, see the implementations of different models, like + *https://github.com/ToniA/arduino-heatpumpir/blob/master/MitsubishiHeatpumpIR.cpp * * power state (see https://github.com/ToniA/arduino-heatpumpir/blob/master/HeatpumpIR.h for modes) * * operating mode * * fan speed @@ -44,12 +46,12 @@ * */ -#include +# include -#include "ESPEasy-Globals.h" +# include "ESPEasy-Globals.h" IRSenderIRremoteESP8266 *Plugin_088_irSender = nullptr; -int panasonicCKPTimer = 0; +int panasonicCKPTimer = 0; boolean Plugin_088(uint8_t function, struct EventStruct *event, String& string) { @@ -58,197 +60,206 @@ boolean Plugin_088(uint8_t function, struct EventStruct *event, String& string) switch (function) { case PLUGIN_DEVICE_ADD: - { - Device[++deviceCount].Number = PLUGIN_ID_088; - Device[deviceCount].Type = DEVICE_TYPE_SINGLE; - Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_NONE; - Device[deviceCount].Ports = 0; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = false; - Device[deviceCount].ValueCount = 0; - Device[deviceCount].SendDataOption = false; - Device[deviceCount].TimerOption = false; - Device[deviceCount].TimerOptional = false; - Device[deviceCount].GlobalSyncOption = false; - Device[deviceCount].DecimalsOnly = false; - - break; - } + { + Device[++deviceCount].Number = PLUGIN_ID_088; + Device[deviceCount].Type = DEVICE_TYPE_SINGLE; + Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_NONE; + Device[deviceCount].Ports = 0; + Device[deviceCount].ValueCount = 0; + Device[deviceCount].Pin1Direction = gpio_direction::gpio_output; + + break; + } case PLUGIN_GET_DEVICENAME: - { - string = F(PLUGIN_NAME_088); - break; - } + { + string = F(PLUGIN_NAME_088); + break; + } case PLUGIN_GET_DEVICEVALUENAMES: - { - break; - } + { + break; + } case PLUGIN_WEBFORM_LOAD: - { - // We need the index of the controller we are: 0-CONTROLLER_MAX - // FIXME TD-er: Why looking for Domoticz MQTT? Other plugins also support IDX values. - controllerIndex_t controllerNr = 0; - for (controllerIndex_t i=0; i < CONTROLLER_MAX; i++) - { - if (Settings.Protocol[i] == 2) { controllerNr = i; } - } + { + // We need the index of the controller we are: 0-CONTROLLER_MAX + // FIXME TD-er: Why looking for Domoticz MQTT? Other plugins also support IDX values. + controllerIndex_t controllerNr = 0; - if (Settings.ControllerEnabled[controllerNr]) - { - addRowLabel(F("IDX")); - String id = F("TDID"); //="taskdeviceid" - id += controllerNr + 1; - addNumericBox(id, Settings.TaskDeviceID[controllerNr][event->TaskIndex], 0, 9999); - } - success = true; - break; + for (controllerIndex_t i = 0; i < CONTROLLER_MAX; i++) + { + if (Settings.Protocol[i] == 2) { controllerNr = i; } } - case PLUGIN_WEBFORM_SAVE: + if (Settings.ControllerEnabled[controllerNr]) { - success = true; - break; + addRowLabel(F("IDX")); + String id = F("TDID"); // ="taskdeviceid" + id += controllerNr + 1; + addNumericBox(id, Settings.TaskDeviceID[controllerNr][event->TaskIndex], 0, 9999); } + success = true; + break; + } + + case PLUGIN_WEBFORM_SAVE: + { + success = true; + break; + } case PLUGIN_INIT: + { + int irPin = CONFIG_PIN1; + + if (validGpio(irPin)) { - int irPin = CONFIG_PIN1; - if (validGpio(irPin)) - { - addLog(LOG_LEVEL_INFO, F("P088: Heatpump IR transmitter activated")); - if (Plugin_088_irSender != nullptr) - { - delete Plugin_088_irSender; - } - Plugin_088_irSender = new (std::nothrow) IRSenderIRremoteESP8266(irPin); - } - if (Plugin_088_irSender != nullptr && irPin == -1) + addLog(LOG_LEVEL_INFO, F("P088: Heatpump IR transmitter activated")); + + if (Plugin_088_irSender != nullptr) { - addLog(LOG_LEVEL_INFO, F("P088: Heatpump IR transmitter deactivated")); delete Plugin_088_irSender; - Plugin_088_irSender = nullptr; } - success = true; - break; + Plugin_088_irSender = new (std::nothrow) IRSenderIRremoteESP8266(irPin); } - case PLUGIN_READ: + if ((Plugin_088_irSender != nullptr) && (irPin == -1)) { - success = true; - break; + addLog(LOG_LEVEL_INFO, F("P088: Heatpump IR transmitter deactivated")); + delete Plugin_088_irSender; + Plugin_088_irSender = nullptr; } + success = true; + break; + } + + case PLUGIN_READ: + { + success = true; + break; + } case PLUGIN_WRITE: + { + String heatpumpModel; + unsigned int powerMode = POWER_ON; + unsigned int operatingMode = MODE_HEAT; + unsigned int fanSpeed = FAN_2; + unsigned int temperature = 22; + unsigned int vDir = VDIR_UP; + unsigned int hDir = HDIR_AUTO; + + String cmd = parseString(string, 1); + + if (cmd.equalsIgnoreCase(F("HEATPUMPIR")) && (Plugin_088_irSender != nullptr)) { - String heatpumpModel; - unsigned int powerMode = POWER_ON; - unsigned int operatingMode = MODE_HEAT; - unsigned int fanSpeed = FAN_2; - unsigned int temperature = 22; - unsigned int vDir = VDIR_UP; - unsigned int hDir = HDIR_AUTO; - - String cmd = parseString(string, 1); - if (cmd.equalsIgnoreCase(F("HEATPUMPIR")) && Plugin_088_irSender != nullptr) - { - String TmpStr1; - if (GetArgv(string.c_str(), TmpStr1, 2)) heatpumpModel = TmpStr1; - if (GetArgv(string.c_str(), TmpStr1, 3)) powerMode = str2int(TmpStr1.c_str()); - if (GetArgv(string.c_str(), TmpStr1, 4)) operatingMode = str2int(TmpStr1.c_str()); - if (GetArgv(string.c_str(), TmpStr1, 5)) fanSpeed = str2int(TmpStr1.c_str()); - if (GetArgv(string.c_str(), TmpStr1, 6)) temperature = str2int(TmpStr1.c_str()); - if (GetArgv(string.c_str(), TmpStr1, 7)) vDir = str2int(TmpStr1.c_str()); - if (GetArgv(string.c_str(), TmpStr1, 8)) hDir = str2int(TmpStr1.c_str()); -#ifdef IR_SEND_TIME - sendHour = node_time.hour(); - sendMinute = node_time.minute(); - sendWeekday = node_time.weekday(); -#endif - HeatpumpIR *heatpumpIR = HeatpumpIRFactory::create(heatpumpModel.c_str()); - - if (heatpumpIR != nullptr) { - enableIR_RX(false); - heatpumpIR->send(*Plugin_088_irSender, powerMode, operatingMode, fanSpeed, temperature, vDir, hDir); - enableIR_RX(true); + String TmpStr1; + + if (GetArgv(string.c_str(), TmpStr1, 2)) { heatpumpModel = TmpStr1; } + + if (GetArgv(string.c_str(), TmpStr1, 3)) { powerMode = str2int(TmpStr1.c_str()); } + + if (GetArgv(string.c_str(), TmpStr1, 4)) { operatingMode = str2int(TmpStr1.c_str()); } + + if (GetArgv(string.c_str(), TmpStr1, 5)) { fanSpeed = str2int(TmpStr1.c_str()); } + + if (GetArgv(string.c_str(), TmpStr1, 6)) { temperature = str2int(TmpStr1.c_str()); } + + if (GetArgv(string.c_str(), TmpStr1, 7)) { vDir = str2int(TmpStr1.c_str()); } + + if (GetArgv(string.c_str(), TmpStr1, 8)) { hDir = str2int(TmpStr1.c_str()); } +# ifdef IR_SEND_TIME + sendHour = node_time.hour(); + sendMinute = node_time.minute(); + sendWeekday = node_time.weekday(); +# endif // ifdef IR_SEND_TIME + HeatpumpIR *heatpumpIR = HeatpumpIRFactory::create(heatpumpModel.c_str()); - delete heatpumpIR; - heatpumpIR = nullptr; - - addLog(LOG_LEVEL_INFO, F("P088: Heatpump IR code transmitted")); -#ifdef IR_DEBUG_PACKET -# ifndef BUILD_NO_DEBUG - addLog(LOG_LEVEL_DEBUG, IRPacket); -#endif -#endif - if (printToWeb) - { - printWebString += F("P088: Heatpump IR code transmitted"); -#ifdef IR_DEBUG_PACKET - printWebString += F("
\n"); // do both
and \n to break line both in browser and curl -s - printWebString += IRPacket; - printWebString += F("\n"); -#endif - } - - // Panasonic CKP can only be turned ON/OFF by using the timer, - // so cancel the timer in 2 minutes, after the heatpump has turned on or off - if (strcmp_P(heatpumpModel.c_str(), PSTR("panasonic_ckp")) == 0) - { - panasonicCKPTimer = 120; - } - - success = true; + if (heatpumpIR != nullptr) { + enableIR_RX(false); + heatpumpIR->send(*Plugin_088_irSender, powerMode, operatingMode, fanSpeed, temperature, vDir, hDir); + enableIR_RX(true); + + delete heatpumpIR; + heatpumpIR = nullptr; + + addLog(LOG_LEVEL_INFO, F("P088: Heatpump IR code transmitted")); +# ifdef IR_DEBUG_PACKET +# ifndef BUILD_NO_DEBUG + addLog(LOG_LEVEL_DEBUG, IRPacket); +# endif // ifndef BUILD_NO_DEBUG +# endif // ifdef IR_DEBUG_PACKET + + if (printToWeb) + { + printWebString += F("P088: Heatpump IR code transmitted"); +# ifdef IR_DEBUG_PACKET + printWebString += F("
\n"); // do both
and \n to break line both in browser and curl -s + printWebString += IRPacket; + printWebString += F("\n"); +# endif // ifdef IR_DEBUG_PACKET } + + // Panasonic CKP can only be turned ON/OFF by using the timer, + // so cancel the timer in 2 minutes, after the heatpump has turned on or off + if (strcmp_P(heatpumpModel.c_str(), PSTR("panasonic_ckp")) == 0) + { + panasonicCKPTimer = 120; + } + + success = true; } - break; } + break; + } case PLUGIN_EXIT: - { - addLog(LOG_LEVEL_INFO, F("P088: Heatpump IR transmitter deactivated")); + { + addLog(LOG_LEVEL_INFO, F("P088: Heatpump IR transmitter deactivated")); - if (Plugin_088_irSender != nullptr) - { - delete Plugin_088_irSender; - Plugin_088_irSender = nullptr; - } + if (Plugin_088_irSender != nullptr) + { + delete Plugin_088_irSender; + Plugin_088_irSender = nullptr; + } - break; - } + break; + } case PLUGIN_ONCE_A_SECOND: + { + if (panasonicCKPTimer > 0) { - if (panasonicCKPTimer > 0) + panasonicCKPTimer--; + + if (panasonicCKPTimer == 0) { - panasonicCKPTimer--; - if (panasonicCKPTimer == 0) - { - PanasonicCKPHeatpumpIR *panasonicHeatpumpIR = new (std::nothrow) PanasonicCKPHeatpumpIR(); - if (panasonicHeatpumpIR != nullptr) { - enableIR_RX(false); - panasonicHeatpumpIR->sendPanasonicCKPCancelTimer(*Plugin_088_irSender); - enableIR_RX(true); - - delete panasonicHeatpumpIR; - addLog(LOG_LEVEL_INFO, F("P088: The TIMER led on Panasonic CKP should now be OFF")); - } + PanasonicCKPHeatpumpIR *panasonicHeatpumpIR = new (std::nothrow) PanasonicCKPHeatpumpIR(); + + if (panasonicHeatpumpIR != nullptr) { + enableIR_RX(false); + panasonicHeatpumpIR->sendPanasonicCKPCancelTimer(*Plugin_088_irSender); + enableIR_RX(true); + + delete panasonicHeatpumpIR; + addLog(LOG_LEVEL_INFO, F("P088: The TIMER led on Panasonic CKP should now be OFF")); } } - success = true; - break; } + success = true; + break; + } case PLUGIN_TEN_PER_SECOND: - { - success = true; - break; - } + { + success = true; + break; + } } return success; } + #endif // USES_P088 diff --git a/src/_P126_74HC595.ino b/src/_P126_74HC595.ino index 5a16874dbd..8178ce0934 100644 --- a/src/_P126_74HC595.ino +++ b/src/_P126_74HC595.ino @@ -79,15 +79,11 @@ boolean Plugin_126(uint8_t function, struct EventStruct *event, String& string) { case PLUGIN_DEVICE_ADD: { - Device[++deviceCount].Number = PLUGIN_ID_126; - Device[deviceCount].Type = DEVICE_TYPE_TRIPLE; - Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_QUAD; - Device[deviceCount].Ports = 0; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = false; - Device[deviceCount].DecimalsOnly = false; - Device[deviceCount].ValueCount = + Device[++deviceCount].Number = PLUGIN_ID_126; + Device[deviceCount].Type = DEVICE_TYPE_TRIPLE; + Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_QUAD; + Device[deviceCount].Ports = 0; + Device[deviceCount].ValueCount = # if P126_MAX_CHIP_COUNT <= 4 1 # elif P126_MAX_CHIP_COUNT <= 8 @@ -98,10 +94,13 @@ boolean Plugin_126(uint8_t function, struct EventStruct *event, String& string) 4 # endif // if P126_MAX_CHIP_COUNT <= 4 ; - Device[deviceCount].SendDataOption = true; - Device[deviceCount].TimerOption = true; - Device[deviceCount].TimerOptional = true; + Device[deviceCount].SendDataOption = true; + Device[deviceCount].TimerOption = true; + Device[deviceCount].TimerOptional = true; Device[deviceCount].HasFormatUserVar = true; + Device[deviceCount].Pin1Direction = gpio_direction::gpio_output; + Device[deviceCount].Pin2Direction = gpio_direction::gpio_output; + Device[deviceCount].Pin3Direction = gpio_direction::gpio_output; break; } diff --git a/src/_P128_NeoPixelBusFX.ino b/src/_P128_NeoPixelBusFX.ino index 38a18dcd26..89c31bbd81 100644 --- a/src/_P128_NeoPixelBusFX.ino +++ b/src/_P128_NeoPixelBusFX.ino @@ -154,18 +154,14 @@ boolean Plugin_128(uint8_t function, struct EventStruct *event, String& string) # if defined(ESP8266) Device[deviceCount].Type = DEVICE_TYPE_DUMMY; # endif // if defined(ESP8266) - Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_QUAD; - Device[deviceCount].Custom = true; - Device[deviceCount].Ports = 0; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = false; - Device[deviceCount].ValueCount = 4; - Device[deviceCount].SendDataOption = true; - Device[deviceCount].TimerOption = true; - Device[deviceCount].TimerOptional = true; - Device[deviceCount].GlobalSyncOption = true; - Device[deviceCount].DecimalsOnly = false; + Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_QUAD; + Device[deviceCount].Custom = true; + Device[deviceCount].Ports = 0; + Device[deviceCount].ValueCount = 4; + Device[deviceCount].SendDataOption = true; + Device[deviceCount].TimerOption = true; + Device[deviceCount].TimerOptional = true; + Device[deviceCount].Pin1Direction = gpio_direction::gpio_output; break; } @@ -237,7 +233,8 @@ boolean Plugin_128(uint8_t function, struct EventStruct *event, String& string) } if (P128_CONFIG_MAX_BRIGHT == 0) { P128_CONFIG_MAX_BRIGHT = 255; } // Set to default for existing installations - success = initPluginTaskData(event->TaskIndex, new (std::nothrow) P128_data_struct(PIN(0), P128_CONFIG_LED_COUNT, P128_CONFIG_MAX_BRIGHT)); + success = initPluginTaskData(event->TaskIndex, + new (std::nothrow) P128_data_struct(PIN(0), P128_CONFIG_LED_COUNT, P128_CONFIG_MAX_BRIGHT)); break; } diff --git a/src/_P129_74HC165.ino b/src/_P129_74HC165.ino index 063be7cfbc..3be2e36005 100644 --- a/src/_P129_74HC165.ino +++ b/src/_P129_74HC165.ino @@ -62,15 +62,11 @@ boolean Plugin_129(uint8_t function, struct EventStruct *event, String& string) { case PLUGIN_DEVICE_ADD: { - Device[++deviceCount].Number = PLUGIN_ID_129; - Device[deviceCount].Type = DEVICE_TYPE_TRIPLE; - Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_QUAD; - Device[deviceCount].Ports = 0; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = false; - Device[deviceCount].DecimalsOnly = false; - Device[deviceCount].ValueCount = + Device[++deviceCount].Number = PLUGIN_ID_129; + Device[deviceCount].Type = DEVICE_TYPE_TRIPLE; + Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_QUAD; + Device[deviceCount].Ports = 0; + Device[deviceCount].ValueCount = # if P129_MAX_CHIP_COUNT <= 4 1 # elif P129_MAX_CHIP_COUNT <= 8 @@ -81,10 +77,12 @@ boolean Plugin_129(uint8_t function, struct EventStruct *event, String& string) 4 # endif // if P129_MAX_CHIP_COUNT <= 4 ; - Device[deviceCount].SendDataOption = true; // No use in sending the Values to a controller - Device[deviceCount].TimerOption = true; // Used to update the Devices page - Device[deviceCount].TimerOptional = true; + Device[deviceCount].SendDataOption = true; // No use in sending the Values to a controller + Device[deviceCount].TimerOption = true; // Used to update the Devices page + Device[deviceCount].TimerOptional = true; Device[deviceCount].HasFormatUserVar = true; + Device[deviceCount].Pin2Direction = gpio_direction::gpio_output; + Device[deviceCount].Pin3Direction = gpio_direction::gpio_output; break; } diff --git a/src/_P131_NeoPixelMatrix.ino b/src/_P131_NeoPixelMatrix.ino index f9e77e0fd4..6b6b564f2d 100644 --- a/src/_P131_NeoPixelMatrix.ino +++ b/src/_P131_NeoPixelMatrix.ino @@ -42,17 +42,14 @@ boolean Plugin_131(uint8_t function, struct EventStruct *event, String& string) { case PLUGIN_DEVICE_ADD: { - Device[++deviceCount].Number = PLUGIN_ID_131; - Device[deviceCount].Type = DEVICE_TYPE_SINGLE; - Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_NONE; - Device[deviceCount].Ports = 0; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = false; - Device[deviceCount].ValueCount = 0; - Device[deviceCount].SendDataOption = false; - Device[deviceCount].TimerOption = true; - Device[deviceCount].TimerOptional = true; + Device[++deviceCount].Number = PLUGIN_ID_131; + Device[deviceCount].Type = DEVICE_TYPE_SINGLE; + Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_NONE; + Device[deviceCount].Ports = 0; + Device[deviceCount].ValueCount = 0; + Device[deviceCount].TimerOption = true; + Device[deviceCount].TimerOptional = true; + Device[deviceCount].Pin1Direction = gpio_direction::gpio_output; break; }