From dea255db26d03e7b43dec6e9e35c0f746c1736fc Mon Sep 17 00:00:00 2001 From: Andre Thomas Date: Mon, 30 Sep 2019 21:31:23 +0200 Subject: [PATCH] MCP230xx: Prevent inadvertent pinmode change We've added support for sensor29 pin,0/1 for OFF/ON but the current code would allow the pinmode to be changed without specifying a default state e.g. sensor29 pin,3 would cause the pinmode to be changed to input even if it was previously configured for output (pinmode 5/6) This change prevents these instances by enforcing the configuration rules as outlined in the wiki e.g. sensor29 pin,pinmode,pullup/default state (if used for output) --- sonoff/xsns_29_mcp230xx.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonoff/xsns_29_mcp230xx.ino b/sonoff/xsns_29_mcp230xx.ino index 9eb98b95a..855de1349 100644 --- a/sonoff/xsns_29_mcp230xx.ino +++ b/sonoff/xsns_29_mcp230xx.ino @@ -655,9 +655,9 @@ bool MCP230xx_Command(void) { intmode = atoi(subStr(sub_string, XdrvMailbox.data, ",", 4)); } #ifdef USE_MCP230xx_OUTPUT - if ((pin < mcp230xx_pincount) && (pinmode > 0) && (pinmode < 7) && (pullup < 2)) { + if ((pin < mcp230xx_pincount) && (pinmode > 0) && (pinmode < 7) && (pullup < 2) && (paramcount > 2)) { #else // not use OUTPUT - if ((pin < mcp230xx_pincount) && (pinmode > 0) && (pinmode < 5) && (pullup < 2)) { + if ((pin < mcp230xx_pincount) && (pinmode > 0) && (pinmode < 5) && (pullup < 2) && (paramcount > 2)) { #endif // USE_MCP230xx_OUTPUT Settings.mcp230xx_config[pin].pinmode=pinmode; Settings.mcp230xx_config[pin].pullup=pullup;