JuReceiver/fs_helper.h

44 lines
983 B
C
Raw Normal View History

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) {
mutex_enter_blocking(&littelfs_mut);
File f = LittleFS.open(path, "r");
bool succ = false;
if (f) {
2023-09-25 17:54:15 +02:00
if (f.readBytes((char *)buffer, len) == len) {
2023-09-21 16:04:40 +02:00
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-25 17:54:15 +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;
}