From b64d889fadc6bfba58c16972a39eb3a825d0fc66 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 25 Apr 2021 22:29:33 +0200 Subject: [PATCH] Rework dispatch_gpio --- src/hasp/hasp_dispatch.cpp | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 8330dece..f443ceb1 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -213,26 +213,17 @@ static void dispatch_gpio(const char* topic, const char* payload) int16_t val; uint8_t pin; - if(topic == strstr_P(topic, PSTR("relay"))) { - topic += 5; - val = Parser::is_true(payload); - - } else if(topic == strstr_P(topic, PSTR("led"))) { - topic += 3; - val = atoi(payload); - - } else if(topic == strstr_P(topic, PSTR("pwm"))) { - topic += 3; - val = atoi(payload); - - } else { - LOG_WARNING(TAG_MSGR, F("Invalid gpio %s"), topic); - return; - } + if(topic == strstr_P(topic, PSTR("output"))) topic += 6; if(Parser::is_only_digits(topic)) { pin = atoi(topic); if(strlen(payload) > 0) { + + if(1) + val = atoi(payload); + else + val = Parser::is_true(payload); + gpio_set_value(pin, val); } else { gpio_get_value(pin); @@ -240,6 +231,7 @@ static void dispatch_gpio(const char* topic, const char* payload) } else { LOG_WARNING(TAG_MSGR, F("Invalid pin %s"), topic); } + #endif }