From a0aacd4b22924f85fc84e19af77bcbeb2f2885e9 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Fri, 6 Jan 2023 15:39:53 +0100 Subject: [PATCH] Display whole status on screen + select file after uploading --- src/main.cpp | 2 +- src/utils.cpp | 24 ++++++++++++++++++------ src/utils.h | 4 +++- src/webHandlers.cpp | 8 +++----- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0490053..824a0a1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,7 +34,7 @@ void setup() diagnosticPrintln("Configuration OK!"); displayWifiCreds(); - displaySelectedFile(); + displayStatus(); // Setup is done, light up the LED Serial.println("All setup & ready to go!"); diff --git a/src/utils.cpp b/src/utils.cpp index 4488e12..9006480 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -75,13 +75,25 @@ void displayWifiCreds() display.display(); } -void displaySelectedFile() +void displayStatus() { + clearMessageArea(); + + String volume = String(preferences.getUChar(CURRENT_VOLUME)); + display.println("Volume: " + volume); + String prefix = "Son: "; - displayText(prefix + preferences.getString(SELECTED_FILE, "").substring(0, LINE_LENGTH - prefix.length())); + display.println(prefix + preferences.getString(SELECTED_FILE, "").substring(0, LINE_LENGTH - prefix.length())); + + display.println("\nRetourne moi !"); + + display.display(); } -void displayVolume() { - String volume = String(preferences.getUChar(CURRENT_VOLUME)); - displayText("Volume: " + volume); -} \ No newline at end of file +void selectFile(String fileName) +{ + preferences.putString(SELECTED_FILE, fileName); + displayStatus(); + Serial.print("Select new file: "); + Serial.println(fileName); +} diff --git a/src/utils.h b/src/utils.h index 29d4abf..a622399 100644 --- a/src/utils.h +++ b/src/utils.h @@ -11,8 +11,10 @@ void clearMessageArea(); void displayText(String text); void play(); +void selectFile(String fileName); + void displayWifiCreds(); -void displaySelectedFile(); +void displayStatus(); void diagnosticPrint(String text); void diagnosticPrintln(String text); diff --git a/src/webHandlers.cpp b/src/webHandlers.cpp index ac4147d..0682e14 100644 --- a/src/webHandlers.cpp +++ b/src/webHandlers.cpp @@ -87,15 +87,12 @@ void onListFiles(AsyncWebServerRequest *request) void onSelectFile(AsyncWebServerRequest *request) { - Serial.print("Select file: "); + Serial.println("Select file"); if (request->hasParam("fileName", true)) { String selectedFile = request->getParam("fileName", true)->value(); - preferences.putString(SELECTED_FILE, selectedFile); - Serial.print(selectedFile); - displaySelectedFile(); + selectFile(selectedFile); } - Serial.println(); onStatus(request); } @@ -152,6 +149,7 @@ void onUploadFile(AsyncWebServerRequest *request, String filename, size_t index, Serial.printf("Upload end: %s, %u B\n", filename.c_str(), index + len); request->_tempFile.close(); request->redirect("/"); + selectFile(filename); } }