diff --git a/sonoff/support.ino b/sonoff/support.ino index 720649c9f..b5ec74df9 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -482,6 +482,96 @@ int GetStateNumber(char *state_text) return state_number; } +boolean GetUsedInModule(byte val, uint8_t *arr) +{ + int offset = 0; + + if (!val) { return false; } // None +#ifndef USE_I2C + if (GPIO_I2C_SCL == val) { return true; } + if (GPIO_I2C_SDA == val) { return true; } +#endif +#ifndef USE_SR04 + if (GPIO_SR04_TRIG == val) { return true; } + if (GPIO_SR04_ECHO == val) { return true; } +#endif +#ifndef USE_WS2812 + if (GPIO_WS2812 == val) { return true; } +#endif +#ifndef USE_IR_REMOTE + if (GPIO_IRSEND == val) { return true; } +#ifndef USE_IR_RECEIVE + if (GPIO_IRRECV == val) { return true; } +#endif +#endif +#ifndef USE_MHZ19 + if (GPIO_MHZ_TXD == val) { return true; } + if (GPIO_MHZ_RXD == val) { return true; } +#endif +#ifndef USE_PZEM004T + if (GPIO_PZEM_TX == val) { return true; } + if (GPIO_PZEM_RX == val) { return true; } +#endif +#ifndef USE_SENSEAIR + if (GPIO_SAIR_TX == val) { return true; } + if (GPIO_SAIR_RX == val) { return true; } +#endif +#ifndef USE_SPI + if (GPIO_SPI_CS == val) { return true; } + if (GPIO_SPI_DC == val) { return true; } +#endif +#ifndef USE_DISPLAY + if (GPIO_BACKLIGHT == val) { return true; } +#endif +#ifndef USE_PMS5003 + if (GPIO_PMS5003 == val) { return true; } +#endif +#ifndef USE_NOVA_SDS + if (GPIO_SDS0X1 == val) { return true; } +#endif +#ifndef USE_SERIAL_BRIDGE + if (GPIO_SBR_TX == val) { return true; } + if (GPIO_SBR_RX == val) { return true; } +#endif +#ifndef USE_SR04 + if (GPIO_SR04_TRIG == val) { return true; } + if (GPIO_SR04_ECHO == val) { return true; } +#endif +#ifndef USE_SDM120 + if (GPIO_SDM120_TX == val) { return true; } + if (GPIO_SDM120_RX == val) { return true; } +#endif +#ifndef USE_SDM630 + if (GPIO_SDM630_TX == val) { return true; } + if (GPIO_SDM630_RX == val) { return true; } +#endif + if ((val >= GPIO_REL1) && (val < GPIO_REL1 + MAX_RELAYS)) { + offset = (GPIO_REL1_INV - GPIO_REL1); + } + if ((val >= GPIO_REL1_INV) && (val < GPIO_REL1_INV + MAX_RELAYS)) { + offset = -(GPIO_REL1_INV - GPIO_REL1); + } + + if ((val >= GPIO_LED1) && (val < GPIO_LED1 + MAX_LEDS)) { + offset = (GPIO_LED1_INV - GPIO_LED1); + } + if ((val >= GPIO_LED1_INV) && (val < GPIO_LED1_INV + MAX_LEDS)) { + offset = -(GPIO_LED1_INV - GPIO_LED1); + } + + if ((val >= GPIO_PWM1) && (val < GPIO_PWM1 + MAX_PWMS)) { + offset = (GPIO_PWM1_INV - GPIO_PWM1); + } + if ((val >= GPIO_PWM1_INV) && (val < GPIO_PWM1_INV + MAX_PWMS)) { + offset = -(GPIO_PWM1_INV - GPIO_PWM1); + } + for (byte i = 0; i < MAX_GPIO_PIN; i++) { + if (arr[i] == val) { return true; } + if (arr[i] == val + offset) { return true; } + } + return false; +} + void SetSerialBaudrate(int baudrate) { Settings.baudrate = baudrate / 1200; diff --git a/sonoff/webserver.ino b/sonoff/webserver.ino index 0cb4cce27..b46c5354b 100644 --- a/sonoff/webserver.ino +++ b/sonoff/webserver.ino @@ -639,96 +639,6 @@ void HandleConfiguration() ShowPage(page); } -boolean GetUsedInModule(byte val, uint8_t *arr) -{ - int offset = 0; - - if (!val) { return false; } // None -#ifndef USE_I2C - if (GPIO_I2C_SCL == val) { return true; } - if (GPIO_I2C_SDA == val) { return true; } -#endif -#ifndef USE_SR04 - if (GPIO_SR04_TRIG == val) { return true; } - if (GPIO_SR04_ECHO == val) { return true; } -#endif -#ifndef USE_WS2812 - if (GPIO_WS2812 == val) { return true; } -#endif -#ifndef USE_IR_REMOTE - if (GPIO_IRSEND == val) { return true; } -#ifndef USE_IR_RECEIVE - if (GPIO_IRRECV == val) { return true; } -#endif -#endif -#ifndef USE_MHZ19 - if (GPIO_MHZ_TXD == val) { return true; } - if (GPIO_MHZ_RXD == val) { return true; } -#endif -#ifndef USE_PZEM004T - if (GPIO_PZEM_TX == val) { return true; } - if (GPIO_PZEM_RX == val) { return true; } -#endif -#ifndef USE_SENSEAIR - if (GPIO_SAIR_TX == val) { return true; } - if (GPIO_SAIR_RX == val) { return true; } -#endif -#ifndef USE_SPI - if (GPIO_SPI_CS == val) { return true; } - if (GPIO_SPI_DC == val) { return true; } -#endif -#ifndef USE_DISPLAY - if (GPIO_BACKLIGHT == val) { return true; } -#endif -#ifndef USE_PMS5003 - if (GPIO_PMS5003 == val) { return true; } -#endif -#ifndef USE_NOVA_SDS - if (GPIO_SDS0X1 == val) { return true; } -#endif -#ifndef USE_SERIAL_BRIDGE - if (GPIO_SBR_TX == val) { return true; } - if (GPIO_SBR_RX == val) { return true; } -#endif -#ifndef USE_SR04 - if (GPIO_SR04_TRIG == val) { return true; } - if (GPIO_SR04_ECHO == val) { return true; } -#endif -#ifndef USE_SDM120 - if (GPIO_SDM120_TX == val) { return true; } - if (GPIO_SDM120_RX == val) { return true; } -#endif -#ifndef USE_SDM630 - if (GPIO_SDM630_TX == val) { return true; } - if (GPIO_SDM630_RX == val) { return true; } -#endif - if ((val >= GPIO_REL1) && (val < GPIO_REL1 + MAX_RELAYS)) { - offset = (GPIO_REL1_INV - GPIO_REL1); - } - if ((val >= GPIO_REL1_INV) && (val < GPIO_REL1_INV + MAX_RELAYS)) { - offset = -(GPIO_REL1_INV - GPIO_REL1); - } - - if ((val >= GPIO_LED1) && (val < GPIO_LED1 + MAX_LEDS)) { - offset = (GPIO_LED1_INV - GPIO_LED1); - } - if ((val >= GPIO_LED1_INV) && (val < GPIO_LED1_INV + MAX_LEDS)) { - offset = -(GPIO_LED1_INV - GPIO_LED1); - } - - if ((val >= GPIO_PWM1) && (val < GPIO_PWM1 + MAX_PWMS)) { - offset = (GPIO_PWM1_INV - GPIO_PWM1); - } - if ((val >= GPIO_PWM1_INV) && (val < GPIO_PWM1_INV + MAX_PWMS)) { - offset = -(GPIO_PWM1_INV - GPIO_PWM1); - } - for (byte i = 0; i < MAX_GPIO_PIN; i++) { - if (arr[i] == val) { return true; } - if (arr[i] == val + offset) { return true; } - } - return false; -} - void HandleModuleConfiguration() { if (HttpUser()) { return; }