From e5a80df2effb45c5799c7481a647b8054aab82ae Mon Sep 17 00:00:00 2001 From: andrethomas Date: Sun, 12 Aug 2018 00:32:56 +0200 Subject: [PATCH 1/2] Rename mcp230xx_config[].b4 to mcp230xx_config[].saved_state --- sonoff/xsns_29_mcp230xx.ino | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sonoff/xsns_29_mcp230xx.ino b/sonoff/xsns_29_mcp230xx.ino index 9d9e7f989..79e95f03a 100644 --- a/sonoff/xsns_29_mcp230xx.ino +++ b/sonoff/xsns_29_mcp230xx.ino @@ -95,7 +95,7 @@ void MCP230xx_ApplySettings(void) { case 5: reg_iodir &= ~(1 << idx); if (Settings.flag.save_state) { // Firmware configuration wants us to use the last pin state - reg_portpins |= (Settings.mcp230xx_config[idx+(mcp230xx_port*8)].b4 << idx); + reg_portpins |= (Settings.mcp230xx_config[idx+(mcp230xx_port*8)].saved_state << idx); } else { if (Settings.mcp230xx_config[idx+(mcp230xx_port*8)].pullup) { reg_portpins |= (1 << idx); @@ -128,12 +128,12 @@ void MCP230xx_ApplySettings(void) { void MCP230xx_Detect() { - uint8_t buffer; - if (mcp230xx_type) { return; } + uint8_t buffer; + for (byte i = 0; i < sizeof(mcp230xx_addresses); i++) { mcp230xx_address = mcp230xx_addresses[i]; I2cWrite8(mcp230xx_address, MCP230xx_IOCON, 0x80); // attempt to set bank mode - this will only work on MCP23017, so its the best way to detect the different chips 23008 vs 23017 @@ -243,7 +243,7 @@ void MCP230xx_SetOutPin(uint8_t pin,uint8_t pinstate) { } I2cWrite8(mcp230xx_address, MCP230xx_GPIO + port, portpins); if (Settings.flag.save_state) { // Firmware configured to save last known state in settings - Settings.mcp230xx_config[pin].b4=portpins>>(pin-(port*8))&1; + Settings.mcp230xx_config[pin].saved_state=portpins>>(pin-(port*8))&1; } switch (pinstate) { case 0: @@ -269,7 +269,7 @@ void MCP230xx_Reset(uint8_t pinmode) { for (uint8_t pinx=0;pinx<16;pinx++) { Settings.mcp230xx_config[pinx].pinmode=pinmode; Settings.mcp230xx_config[pinx].pullup=pullup; - Settings.mcp230xx_config[pinx].b4=0; + Settings.mcp230xx_config[pinx].saved_state=0; Settings.mcp230xx_config[pinx].b5=0; Settings.mcp230xx_config[pinx].b6=0; Settings.mcp230xx_config[pinx].b7=0; From f40c3c3a1158452385b28a4e120429f90b247acd Mon Sep 17 00:00:00 2001 From: andrethomas Date: Sun, 12 Aug 2018 00:38:54 +0200 Subject: [PATCH 2/2] Update mcp230xx_config[].b4 -> .saved_state in settings.h --- sonoff/settings.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonoff/settings.h b/sonoff/settings.h index 38cadabb2..c2def2466 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -154,9 +154,9 @@ typedef union { typedef union { uint8_t data; struct { - uint8_t pinmode : 3; // Enable INPUT + uint8_t pinmode : 3; // Pin mode (1 through 5) uint8_t pullup : 1; // Enable internal weak pull-up resistor - uint8_t b4 : 1; + uint8_t saved_state : 1; // Save output state, if used. uint8_t b5 : 1; uint8_t b6 : 1; uint8_t b7 : 1;