From 560561c5b76a762ce65b6394b00552b42e94b918 Mon Sep 17 00:00:00 2001 From: "Sergio R. Caprile" Date: Fri, 8 Dec 2023 16:35:03 -0300 Subject: [PATCH] fixes --- examples/mqtt-dashboard/device/main.c | 4 ++-- examples/mqtt-dashboard/device/net.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/mqtt-dashboard/device/main.c b/examples/mqtt-dashboard/device/main.c index be5e084d..5305b7ac 100644 --- a/examples/mqtt-dashboard/device/main.c +++ b/examples/mqtt-dashboard/device/main.c @@ -13,13 +13,13 @@ static void signal_handler(int signo) { static bool s_pins[100]; void hal_gpio_write(int pin, bool status) { - if (pin >= 0 && pin <= (int) (sizeof(s_pins) / sizeof(s_pins[0]))) { + if (pin >= 0 && pin < (int) (sizeof(s_pins) / sizeof(s_pins[0]))) { s_pins[pin] = status; } } bool hal_gpio_read(int pin) { - return (pin >= 0 && pin <= (int) (sizeof(s_pins) / sizeof(s_pins[0]))) + return (pin >= 0 && pin < (int) (sizeof(s_pins) / sizeof(s_pins[0]))) ? s_pins[pin] : false; } diff --git a/examples/mqtt-dashboard/device/net.c b/examples/mqtt-dashboard/device/net.c index f9f22e36..ce3495c8 100644 --- a/examples/mqtt-dashboard/device/net.c +++ b/examples/mqtt-dashboard/device/net.c @@ -111,9 +111,9 @@ static void rpc_config_set(struct mg_rpc_req *r) { } tmp_pin = (int8_t) mg_json_get_long(r->frame, "$.params.led_pin", -1); - if (tmp_pin > 0) s_device_config.led_pin = tmp_pin; + if (tmp_pin >= 0) s_device_config.led_pin = tmp_pin; - if (tmp_pin > 0 && ok) { + if (tmp_pin >= 0 && ok) { hal_gpio_write(s_device_config.led_pin, s_device_config.led_status); }