From 70683fc8e7a8da4f79c5ae0e3ccf2a0520d3f505 Mon Sep 17 00:00:00 2001 From: "Sergio R. Caprile" Date: Tue, 2 Aug 2022 14:39:36 -0300 Subject: [PATCH] Fix for new mg_iobuf API --- examples/esp32/uart-bridge/Makefile | 2 +- examples/esp32/uart-bridge/main/cli.c | 10 +++++++--- examples/esp32/uart-bridge/main/main.c | 1 + examples/esp32/uart-bridge/main/main.h | 1 + 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/esp32/uart-bridge/Makefile b/examples/esp32/uart-bridge/Makefile index 933df536..16fec210 100644 --- a/examples/esp32/uart-bridge/Makefile +++ b/examples/esp32/uart-bridge/Makefile @@ -16,7 +16,7 @@ flash: CMD = flash flash: DA = --device $(PORT) flash: build -.PHONY: flash +.PHONY: build bridge.hex: build esputil mkhex \ diff --git a/examples/esp32/uart-bridge/main/cli.c b/examples/esp32/uart-bridge/main/cli.c index bf938773..fe07a478 100644 --- a/examples/esp32/uart-bridge/main/cli.c +++ b/examples/esp32/uart-bridge/main/cli.c @@ -44,12 +44,12 @@ static void cli_rm(const char *fname) { remove(path); } -void cli(uint8_t input_byte) { - static struct mg_iobuf in; +static struct mg_iobuf in; +void cli(uint8_t input_byte) { if (input_byte == 0 || input_byte == 0xff) return; if (in.len >= 128) in.len = 0; - mg_iobuf_add(&in, in.len, &input_byte, sizeof(input_byte), 32); + mg_iobuf_add(&in, in.len, &input_byte, sizeof(input_byte)); if (input_byte == '\n') { const char *arrow = "---"; @@ -87,3 +87,7 @@ void cli(uint8_t input_byte) { in.len = 0; } } + +void cli_init(void) { + mg_iobuf_init(&in, 0, 32); +} diff --git a/examples/esp32/uart-bridge/main/main.c b/examples/esp32/uart-bridge/main/main.c index 0474d105..6b4abedb 100644 --- a/examples/esp32/uart-bridge/main/main.c +++ b/examples/esp32/uart-bridge/main/main.c @@ -32,6 +32,7 @@ void app_main(void) { } else { // If WiFi is not configured, run CLI until configured MG_INFO(("WiFi is not configured, running CLI. Press enter")); + cli_init(); for (;;) { uint8_t ch = getchar(); cli(ch); diff --git a/examples/esp32/uart-bridge/main/main.h b/examples/esp32/uart-bridge/main/main.h index 458e0503..d7363055 100644 --- a/examples/esp32/uart-bridge/main/main.h +++ b/examples/esp32/uart-bridge/main/main.h @@ -15,3 +15,4 @@ void uart_bridge_fn(struct mg_connection *, int, void *, void *); int uart_read(void *buf, size_t len); bool wifi_init(const char *ssid, const char *pass); void cli(uint8_t ch); +void cli_init(void);