JuReceiver/fs_helper.h

46 lines
No EOL
1 KiB
C

#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, &centerData, 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);
File f = LittleFS.open(path, "w");
bool succ = false;
if (f) {
if (f.write((const unsigned char *)buffer, len) == len) {
succ = true;
}
f.close();
}
mutex_exit(&littelfs_mut);
return succ;
}