From c939077514c9efd51de274cf2168c58c45f78d5b Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 27 Apr 2020 12:54:07 +0200 Subject: [PATCH] Change pin handling part 3 --- tasmota/support.ino | 7 ++++++- tasmota/support_button.ino | 4 ++-- tasmota/support_button_v2.ino | 6 +++--- tasmota/support_command.ino | 2 +- tasmota/support_rotary.ino | 2 +- tasmota/support_switch.ino | 6 +++--- tasmota/support_tasmota.ino | 32 +++++++++++++++--------------- tasmota/xdrv_04_light.ino | 10 +++++----- tasmota/xdrv_05_irremote.ino | 10 +++++----- tasmota/xdrv_05_irremote_full.ino | 10 +++++----- tasmota/xdrv_07_domoticz.ino | 2 +- tasmota/xdrv_08_serial_bridge.ino | 2 +- tasmota/xdrv_10_rules.ino | 4 ++-- tasmota/xdrv_12_home_assistant.ino | 4 ++-- tasmota/xdrv_14_mp3.ino | 2 +- tasmota/xdrv_16_tuyamcu.ino | 2 +- tasmota/xdrv_17_rcswitch.ino | 10 +++++----- tasmota/xdrv_23_zigbee_9_impl.ino | 2 +- tasmota/xdrv_24_buzzer.ino | 2 +- tasmota/xdrv_25_A4988_Stepper.ino | 4 ++-- tasmota/xdrv_26_ariluxrf.ino | 6 +++--- tasmota/xdrv_27_shutter.ino | 2 +- tasmota/xdrv_29_deepsleep.ino | 2 +- tasmota/xdrv_31_tasmota_slave.ino | 6 +++--- tasmota/xdrv_33_nrf24l01.ino | 2 +- tasmota/xdrv_35_pwm_dimmer.ino | 6 +++--- tasmota/xdsp_02_ssd1306.ino | 2 +- tasmota/xdsp_04_ili9341.ino | 2 +- tasmota/xdsp_05_epaper_29.ino | 4 ++-- tasmota/xdsp_06_epaper_42.ino | 4 ++-- tasmota/xdsp_08_ILI9488.ino | 6 +++--- tasmota/xdsp_09_SSD1351.ino | 4 ++-- tasmota/xdsp_10_RA8876.ino | 4 ++-- tasmota/xlgt_01_ws2812.ino | 2 +- tasmota/xlgt_02_my92x1.ino | 2 +- tasmota/xlgt_03_sm16716.ino | 6 +++--- tasmota/xlgt_04_sm2135.ino | 2 +- tasmota/xlgt_05_sonoff_l1.ino | 2 +- tasmota/xlgt_06_electriq_moodl.ino | 2 +- tasmota/xnrg_01_hlw8012.ino | 14 ++++++------- tasmota/xnrg_02_cse7766.ino | 4 ++-- tasmota/xnrg_03_pzem004t.ino | 2 +- tasmota/xnrg_04_mcp39f501.ino | 4 ++-- tasmota/xnrg_05_pzem_ac.ino | 2 +- tasmota/xnrg_06_pzem_dc.ino | 2 +- tasmota/xnrg_07_ade7953.ino | 2 +- tasmota/xnrg_08_sdm120.ino | 2 +- tasmota/xnrg_09_dds2382.ino | 2 +- tasmota/xnrg_10_sdm630.ino | 2 +- tasmota/xnrg_11_ddsu666.ino | 2 +- tasmota/xnrg_12_solaxX1.ino | 2 +- tasmota/xnrg_13_fif_le01mr.ino | 2 +- tasmota/xsns_01_counter.ino | 12 +++++------ tasmota/xsns_05_ds18x20.ino | 8 ++++---- tasmota/xsns_06_dht.ino | 4 ++-- tasmota/xsns_07_sht1x.ino | 4 ++-- tasmota/xsns_15_mhz19.ino | 4 ++-- tasmota/xsns_17_senseair.ino | 4 ++-- tasmota/xsns_18_pms5003.ino | 8 ++++---- tasmota/xsns_20_novasds.ino | 4 ++-- tasmota/xsns_22_sr04.ino | 10 +++++----- tasmota/xsns_28_tm1638.ino | 8 ++++---- 62 files changed, 151 insertions(+), 146 deletions(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index 03bc8d9e9..10e34ada7 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -1094,6 +1094,11 @@ uint32_t Pin(uint32_t gpio, uint32_t index) { */ } +boolean PinUsed(uint32_t gpio, uint32_t index = 0); +boolean PinUsed(uint32_t gpio, uint32_t index) { + return (Pin(gpio, index) < 99); +} + void SetPin(uint32_t lpin, uint32_t gpio) { //#ifdef ESP8266 pin[gpio] = lpin; @@ -1106,7 +1111,7 @@ void SetPin(uint32_t lpin, uint32_t gpio) { void DigitalWrite(uint32_t gpio_pin, uint32_t index, uint32_t state) { - if (Pin(gpio_pin, index) < 99) { + if (PinUsed(gpio_pin, index)) { digitalWrite(Pin(gpio_pin, index), state &1); } } diff --git a/tasmota/support_button.ino b/tasmota/support_button.ino index 59b90e39d..659a02348 100644 --- a/tasmota/support_button.ino +++ b/tasmota/support_button.ino @@ -60,7 +60,7 @@ void ButtonInit(void) { Button.present = 0; for (uint32_t i = 0; i < MAX_KEYS; i++) { - if (Pin(GPIO_KEY1, i) < 99) { + if (PinUsed(GPIO_KEY1, i)) { Button.present++; pinMode(Pin(GPIO_KEY1, i), bitRead(Button.no_pullup_mask, i) ? INPUT : ((16 == Pin(GPIO_KEY1, i)) ? INPUT_PULLDOWN_16 : INPUT_PULLUP)); } @@ -135,7 +135,7 @@ void ButtonHandler(void) } else #endif // ESP8266 - if (Pin(GPIO_KEY1, button_index) < 99) { + if (PinUsed(GPIO_KEY1, button_index)) { button_present = 1; button = (digitalRead(Pin(GPIO_KEY1, button_index)) != bitRead(Button.inverted_mask, button_index)); } diff --git a/tasmota/support_button_v2.ino b/tasmota/support_button_v2.ino index 3bb1f9153..4dc94cf13 100644 --- a/tasmota/support_button_v2.ino +++ b/tasmota/support_button_v2.ino @@ -60,7 +60,7 @@ void ButtonInit(void) { Button.present = 0; for (uint32_t i = 0; i < MAX_KEYS; i++) { - if (Pin(GPIO_KEY1, i) < 99) { + if (PinUsed(GPIO_KEY1, i)) { Button.present++; pinMode(Pin(GPIO_KEY1, i), bitRead(Button.no_pullup_mask, i) ? INPUT : ((16 == Pin(GPIO_KEY1, i)) ? INPUT_PULLDOWN_16 : INPUT_PULLUP)); } @@ -132,7 +132,7 @@ void ButtonHandler(void) } else #endif // ESP8266 - if (Pin(GPIO_KEY1, button_index) < 99) { + if (PinUsed(GPIO_KEY1, button_index)) { button_present = 1; button = (digitalRead(Pin(GPIO_KEY1, button_index)) != bitRead(Button.inverted_mask, button_index)); } @@ -266,7 +266,7 @@ void ButtonHandler(void) } else { SendKey(KEY_BUTTON, button_index +1, Button.press_counter[button_index] +9); // 2,3,4 and 5 press send just the key value (11,12,13 and 14) for rules if (0 == button_index) { // BUTTON1 can toggle up to 5 relays if present. If a relay is not present will send out the key value (2,11,12,13 and 14) for rules - if ((Button.press_counter[button_index] > 1 && Pin(GPIO_REL1, Button.press_counter[button_index]-1) < 99) && Button.press_counter[button_index] <= MAX_RELAY_BUTTON1) { + if ((Button.press_counter[button_index] > 1 && PinUsed(GPIO_REL1, Button.press_counter[button_index]-1)) && Button.press_counter[button_index] <= MAX_RELAY_BUTTON1) { ExecuteCommandPower(button_index + Button.press_counter[button_index], POWER_TOGGLE, SRC_BUTTON); // Execute Toggle command internally AddLog_P2(LOG_LEVEL_DEBUG, PSTR("DBG: Relay%d found on GPIO%d"), Button.press_counter[button_index], Pin(GPIO_REL1, Button.press_counter[button_index]-1)); } diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 2066ee56c..cc8bb92ae 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -1167,7 +1167,7 @@ void CmndTemplate(void) void CmndPwm(void) { if (pwm_present && (XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_PWMS)) { - if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= Settings.pwm_range) && (Pin(GPIO_PWM1, XdrvMailbox.index -1) < 99)) { + if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= Settings.pwm_range) && PinUsed(GPIO_PWM1, XdrvMailbox.index -1)) { Settings.pwm_value[XdrvMailbox.index -1] = XdrvMailbox.payload; analogWrite(Pin(GPIO_PWM1, XdrvMailbox.index -1), bitRead(pwm_inverted, XdrvMailbox.index -1) ? Settings.pwm_range - XdrvMailbox.payload : XdrvMailbox.payload); } diff --git a/tasmota/support_rotary.ino b/tasmota/support_rotary.ino index f93b288c5..25c064a18 100644 --- a/tasmota/support_rotary.ino +++ b/tasmota/support_rotary.ino @@ -80,7 +80,7 @@ bool RotaryButtonPressed(void) void RotaryInit(void) { Rotary.present = 0; - if ((Pin(GPIO_ROT1A) < 99) && (Pin(GPIO_ROT1B) < 99)) { + if (PinUsed(GPIO_ROT1A) && PinUsed(GPIO_ROT1B)) { Rotary.present++; pinMode(Pin(GPIO_ROT1A), INPUT_PULLUP); pinMode(Pin(GPIO_ROT1B), INPUT_PULLUP); diff --git a/tasmota/support_switch.ino b/tasmota/support_switch.ino index 3fba37b3c..64837c74c 100644 --- a/tasmota/support_switch.ino +++ b/tasmota/support_switch.ino @@ -86,7 +86,7 @@ void SwitchProbe(void) uint8_t force_low = (Settings.switch_debounce % 50) &2; // 52, 102, 152 etc for (uint32_t i = 0; i < MAX_SWITCHES; i++) { - if (Pin(GPIO_SWT1, i) < 99) { + if (PinUsed(GPIO_SWT1, i)) { // Olimex user_switch2.c code to fix 50Hz induced pulses if (1 == digitalRead(Pin(GPIO_SWT1, i))) { @@ -127,7 +127,7 @@ void SwitchInit(void) Switch.present = 0; for (uint32_t i = 0; i < MAX_SWITCHES; i++) { Switch.last_state[i] = 1; // Init global to virtual switch state; - if (Pin(GPIO_SWT1, i) < 99) { + if (PinUsed(GPIO_SWT1, i)) { Switch.present++; pinMode(Pin(GPIO_SWT1, i), bitRead(Switch.no_pullup_mask, i) ? INPUT : ((16 == Pin(GPIO_SWT1, i)) ? INPUT_PULLDOWN_16 : INPUT_PULLUP)); Switch.last_state[i] = digitalRead(Pin(GPIO_SWT1, i)); // Set global now so doesn't change the saved power state on first switch check @@ -148,7 +148,7 @@ void SwitchHandler(uint8_t mode) uint16_t loops_per_second = 1000 / Settings.switch_debounce; for (uint32_t i = 0; i < MAX_SWITCHES; i++) { - if ((Pin(GPIO_SWT1, i) < 99) || (mode)) { + if (PinUsed(GPIO_SWT1, i) || (mode)) { uint8_t button = Switch.virtual_state[i]; uint8_t switchflag = POWER_TOGGLE +1; diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index 85a3e1a04..1f2ad385c 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -325,7 +325,7 @@ void SetPowerOnState(void) // Issue #526 and #909 for (uint32_t i = 0; i < devices_present; i++) { if (!Settings.flag3.no_power_feedback) { // SetOption63 - Don't scan relay power state at restart - #5594 and #5663 - if ((i < MAX_RELAYS) && (Pin(GPIO_REL1, i) < 99)) { + if ((i < MAX_RELAYS) && PinUsed(GPIO_REL1, i)) { bitWrite(power, i, digitalRead(Pin(GPIO_REL1, i)) ^ bitRead(rel_inverted, i)); } } @@ -339,11 +339,11 @@ void SetPowerOnState(void) void SetLedPowerIdx(uint32_t led, uint32_t state) { if ((99 == Pin(GPIO_LEDLNK)) && (0 == led)) { // Legacy - LED1 is link led only if LED2 is present - if (Pin(GPIO_LED1, 1) < 99) { + if (PinUsed(GPIO_LED1, 1)) { led = 1; } } - if (Pin(GPIO_LED1, led) < 99) { + if (PinUsed(GPIO_LED1, led)) { uint32_t mask = 1 << led; if (state) { state = 1; @@ -608,7 +608,7 @@ void MqttShowPWMState(void) ResponseAppend_P(PSTR("\"" D_CMND_PWM "\":{")); bool first = true; for (uint32_t i = 0; i < MAX_PWMS; i++) { - if (Pin(GPIO_PWM1, i) < 99) { + if (PinUsed(GPIO_PWM1, i)) { ResponseAppend_P(PSTR("%s\"" D_CMND_PWM "%d\":%d"), first ? "" : ",", i+1, Settings.pwm_value[i]); first = false; } @@ -703,9 +703,9 @@ bool MqttShowSensor(void) int json_data_start = strlen(mqtt_data); for (uint32_t i = 0; i < MAX_SWITCHES; i++) { #ifdef USE_TM1638 - if ((Pin(GPIO_SWT1, i) < 99) || ((Pin(GPIO_TM16CLK) < 99) && (Pin(GPIO_TM16DIO) < 99) && (Pin(GPIO_TM16STB) < 99))) { + if (PinUsed(GPIO_SWT1, i) || (PinUsed(GPIO_TM16CLK) && PinUsed(GPIO_TM16DIO) && PinUsed(GPIO_TM16STB))) { #else - if (Pin(GPIO_SWT1, i) < 99) { + if (PinUsed(GPIO_SWT1, i)) { #endif // USE_TM1638 ResponseAppend_P(PSTR(",\"" D_JSON_SWITCH "%d\":\"%s\""), i +1, GetStateText(SwitchState(i))); } @@ -913,7 +913,7 @@ void Every250mSeconds(void) if (200 == blinks) blinks = 0; // Disable blink } } - if (Settings.ledstate &1 && (Pin(GPIO_LEDLNK) < 99 || !(blinks || restart_flag || ota_state_flag)) ) { + if (Settings.ledstate &1 && (PinUsed(GPIO_LEDLNK) || !(blinks || restart_flag || ota_state_flag)) ) { bool tstate = power & Settings.ledmask; #ifdef ESP8266 if ((SONOFF_TOUCH == my_module_type) || (SONOFF_T11 == my_module_type) || (SONOFF_T12 == my_module_type) || (SONOFF_T13 == my_module_type)) { @@ -1320,7 +1320,7 @@ void SerialInput(void) void ResetPwm(void) { for (uint32_t i = 0; i < MAX_PWMS; i++) { // Basic PWM control only - if (Pin(GPIO_PWM1, i) < 99) { + if (PinUsed(GPIO_PWM1, i)) { analogWrite(Pin(GPIO_PWM1, i), bitRead(pwm_inverted, i) ? Settings.pwm_range : 0); // analogWrite(Pin(GPIO_PWM1, i), bitRead(pwm_inverted, i) ? Settings.pwm_range - Settings.pwm_value[i] : Settings.pwm_value[i]); } @@ -1446,7 +1446,7 @@ void GpioInit(void) analogWriteFreq(Settings.pwm_frequency); // Default is 1000 (core_esp8266_wiring_pwm.c) #ifdef USE_SPI - spi_flg = ((((Pin(GPIO_SPI_CS) < 99) && (Pin(GPIO_SPI_CS) > 14)) || (Pin(GPIO_SPI_CS) < 12)) || (((Pin(GPIO_SPI_DC) < 99) && (Pin(GPIO_SPI_DC) > 14)) || (Pin(GPIO_SPI_DC) < 12))); + spi_flg = (((PinUsed(GPIO_SPI_CS) && (Pin(GPIO_SPI_CS) > 14)) || (Pin(GPIO_SPI_CS) < 12)) || ((PinUsed(GPIO_SPI_DC) && (Pin(GPIO_SPI_DC) > 14)) || (Pin(GPIO_SPI_DC) < 12))); if (spi_flg) { for (uint32_t i = 0; i < GPIO_MAX; i++) { if ((Pin(i) >= 12) && (Pin(i) <=14)) { SetPin(99, i); } @@ -1458,7 +1458,7 @@ void GpioInit(void) my_module.io[14] = GPIO_SPI_CLK; SetPin(14, GPIO_SPI_CLK); } - soft_spi_flg = ((Pin(GPIO_SSPI_CS) < 99) && (Pin(GPIO_SSPI_SCLK) < 99) && ((Pin(GPIO_SSPI_MOSI) < 99) || (Pin(GPIO_SSPI_MOSI) < 99))); + soft_spi_flg = (PinUsed(GPIO_SSPI_CS) && PinUsed(GPIO_SSPI_SCLK) && (PinUsed(GPIO_SSPI_MOSI) || PinUsed(GPIO_SSPI_MOSI))); #endif // USE_SPI // Set any non-used GPIO to INPUT - Related to resetPins() in support_legacy_cores.ino @@ -1474,7 +1474,7 @@ void GpioInit(void) } #ifdef USE_I2C - i2c_flg = ((Pin(GPIO_I2C_SCL) < 99) && (Pin(GPIO_I2C_SDA) < 99)); + i2c_flg = (PinUsed(GPIO_I2C_SCL) && PinUsed(GPIO_I2C_SDA)); if (i2c_flg) { Wire.begin(Pin(GPIO_I2C_SDA), Pin(GPIO_I2C_SCL)); } @@ -1506,7 +1506,7 @@ void GpioInit(void) #endif // ESP8266 for (uint32_t i = 0; i < MAX_PWMS; i++) { // Basic PWM control only - if (Pin(GPIO_PWM1, i) < 99) { + if (PinUsed(GPIO_PWM1, i)) { pinMode(Pin(GPIO_PWM1, i), OUTPUT); if (light_type) { // force PWM GPIOs to low or high mode, see #7165 @@ -1519,7 +1519,7 @@ void GpioInit(void) } for (uint32_t i = 0; i < MAX_RELAYS; i++) { - if (Pin(GPIO_REL1, i) < 99) { + if (PinUsed(GPIO_REL1, i)) { pinMode(Pin(GPIO_REL1, i), OUTPUT); devices_present++; #ifdef ESP8266 @@ -1532,7 +1532,7 @@ void GpioInit(void) } for (uint32_t i = 0; i < MAX_LEDS; i++) { - if (Pin(GPIO_LED1, i) < 99) { + if (PinUsed(GPIO_LED1, i)) { #ifdef USE_ARILUX_RF if ((3 == i) && (leds_present < 2) && (99 == Pin(GPIO_ARIRFSEL))) { SetPin(Pin(GPIO_LED4), GPIO_ARIRFSEL); // Legacy support where LED4 was Arilux RF enable @@ -1547,13 +1547,13 @@ void GpioInit(void) #endif } } - if (Pin(GPIO_LEDLNK) < 99) { + if (PinUsed(GPIO_LEDLNK)) { pinMode(Pin(GPIO_LEDLNK), OUTPUT); digitalWrite(Pin(GPIO_LEDLNK), ledlnk_inverted); } #ifdef USE_PWM_DIMMER - if (PWM_DIMMER == my_module_type && Pin(GPIO_REL1) < 99) { devices_present--; } + if (PWM_DIMMER == my_module_type && PinUsed(GPIO_REL1)) { devices_present--; } #endif // USE_PWM_DIMMER ButtonInit(); diff --git a/tasmota/xdrv_04_light.ino b/tasmota/xdrv_04_light.ino index 5e3afb9d6..9aaa9c9c0 100644 --- a/tasmota/xdrv_04_light.ino +++ b/tasmota/xdrv_04_light.ino @@ -1244,7 +1244,7 @@ bool LightModuleInit(void) if (Settings.flag.pwm_control) { // SetOption15 - Switch between commands PWM or COLOR/DIMMER/CT/CHANNEL for (uint32_t i = 0; i < MAX_PWMS; i++) { - if (Pin(GPIO_PWM1, i) < 99) { light_type++; } // Use Dimmer/Color control for all PWM as SetOption15 = 1 + if (PinUsed(GPIO_PWM1, i)) { light_type++; } // Use Dimmer/Color control for all PWM as SetOption15 = 1 } } @@ -1347,12 +1347,12 @@ void LightInit(void) if (light_type < LT_PWM6) { // PWM for (uint32_t i = 0; i < light_type; i++) { Settings.pwm_value[i] = 0; // Disable direct PWM control - if (Pin(GPIO_PWM1, i) < 99) { + if (PinUsed(GPIO_PWM1, i)) { pinMode(Pin(GPIO_PWM1, i), OUTPUT); } } - if (Pin(GPIO_ARIRFRCV) < 99) { - if (Pin(GPIO_ARIRFSEL) < 99) { + if (PinUsed(GPIO_ARIRFRCV)) { + if (PinUsed(GPIO_ARIRFSEL)) { pinMode(Pin(GPIO_ARIRFSEL), OUTPUT); digitalWrite(Pin(GPIO_ARIRFSEL), 1); // Turn off RF } @@ -2133,7 +2133,7 @@ void LightSetOutputs(const uint16_t *cur_col_10) { // now apply the actual PWM values, adjusted and remapped 10-bits range if (light_type < LT_PWM6) { // only for direct PWM lights, not for Tuya, Armtronix... for (uint32_t i = 0; i < (Light.subtype - Light.pwm_offset); i++) { - if (Pin(GPIO_PWM1, i) < 99) { + if (PinUsed(GPIO_PWM1, i)) { //AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION "Cur_Col%d 10 bits %d"), i, cur_col_10[i]); uint16_t cur_col = cur_col_10[i + Light.pwm_offset]; if (!isChannelCT(i)) { // if CT don't use pwm_min and pwm_max diff --git a/tasmota/xdrv_05_irremote.ino b/tasmota/xdrv_05_irremote.ino index 1a961a0f2..87a51de53 100644 --- a/tasmota/xdrv_05_irremote.ino +++ b/tasmota/xdrv_05_irremote.ino @@ -279,28 +279,28 @@ bool Xdrv05(uint8_t function) { bool result = false; - if ((Pin(GPIO_IRSEND) < 99) || (Pin(GPIO_IRRECV) < 99)) { + if (PinUsed(GPIO_IRSEND) || PinUsed(GPIO_IRRECV)) { switch (function) { case FUNC_PRE_INIT: - if (Pin(GPIO_IRSEND) < 99) { + if (PinUsed(GPIO_IRSEND)) { IrSendInit(); } #ifdef USE_IR_RECEIVE - if (Pin(GPIO_IRRECV) < 99) { + if (PinUsed(GPIO_IRRECV)) { IrReceiveInit(); } #endif // USE_IR_RECEIVE break; case FUNC_EVERY_50_MSECOND: #ifdef USE_IR_RECEIVE - if (Pin(GPIO_IRRECV) < 99) { + if (PinUsed(GPIO_IRRECV)) { IrReceiveCheck(); // check if there's anything on IR side } #endif // USE_IR_RECEIVE irsend_active = false; // re-enable IR reception break; case FUNC_COMMAND: - if (Pin(GPIO_IRSEND) < 99) { + if (PinUsed(GPIO_IRSEND)) { result = DecodeCommand(kIrRemoteCommands, IrRemoteCommand); } break; diff --git a/tasmota/xdrv_05_irremote_full.ino b/tasmota/xdrv_05_irremote_full.ino index 83ec56343..60e16b30d 100644 --- a/tasmota/xdrv_05_irremote_full.ino +++ b/tasmota/xdrv_05_irremote_full.ino @@ -635,24 +635,24 @@ bool Xdrv05(uint8_t function) { bool result = false; - if ((Pin(GPIO_IRSEND) < 99) || (Pin(GPIO_IRRECV) < 99)) { + if (PinUsed(GPIO_IRSEND) || PinUsed(GPIO_IRRECV)) { switch (function) { case FUNC_PRE_INIT: - if (Pin(GPIO_IRSEND) < 99) { + if (PinUsed(GPIO_IRSEND)) { IrSendInit(); } - if (Pin(GPIO_IRRECV) < 99) { + if (PinUsed(GPIO_IRRECV)) { IrReceiveInit(); } break; case FUNC_EVERY_50_MSECOND: - if (Pin(GPIO_IRRECV) < 99) { + if (PinUsed(GPIO_IRRECV)) { IrReceiveCheck(); // check if there's anything on IR side } irsend_active = false; // re-enable IR reception break; case FUNC_COMMAND: - if (Pin(GPIO_IRSEND) < 99) { + if (PinUsed(GPIO_IRSEND)) { result = DecodeCommand(kIrRemoteCommands, IrRemoteCommand); } break; diff --git a/tasmota/xdrv_07_domoticz.ino b/tasmota/xdrv_07_domoticz.ino index a5b284fc2..4face9bfb 100644 --- a/tasmota/xdrv_07_domoticz.ino +++ b/tasmota/xdrv_07_domoticz.ino @@ -576,7 +576,7 @@ void HandleDomoticzConfiguration(void) i +1, i, Settings.domoticz_relay_idx[i], i +1, i, Settings.domoticz_key_idx[i]); } - if (Pin(GPIO_SWT1, i) < 99) { + if (PinUsed(GPIO_SWT1, i)) { WSContentSend_P(HTTP_FORM_DOMOTICZ_SWITCH, i +1, i, Settings.domoticz_switch_idx[i]); } diff --git a/tasmota/xdrv_08_serial_bridge.ino b/tasmota/xdrv_08_serial_bridge.ino index 313cc9d6d..a3ae5ae32 100644 --- a/tasmota/xdrv_08_serial_bridge.ino +++ b/tasmota/xdrv_08_serial_bridge.ino @@ -87,7 +87,7 @@ void SerialBridgeInput(void) void SerialBridgeInit(void) { serial_bridge_active = false; - if ((Pin(GPIO_SBR_RX) < 99) && (Pin(GPIO_SBR_TX) < 99)) { + if (PinUsed(GPIO_SBR_RX) && PinUsed(GPIO_SBR_TX)) { SerialBridgeSerial = new TasmotaSerial(Pin(GPIO_SBR_RX), Pin(GPIO_SBR_TX)); if (SerialBridgeSerial->begin(Settings.sbaudrate * 300)) { // Baud rate is stored div 300 so it fits into 16 bits if (SerialBridgeSerial->hardwareSerial()) { diff --git a/tasmota/xdrv_10_rules.ino b/tasmota/xdrv_10_rules.ino index cfd633f38..fa5841564 100644 --- a/tasmota/xdrv_10_rules.ino +++ b/tasmota/xdrv_10_rules.ino @@ -580,9 +580,9 @@ void RulesEvery50ms(void) // Boot time SWITCHES Status for (uint32_t i = 0; i < MAX_SWITCHES; i++) { #ifdef USE_TM1638 - if ((Pin(GPIO_SWT1, i) < 99) || ((Pin(GPIO_TM16CLK) < 99) && (Pin(GPIO_TM16DIO) < 99) && (Pin(GPIO_TM16STB) < 99))) { + if (PinUsed(GPIO_SWT1, i) || (PinUsed(GPIO_TM16CLK) && PinUsed(GPIO_TM16DIO) && PinUsed(GPIO_TM16STB))) { #else - if (Pin(GPIO_SWT1, i) < 99) { + if (PinUsed(GPIO_SWT1, i)) { #endif // USE_TM1638 snprintf_P(json_event, sizeof(json_event), PSTR("{\"" D_JSON_SWITCH "%d\":{\"Boot\":%d}}"), i +1, (SwitchState(i))); RulesProcessEvent(json_event); diff --git a/tasmota/xdrv_12_home_assistant.ino b/tasmota/xdrv_12_home_assistant.ino index 30d17681c..2a95fa591 100644 --- a/tasmota/xdrv_12_home_assistant.ino +++ b/tasmota/xdrv_12_home_assistant.ino @@ -370,7 +370,7 @@ void HAssAnnounceSwitches(void) uint8_t hold = 0; uint8_t pir = 0; - if (Pin(GPIO_SWT1, switch_index) < 99) { switch_present = 1; } + if (PinUsed(GPIO_SWT1, switch_index)) { switch_present = 1; } if (KeyTopicActive(1) && strcmp(SettingsText(SET_MQTT_SWITCH_TOPIC), mqtt_topic)) // Enable Discovery for Switches only if Switchtopic is set to a custom name { @@ -451,7 +451,7 @@ void HAssAnnounceButtons(void) } else #endif { - if (Pin(GPIO_KEY1, button_index) < 99) { + if (PinUsed(GPIO_KEY1, button_index)) { button_present = 1; } } diff --git a/tasmota/xdrv_14_mp3.ino b/tasmota/xdrv_14_mp3.ino index 3bd722119..ed6beee63 100644 --- a/tasmota/xdrv_14_mp3.ino +++ b/tasmota/xdrv_14_mp3.ino @@ -232,7 +232,7 @@ bool Xdrv14(uint8_t function) { bool result = false; - if (Pin(GPIO_MP3_DFR562) < 99) { + if (PinUsed(GPIO_MP3_DFR562)) { switch (function) { case FUNC_PRE_INIT: MP3PlayerInit(); // init and start communication diff --git a/tasmota/xdrv_16_tuyamcu.ino b/tasmota/xdrv_16_tuyamcu.ino index 8b1bd73bd..bada16061 100644 --- a/tasmota/xdrv_16_tuyamcu.ino +++ b/tasmota/xdrv_16_tuyamcu.ino @@ -596,7 +596,7 @@ void TuyaNormalPowerModePacketProcess(void) bool TuyaModuleSelected(void) { - if (!(Pin(GPIO_TUYA_RX) < 99) || !(Pin(GPIO_TUYA_TX) < 99)) { // fallback to hardware-serial if not explicitly selected + if (!PinUsed(GPIO_TUYA_RX) || !PinUsed(GPIO_TUYA_TX)) { // fallback to hardware-serial if not explicitly selected SetPin(1, GPIO_TUYA_TX); SetPin(3, GPIO_TUYA_RX); Settings.my_gp.io[1] = GPIO_TUYA_TX; diff --git a/tasmota/xdrv_17_rcswitch.ino b/tasmota/xdrv_17_rcswitch.ino index 94323db1d..c5013828c 100644 --- a/tasmota/xdrv_17_rcswitch.ino +++ b/tasmota/xdrv_17_rcswitch.ino @@ -81,10 +81,10 @@ void RfReceiveCheck(void) void RfInit(void) { - if (Pin(GPIO_RFSEND) < 99) { + if (PinUsed(GPIO_RFSEND)) { mySwitch.enableTransmit(Pin(GPIO_RFSEND)); } - if (Pin(GPIO_RFRECV) < 99) { + if (PinUsed(GPIO_RFRECV)) { pinMode( Pin(GPIO_RFRECV), INPUT); mySwitch.enableReceive(Pin(GPIO_RFRECV)); } @@ -170,15 +170,15 @@ bool Xdrv17(uint8_t function) { bool result = false; - if ((Pin(GPIO_RFSEND) < 99) || (Pin(GPIO_RFRECV) < 99)) { + if (PinUsed(GPIO_RFSEND) || PinUsed(GPIO_RFRECV)) { switch (function) { case FUNC_EVERY_50_MSECOND: - if (Pin(GPIO_RFRECV) < 99) { + if (PinUsed(GPIO_RFRECV)) { RfReceiveCheck(); } break; case FUNC_COMMAND: - if (Pin(GPIO_RFSEND) < 99) { + if (PinUsed(GPIO_RFSEND)) { result = DecodeCommand(kRfSendCommands, RfSendCommand); } break; diff --git a/tasmota/xdrv_23_zigbee_9_impl.ino b/tasmota/xdrv_23_zigbee_9_impl.ino index e9024299a..983c76cf3 100644 --- a/tasmota/xdrv_23_zigbee_9_impl.ino +++ b/tasmota/xdrv_23_zigbee_9_impl.ino @@ -162,7 +162,7 @@ void ZigbeeInit(void) // AddLog_P2(LOG_LEVEL_INFO, PSTR("ZigbeeInit Mem1 = %d"), ESP_getFreeHeap()); zigbee.active = false; - if ((Pin(GPIO_ZIGBEE_RX) < 99) && (Pin(GPIO_ZIGBEE_TX) < 99)) { + if (PinUsed(GPIO_ZIGBEE_RX) && PinUsed(GPIO_ZIGBEE_TX)) { AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_ZIGBEE "GPIOs Rx:%d Tx:%d"), Pin(GPIO_ZIGBEE_RX), Pin(GPIO_ZIGBEE_TX)); // if seriallog_level is 0, we allow GPIO 13/15 to switch to Hardware Serial ZigbeeSerial = new TasmotaSerial(Pin(GPIO_ZIGBEE_RX), Pin(GPIO_ZIGBEE_TX), seriallog_level ? 1 : 2, 0, 256); // set a receive buffer of 256 bytes diff --git a/tasmota/xdrv_24_buzzer.ino b/tasmota/xdrv_24_buzzer.ino index 7c522fa7e..f158f3cd9 100644 --- a/tasmota/xdrv_24_buzzer.ino +++ b/tasmota/xdrv_24_buzzer.ino @@ -111,7 +111,7 @@ bool BuzzerPinState(void) void BuzzerInit(void) { - if (Pin(GPIO_BUZZER) < 99) { + if (PinUsed(GPIO_BUZZER)) { pinMode(Pin(GPIO_BUZZER), OUTPUT); BuzzerOff(); } else { diff --git a/tasmota/xdrv_25_A4988_Stepper.ino b/tasmota/xdrv_25_A4988_Stepper.ino index bf75c413f..48f559314 100644 --- a/tasmota/xdrv_25_A4988_Stepper.ino +++ b/tasmota/xdrv_25_A4988_Stepper.ino @@ -93,7 +93,7 @@ void CmndDoTurn(void) { } void CmndSetMIS(void) { - if ((Pin(GPIO_A4988_MS1) < 99) && (Pin(GPIO_A4988_MS2) < 99) && (Pin(GPIO_A4988_MS3) < 99) && (XdrvMailbox.data_len > 0)) { + if (PinUsed(GPIO_A4988_MS1) && PinUsed(GPIO_A4988_MS2) && PinUsed(GPIO_A4988_MS3) && (XdrvMailbox.data_len > 0)) { short newMIS = strtoul(XdrvMailbox.data,nullptr,10); myA4988->setMIS(newMIS); ResponseCmndDone(); @@ -122,7 +122,7 @@ void CmndSetRPM(void) { bool Xdrv25(uint8_t function) { bool result = false; - if ((Pin(GPIO_A4988_DIR) < 99) && (Pin(GPIO_A4988_STP) < 99)) { + if (PinUsed(GPIO_A4988_DIR) && PinUsed(GPIO_A4988_STP)) { switch (function) { case FUNC_INIT: A4988Init(); diff --git a/tasmota/xdrv_26_ariluxrf.ino b/tasmota/xdrv_26_ariluxrf.ino index af3b80ebc..5027dfdcb 100644 --- a/tasmota/xdrv_26_ariluxrf.ino +++ b/tasmota/xdrv_26_ariluxrf.ino @@ -147,7 +147,7 @@ void AriluxRfHandler(void) void AriluxRfInit(void) { - if ((Pin(GPIO_ARIRFRCV) < 99) && (Pin(GPIO_ARIRFSEL) < 99)) { + if (PinUsed(GPIO_ARIRFRCV) && PinUsed(GPIO_ARIRFSEL)) { if (Settings.last_module != Settings.module) { Settings.rf_code[1][6] = 0; Settings.rf_code[1][7] = 0; @@ -162,7 +162,7 @@ void AriluxRfInit(void) void AriluxRfDisable(void) { - if ((Pin(GPIO_ARIRFRCV) < 99) && (Pin(GPIO_ARIRFSEL) < 99)) { + if (PinUsed(GPIO_ARIRFRCV) && PinUsed(GPIO_ARIRFSEL)) { detachInterrupt(Pin(GPIO_ARIRFRCV)); digitalWrite(Pin(GPIO_ARIRFSEL), 1); // Turn off RF } @@ -178,7 +178,7 @@ bool Xdrv26(uint8_t function) switch (function) { case FUNC_EVERY_50_MSECOND: - if (Pin(GPIO_ARIRFRCV) < 99) { AriluxRfHandler(); } + if (PinUsed(GPIO_ARIRFRCV)) { AriluxRfHandler(); } break; case FUNC_EVERY_SECOND: if (10 == uptime) { AriluxRfInit(); } // Needs rest before enabling RF interrupts diff --git a/tasmota/xdrv_27_shutter.ino b/tasmota/xdrv_27_shutter.ino index b2d0609ed..8e001abb9 100644 --- a/tasmota/xdrv_27_shutter.ino +++ b/tasmota/xdrv_27_shutter.ino @@ -201,7 +201,7 @@ void ShutterInit(void) } } else { Shutter.mode = SHT_OFF_ON__OPEN_CLOSE; - if ((Pin(GPIO_PWM1, i) < 99) && (Pin(GPIO_CNTR1, i) < 99)) { + if (PinUsed(GPIO_PWM1, i) && PinUsed(GPIO_CNTR1, i)) { Shutter.mode = SHT_OFF_ON__OPEN_CLOSE_STEPPER; Shutter.pwm_frequency[i] = 0; Shutter.accelerator[i] = 0; diff --git a/tasmota/xdrv_29_deepsleep.ino b/tasmota/xdrv_29_deepsleep.ino index c78a5fbbd..4ac0531db 100644 --- a/tasmota/xdrv_29_deepsleep.ino +++ b/tasmota/xdrv_29_deepsleep.ino @@ -54,7 +54,7 @@ bool DeepSleepEnabled(void) return false; // Disabled } - if (Pin(GPIO_DEEPSLEEP) < 99) { + if (PinUsed(GPIO_DEEPSLEEP)) { pinMode(Pin(GPIO_DEEPSLEEP), INPUT_PULLUP); return (digitalRead(Pin(GPIO_DEEPSLEEP))); // Disable DeepSleep if user holds pin GPIO_DEEPSLEEP low } diff --git a/tasmota/xdrv_31_tasmota_slave.ino b/tasmota/xdrv_31_tasmota_slave.ino index 52a43178a..37b98c897 100644 --- a/tasmota/xdrv_31_tasmota_slave.ino +++ b/tasmota/xdrv_31_tasmota_slave.ino @@ -437,15 +437,15 @@ void TasmotaSlave_Init(void) return; } if (!TSlave.SerialEnabled) { - if ((Pin(GPIO_TASMOTASLAVE_RXD) < 99) && (Pin(GPIO_TASMOTASLAVE_TXD) < 99) && - ((Pin(GPIO_TASMOTASLAVE_RST) < 99) || (Pin(GPIO_TASMOTASLAVE_RST_INV) < 99))) { + if (PinUsed(GPIO_TASMOTASLAVE_RXD) && PinUsed(GPIO_TASMOTASLAVE_TXD) && + (PinUsed(GPIO_TASMOTASLAVE_RST) || PinUsed(GPIO_TASMOTASLAVE_RST_INV))) { TasmotaSlave_Serial = new TasmotaSerial(Pin(GPIO_TASMOTASLAVE_RXD), Pin(GPIO_TASMOTASLAVE_TXD), 1, 0, 200); if (TasmotaSlave_Serial->begin(USE_TASMOTA_SLAVE_SERIAL_SPEED)) { if (TasmotaSlave_Serial->hardwareSerial()) { ClaimSerial(); } TasmotaSlave_Serial->setTimeout(50); - if (Pin(GPIO_TASMOTASLAVE_RST_INV) < 99) { + if (PinUsed(GPIO_TASMOTASLAVE_RST_INV)) { SetPin(Pin(GPIO_TASMOTASLAVE_RST_INV), GPIO_TASMOTASLAVE_RST); SetPin(99, GPIO_TASMOTASLAVE_RST_INV); TSlave.inverted = HIGH; diff --git a/tasmota/xdrv_33_nrf24l01.ino b/tasmota/xdrv_33_nrf24l01.ino index 3e7d8c63d..442bcb4db 100644 --- a/tasmota/xdrv_33_nrf24l01.ino +++ b/tasmota/xdrv_33_nrf24l01.ino @@ -73,7 +73,7 @@ bool NRF24initRadio() bool NRF24Detect(void) { - if ((Pin(GPIO_SPI_CS)<99) && (Pin(GPIO_SPI_DC)<99)){ + if (PinUsed(GPIO_SPI_CS) && PinUsed(GPIO_SPI_DC)) { SPI.pins(SCK,MOSI,MISO,-1); if(NRF24initRadio()){ NRF24.chipType = 32; // SPACE diff --git a/tasmota/xdrv_35_pwm_dimmer.ino b/tasmota/xdrv_35_pwm_dimmer.ino index 429bc7421..fd7a9d86b 100644 --- a/tasmota/xdrv_35_pwm_dimmer.ino +++ b/tasmota/xdrv_35_pwm_dimmer.ino @@ -94,7 +94,7 @@ void PWMModulePreInit(void) PWMDimmerSetPoweredOffLed(); // The relay initializes to on. If the power is supposed to be off, turn the relay off. - if (!power && Pin(GPIO_REL1) < 99) digitalWrite(Pin(GPIO_REL1), bitRead(rel_inverted, 0) ? 1 : 0); + if (!power && PinUsed(GPIO_REL1)) digitalWrite(Pin(GPIO_REL1), bitRead(rel_inverted, 0) ? 1 : 0); #ifdef USE_PWM_DIMMER_REMOTE // If remote device mode is enabled, set the device group count to the number of buttons @@ -104,7 +104,7 @@ void PWMModulePreInit(void) device_group_count = 0; for (uint32_t button_index = 0; button_index < MAX_KEYS; button_index++) { - if (Pin(GPIO_KEY1, button_index) < 99) device_group_count++; + if (PinUsed(GPIO_KEY1, button_index)) device_group_count++; } remote_pwm_dimmer_count = device_group_count - 1; @@ -156,7 +156,7 @@ void PWMDimmerSetBrightnessLeds(int32_t operation) void PWMDimmerSetPoweredOffLed(void) { // Set the powered-off LED state. - if (Pin(GPIO_LEDLNK) < 99) { + if (PinUsed(GPIO_LEDLNK)) { bool power_off_led_on = !power && Settings.flag4.powered_off_led; if (ledlnk_inverted) power_off_led_on ^= 1; digitalWrite(Pin(GPIO_LEDLNK), power_off_led_on); diff --git a/tasmota/xdsp_02_ssd1306.ino b/tasmota/xdsp_02_ssd1306.ino index 64ee72794..24700b0af 100644 --- a/tasmota/xdsp_02_ssd1306.ino +++ b/tasmota/xdsp_02_ssd1306.ino @@ -71,7 +71,7 @@ void SSD1306InitDriver(void) } uint8_t reset_pin = -1; - if (Pin(GPIO_OLED_RESET) < 99) { + if (PinUsed(GPIO_OLED_RESET)) { reset_pin = Pin(GPIO_OLED_RESET); } diff --git a/tasmota/xdsp_04_ili9341.ino b/tasmota/xdsp_04_ili9341.ino index 85432de52..f755314c8 100644 --- a/tasmota/xdsp_04_ili9341.ino +++ b/tasmota/xdsp_04_ili9341.ino @@ -128,7 +128,7 @@ void Ili9341DisplayOnOff(uint8_t on) { // tft->showDisplay(on); // tft->invertDisplay(on); - if (Pin(GPIO_BACKLIGHT) < 99) { + if (PinUsed(GPIO_BACKLIGHT)) { pinMode(Pin(GPIO_BACKLIGHT), OUTPUT); digitalWrite(Pin(GPIO_BACKLIGHT), on); } diff --git a/tasmota/xdsp_05_epaper_29.ino b/tasmota/xdsp_05_epaper_29.ino index c46a13229..dc7397221 100644 --- a/tasmota/xdsp_05_epaper_29.ino +++ b/tasmota/xdsp_05_epaper_29.ino @@ -67,11 +67,11 @@ void EpdInitDriver29() epd = new Epd(EPD_WIDTH,EPD_HEIGHT); // whiten display with full update, takes 3 seconds - if ((Pin(GPIO_SPI_CS) < 99) && (Pin(GPIO_SPI_CLK) < 99) && (Pin(GPIO_SPI_MOSI) < 99)) { + if (PinUsed(GPIO_SPI_CS) && PinUsed(GPIO_SPI_CLK) && PinUsed(GPIO_SPI_MOSI)) { epd->Begin(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_CLK)); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("EPD: HardSPI CS %d, CLK %d, MOSI %d"),Pin(GPIO_SPI_CS), Pin(GPIO_SPI_CLK), Pin(GPIO_SPI_MOSI)); } - else if ((Pin(GPIO_SSPI_CS) < 99) && (Pin(GPIO_SSPI_SCLK) < 99) && (Pin(GPIO_SSPI_MOSI) < 99)) { + else if (PinUsed(GPIO_SSPI_CS) && PinUsed(GPIO_SSPI_SCLK) && PinUsed(GPIO_SSPI_MOSI)) { epd->Begin(Pin(GPIO_SSPI_CS),Pin(GPIO_SSPI_MOSI),Pin(GPIO_SSPI_SCLK)); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("EPD: SoftSPI CS %d, CLK %d, MOSI %d"),Pin(GPIO_SSPI_CS), Pin(GPIO_SSPI_SCLK), Pin(GPIO_SSPI_MOSI)); } else { diff --git a/tasmota/xdsp_06_epaper_42.ino b/tasmota/xdsp_06_epaper_42.ino index b48f159bb..fee42db6c 100644 --- a/tasmota/xdsp_06_epaper_42.ino +++ b/tasmota/xdsp_06_epaper_42.ino @@ -65,14 +65,14 @@ void EpdInitDriver42() epd42 = new Epd42(EPD_WIDTH42,EPD_HEIGHT42); #ifdef USE_SPI - if ((Pin(GPIO_SSPI_CS)<99) && (Pin(GPIO_SSPI_MOSI)<99) && (Pin(GPIO_SSPI_SCLK)<99)) { + if (PinUsed(GPIO_SSPI_CS) && PinUsed(GPIO_SSPI_MOSI) && PinUsed(GPIO_SSPI_SCLK)) { epd42->Begin(Pin(GPIO_SSPI_CS),Pin(GPIO_SSPI_MOSI),Pin(GPIO_SSPI_SCLK)); } else { free(buffer); return; } #else - if ((Pin(GPIO_SPI_CS)<99) && (Pin(GPIO_SPI_MOSI)<99) && (Pin(GPIO_SPI_CLK)<99)) { + if (PinUsed(GPIO_SPI_CS) && PinUsed(GPIO_SPI_MOSI) && PinUsed(GPIO_SPI_CLK)) { epd42->Begin(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_CLK)); } else { free(buffer); diff --git a/tasmota/xdsp_08_ILI9488.ino b/tasmota/xdsp_08_ILI9488.ino index eeb1328dc..1dc877e18 100644 --- a/tasmota/xdsp_08_ILI9488.ino +++ b/tasmota/xdsp_08_ILI9488.ino @@ -80,15 +80,15 @@ void ILI9488_InitDriver() bg_color = ILI9488_BLACK; uint8_t bppin=BACKPLANE_PIN; - if (Pin(GPIO_BACKLIGHT)<99) { + if (PinUsed(GPIO_BACKLIGHT)) { bppin=Pin(GPIO_BACKLIGHT); } // init renderer - if ((Pin(GPIO_SSPI_CS)<99) && (Pin(GPIO_SSPI_MOSI)<99) && (Pin(GPIO_SSPI_SCLK)<99)){ + if (PinUsed(GPIO_SSPI_CS) && PinUsed(GPIO_SSPI_MOSI) && PinUsed(GPIO_SSPI_SCLK)) { ili9488 = new ILI9488(Pin(GPIO_SSPI_CS),Pin(GPIO_SSPI_MOSI),Pin(GPIO_SSPI_SCLK),bppin); } else { - if ((Pin(GPIO_SPI_CS)<99) && (Pin(GPIO_SPI_MOSI)<99) && (Pin(GPIO_SPI_CLK)<99)) { + if (PinUsed(GPIO_SPI_CS) && PinUsed(GPIO_SPI_MOSI) && PinUsed(GPIO_SPI_CLK)) { ili9488 = new ILI9488(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_CLK),bppin); } else { return; diff --git a/tasmota/xdsp_09_SSD1351.ino b/tasmota/xdsp_09_SSD1351.ino index 978973c0d..5f3148be6 100644 --- a/tasmota/xdsp_09_SSD1351.ino +++ b/tasmota/xdsp_09_SSD1351.ino @@ -60,10 +60,10 @@ void SSD1351_InitDriver() { bg_color = SSD1351_BLACK; // init renderer - if ((Pin(GPIO_SSPI_CS)<99) && (Pin(GPIO_SSPI_MOSI)<99) && (Pin(GPIO_SSPI_SCLK)<99)){ + if (PinUsed(GPIO_SSPI_CS) && PinUsed(GPIO_SSPI_MOSI) && PinUsed(GPIO_SSPI_SCLK)){ ssd1351 = new SSD1351(Pin(GPIO_SSPI_CS),Pin(GPIO_SSPI_MOSI),Pin(GPIO_SSPI_SCLK)); } else { - if ((Pin(GPIO_SPI_CS)<99) && (Pin(GPIO_SPI_MOSI)<99) && (Pin(GPIO_SPI_CLK)<99)) { + if (PinUsed(GPIO_SPI_CS) && PinUsed(GPIO_SPI_MOSI) && PinUsed(GPIO_SPI_CLK)) { ssd1351 = new SSD1351(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_CLK)); } else { return; diff --git a/tasmota/xdsp_10_RA8876.ino b/tasmota/xdsp_10_RA8876.ino index a91644f3e..9c86ff2d7 100644 --- a/tasmota/xdsp_10_RA8876.ino +++ b/tasmota/xdsp_10_RA8876.ino @@ -72,10 +72,10 @@ void RA8876_InitDriver() bg_color = RA8876_BLACK; // init renderer, must use hardware spi - if ((Pin(GPIO_SSPI_CS)<99) && (Pin(GPIO_SSPI_MOSI)==13) && (Pin(GPIO_SSPI_MISO)==12) && (Pin(GPIO_SSPI_SCLK)==14)) { + if (PinUsed(GPIO_SSPI_CS) && (Pin(GPIO_SSPI_MOSI)==13) && (Pin(GPIO_SSPI_MISO)==12) && (Pin(GPIO_SSPI_SCLK)==14)) { ra8876 = new RA8876(Pin(GPIO_SSPI_CS),Pin(GPIO_SSPI_MOSI),Pin(GPIO_SSPI_MISO),Pin(GPIO_SSPI_SCLK),Pin(GPIO_BACKLIGHT)); } else { - if ((Pin(GPIO_SPI_CS)<99) && (Pin(GPIO_SPI_MOSI)==13) && (Pin(GPIO_SPI_MISO)==12) && (Pin(GPIO_SPI_CLK)==14)) { + if (PinUsed(GPIO_SPI_CS) && (Pin(GPIO_SPI_MOSI)==13) && (Pin(GPIO_SPI_MISO)==12) && (Pin(GPIO_SPI_CLK)==14)) { ra8876 = new RA8876(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_MISO),Pin(GPIO_SPI_CLK),Pin(GPIO_BACKLIGHT)); } else { return; diff --git a/tasmota/xlgt_01_ws2812.ino b/tasmota/xlgt_01_ws2812.ino index fe31f9779..368567181 100644 --- a/tasmota/xlgt_01_ws2812.ino +++ b/tasmota/xlgt_01_ws2812.ino @@ -449,7 +449,7 @@ void Ws2812ShowScheme(void) void Ws2812ModuleSelected(void) { - if (Pin(GPIO_WS2812) < 99) { // RGB led + if (PinUsed(GPIO_WS2812)) { // RGB led // For DMA, the Pin is ignored as it uses GPIO3 due to DMA hardware use. strip = new NeoPixelBus(WS2812_MAX_LEDS, Pin(GPIO_WS2812)); diff --git a/tasmota/xlgt_02_my92x1.ino b/tasmota/xlgt_02_my92x1.ino index b129a80b0..6d12abf84 100644 --- a/tasmota/xlgt_02_my92x1.ino +++ b/tasmota/xlgt_02_my92x1.ino @@ -115,7 +115,7 @@ bool My92x1SetChannels(void) void My92x1ModuleSelected(void) { - if ((Pin(GPIO_DCKI) < 99) && (Pin(GPIO_DI) < 99)) { + if (PinUsed(GPIO_DCKI) && PinUsed(GPIO_DI)) { My92x1.pdi_pin = Pin(GPIO_DI); My92x1.pdcki_pin = Pin(GPIO_DCKI); diff --git a/tasmota/xlgt_03_sm16716.ino b/tasmota/xlgt_03_sm16716.ino index 5269749fa..314122a8b 100644 --- a/tasmota/xlgt_03_sm16716.ino +++ b/tasmota/xlgt_03_sm16716.ino @@ -122,7 +122,7 @@ bool Sm16716SetChannels(void) /* // handle any PWM pins, skipping the first 3 values for sm16716 for (uint32_t i = 3; i < Light.subtype; i++) { - if (Pin(GPIO_PWM1, i-3) < 99) { + if (PinUsed(GPIO_PWM1, i-3)) { //AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION "Cur_Col%d 10 bits %d, Pwm%d %d"), i, cur_col[i], i+1, curcol); analogWrite(Pin(GPIO_PWM1, i-3), bitRead(pwm_inverted, i-3) ? Settings.pwm_range - cur_col_10bits[i] : cur_col_10bits[i]); } @@ -138,7 +138,7 @@ bool Sm16716SetChannels(void) void Sm16716ModuleSelected(void) { - if ((Pin(GPIO_SM16716_CLK) < 99) && (Pin(GPIO_SM16716_DAT) < 99)) { + if (PinUsed(GPIO_SM16716_CLK) && PinUsed(GPIO_SM16716_DAT)) { Sm16716.pin_clk = Pin(GPIO_SM16716_CLK); Sm16716.pin_dat = Pin(GPIO_SM16716_DAT); Sm16716.pin_sel = Pin(GPIO_SM16716_SEL); @@ -147,7 +147,7 @@ void Sm16716ModuleSelected(void) // init PWM for (uint32_t i = 0; i < Light.subtype; i++) { Settings.pwm_value[i] = 0; // Disable direct PWM control - if (Pin(GPIO_PWM1, i) < 99) { + if (PinUsed(GPIO_PWM1, i)) { pinMode(Pin(GPIO_PWM1, i), OUTPUT); } } diff --git a/tasmota/xlgt_04_sm2135.ino b/tasmota/xlgt_04_sm2135.ino index 2c0374123..e262395a8 100644 --- a/tasmota/xlgt_04_sm2135.ino +++ b/tasmota/xlgt_04_sm2135.ino @@ -134,7 +134,7 @@ bool Sm2135SetChannels(void) void Sm2135ModuleSelected(void) { - if ((Pin(GPIO_SM2135_CLK) < 99) && (Pin(GPIO_SM2135_DAT) < 99)) { + if (PinUsed(GPIO_SM2135_CLK) && PinUsed(GPIO_SM2135_DAT)) { Sm2135.clk = Pin(GPIO_SM2135_CLK); Sm2135.data = Pin(GPIO_SM2135_DAT); diff --git a/tasmota/xlgt_05_sonoff_l1.ino b/tasmota/xlgt_05_sonoff_l1.ino index 1a32fa9ae..295330142 100644 --- a/tasmota/xlgt_05_sonoff_l1.ino +++ b/tasmota/xlgt_05_sonoff_l1.ino @@ -221,7 +221,7 @@ bool SnfL1SetChannels(void) void SnfL1ModuleSelected(void) { if (SONOFF_L1 == my_module_type) { - if ((Pin(GPIO_RXD) < 99) && (Pin(GPIO_TXD) < 99)) { + if (PinUsed(GPIO_RXD) && PinUsed(GPIO_TXD)) { SetSerial(19200, TS_SERIAL_8N1); light_type = LT_RGB; diff --git a/tasmota/xlgt_06_electriq_moodl.ino b/tasmota/xlgt_06_electriq_moodl.ino index 36a1e9e7a..57c493e64 100644 --- a/tasmota/xlgt_06_electriq_moodl.ino +++ b/tasmota/xlgt_06_electriq_moodl.ino @@ -70,7 +70,7 @@ bool ElectriqMoodLSetChannels(void) void ElectriqMoodLModuleSelected(void) { - if (Pin(GPIO_ELECTRIQ_MOODL_TX) < 99) { + if (PinUsed(GPIO_ELECTRIQ_MOODL_TX)) { SetSerial(9600, TS_SERIAL_8N1); light_type = LT_RGBW; light_flg = XLGT_06; diff --git a/tasmota/xnrg_01_hlw8012.ino b/tasmota/xnrg_01_hlw8012.ino index 6a106e985..9a054422e 100644 --- a/tasmota/xnrg_01_hlw8012.ino +++ b/tasmota/xnrg_01_hlw8012.ino @@ -138,7 +138,7 @@ void HlwEvery200ms(void) } } - if (Pin(GPIO_NRG_CF1) < 99) { + if (PinUsed(GPIO_NRG_CF1)) { Hlw.cf1_timer++; if (Hlw.cf1_timer >= 8) { Hlw.cf1_timer = 0; @@ -233,11 +233,11 @@ void HlwSnsInit(void) Hlw.current_ratio = HLW_IREF; } - if (Pin(GPIO_NRG_SEL) < 99) { + if (PinUsed(GPIO_NRG_SEL)) { pinMode(Pin(GPIO_NRG_SEL), OUTPUT); digitalWrite(Pin(GPIO_NRG_SEL), Hlw.select_ui_flag); } - if (Pin(GPIO_NRG_CF1) < 99) { + if (PinUsed(GPIO_NRG_CF1)) { pinMode(Pin(GPIO_NRG_CF1), INPUT_PULLUP); attachInterrupt(Pin(GPIO_NRG_CF1), HlwCf1Interrupt, FALLING); } @@ -248,7 +248,7 @@ void HlwSnsInit(void) void HlwDrvInit(void) { Hlw.model_type = 0; // HLW8012 - if (Pin(GPIO_HJL_CF) < 99) { + if (PinUsed(GPIO_HJL_CF)) { // pin[GPIO_HLW_CF] = pin[GPIO_HJL_CF]; // pin[GPIO_HJL_CF] = 99; SetPin(Pin(GPIO_HJL_CF), GPIO_HLW_CF); @@ -256,10 +256,10 @@ void HlwDrvInit(void) Hlw.model_type = 1; // HJL-01/BL0937 } - if (Pin(GPIO_HLW_CF) < 99) { // HLW8012 or HJL-01 based device Power monitor + if (PinUsed(GPIO_HLW_CF)) { // HLW8012 or HJL-01 based device Power monitor Hlw.ui_flag = true; // Voltage on high - if (Pin(GPIO_NRG_SEL_INV) < 99) { + if (PinUsed(GPIO_NRG_SEL_INV)) { // pin[GPIO_NRG_SEL] = pin[GPIO_NRG_SEL_INV]; // pin[GPIO_NRG_SEL_INV] = 99; SetPin(Pin(GPIO_NRG_SEL_INV), GPIO_NRG_SEL); @@ -267,7 +267,7 @@ void HlwDrvInit(void) Hlw.ui_flag = false; // Voltage on low } - if (Pin(GPIO_NRG_CF1) < 99) { // Voltage and/or Current monitor + if (PinUsed(GPIO_NRG_CF1)) { // Voltage and/or Current monitor if (99 == Pin(GPIO_NRG_SEL)) { // Voltage and/or Current selector Energy.current_available = false; // Assume Voltage } diff --git a/tasmota/xnrg_02_cse7766.ino b/tasmota/xnrg_02_cse7766.ino index 13be8d7f9..dae622845 100644 --- a/tasmota/xnrg_02_cse7766.ino +++ b/tasmota/xnrg_02_cse7766.ino @@ -245,8 +245,8 @@ void CseDrvInit(void) { Cse.rx_buffer = (uint8_t*)(malloc(CSE_BUFFER_SIZE)); if (Cse.rx_buffer != nullptr) { -// if ((Pin(GPIO_CSE7766_RX) < 99) && (Pin(GPIO_CSE7766_TX) < 99)) { - if (Pin(GPIO_CSE7766_RX) < 99) { +// if (PinUsed(GPIO_CSE7766_RX) && PinUsed(GPIO_CSE7766_TX)) { + if (PinUsed(GPIO_CSE7766_RX)) { energy_flg = XNRG_02; } } diff --git a/tasmota/xnrg_03_pzem004t.ino b/tasmota/xnrg_03_pzem004t.ino index d61608aa6..f06b34b0e 100644 --- a/tasmota/xnrg_03_pzem004t.ino +++ b/tasmota/xnrg_03_pzem004t.ino @@ -256,7 +256,7 @@ void PzemSnsInit(void) void PzemDrvInit(void) { - if ((Pin(GPIO_PZEM004_RX) < 99) && (Pin(GPIO_PZEM0XX_TX) < 99)) { // Any device with a Pzem004T + if (PinUsed(GPIO_PZEM004_RX) && PinUsed(GPIO_PZEM0XX_TX)) { // Any device with a Pzem004T energy_flg = XNRG_03; } } diff --git a/tasmota/xnrg_04_mcp39f501.ino b/tasmota/xnrg_04_mcp39f501.ino index 3c1e97d09..b3f8dbe6c 100644 --- a/tasmota/xnrg_04_mcp39f501.ino +++ b/tasmota/xnrg_04_mcp39f501.ino @@ -578,8 +578,8 @@ void McpSnsInit(void) void McpDrvInit(void) { - if ((Pin(GPIO_MCP39F5_RX) < 99) && (Pin(GPIO_MCP39F5_TX) < 99)) { - if (Pin(GPIO_MCP39F5_RST) < 99) { + if (PinUsed(GPIO_MCP39F5_RX) && PinUsed(GPIO_MCP39F5_TX)) { + if (PinUsed(GPIO_MCP39F5_RST)) { pinMode(Pin(GPIO_MCP39F5_RST), OUTPUT); digitalWrite(Pin(GPIO_MCP39F5_RST), 0); // MCP disable - Reset Delta Sigma ADC's } diff --git a/tasmota/xnrg_05_pzem_ac.ino b/tasmota/xnrg_05_pzem_ac.ino index 23b4bf9dd..bd656a874 100644 --- a/tasmota/xnrg_05_pzem_ac.ino +++ b/tasmota/xnrg_05_pzem_ac.ino @@ -130,7 +130,7 @@ void PzemAcSnsInit(void) void PzemAcDrvInit(void) { - if ((Pin(GPIO_PZEM016_RX) < 99) && (Pin(GPIO_PZEM0XX_TX) < 99)) { + if (PinUsed(GPIO_PZEM016_RX) && PinUsed(GPIO_PZEM0XX_TX)) { energy_flg = XNRG_05; } } diff --git a/tasmota/xnrg_06_pzem_dc.ino b/tasmota/xnrg_06_pzem_dc.ino index 5ac58a035..444861fb0 100644 --- a/tasmota/xnrg_06_pzem_dc.ino +++ b/tasmota/xnrg_06_pzem_dc.ino @@ -127,7 +127,7 @@ void PzemDcSnsInit(void) void PzemDcDrvInit(void) { - if ((Pin(GPIO_PZEM017_RX) < 99) && (Pin(GPIO_PZEM0XX_TX) < 99)) { + if (PinUsed(GPIO_PZEM017_RX) && PinUsed(GPIO_PZEM0XX_TX)) { energy_flg = XNRG_06; } } diff --git a/tasmota/xnrg_07_ade7953.ino b/tasmota/xnrg_07_ade7953.ino index 1792cc255..44bec2e59 100644 --- a/tasmota/xnrg_07_ade7953.ino +++ b/tasmota/xnrg_07_ade7953.ino @@ -199,7 +199,7 @@ void Ade7953EnergyEverySecond(void) void Ade7953DrvInit(void) { - if (Pin(GPIO_ADE7953_IRQ) < 99) { // Irq on GPIO16 is not supported... + if (PinUsed(GPIO_ADE7953_IRQ)) { // Irq on GPIO16 is not supported... delay(100); // Need 100mS to init ADE7953 if (I2cSetDevice(ADE7953_ADDR)) { if (HLW_PREF_PULSE == Settings.energy_power_calibration) { diff --git a/tasmota/xnrg_08_sdm120.ino b/tasmota/xnrg_08_sdm120.ino index 2083f348c..93af326f8 100644 --- a/tasmota/xnrg_08_sdm120.ino +++ b/tasmota/xnrg_08_sdm120.ino @@ -187,7 +187,7 @@ void Sdm120SnsInit(void) void Sdm120DrvInit(void) { - if ((Pin(GPIO_SDM120_RX) < 99) && (Pin(GPIO_SDM120_TX) < 99)) { + if (PinUsed(GPIO_SDM120_RX) && PinUsed(GPIO_SDM120_TX)) { energy_flg = XNRG_08; } } diff --git a/tasmota/xnrg_09_dds2382.ino b/tasmota/xnrg_09_dds2382.ino index a713ded1f..a516ea4a8 100644 --- a/tasmota/xnrg_09_dds2382.ino +++ b/tasmota/xnrg_09_dds2382.ino @@ -102,7 +102,7 @@ void Dds2382SnsInit(void) void Dds2382DrvInit(void) { - if ((Pin(GPIO_DDS2382_RX) < 99) && (Pin(GPIO_DDS2382_TX) < 99)) { + if (PinUsed(GPIO_DDS2382_RX) && PinUsed(GPIO_DDS2382_TX)) { energy_flg = XNRG_09; } } diff --git a/tasmota/xnrg_10_sdm630.ino b/tasmota/xnrg_10_sdm630.ino index f2c474204..4bfeecc96 100644 --- a/tasmota/xnrg_10_sdm630.ino +++ b/tasmota/xnrg_10_sdm630.ino @@ -186,7 +186,7 @@ void Sdm630SnsInit(void) void Sdm630DrvInit(void) { - if ((Pin(GPIO_SDM630_RX) < 99) && (Pin(GPIO_SDM630_TX) < 99)) { + if (PinUsed(GPIO_SDM630_RX) && PinUsed(GPIO_SDM630_TX)) { energy_flg = XNRG_10; } } diff --git a/tasmota/xnrg_11_ddsu666.ino b/tasmota/xnrg_11_ddsu666.ino index 864f8c987..87b585d84 100644 --- a/tasmota/xnrg_11_ddsu666.ino +++ b/tasmota/xnrg_11_ddsu666.ino @@ -144,7 +144,7 @@ void Ddsu666SnsInit(void) void Ddsu666DrvInit(void) { - if ((Pin(GPIO_DDSU666_RX) < 99) && (Pin(GPIO_DDSU666_TX) < 99)) { + if (PinUsed(GPIO_DDSU666_RX) && PinUsed(GPIO_DDSU666_TX)) { energy_flg = XNRG_11; } } diff --git a/tasmota/xnrg_12_solaxX1.ino b/tasmota/xnrg_12_solaxX1.ino index c04ed8bca..418a92acb 100644 --- a/tasmota/xnrg_12_solaxX1.ino +++ b/tasmota/xnrg_12_solaxX1.ino @@ -419,7 +419,7 @@ void solaxX1SnsInit(void) void solaxX1DrvInit(void) { - if ((Pin(GPIO_SOLAXX1_RX) < 99) && (Pin(GPIO_SOLAXX1_TX) < 99)) { + if (PinUsed(GPIO_SOLAXX1_RX) && PinUsed(GPIO_SOLAXX1_TX)) { energy_flg = XNRG_12; } } diff --git a/tasmota/xnrg_13_fif_le01mr.ino b/tasmota/xnrg_13_fif_le01mr.ino index 0fcac2658..71e77793a 100644 --- a/tasmota/xnrg_13_fif_le01mr.ino +++ b/tasmota/xnrg_13_fif_le01mr.ino @@ -224,7 +224,7 @@ void FifLESnsInit(void) void FifLEDrvInit(void) { - if ((Pin(GPIO_LE01MR_RX) < 99) && (Pin(GPIO_LE01MR_TX) < 99)) { + if (PinUsed(GPIO_LE01MR_RX) && PinUsed(GPIO_LE01MR_TX)) { energy_flg = XNRG_13; } } diff --git a/tasmota/xsns_01_counter.ino b/tasmota/xsns_01_counter.ino index 4e6db3eb7..fec5791f7 100644 --- a/tasmota/xsns_01_counter.ino +++ b/tasmota/xsns_01_counter.ino @@ -127,7 +127,7 @@ void CounterInit(void) function counter_callbacks[] = { CounterUpdate1, CounterUpdate2, CounterUpdate3, CounterUpdate4 }; for (uint32_t i = 0; i < MAX_COUNTERS; i++) { - if (Pin(GPIO_CNTR1, i) < 99) { + if (PinUsed(GPIO_CNTR1, i)) { Counter.any_counter = true; pinMode(Pin(GPIO_CNTR1, i), bitRead(Counter.no_pullup, i) ? INPUT : INPUT_PULLUP); if ((0 == Settings.pulse_counter_debounce_low) && (0 == Settings.pulse_counter_debounce_high)) { @@ -144,7 +144,7 @@ void CounterInit(void) void CounterEverySecond(void) { for (uint32_t i = 0; i < MAX_COUNTERS; i++) { - if (Pin(GPIO_CNTR1, i) < 99) { + if (PinUsed(GPIO_CNTR1, i)) { if (bitRead(Settings.pulse_counter_type, i)) { uint32_t time = micros() - Counter.timer[i]; if (time > 4200000000) { // 70 minutes @@ -158,7 +158,7 @@ void CounterEverySecond(void) void CounterSaveState(void) { for (uint32_t i = 0; i < MAX_COUNTERS; i++) { - if (Pin(GPIO_CNTR1, i) < 99) { + if (PinUsed(GPIO_CNTR1, i)) { Settings.pulse_counter[i] = RtcSettings.pulse_counter[i]; } } @@ -169,7 +169,7 @@ void CounterShow(bool json) bool header = false; uint8_t dsxflg = 0; for (uint32_t i = 0; i < MAX_COUNTERS; i++) { - if (Pin(GPIO_CNTR1, i) < 99) { + if (PinUsed(GPIO_CNTR1, i)) { char counter[33]; if (bitRead(Settings.pulse_counter_type, i)) { dtostrfd((double)RtcSettings.pulse_counter[i] / 1000000, 6, counter); @@ -213,7 +213,7 @@ void CounterShow(bool json) void CmndCounter(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_COUNTERS)) { - if ((XdrvMailbox.data_len > 0) && (Pin(GPIO_CNTR1, XdrvMailbox.index -1) < 99)) { + if ((XdrvMailbox.data_len > 0) && PinUsed(GPIO_CNTR1, XdrvMailbox.index -1)) { if ((XdrvMailbox.data[0] == '-') || (XdrvMailbox.data[0] == '+')) { RtcSettings.pulse_counter[XdrvMailbox.index -1] += XdrvMailbox.payload; Settings.pulse_counter[XdrvMailbox.index -1] += XdrvMailbox.payload; @@ -229,7 +229,7 @@ void CmndCounter(void) void CmndCounterType(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_COUNTERS)) { - if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1) && (Pin(GPIO_CNTR1, XdrvMailbox.index -1) < 99)) { + if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1) && PinUsed(GPIO_CNTR1, XdrvMailbox.index -1)) { bitWrite(Settings.pulse_counter_type, XdrvMailbox.index -1, XdrvMailbox.payload &1); RtcSettings.pulse_counter[XdrvMailbox.index -1] = 0; Settings.pulse_counter[XdrvMailbox.index -1] = 0; diff --git a/tasmota/xsns_05_ds18x20.ino b/tasmota/xsns_05_ds18x20.ino index 046fb11c4..a762014c7 100644 --- a/tasmota/xsns_05_ds18x20.ino +++ b/tasmota/xsns_05_ds18x20.ino @@ -304,10 +304,10 @@ void Ds18x20Init(void) { uint64_t ids[DS18X20_MAX_SENSORS]; - ds18x20_pin = pin[GPIO_DSB]; + ds18x20_pin = Pin(GPIO_DSB); - if (pin[GPIO_DSB_OUT] < 99) { - ds18x20_pin_out = pin[GPIO_DSB_OUT]; + if (PinUsed(GPIO_DSB_OUT)) { + ds18x20_pin_out = Pin(GPIO_DSB_OUT); ds18x20_dual_mode = true; // Dual pins mode as used by Shelly pinMode(ds18x20_pin_out, OUTPUT); pinMode(ds18x20_pin, Settings.flag3.ds18x20_internal_pullup ? INPUT_PULLUP : INPUT); // SetOption74 - Enable internal pullup for single DS18x20 sensor @@ -518,7 +518,7 @@ bool Xsns05(uint8_t function) { bool result = false; - if (pin[GPIO_DSB] < 99) { + if (PinUsed(GPIO_DSB)) { switch (function) { case FUNC_INIT: Ds18x20Init(); diff --git a/tasmota/xsns_06_dht.ino b/tasmota/xsns_06_dht.ino index 2edc4abfa..46fb69fa5 100644 --- a/tasmota/xsns_06_dht.ino +++ b/tasmota/xsns_06_dht.ino @@ -204,8 +204,8 @@ bool DhtPinState() void DhtInit(void) { if (dht_sensors) { - if (pin[GPIO_DHT11_OUT] < 99) { - dht_pin_out = pin[GPIO_DHT11_OUT]; + if (PinUsed(GPIO_DHT11_OUT)) { + dht_pin_out = Pin(GPIO_DHT11_OUT); dht_dual_mode = true; // Dual pins mode as used by Shelly dht_sensors = 1; // We only support one sensor in pseudo mode pinMode(dht_pin_out, OUTPUT); diff --git a/tasmota/xsns_07_sht1x.ino b/tasmota/xsns_07_sht1x.ino index 735802ca2..e58c5553f 100644 --- a/tasmota/xsns_07_sht1x.ino +++ b/tasmota/xsns_07_sht1x.ino @@ -159,8 +159,8 @@ bool ShtRead(void) void ShtDetect(void) { - sht_sda_pin = pin[GPIO_I2C_SDA]; - sht_scl_pin = pin[GPIO_I2C_SCL]; + sht_sda_pin = Pin(GPIO_I2C_SDA); + sht_scl_pin = Pin(GPIO_I2C_SCL); if (ShtRead()) { sht_type = 1; AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_I2C D_SHT1X_FOUND)); diff --git a/tasmota/xsns_15_mhz19.ino b/tasmota/xsns_15_mhz19.ino index 633ca3f59..bc0ee8904 100644 --- a/tasmota/xsns_15_mhz19.ino +++ b/tasmota/xsns_15_mhz19.ino @@ -325,8 +325,8 @@ bool MhzCommandSensor(void) void MhzInit(void) { mhz_type = 0; - if ((pin[GPIO_MHZ_RXD] < 99) && (pin[GPIO_MHZ_TXD] < 99)) { - MhzSerial = new TasmotaSerial(pin[GPIO_MHZ_RXD], pin[GPIO_MHZ_TXD], 1); + if (PinUsed(GPIO_MHZ_RXD) && PinUsed(GPIO_MHZ_TXD)) { + MhzSerial = new TasmotaSerial(Pin(GPIO_MHZ_RXD), Pin(GPIO_MHZ_TXD), 1); if (MhzSerial->begin(9600)) { if (MhzSerial->hardwareSerial()) { ClaimSerial(); } mhz_type = 1; diff --git a/tasmota/xsns_17_senseair.ino b/tasmota/xsns_17_senseair.ino index 60614b4c7..90ba979bb 100644 --- a/tasmota/xsns_17_senseair.ino +++ b/tasmota/xsns_17_senseair.ino @@ -132,8 +132,8 @@ void Senseair250ms(void) // Every 250 mSec void SenseairInit(void) { senseair_type = 0; - if ((pin[GPIO_SAIR_RX] < 99) && (pin[GPIO_SAIR_TX] < 99)) { - SenseairModbus = new TasmotaModbus(pin[GPIO_SAIR_RX], pin[GPIO_SAIR_TX]); + if (PinUsed(GPIO_SAIR_RX) && PinUsed(GPIO_SAIR_TX)) { + SenseairModbus = new TasmotaModbus(Pin(GPIO_SAIR_RX), Pin(GPIO_SAIR_TX)); uint8_t result = SenseairModbus->Begin(SENSEAIR_MODBUS_SPEED); if (result) { if (2 == result) { ClaimSerial(); } diff --git a/tasmota/xsns_18_pms5003.ino b/tasmota/xsns_18_pms5003.ino index 525012f5a..dbac02936 100644 --- a/tasmota/xsns_18_pms5003.ino +++ b/tasmota/xsns_18_pms5003.ino @@ -171,7 +171,7 @@ bool PmsReadData(void) bool PmsCommandSensor(void) { - if ((pin[GPIO_PMS5003_TX] < 99) && (XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 32001)) { + if (PinUsed(GPIO_PMS5003_TX) && (XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 32001)) { if (XdrvMailbox.payload < MIN_INTERVAL_PERIOD) { // Set Active Mode if interval is less than 60 seconds Settings.pms_wake_interval = 0; @@ -239,12 +239,12 @@ void PmsSecond(void) // Every second void PmsInit(void) { Pms.type = 0; - if (pin[GPIO_PMS5003_RX] < 99) { - PmsSerial = new TasmotaSerial(pin[GPIO_PMS5003_RX], (pin[GPIO_PMS5003_TX] < 99) ? pin[GPIO_PMS5003_TX] : -1, 1); + if (PinUsed(GPIO_PMS5003_RX)) { + PmsSerial = new TasmotaSerial(Pin(GPIO_PMS5003_RX), (PinUsed(GPIO_PMS5003_TX)) ? Pin(GPIO_PMS5003_TX) : -1, 1); if (PmsSerial->begin(9600)) { if (PmsSerial->hardwareSerial()) { ClaimSerial(); } - if (99 == pin[GPIO_PMS5003_TX]) { // setting interval not supported if TX pin not connected + if (99 == Pin(GPIO_PMS5003_TX)) { // setting interval not supported if TX pin not connected Settings.pms_wake_interval = 0; Pms.ready = 1; } diff --git a/tasmota/xsns_20_novasds.ino b/tasmota/xsns_20_novasds.ino index 0b1580dde..ffaee14bc 100644 --- a/tasmota/xsns_20_novasds.ino +++ b/tasmota/xsns_20_novasds.ino @@ -202,8 +202,8 @@ bool NovaSdsCommandSensor(void) void NovaSdsInit(void) { novasds_type = 0; - if (pin[GPIO_SDS0X1_RX] < 99 && pin[GPIO_SDS0X1_TX] < 99) { - NovaSdsSerial = new TasmotaSerial(pin[GPIO_SDS0X1_RX], pin[GPIO_SDS0X1_TX], 1); + if (PinUsed(GPIO_SDS0X1_RX) && PinUsed(GPIO_SDS0X1_TX)) { + NovaSdsSerial = new TasmotaSerial(Pin(GPIO_SDS0X1_RX), Pin(GPIO_SDS0X1_TX), 1); if (NovaSdsSerial->begin(9600)) { if (NovaSdsSerial->hardwareSerial()) { ClaimSerial(); diff --git a/tasmota/xsns_22_sr04.ino b/tasmota/xsns_22_sr04.ino index dd8d87ab1..116729f66 100644 --- a/tasmota/xsns_22_sr04.ino +++ b/tasmota/xsns_22_sr04.ino @@ -40,10 +40,10 @@ TasmotaSerial* sonar_serial = nullptr; uint8_t Sr04TModeDetect(void) { sr04_type = 0; - if (99 == pin[GPIO_SR04_ECHO]) { return sr04_type; } + if (99 == Pin(GPIO_SR04_ECHO)) { return sr04_type; } - int sr04_echo_pin = pin[GPIO_SR04_ECHO]; - int sr04_trig_pin = (pin[GPIO_SR04_TRIG] < 99) ? pin[GPIO_SR04_TRIG] : pin[GPIO_SR04_ECHO]; // if GPIO_SR04_TRIG is not configured use single PIN mode with GPIO_SR04_ECHO only + int sr04_echo_pin = Pin(GPIO_SR04_ECHO); + int sr04_trig_pin = (PinUsed(GPIO_SR04_TRIG)) ? Pin(GPIO_SR04_TRIG) : Pin(GPIO_SR04_ECHO); // if GPIO_SR04_TRIG is not configured use single PIN mode with GPIO_SR04_ECHO only sonar_serial = new TasmotaSerial(sr04_echo_pin, sr04_trig_pin, 1); if (sonar_serial->begin(9600,1)) { @@ -62,7 +62,7 @@ uint8_t Sr04TModeDetect(void) delete sonar_serial; sonar_serial = nullptr; if (-1 == sr04_trig_pin) { - sr04_trig_pin = pin[GPIO_SR04_ECHO]; // if GPIO_SR04_TRIG is not configured use single PIN mode with GPIO_SR04_ECHO only + sr04_trig_pin = Pin(GPIO_SR04_ECHO); // if GPIO_SR04_TRIG is not configured use single PIN mode with GPIO_SR04_ECHO only } sonar = new NewPing(sr04_trig_pin, sr04_echo_pin, 300); } else { @@ -193,7 +193,7 @@ bool Xsns22(uint8_t function) if (sr04_type) { switch (function) { case FUNC_INIT: - result = (pin[GPIO_SR04_ECHO]<99); + result = (PinUsed(GPIO_SR04_ECHO)); break; case FUNC_EVERY_SECOND: Sr04TReading(); diff --git a/tasmota/xsns_28_tm1638.ino b/tasmota/xsns_28_tm1638.ino index da4de6999..9df220848 100644 --- a/tasmota/xsns_28_tm1638.ino +++ b/tasmota/xsns_28_tm1638.ino @@ -144,10 +144,10 @@ uint8_t Tm1638GetButtons(void) void TmInit(void) { tm1638_type = 0; - if ((pin[GPIO_TM16CLK] < 99) && (pin[GPIO_TM16DIO] < 99) && (pin[GPIO_TM16STB] < 99)) { - tm1638_clock_pin = pin[GPIO_TM16CLK]; - tm1638_data_pin = pin[GPIO_TM16DIO]; - tm1638_strobe_pin = pin[GPIO_TM16STB]; + if (PinUsed(GPIO_TM16CLK) && PinUsed(GPIO_TM16DIO) && PinUsed(GPIO_TM16STB)) { + tm1638_clock_pin = Pin(GPIO_TM16CLK); + tm1638_data_pin = Pin(GPIO_TM16DIO); + tm1638_strobe_pin = Pin(GPIO_TM16STB); pinMode(tm1638_data_pin, OUTPUT); pinMode(tm1638_clock_pin, OUTPUT);