diff --git a/src/_P162_MCP42xxx.ino b/src/_P162_MCP42xxx.ino index 9e6a3c056..fd8576699 100644 --- a/src/_P162_MCP42xxx.ino +++ b/src/_P162_MCP42xxx.ino @@ -6,6 +6,7 @@ // ####################################################################################################### /** Changelog: + * 2024-04-16 tonhuisman: Add Send values on change option, so Interval can be set to 0, and the data will be sent when changed * 2024-04-10 tonhuisman: Initial version. Support for Digipot MCP42xxx (dual channel) and MCP41xxx (single channel). * No support for daisy-chaining (MCP42xxx can do that, but not implemented) * RST and SHDN pins are not available on all boards, so should be set to none when not available. @@ -91,6 +92,8 @@ boolean Plugin_162(uint8_t function, struct EventStruct *event, String& string) addFormNumericBox(F("Value at Shutdown"), F("shd"), P162_SHUTDOWN_VALUE, -1, 256); addUnit(F("-1..256")); + addFormCheckBox(F("Send values on change"), F("chg"), P162_CHANGED_EVENTS); + success = true; break; } @@ -102,6 +105,7 @@ boolean Plugin_162(uint8_t function, struct EventStruct *event, String& string) P162_SHUTDOWN_W0 = isFormItemChecked(F("sw0")); P162_SHUTDOWN_W1 = isFormItemChecked(F("sw1")); P162_SHUTDOWN_VALUE = getFormItemInt(F("shd")); + P162_CHANGED_EVENTS = isFormItemChecked(F("chg")); success = true; break; diff --git a/src/src/PluginStructs/P162_data_struct.cpp b/src/src/PluginStructs/P162_data_struct.cpp index f2102fd36..809b020eb 100644 --- a/src/src/PluginStructs/P162_data_struct.cpp +++ b/src/src/PluginStructs/P162_data_struct.cpp @@ -179,9 +179,16 @@ void P162_data_struct::write_pot(uint8_t cmd, * Set current values to UserVar ********************************************************************************/ void P162_data_struct::updateUserVars(struct EventStruct *event) { + const int16_t pot0_old = UserVar.getFloat(event->TaskIndex, 0, true); + const int16_t pot1_old = UserVar.getFloat(event->TaskIndex, 1, true); + UserVar.setFloat(event->TaskIndex, 0, _pot0_value); UserVar.setFloat(event->TaskIndex, 1, _pot1_value); + if (P162_CHANGED_EVENTS && ((pot0_old != _pot0_value) || (pot1_old != _pot1_value))) { + sendData(event); + } + if (loglevelActiveFor(LOG_LEVEL_INFO)) { addLog(LOG_LEVEL_INFO, strformat(F("Digipot: W0 = %d, W1 = %d"), _pot0_value, _pot1_value)); } diff --git a/src/src/PluginStructs/P162_data_struct.h b/src/src/PluginStructs/P162_data_struct.h index 6254cb1b7..b26916a3b 100644 --- a/src/src/PluginStructs/P162_data_struct.h +++ b/src/src/PluginStructs/P162_data_struct.h @@ -13,6 +13,7 @@ # define P162_SHUTDOWN_W0 PCONFIG(2) # define P162_SHUTDOWN_W1 PCONFIG(3) # define P162_SHUTDOWN_VALUE PCONFIG(4) +# define P162_CHANGED_EVENTS PCONFIG(5) // # define P162_REMOVALVALUE PCONFIG_LONG(0) // # define P162_REMOVALTIMEOUT PCONFIG_LONG(1)