mirror of
https://github.com/Crocmagnon/buzzer.git
synced 2024-11-25 01:18:06 +01:00
Remember selected file after power loss
This commit is contained in:
parent
70f47e8668
commit
aed9942c02
1 changed files with 22 additions and 12 deletions
34
src/main.cpp
34
src/main.cpp
|
@ -7,6 +7,7 @@
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <Adafruit_GFX.h>
|
#include <Adafruit_GFX.h>
|
||||||
#include <Adafruit_SSD1306.h>
|
#include <Adafruit_SSD1306.h>
|
||||||
|
#include <Preferences.h>
|
||||||
|
|
||||||
// Toggle on to switch to AP mode.
|
// Toggle on to switch to AP mode.
|
||||||
// Leave commented for wifi station mode.
|
// Leave commented for wifi station mode.
|
||||||
|
@ -50,6 +51,7 @@ String selectedFile = "";
|
||||||
|
|
||||||
AsyncWebServer server(80);
|
AsyncWebServer server(80);
|
||||||
Audio audio;
|
Audio audio;
|
||||||
|
Preferences preferences;
|
||||||
|
|
||||||
byte buttonLastState = HIGH;
|
byte buttonLastState = HIGH;
|
||||||
byte currentVolume = 12;
|
byte currentVolume = 12;
|
||||||
|
@ -123,6 +125,7 @@ void onSelectFile(AsyncWebServerRequest *request)
|
||||||
if (request->hasParam("fileName", true))
|
if (request->hasParam("fileName", true))
|
||||||
{
|
{
|
||||||
selectedFile = request->getParam("fileName", true)->value();
|
selectedFile = request->getParam("fileName", true)->value();
|
||||||
|
preferences.putString("selectedFile", selectedFile);
|
||||||
Serial.print(selectedFile);
|
Serial.print(selectedFile);
|
||||||
displayText("Selectionne : " + selectedFile);
|
displayText("Selectionne : " + selectedFile);
|
||||||
}
|
}
|
||||||
|
@ -160,6 +163,8 @@ void setup()
|
||||||
pinMode(LED, OUTPUT);
|
pinMode(LED, OUTPUT);
|
||||||
digitalWrite(LED, LOW);
|
digitalWrite(LED, LOW);
|
||||||
|
|
||||||
|
preferences.begin("buzzer", false);
|
||||||
|
|
||||||
// Screen
|
// Screen
|
||||||
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS))
|
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS))
|
||||||
{
|
{
|
||||||
|
@ -197,21 +202,26 @@ void setup()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
File root = SD.open("/");
|
selectedFile = preferences.getString("selectedFile", "");
|
||||||
File file = root.openNextFile();
|
if (selectedFile == "" || !fileIsValid(selectedFile))
|
||||||
while (file)
|
|
||||||
{
|
{
|
||||||
String fileName = file.name();
|
File root = SD.open("/");
|
||||||
if (fileIsValid(fileName))
|
File file = root.openNextFile();
|
||||||
|
while (file)
|
||||||
{
|
{
|
||||||
selectedFile = fileName;
|
String fileName = file.name();
|
||||||
Serial.println("Selected " + fileName);
|
if (fileIsValid(fileName))
|
||||||
display.println("Selectionne : " + fileName);
|
{
|
||||||
display.display();
|
selectedFile = fileName;
|
||||||
break;
|
Serial.println("Selected " + fileName);
|
||||||
|
display.println("Selectionne : " + fileName);
|
||||||
|
display.display();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
file = root.openNextFile();
|
||||||
}
|
}
|
||||||
file.close();
|
root.close();
|
||||||
file = root.openNextFile();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
|
|
Loading…
Reference in a new issue