rename esp32 project folder
This commit is contained in:
5
FW/leo_muziekdoos_esp32/.gitignore
vendored
Normal file
5
FW/leo_muziekdoos_esp32/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
||||
BIN
FW/leo_muziekdoos_esp32/data/Billy-Jean.mp3
Normal file
BIN
FW/leo_muziekdoos_esp32/data/Billy-Jean.mp3
Normal file
Binary file not shown.
BIN
FW/leo_muziekdoos_esp32/data/Let_it_be.mp3
Normal file
BIN
FW/leo_muziekdoos_esp32/data/Let_it_be.mp3
Normal file
Binary file not shown.
BIN
FW/leo_muziekdoos_esp32/data/ringoffire.mp3
Normal file
BIN
FW/leo_muziekdoos_esp32/data/ringoffire.mp3
Normal file
Binary file not shown.
1
FW/leo_muziekdoos_esp32/data/test.txt
Normal file
1
FW/leo_muziekdoos_esp32/data/test.txt
Normal file
@@ -0,0 +1 @@
|
||||
test_test_test
|
||||
39
FW/leo_muziekdoos_esp32/include/README
Normal file
39
FW/leo_muziekdoos_esp32/include/README
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the usual convention is to give header files names that end with `.h'.
|
||||
It is most portable to use only letters, digits, dashes, and underscores in
|
||||
header file names, and at most one dot.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||
51
FW/leo_muziekdoos_esp32/lib/README
Normal file
51
FW/leo_muziekdoos_esp32/lib/README
Normal file
@@ -0,0 +1,51 @@
|
||||
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into executable file.
|
||||
|
||||
The source code of each library should be placed in a an own separate directory
|
||||
("lib/your_library_name/[here are source files]").
|
||||
|
||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||
| |
|
||||
| |--Foo
|
||||
| | |- Foo.c
|
||||
| | |- Foo.h
|
||||
| |
|
||||
| |- README --> THIS FILE
|
||||
|
|
||||
|- platformio.ini
|
||||
|--src
|
||||
|- main.c
|
||||
|
||||
and a contents of `src/main.c`:
|
||||
```
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
PlatformIO Library Dependency Finder will find automatically dependent
|
||||
libraries scanning project source files.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||
|
||||
|
||||
update submodules force
|
||||
|
||||
$git submodule update --init --force --remote
|
||||
2
FW/leo_muziekdoos_esp32/littlefsbuilder.py
Normal file
2
FW/leo_muziekdoos_esp32/littlefsbuilder.py
Normal file
@@ -0,0 +1,2 @@
|
||||
Import("env")
|
||||
env.Replace( MKSPIFFSTOOL=env.get("PROJECT_DIR") + '/mklittlefs' )
|
||||
BIN
FW/leo_muziekdoos_esp32/mklittlefs
Executable file
BIN
FW/leo_muziekdoos_esp32/mklittlefs
Executable file
Binary file not shown.
21
FW/leo_muziekdoos_esp32/platformio.ini
Normal file
21
FW/leo_muziekdoos_esp32/platformio.ini
Normal file
@@ -0,0 +1,21 @@
|
||||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:m5stack-core2]
|
||||
platform = espressif32
|
||||
board = m5stack-atom
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
;http://192.168.2.3/Bonobo.Git.Server/ESP8266Audio.git
|
||||
;http://192.168.2.3/Bonobo.Git.Server/LittleFS_esp32.git
|
||||
monitor_speed = 115200
|
||||
lib_ldf_mode = deep+
|
||||
|
||||
extra_scripts = ./littlefsbuilder.py
|
||||
94
FW/leo_muziekdoos_esp32/src/audio.cpp
Normal file
94
FW/leo_muziekdoos_esp32/src/audio.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
#include "audio.h"
|
||||
|
||||
AudioGeneratorMP3 *mp3;
|
||||
AudioFileSourceID3 *id3;
|
||||
AudioFileSourceLittleFS *file;
|
||||
AudioOutputI2S *out;
|
||||
|
||||
uint8_t i = 0;
|
||||
uint8_t n = 0;
|
||||
|
||||
const char *waveFile[] =
|
||||
{"/ringoffire.mp3",
|
||||
"/Let_it_be.mp3",
|
||||
"/Billy-Jean.mp3"};
|
||||
|
||||
// Called when a metadata event occurs (i.e. an ID3 tag, an ICY block, etc.
|
||||
void MDCallback(void *cbData, const char *type, bool isUnicode, const char *string)
|
||||
{
|
||||
(void)cbData;
|
||||
Serial.printf("ID3 callback for: %s = '", type);
|
||||
|
||||
if (isUnicode)
|
||||
{
|
||||
string += 2;
|
||||
}
|
||||
|
||||
while (*string)
|
||||
{
|
||||
char a = *(string++);
|
||||
if (isUnicode)
|
||||
{
|
||||
string++;
|
||||
}
|
||||
Serial.printf("%c", a);
|
||||
}
|
||||
Serial.printf("'\n");
|
||||
Serial.flush();
|
||||
}
|
||||
|
||||
// Called when there's a warning or error (like a buffer underflow or decode hiccup)
|
||||
void StatusCallback(void *cbData, int code, const char *string)
|
||||
{
|
||||
const char *ptr = reinterpret_cast<const char *>(cbData);
|
||||
// Note that the string may be in PROGMEM, so copy it to RAM for printf
|
||||
char s1[64];
|
||||
strncpy_P(s1, string, sizeof(s1));
|
||||
s1[sizeof(s1) - 1] = 0;
|
||||
Serial.printf("STATUS(%s) '%d' = '%s'\n", ptr, code, s1);
|
||||
Serial.flush();
|
||||
}
|
||||
|
||||
void playSong(uint8_t index)
|
||||
{
|
||||
if (index > AUDIONSONGS)
|
||||
return;
|
||||
Serial.printf("now playing %s\n", waveFile[index]);
|
||||
file = new AudioFileSourceLittleFS(waveFile[index]);
|
||||
id3 = new AudioFileSourceID3(file);
|
||||
id3->RegisterMetadataCB(MDCallback, (void *)"ID3TAG");
|
||||
mp3->begin(id3, out);
|
||||
}
|
||||
|
||||
void initAudio()
|
||||
{
|
||||
Serial.println("init Audio");
|
||||
audioLogger = &Serial;
|
||||
|
||||
out = new AudioOutputI2S();
|
||||
out->SetPinout(I2S_BCLK, I2S_WCLK, I2S_DATA); //bclk, wclk, data
|
||||
out->SetGain(AUDIOGAIN);
|
||||
|
||||
mp3 = new AudioGeneratorMP3();
|
||||
mp3->RegisterStatusCB(StatusCallback, (void *)"mp3");
|
||||
Serial.println("init Audio Done");
|
||||
playSong(i);
|
||||
}
|
||||
|
||||
void handleAudio()
|
||||
{
|
||||
if (mp3->isRunning())
|
||||
{
|
||||
if (!mp3->loop())
|
||||
{
|
||||
//mp3->stop();
|
||||
if(n++ >= AUDIOREPEATS)
|
||||
{
|
||||
i++;
|
||||
n= 0;
|
||||
}
|
||||
playSong(i);
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
FW/leo_muziekdoos_esp32/src/audio.h
Normal file
18
FW/leo_muziekdoos_esp32/src/audio.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "board.h"
|
||||
#include "AudioFileSourcePROGMEM.h"
|
||||
#include <AudioFileSourceLittleFS.h>
|
||||
#include "AudioGeneratorMP3.h"
|
||||
#include "AudioFileSourceID3.h"
|
||||
#include "AudioOutputI2S.h"
|
||||
|
||||
#define AUDIOGAIN 1
|
||||
#define AUDIONSONGS 3
|
||||
#define AUDIOREPEATS 3
|
||||
|
||||
|
||||
|
||||
void initAudio(void);
|
||||
void handleAudio(void);
|
||||
|
||||
6
FW/leo_muziekdoos_esp32/src/board.h
Normal file
6
FW/leo_muziekdoos_esp32/src/board.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#define I2S_BCLK 19
|
||||
#define I2S_WCLK 33
|
||||
#define I2S_DATA 22
|
||||
20
FW/leo_muziekdoos_esp32/src/main.cpp
Normal file
20
FW/leo_muziekdoos_esp32/src/main.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
#include "storage.h"
|
||||
#include "audio.h"
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
|
||||
initStorage();
|
||||
initAudio();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
handleAudio();
|
||||
}
|
||||
154
FW/leo_muziekdoos_esp32/src/rfid.cpp
Normal file
154
FW/leo_muziekdoos_esp32/src/rfid.cpp
Normal file
@@ -0,0 +1,154 @@
|
||||
#include "rfid.h"
|
||||
|
||||
|
||||
|
||||
// void initRfid(void)
|
||||
// {
|
||||
|
||||
// }
|
||||
|
||||
// void handleRfid(void)
|
||||
// {
|
||||
|
||||
// }
|
||||
|
||||
/*
|
||||
* Initial Author: ryand1011 (https://github.com/ryand1011)
|
||||
*
|
||||
* Reads data written by a program such as "rfid_write_personal_data.ino"
|
||||
*
|
||||
* See: https://github.com/miguelbalboa/rfid/tree/master/examples/rfid_write_personal_data
|
||||
*
|
||||
* Uses MIFARE RFID card using RFID-RC522 reader
|
||||
* Uses MFRC522 - Library
|
||||
* -----------------------------------------------------------------------------------------
|
||||
* MFRC522 Arduino Arduino Arduino Arduino Arduino
|
||||
* Reader/PCD Uno/101 Mega Nano v3 Leonardo/Micro Pro Micro
|
||||
* Signal Pin Pin Pin Pin Pin Pin
|
||||
* -----------------------------------------------------------------------------------------
|
||||
* RST/Reset RST 9 5 D9 RESET/ICSP-5 RST
|
||||
* SPI SS SDA(SS) 10 53 D10 10 10
|
||||
* SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
|
||||
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
|
||||
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
|
||||
*
|
||||
* More pin layouts for other boards can be found here: https://github.com/miguelbalboa/rfid#pin-layout
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <MFRC522.h>
|
||||
|
||||
#define RST_PIN 9 // Configurable, see typical pin layout above
|
||||
#define SS_PIN 10 // Configurable, see typical pin layout above
|
||||
|
||||
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
|
||||
|
||||
//*****************************************************************************************//
|
||||
void initRfid() {
|
||||
SPI.begin(); // Init SPI bus
|
||||
mfrc522.PCD_Init(); // Init MFRC522 card
|
||||
Serial.println(F("Read personal data on a MIFARE PICC:")); //shows in serial that it is ready to read
|
||||
}
|
||||
|
||||
//*****************************************************************************************//
|
||||
void handleRfid() {
|
||||
|
||||
// Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
|
||||
MFRC522::MIFARE_Key key;
|
||||
for (byte i = 0; i < 6; i++) key.keyByte[i] = 0xFF;
|
||||
|
||||
//some variables we need
|
||||
byte block;
|
||||
byte len;
|
||||
MFRC522::StatusCode status;
|
||||
|
||||
//-------------------------------------------
|
||||
|
||||
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
|
||||
if ( ! mfrc522.PICC_IsNewCardPresent()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Select one of the cards
|
||||
if ( ! mfrc522.PICC_ReadCardSerial()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.println(F("**Card Detected:**"));
|
||||
|
||||
//-------------------------------------------
|
||||
|
||||
mfrc522.PICC_DumpDetailsToSerial(&(mfrc522.uid)); //dump some details about the card
|
||||
|
||||
//mfrc522.PICC_DumpToSerial(&(mfrc522.uid)); //uncomment this to see all blocks in hex
|
||||
|
||||
//-------------------------------------------
|
||||
|
||||
Serial.print(F("Name: "));
|
||||
|
||||
byte buffer1[18];
|
||||
|
||||
block = 4;
|
||||
len = 18;
|
||||
|
||||
//------------------------------------------- GET FIRST NAME
|
||||
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 4, &key, &(mfrc522.uid)); //line 834 of MFRC522.cpp file
|
||||
if (status != MFRC522::STATUS_OK) {
|
||||
Serial.print(F("Authentication failed: "));
|
||||
Serial.println(mfrc522.GetStatusCodeName(status));
|
||||
return;
|
||||
}
|
||||
|
||||
status = mfrc522.MIFARE_Read(block, buffer1, &len);
|
||||
if (status != MFRC522::STATUS_OK) {
|
||||
Serial.print(F("Reading failed: "));
|
||||
Serial.println(mfrc522.GetStatusCodeName(status));
|
||||
return;
|
||||
}
|
||||
|
||||
//PRINT FIRST NAME
|
||||
for (uint8_t i = 0; i < 16; i++)
|
||||
{
|
||||
if (buffer1[i] != 32)
|
||||
{
|
||||
Serial.write(buffer1[i]);
|
||||
}
|
||||
}
|
||||
Serial.print(" ");
|
||||
|
||||
//---------------------------------------- GET LAST NAME
|
||||
|
||||
byte buffer2[18];
|
||||
block = 1;
|
||||
|
||||
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 1, &key, &(mfrc522.uid)); //line 834
|
||||
if (status != MFRC522::STATUS_OK) {
|
||||
Serial.print(F("Authentication failed: "));
|
||||
Serial.println(mfrc522.GetStatusCodeName(status));
|
||||
return;
|
||||
}
|
||||
|
||||
status = mfrc522.MIFARE_Read(block, buffer2, &len);
|
||||
if (status != MFRC522::STATUS_OK) {
|
||||
Serial.print(F("Reading failed: "));
|
||||
Serial.println(mfrc522.GetStatusCodeName(status));
|
||||
return;
|
||||
}
|
||||
|
||||
//PRINT LAST NAME
|
||||
for (uint8_t i = 0; i < 16; i++) {
|
||||
Serial.write(buffer2[i] );
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
Serial.println(F("\n**End Reading**\n"));
|
||||
|
||||
delay(1000); //change value if you want to read cards faster
|
||||
|
||||
mfrc522.PICC_HaltA();
|
||||
mfrc522.PCD_StopCrypto1();
|
||||
}
|
||||
//*****************************************************************************************//
|
||||
|
||||
6
FW/leo_muziekdoos_esp32/src/rfid.h
Normal file
6
FW/leo_muziekdoos_esp32/src/rfid.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <MFRC522.h>
|
||||
|
||||
void initRfid(void);
|
||||
void handleRfid(void);
|
||||
337
FW/leo_muziekdoos_esp32/src/storage.cpp
Normal file
337
FW/leo_muziekdoos_esp32/src/storage.cpp
Normal file
@@ -0,0 +1,337 @@
|
||||
|
||||
#include "storage.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "FS.h"
|
||||
#include <LITTLEFS.h>
|
||||
|
||||
#ifndef CONFIG_LITTLEFS_FOR_IDF_3_2
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
/* You only need to format LITTLEFS the first time you run a
|
||||
test or else use the LITTLEFS plugin to create a partition
|
||||
https://github.com/lorol/arduino-esp32littlefs-plugin */
|
||||
|
||||
#define FORMAT_LITTLEFS_IF_FAILED false
|
||||
|
||||
void listDir(fs::FS &fs, const char *dirname, uint8_t levels)
|
||||
{
|
||||
Serial.printf("Listing directory: %s\r\n", dirname);
|
||||
|
||||
File root = fs.open(dirname);
|
||||
if (!root)
|
||||
{
|
||||
Serial.println("- failed to open directory");
|
||||
return;
|
||||
}
|
||||
if (!root.isDirectory())
|
||||
{
|
||||
Serial.println(" - not a directory");
|
||||
return;
|
||||
}
|
||||
|
||||
File file = root.openNextFile();
|
||||
while (file)
|
||||
{
|
||||
if (file.isDirectory())
|
||||
{
|
||||
Serial.print(" DIR : ");
|
||||
|
||||
#ifdef CONFIG_LITTLEFS_FOR_IDF_3_2
|
||||
Serial.println(file.name());
|
||||
#else
|
||||
Serial.print(file.name());
|
||||
time_t t = file.getLastWrite();
|
||||
struct tm *tmstruct = localtime(&t);
|
||||
Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
|
||||
#endif
|
||||
|
||||
if (levels)
|
||||
{
|
||||
listDir(fs, file.name(), levels - 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print(" FILE: ");
|
||||
Serial.print(file.name());
|
||||
Serial.print(" SIZE: ");
|
||||
|
||||
#ifdef CONFIG_LITTLEFS_FOR_IDF_3_2
|
||||
Serial.println(file.size());
|
||||
#else
|
||||
Serial.print(file.size());
|
||||
time_t t = file.getLastWrite();
|
||||
struct tm *tmstruct = localtime(&t);
|
||||
Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
|
||||
#endif
|
||||
}
|
||||
file = root.openNextFile();
|
||||
}
|
||||
}
|
||||
|
||||
void createDir(fs::FS &fs, const char *path)
|
||||
{
|
||||
Serial.printf("Creating Dir: %s\n", path);
|
||||
if (fs.mkdir(path))
|
||||
{
|
||||
Serial.println("Dir created");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("mkdir failed");
|
||||
}
|
||||
}
|
||||
|
||||
void removeDir(fs::FS &fs, const char *path)
|
||||
{
|
||||
Serial.printf("Removing Dir: %s\n", path);
|
||||
if (fs.rmdir(path))
|
||||
{
|
||||
Serial.println("Dir removed");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("rmdir failed");
|
||||
}
|
||||
}
|
||||
|
||||
void readFile(fs::FS &fs, const char *path)
|
||||
{
|
||||
Serial.printf("Reading file: %s\r\n", path);
|
||||
|
||||
File file = fs.open(path);
|
||||
if (!file || file.isDirectory())
|
||||
{
|
||||
Serial.println("- failed to open file for reading");
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.println("- read from file:");
|
||||
while (file.available())
|
||||
{
|
||||
Serial.write(file.read());
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
void writeFile(fs::FS &fs, const char *path, const char *message)
|
||||
{
|
||||
Serial.printf("Writing file: %s\r\n", path);
|
||||
|
||||
File file = fs.open(path, FILE_WRITE);
|
||||
if (!file)
|
||||
{
|
||||
Serial.println("- failed to open file for writing");
|
||||
return;
|
||||
}
|
||||
if (file.print(message))
|
||||
{
|
||||
Serial.println("- file written");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("- write failed");
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
void appendFile(fs::FS &fs, const char *path, const char *message)
|
||||
{
|
||||
Serial.printf("Appending to file: %s\r\n", path);
|
||||
|
||||
File file = fs.open(path, FILE_APPEND);
|
||||
if (!file)
|
||||
{
|
||||
Serial.println("- failed to open file for appending");
|
||||
return;
|
||||
}
|
||||
if (file.print(message))
|
||||
{
|
||||
Serial.println("- message appended");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("- append failed");
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
void renameFile(fs::FS &fs, const char *path1, const char *path2)
|
||||
{
|
||||
Serial.printf("Renaming file %s to %s\r\n", path1, path2);
|
||||
if (fs.rename(path1, path2))
|
||||
{
|
||||
Serial.println("- file renamed");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("- rename failed");
|
||||
}
|
||||
}
|
||||
|
||||
void deleteFile(fs::FS &fs, const char *path)
|
||||
{
|
||||
Serial.printf("Deleting file: %s\r\n", path);
|
||||
if (fs.remove(path))
|
||||
{
|
||||
Serial.println("- file deleted");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("- delete failed");
|
||||
}
|
||||
}
|
||||
|
||||
// SPIFFS-like write and delete file, better use #define CONFIG_LITTLEFS_SPIFFS_COMPAT 1
|
||||
|
||||
void writeFile2(fs::FS &fs, const char *path, const char *message)
|
||||
{
|
||||
if (!fs.exists(path))
|
||||
{
|
||||
if (strchr(path, '/'))
|
||||
{
|
||||
Serial.printf("Create missing folders of: %s\r\n", path);
|
||||
char *pathStr = strdup(path);
|
||||
if (pathStr)
|
||||
{
|
||||
char *ptr = strchr(pathStr, '/');
|
||||
while (ptr)
|
||||
{
|
||||
*ptr = 0;
|
||||
fs.mkdir(pathStr);
|
||||
*ptr = '/';
|
||||
ptr = strchr(ptr + 1, '/');
|
||||
}
|
||||
}
|
||||
free(pathStr);
|
||||
}
|
||||
}
|
||||
|
||||
Serial.printf("Writing file to: %s\r\n", path);
|
||||
File file = fs.open(path, FILE_WRITE);
|
||||
if (!file)
|
||||
{
|
||||
Serial.println("- failed to open file for writing");
|
||||
return;
|
||||
}
|
||||
if (file.print(message))
|
||||
{
|
||||
Serial.println("- file written");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("- write failed");
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
void deleteFile2(fs::FS &fs, const char *path)
|
||||
{
|
||||
Serial.printf("Deleting file and empty folders on path: %s\r\n", path);
|
||||
|
||||
if (fs.remove(path))
|
||||
{
|
||||
Serial.println("- file deleted");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("- delete failed");
|
||||
}
|
||||
|
||||
char *pathStr = strdup(path);
|
||||
if (pathStr)
|
||||
{
|
||||
char *ptr = strrchr(pathStr, '/');
|
||||
if (ptr)
|
||||
{
|
||||
Serial.printf("Removing all empty folders on path: %s\r\n", path);
|
||||
}
|
||||
while (ptr)
|
||||
{
|
||||
*ptr = 0;
|
||||
fs.rmdir(pathStr);
|
||||
ptr = strrchr(pathStr, '/');
|
||||
}
|
||||
free(pathStr);
|
||||
}
|
||||
}
|
||||
|
||||
void testFileIO(fs::FS &fs, const char *path)
|
||||
{
|
||||
Serial.printf("Testing file I/O with %s\r\n", path);
|
||||
|
||||
static uint8_t buf[512];
|
||||
size_t len = 0;
|
||||
File file = fs.open(path, FILE_WRITE);
|
||||
if (!file)
|
||||
{
|
||||
Serial.println("- failed to open file for writing");
|
||||
return;
|
||||
}
|
||||
|
||||
size_t i;
|
||||
Serial.print("- writing");
|
||||
uint32_t start = millis();
|
||||
for (i = 0; i < 2048; i++)
|
||||
{
|
||||
if ((i & 0x001F) == 0x001F)
|
||||
{
|
||||
Serial.print(".");
|
||||
}
|
||||
file.write(buf, 512);
|
||||
}
|
||||
Serial.println("");
|
||||
uint32_t end = millis() - start;
|
||||
Serial.printf(" - %u bytes written in %u ms\r\n", 2048 * 512, end);
|
||||
file.close();
|
||||
|
||||
file = fs.open(path);
|
||||
start = millis();
|
||||
end = start;
|
||||
i = 0;
|
||||
if (file && !file.isDirectory())
|
||||
{
|
||||
len = file.size();
|
||||
size_t flen = len;
|
||||
start = millis();
|
||||
Serial.print("- reading");
|
||||
while (len)
|
||||
{
|
||||
size_t toRead = len;
|
||||
if (toRead > 512)
|
||||
{
|
||||
toRead = 512;
|
||||
}
|
||||
file.read(buf, toRead);
|
||||
if ((i++ & 0x001F) == 0x001F)
|
||||
{
|
||||
Serial.print(".");
|
||||
}
|
||||
len -= toRead;
|
||||
}
|
||||
Serial.println("");
|
||||
end = millis() - start;
|
||||
Serial.printf("- %u bytes read in %u ms\r\n", flen, end);
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("- failed to open file for reading");
|
||||
}
|
||||
}
|
||||
|
||||
void initStorage()
|
||||
{
|
||||
if (!LITTLEFS.begin(FORMAT_LITTLEFS_IF_FAILED))
|
||||
{
|
||||
Serial.println("LITTLEFS Mount Failed");
|
||||
return;
|
||||
}
|
||||
listDir(LITTLEFS, "/", 0);
|
||||
}
|
||||
|
||||
void handleStorage()
|
||||
{
|
||||
}
|
||||
5
FW/leo_muziekdoos_esp32/src/storage.h
Normal file
5
FW/leo_muziekdoos_esp32/src/storage.h
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
void initStorage();
|
||||
11
FW/leo_muziekdoos_esp32/test/README
Normal file
11
FW/leo_muziekdoos_esp32/test/README
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
This directory is intended for PlatformIO Unit Testing and project tests.
|
||||
|
||||
Unit Testing is a software testing method by which individual units of
|
||||
source code, sets of one or more MCU program modules together with associated
|
||||
control data, usage procedures, and operating procedures, are tested to
|
||||
determine whether they are fit for use. Unit testing finds problems early
|
||||
in the development cycle.
|
||||
|
||||
More information about PlatformIO Unit Testing:
|
||||
- https://docs.platformio.org/page/plus/unit-testing.html
|
||||
Reference in New Issue
Block a user