mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-26 20:56:37 +00:00
Add support for LittleFS
This commit is contained in:
parent
5ec7e1b45e
commit
26708d7dc8
@ -15,9 +15,25 @@
|
|||||||
#if LV_FS_IF_SPIFFS != '\0'
|
#if LV_FS_IF_SPIFFS != '\0'
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
|
#if HASP_USE_SPIFFS > 0
|
||||||
#include "SPIFFS.h"
|
#include "SPIFFS.h"
|
||||||
|
#elif HASP_USE_LITTLEFS > 0
|
||||||
|
#include "LITTLEFS.h"
|
||||||
#endif
|
#endif
|
||||||
#include "FS.h" // Include the SPIFFS library
|
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||||
|
// included by default
|
||||||
|
#endif // ARDUINO_ARCH
|
||||||
|
|
||||||
|
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||||
|
#include <FS.h>
|
||||||
|
#include <Esp.h>
|
||||||
|
|
||||||
|
#if HASP_USE_SPIFFS > 0
|
||||||
|
#define LV_FS_SPIFFS SPIFFS
|
||||||
|
#elif HASP_USE_LITTLEFS > 0
|
||||||
|
#define LV_FS_SPIFFS LITTLEFS
|
||||||
|
#endif // HASP_USE
|
||||||
|
#endif // ARDUINO_ARCH
|
||||||
|
|
||||||
#define TAG_LVFS 91
|
#define TAG_LVFS 91
|
||||||
|
|
||||||
@ -118,7 +134,7 @@ void lv_fs_if_spiffs_init(void)
|
|||||||
/* Initialize your Storage device and File system. */
|
/* Initialize your Storage device and File system. */
|
||||||
static void fs_init(void)
|
static void fs_init(void)
|
||||||
{
|
{
|
||||||
SPIFFS.begin();
|
LV_FS_SPIFFS.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -136,24 +152,27 @@ static lv_fs_res_t fs_open(lv_fs_drv_t * drv, void * file_p, const char * path,
|
|||||||
char filename[32];
|
char filename[32];
|
||||||
snprintf_P(filename, sizeof(filename), PSTR("/%s"), path);
|
snprintf_P(filename, sizeof(filename), PSTR("/%s"), path);
|
||||||
|
|
||||||
|
lv_spiffs_file_t * fp = (lv_spiffs_file_t *)file_p;
|
||||||
|
if(fp == NULL) return LV_FS_RES_INV_PARAM;
|
||||||
|
|
||||||
Log.verbose(TAG_LVFS, F("Opening %s"), filename);
|
Log.verbose(TAG_LVFS, F("Opening %s"), filename);
|
||||||
File file = SPIFFS.open(filename, mode == LV_FS_MODE_WR ? FILE_WRITE : FILE_READ);
|
*fp = LV_FS_SPIFFS.open(filename, mode == LV_FS_MODE_WR ? FILE_WRITE : FILE_READ);
|
||||||
|
|
||||||
Log.verbose(TAG_LVFS, F("%d"), __LINE__);
|
Log.verbose(TAG_LVFS, F("%d"), __LINE__);
|
||||||
if(!file) {
|
if(!(*fp)) {
|
||||||
|
Log.verbose(TAG_LVFS, F("Invalid file"));
|
||||||
return LV_FS_RES_NOT_EX;
|
return LV_FS_RES_NOT_EX;
|
||||||
|
|
||||||
} else if(file.isDirectory()) {
|
// } else if((*fp).isDirectory()) {
|
||||||
return LV_FS_RES_UNKNOWN;
|
// Log.verbose(TAG_LVFS, F("Cannot open directory as a file"));
|
||||||
|
// return LV_FS_RES_UNKNOWN;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// f.seek(0, SeekSet);
|
// f.seek(0, SeekSet);
|
||||||
// Log.verbose(TAG_LVFS,F("Assigning %s"), f.name());
|
// Log.verbose(TAG_LVFS,F("Assigning %s"), f.name());
|
||||||
Log.verbose(TAG_LVFS, F("%d"), __LINE__);
|
Log.verbose(TAG_LVFS, F("%d"), __LINE__);
|
||||||
lv_spiffs_file_t * fp = (lv_spiffs_file_t *)file_p; /*Just avoid the confusing casings*/
|
|
||||||
// Log.verbose(TAG_LVFS,F("Copying %s"), f.name());
|
// Log.verbose(TAG_LVFS,F("Copying %s"), f.name());
|
||||||
Log.verbose(TAG_LVFS, F("%d - %x - %d"), __LINE__, fp, sizeof(lv_spiffs_file_t));
|
Log.verbose(TAG_LVFS, F("%d - %x - %d"), __LINE__, fp, sizeof(lv_spiffs_file_t));
|
||||||
if(fp != NULL) (*fp) = file;
|
|
||||||
// memcpy(fp,&file,sizeof(lv_spiffs_file_t));
|
// memcpy(fp,&file,sizeof(lv_spiffs_file_t));
|
||||||
Log.verbose(TAG_LVFS, F("%d"), __LINE__);
|
Log.verbose(TAG_LVFS, F("%d"), __LINE__);
|
||||||
return LV_FS_RES_OK;
|
return LV_FS_RES_OK;
|
||||||
@ -170,12 +189,13 @@ static lv_fs_res_t fs_open(lv_fs_drv_t * drv, void * file_p, const char * path,
|
|||||||
static lv_fs_res_t fs_close(lv_fs_drv_t * drv, void * file_p)
|
static lv_fs_res_t fs_close(lv_fs_drv_t * drv, void * file_p)
|
||||||
{
|
{
|
||||||
(void)drv; /*Unused*/
|
(void)drv; /*Unused*/
|
||||||
lv_spiffs_file_t file = *(lv_spiffs_file_t *)file_p;
|
lv_spiffs_file_t * fp = (lv_spiffs_file_t *)file_p;
|
||||||
// File file = fp;
|
if(fp == NULL) return LV_FS_RES_INV_PARAM;
|
||||||
// file = SPIFFS.open("/background.bin");
|
|
||||||
|
lv_spiffs_file_t file = *fp;
|
||||||
|
|
||||||
if(!file) {
|
if(!file) {
|
||||||
// Log.verbose(TAG_LVFS,F("Invalid file"));
|
Log.verbose(TAG_LVFS, F("Invalid file"));
|
||||||
return LV_FS_RES_NOT_EX;
|
return LV_FS_RES_NOT_EX;
|
||||||
|
|
||||||
} else if(file.isDirectory()) {
|
} else if(file.isDirectory()) {
|
||||||
@ -201,15 +221,28 @@ static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_
|
|||||||
{
|
{
|
||||||
(void)drv; /*Unused*/
|
(void)drv; /*Unused*/
|
||||||
lv_spiffs_file_t * fp = (lv_spiffs_file_t *)file_p;
|
lv_spiffs_file_t * fp = (lv_spiffs_file_t *)file_p;
|
||||||
|
if(fp == NULL) return LV_FS_RES_INV_PARAM;
|
||||||
|
|
||||||
lv_spiffs_file_t file = *fp;
|
lv_spiffs_file_t file = *fp;
|
||||||
|
|
||||||
if(!file) {
|
if(!file) {
|
||||||
// Log.verbose(TAG_LVFS,F("Invalid file"));
|
Log.error(TAG_LVFS, F("Invalid file"));
|
||||||
return LV_FS_RES_NOT_EX;
|
return LV_FS_RES_NOT_EX;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//Log.verbose(TAG_LVFS, F("Reading %u bytes from %s at position %u"), btr, file.name(), file.position());
|
//Log.verbose(TAG_LVFS, F("Reading %u bytes from %s at position %u"), btr, file.name(), file.position());
|
||||||
*br = (uint32_t)file.readBytes((char *)buf, btr);
|
uint32_t len = 0;
|
||||||
|
char * chp = (char *)buf;
|
||||||
|
if(chp != NULL && btr > 0)
|
||||||
|
len = file.readBytes(chp, btr);
|
||||||
|
else
|
||||||
|
Log.verbose(TAG_LVFS, F("Buffer is NULL"), btr, file.name(), file.position());
|
||||||
|
|
||||||
|
if(br != NULL)
|
||||||
|
*br = len;
|
||||||
|
else
|
||||||
|
Log.verbose(TAG_LVFS, F("BYTESREAD is NULL"), btr, file.name(), file.position());
|
||||||
|
|
||||||
Serial.print("!");
|
Serial.print("!");
|
||||||
return LV_FS_RES_OK;
|
return LV_FS_RES_OK;
|
||||||
}
|
}
|
||||||
@ -324,10 +357,10 @@ static lv_fs_res_t fs_remove(lv_fs_drv_t * drv, const char * path)
|
|||||||
char filename[32];
|
char filename[32];
|
||||||
snprintf_P(filename, sizeof(filename), PSTR("/%s"), path);
|
snprintf_P(filename, sizeof(filename), PSTR("/%s"), path);
|
||||||
|
|
||||||
if(!SPIFFS.exists(filename)) {
|
if(!LV_FS_SPIFFS.exists(filename)) {
|
||||||
return LV_FS_RES_NOT_EX;
|
return LV_FS_RES_NOT_EX;
|
||||||
|
|
||||||
} else if(SPIFFS.remove(filename)) {
|
} else if(LV_FS_SPIFFS.remove(filename)) {
|
||||||
return LV_FS_RES_OK;
|
return LV_FS_RES_OK;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -363,7 +396,7 @@ static lv_fs_res_t fs_rename(lv_fs_drv_t * drv, const char * oldname, const char
|
|||||||
snprintf_P(fromname, sizeof(fromname), PSTR("/%s"), oldname);
|
snprintf_P(fromname, sizeof(fromname), PSTR("/%s"), oldname);
|
||||||
snprintf_P(toname, sizeof(toname), PSTR("/%s"), newname);
|
snprintf_P(toname, sizeof(toname), PSTR("/%s"), newname);
|
||||||
|
|
||||||
if(SPIFFS.rename(fromname, toname)) {
|
if(LV_FS_SPIFFS.rename(fromname, toname)) {
|
||||||
return LV_FS_RES_OK;
|
return LV_FS_RES_OK;
|
||||||
} else {
|
} else {
|
||||||
return LV_FS_RES_UNKNOWN;
|
return LV_FS_RES_UNKNOWN;
|
||||||
@ -384,14 +417,14 @@ static lv_fs_res_t fs_free(lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * fre
|
|||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
FSInfo fs_info;
|
FSInfo fs_info;
|
||||||
SPIFFS.info(fs_info);
|
LV_FS_SPIFFS.info(fs_info);
|
||||||
*total_p = (uint32_t)fs_info.totalBytes;
|
*total_p = (uint32_t)fs_info.totalBytes;
|
||||||
*free_p = (uint32_t)fs_info.totalBytes - fs_info.usedBytes;
|
*free_p = (uint32_t)fs_info.totalBytes - fs_info.usedBytes;
|
||||||
return LV_FS_RES_OK;
|
return LV_FS_RES_OK;
|
||||||
|
|
||||||
#elif defined(ARDUINO_ARCH_ESP32)
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
*total_p = (uint32_t)SPIFFS.totalBytes();
|
*total_p = (uint32_t)LV_FS_SPIFFS.totalBytes();
|
||||||
*free_p = (uint32_t)SPIFFS.totalBytes() - SPIFFS.usedBytes();
|
*free_p = (uint32_t)LV_FS_SPIFFS.totalBytes() - LV_FS_SPIFFS.usedBytes();
|
||||||
return LV_FS_RES_OK;
|
return LV_FS_RES_OK;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -411,14 +444,14 @@ static lv_fs_res_t fs_dir_open(lv_fs_drv_t * drv, void * dir_p, const char * pat
|
|||||||
lv_spiffs_dir_t dir;
|
lv_spiffs_dir_t dir;
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
dir = SPIFFS.open(path);
|
dir = LV_FS_SPIFFS.open(path);
|
||||||
if(!dir) {
|
if(!dir) {
|
||||||
return LV_FS_RES_UNKNOWN;
|
return LV_FS_RES_UNKNOWN;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
dir = SPIFFS.openDir(path);
|
dir = LV_FS_SPIFFS.openDir(path);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
lv_spiffs_dir_t * dp = (lv_spiffs_dir_t *)dir_p; /*Just avoid the confusing casings*/
|
lv_spiffs_dir_t * dp = (lv_spiffs_dir_t *)dir_p; /*Just avoid the confusing casings*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user