Add some GPIO checks

This commit is contained in:
Theo Arends 2019-12-18 18:21:10 +01:00
parent e574f7dd84
commit 5c282db649
5 changed files with 15 additions and 14 deletions

View File

@ -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)

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}