[P162] Add Send data on change option

This commit is contained in:
Ton Huisman
2024-04-16 22:20:23 +02:00
parent d665c9c982
commit b02cbbbff9
3 changed files with 12 additions and 0 deletions
+4
View File
@@ -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;
@@ -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));
}
+1
View File
@@ -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)