2023-09-21 16:04:40 +02:00
|
|
|
#include <LittleFS.h>
|
|
|
|
#include <jmutex.h>
|
|
|
|
|
|
|
|
#include "FS.h"
|
|
|
|
|
|
|
|
mutex_t littelfs_mut;
|
|
|
|
|
|
|
|
void init_little_fs() {
|
|
|
|
mutex_init(&littelfs_mut);
|
|
|
|
mutex_enter_blocking(&littelfs_mut);
|
|
|
|
if (!LittleFS.begin()) {
|
|
|
|
LittleFS.format();
|
|
|
|
LittleFS.begin();
|
|
|
|
}
|
|
|
|
mutex_exit(&littelfs_mut);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool fs_read(String path, void *buffer, size_t len) {
|
|
|
|
char centerData[len];
|
|
|
|
mutex_enter_blocking(&littelfs_mut);
|
|
|
|
File f = LittleFS.open(path, "r");
|
|
|
|
bool succ = false;
|
|
|
|
if (f) {
|
|
|
|
if (f.readBytes((char *)centerData, len) == len) {
|
|
|
|
memmove(&buffer, ¢erData, len);
|
|
|
|
succ = true;
|
|
|
|
}
|
|
|
|
f.close();
|
|
|
|
}
|
|
|
|
mutex_exit(&littelfs_mut);
|
|
|
|
return succ;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool fs_write(String path, void *buffer, size_t len) {
|
|
|
|
mutex_enter_blocking(&littelfs_mut);
|
2023-09-24 21:28:11 +02:00
|
|
|
File f = LittleFS.open(path, "w+");
|
2023-09-21 16:04:40 +02:00
|
|
|
bool succ = false;
|
|
|
|
if (f) {
|
|
|
|
if (f.write((const unsigned char *)buffer, len) == len) {
|
|
|
|
succ = true;
|
|
|
|
}
|
|
|
|
f.close();
|
|
|
|
}
|
|
|
|
mutex_exit(&littelfs_mut);
|
|
|
|
return succ;
|
|
|
|
}
|