From 9d5bfffc145cd6a023a8fcd41451f5532673bce5 Mon Sep 17 00:00:00 2001 From: Bartlomiej Zimon Date: Wed, 3 Jan 2018 09:59:26 +0100 Subject: [PATCH] - add ajax /console/clear - fix #348 --- esp-link/main.c | 1 + html/console.html | 5 ++++- serial/console.c | 9 +++++++++ serial/console.h | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/esp-link/main.c b/esp-link/main.c index d2a316e..31bcf6e 100644 --- a/esp-link/main.c +++ b/esp-link/main.c @@ -88,6 +88,7 @@ HttpdBuiltInUrl builtInUrls[] = { { "/log/reset", cgiReset, NULL }, { "/console/reset", ajaxConsoleReset, NULL }, { "/console/baud", ajaxConsoleBaud, NULL }, + { "/console/clear", ajaxConsoleClear, NULL }, { "/console/fmt", ajaxConsoleFormat, NULL }, { "/console/text", ajaxConsole, NULL }, { "/console/send", ajaxConsoleSend, NULL }, diff --git a/html/console.html b/html/console.html index e621f05..6cb74af 100644 --- a/html/console.html +++ b/html/console.html @@ -91,7 +91,10 @@ $("#clear-button").addEventListener("click", function(e) { e.preventDefault(); var co = $("#console"); - co.innerHTML = ""; + ajaxSpin('POST', "/console/clear", + function(resp) { showNotification("uC buffer cleared"); co.innerHTML = ""; co.textEnd = 0;}, + function(s, st) { showWarning("Error clearing buffer in uC"); } + ); }); ajaxJson('GET', "/console/baud", diff --git a/serial/console.c b/serial/console.c index d082036..473bcf6 100644 --- a/serial/console.c +++ b/serial/console.c @@ -59,6 +59,15 @@ ajaxConsoleReset(HttpdConnData *connData) { return HTTPD_CGI_DONE; } +int ICACHE_FLASH_ATTR +ajaxConsoleClear(HttpdConnData *connData) { + if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. + jsonHeader(connData, 200); + //reset buffer + console_rd = console_wr = console_pos = 0; + return HTTPD_CGI_DONE; +} + int ICACHE_FLASH_ATTR ajaxConsoleBaud(HttpdConnData *connData) { if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. diff --git a/serial/console.h b/serial/console.h index 3020903..f1d2261 100644 --- a/serial/console.h +++ b/serial/console.h @@ -7,6 +7,7 @@ void consoleInit(void); void ICACHE_FLASH_ATTR console_write_char(char c); int ajaxConsole(HttpdConnData *connData); int ajaxConsoleReset(HttpdConnData *connData); +int ajaxConsoleClear(HttpdConnData *connData); int ajaxConsoleBaud(HttpdConnData *connData); int ajaxConsoleFormat(HttpdConnData *connData); int ajaxConsoleSend(HttpdConnData *connData);