diff --git a/tasmota/support.ino b/tasmota/support.ino index 87f05ad27..4b2bc49fb 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -995,6 +995,13 @@ int ResponseJsonEndEnd(void) * GPIO Module and Template management \*********************************************************************************************/ +void DigitalWrite(uint32_t gpio_pin, uint32_t state) +{ + if (pin[gpio_pin] < 99) { + digitalWrite(pin[gpio_pin], state &1); + } +} + uint8_t ModuleNr(void) { // 0 = User module (255) diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index ff2b6f40a..0935d9a28 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -166,9 +166,7 @@ void SetLatchingRelay(power_t lpower, uint32_t state) for (uint32_t i = 0; i < devices_present; i++) { uint32_t port = (i << 1) + ((latching_power >> i) &1); - if (pin[GPIO_REL1 +port] < 99) { - digitalWrite(pin[GPIO_REL1 +port], bitRead(rel_inverted, port) ? !state : state); - } + DigitalWrite(GPIO_REL1 +port, bitRead(rel_inverted, port) ? !state : state); } } @@ -226,8 +224,8 @@ void SetDevicePower(power_t rpower, uint32_t source) else { for (uint32_t i = 0; i < devices_present; i++) { power_t state = rpower &1; - if ((i < MAX_RELAYS) && (pin[GPIO_REL1 +i] < 99)) { - digitalWrite(pin[GPIO_REL1 +i], bitRead(rel_inverted, i) ? !state : state); + if (i < MAX_RELAYS) { + DigitalWrite(GPIO_REL1 +i, bitRead(rel_inverted, i) ? !state : state); } rpower >>= 1; } @@ -293,7 +291,7 @@ void SetLedPowerIdx(uint32_t led, uint32_t state) } else { led_power &= (0xFF ^ mask); } - digitalWrite(pin[GPIO_LED1 + led], bitRead(led_inverted, led) ? !state : state); + DigitalWrite(GPIO_LED1 + led, bitRead(led_inverted, led) ? !state : state); } } diff --git a/tasmota/xdrv_24_buzzer.ino b/tasmota/xdrv_24_buzzer.ino index 2266b1af7..968f91cad 100644 --- a/tasmota/xdrv_24_buzzer.ino +++ b/tasmota/xdrv_24_buzzer.ino @@ -39,7 +39,7 @@ struct BUZZER { void BuzzerOff(void) { - digitalWrite(pin[GPIO_BUZZER], Buzzer.inverted); // Buzzer Off + DigitalWrite(GPIO_BUZZER, Buzzer.inverted); // Buzzer Off } //void BuzzerBeep(uint32_t count = 1, uint32_t on = 1, uint32_t off = 1, uint32_t tune = 0); @@ -124,7 +124,7 @@ void BuzzerEvery100mSec(void) Buzzer.duration = Buzzer.set[Buzzer.state]; } } - digitalWrite(pin[GPIO_BUZZER], (Buzzer.inverted) ? !Buzzer.state : Buzzer.state); + DigitalWrite(GPIO_BUZZER, (Buzzer.inverted) ? !Buzzer.state : Buzzer.state); } else { Buzzer.enable = false; } diff --git a/tasmota/xnrg_01_hlw8012.ino b/tasmota/xnrg_01_hlw8012.ino index 488da7059..3b01eaea7 100644 --- a/tasmota/xnrg_01_hlw8012.ino +++ b/tasmota/xnrg_01_hlw8012.ino @@ -143,9 +143,7 @@ void HlwEvery200ms(void) if (Hlw.cf1_timer >= 8) { Hlw.cf1_timer = 0; Hlw.select_ui_flag = (Hlw.select_ui_flag) ? false : true; - if (pin[GPIO_NRG_SEL] < 99) { - digitalWrite(pin[GPIO_NRG_SEL], Hlw.select_ui_flag); - } + DigitalWrite(GPIO_NRG_SEL, Hlw.select_ui_flag); if (Hlw.cf1_pulse_counter) { cf1_pulse_length = Hlw.cf1_summed_pulse_length / Hlw.cf1_pulse_counter; diff --git a/tasmota/xnrg_04_mcp39f501.ino b/tasmota/xnrg_04_mcp39f501.ino index 2fa98276d..d5a5dde4a 100644 --- a/tasmota/xnrg_04_mcp39f501.ino +++ b/tasmota/xnrg_04_mcp39f501.ino @@ -570,9 +570,7 @@ void McpSnsInit(void) } else { mcp_buffer = (char*)(malloc(MCP_BUFFER_SIZE)); } - if (pin[GPIO_MCP39F5_RST] < 99) { - digitalWrite(pin[GPIO_MCP39F5_RST], 1); // MCP enable - } + DigitalWrite(GPIO_MCP39F5_RST, 1); // MCP enable } else { energy_flg = ENERGY_NONE; }