Display whole status on screen + select file after uploading

This commit is contained in:
Gabriel Augendre 2023-01-06 15:39:53 +01:00
parent 4bee1156b1
commit a0aacd4b22
4 changed files with 25 additions and 13 deletions

View file

@ -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!");

View file

@ -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);
void selectFile(String fileName)
{
preferences.putString(SELECTED_FILE, fileName);
displayStatus();
Serial.print("Select new file: ");
Serial.println(fileName);
}

View file

@ -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);

View file

@ -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);
}
}