From 560561c5b76a762ce65b6394b00552b42e94b918 Mon Sep 17 00:00:00 2001 From: "Sergio R. Caprile" Date: Fri, 8 Dec 2023 16:35:03 -0300 Subject: [PATCH 1/2] 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); } From 9de31ba816b6251ead41d4d2c16414e7d8851cd3 Mon Sep 17 00:00:00 2001 From: "Sergio R. Caprile" Date: Fri, 8 Dec 2023 18:03:59 -0300 Subject: [PATCH 2/2] updates --- examples/mqtt-dashboard/Makefile | 4 ++++ .../{client => dashboard}/Makefile | 0 .../{client => dashboard}/bundle.js | 0 .../{client => dashboard}/components.js | 0 .../{client => dashboard}/history.min.js | 0 .../{client => dashboard}/index.html | 0 .../{client => dashboard}/main.css | 0 .../{client => dashboard}/main.js | 0 .../{client => dashboard}/tailwind.config.js | 0 examples/mqtt-dashboard/device/main.c | 4 ++++ examples/mqtt-dashboard/device/net.c | 22 +++++++++---------- examples/mqtt-dashboard/device/net.h | 1 + .../main.c | 4 ++++ 13 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 examples/mqtt-dashboard/Makefile rename examples/mqtt-dashboard/{client => dashboard}/Makefile (100%) rename examples/mqtt-dashboard/{client => dashboard}/bundle.js (100%) rename examples/mqtt-dashboard/{client => dashboard}/components.js (100%) rename examples/mqtt-dashboard/{client => dashboard}/history.min.js (100%) rename examples/mqtt-dashboard/{client => dashboard}/index.html (100%) rename examples/mqtt-dashboard/{client => dashboard}/main.css (100%) rename examples/mqtt-dashboard/{client => dashboard}/main.js (100%) rename examples/mqtt-dashboard/{client => dashboard}/tailwind.config.js (100%) diff --git a/examples/mqtt-dashboard/Makefile b/examples/mqtt-dashboard/Makefile new file mode 100644 index 00000000..a2290f1d --- /dev/null +++ b/examples/mqtt-dashboard/Makefile @@ -0,0 +1,4 @@ +# for internal testing purposes + +all clean example: + $(MAKE) -C device $@ CFLAGS_EXTRA=$(CFLAGS_EXTRA) diff --git a/examples/mqtt-dashboard/client/Makefile b/examples/mqtt-dashboard/dashboard/Makefile similarity index 100% rename from examples/mqtt-dashboard/client/Makefile rename to examples/mqtt-dashboard/dashboard/Makefile diff --git a/examples/mqtt-dashboard/client/bundle.js b/examples/mqtt-dashboard/dashboard/bundle.js similarity index 100% rename from examples/mqtt-dashboard/client/bundle.js rename to examples/mqtt-dashboard/dashboard/bundle.js diff --git a/examples/mqtt-dashboard/client/components.js b/examples/mqtt-dashboard/dashboard/components.js similarity index 100% rename from examples/mqtt-dashboard/client/components.js rename to examples/mqtt-dashboard/dashboard/components.js diff --git a/examples/mqtt-dashboard/client/history.min.js b/examples/mqtt-dashboard/dashboard/history.min.js similarity index 100% rename from examples/mqtt-dashboard/client/history.min.js rename to examples/mqtt-dashboard/dashboard/history.min.js diff --git a/examples/mqtt-dashboard/client/index.html b/examples/mqtt-dashboard/dashboard/index.html similarity index 100% rename from examples/mqtt-dashboard/client/index.html rename to examples/mqtt-dashboard/dashboard/index.html diff --git a/examples/mqtt-dashboard/client/main.css b/examples/mqtt-dashboard/dashboard/main.css similarity index 100% rename from examples/mqtt-dashboard/client/main.css rename to examples/mqtt-dashboard/dashboard/main.css diff --git a/examples/mqtt-dashboard/client/main.js b/examples/mqtt-dashboard/dashboard/main.js similarity index 100% rename from examples/mqtt-dashboard/client/main.js rename to examples/mqtt-dashboard/dashboard/main.js diff --git a/examples/mqtt-dashboard/client/tailwind.config.js b/examples/mqtt-dashboard/dashboard/tailwind.config.js similarity index 100% rename from examples/mqtt-dashboard/client/tailwind.config.js rename to examples/mqtt-dashboard/dashboard/tailwind.config.js diff --git a/examples/mqtt-dashboard/device/main.c b/examples/mqtt-dashboard/device/main.c index 5305b7ac..058ade1c 100644 --- a/examples/mqtt-dashboard/device/main.c +++ b/examples/mqtt-dashboard/device/main.c @@ -24,6 +24,10 @@ bool hal_gpio_read(int pin) { : false; } +int hal_led_pin(void) { + return 0; +} + int main(int argc, char *argv[]) { struct mg_mgr mgr; diff --git a/examples/mqtt-dashboard/device/net.c b/examples/mqtt-dashboard/device/net.c index ce3495c8..11e19260 100644 --- a/examples/mqtt-dashboard/device/net.c +++ b/examples/mqtt-dashboard/device/net.c @@ -12,9 +12,9 @@ static struct mg_rpc *s_rpc_head = NULL; struct device_config { bool led_status; - uint8_t led_pin; - uint8_t brightness; - uint8_t log_level; + int led_pin; + int brightness; + int log_level; }; static struct device_config s_device_config; @@ -95,25 +95,24 @@ static void subscribe(struct mg_connection *c) { static void rpc_config_set(struct mg_rpc_req *r) { bool tmp_status, ok; - int8_t tmp_brightness, tmp_level, tmp_pin; + int tmp_brightness, tmp_level, tmp_pin; ok = mg_json_get_bool(r->frame, "$.params.led_status", &tmp_status); if (ok) s_device_config.led_status = tmp_status; - tmp_brightness = - (int8_t) mg_json_get_long(r->frame, "$.params.brightness", -1); + tmp_brightness = (int) mg_json_get_long(r->frame, "$.params.brightness", -1); if (tmp_brightness >= 0) s_device_config.brightness = tmp_brightness; - tmp_level = (int8_t) mg_json_get_long(r->frame, "$.params.log_level", -1); + tmp_level = (int) mg_json_get_long(r->frame, "$.params.log_level", -1); if (tmp_level >= 0) { s_device_config.log_level = tmp_level; mg_log_set(s_device_config.log_level); } - 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; + tmp_pin = (int) mg_json_get_long(r->frame, "$.params.led_pin", -1); + if (tmp_pin != -1) s_device_config.led_pin = tmp_pin; - if (tmp_pin >= 0 && ok) { + if (tmp_pin != -1 && ok) { hal_gpio_write(s_device_config.led_pin, s_device_config.led_status); } @@ -237,7 +236,8 @@ void web_init(struct mg_mgr *mgr) { int pingreq_interval_ms = MQTT_KEEP_ALIVE_INTERVAL * 1000 - 500; if (!g_device_id) generate_device_id(); if (!g_root_topic) g_root_topic = MQTT_ROOT_TOPIC; - s_device_config.log_level = (uint8_t) mg_log_level; + s_device_config.log_level = (int) mg_log_level; + s_device_config.led_pin = hal_led_pin(); // Configure JSON-RPC functions we're going to handle mg_rpc_add(&s_rpc_head, mg_str("config.set"), rpc_config_set, NULL); diff --git a/examples/mqtt-dashboard/device/net.h b/examples/mqtt-dashboard/device/net.h index 3fbd6f74..77a5ff29 100644 --- a/examples/mqtt-dashboard/device/net.h +++ b/examples/mqtt-dashboard/device/net.h @@ -26,6 +26,7 @@ void web_destroy(); void hal_gpio_write(int pin, bool status); bool hal_gpio_read(int pin); +int hal_led_pin(void); #ifdef __cplusplus } diff --git a/examples/stm32/nucleo-h723zg-make-baremetal-builtin/main.c b/examples/stm32/nucleo-h723zg-make-baremetal-builtin/main.c index 00e1915c..d50ecd1a 100644 --- a/examples/stm32/nucleo-h723zg-make-baremetal-builtin/main.c +++ b/examples/stm32/nucleo-h723zg-make-baremetal-builtin/main.c @@ -31,6 +31,10 @@ void hal_gpio_write(int pin, bool status) { // For MQTT dashboard HAL bool hal_gpio_read(int pin) { // For MQTT dashboard HAL return gpio_read((uint16_t) pin); } + +int hal_led_pin(void) { + return (int) LED1; +} #endif static void timer_fn(void *arg) {