mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 05:36:37 +00:00
Prepare for LittleFS
This commit is contained in:
parent
88ab7b9bfb
commit
68a38d0b38
@ -42,7 +42,15 @@
|
|||||||
#define HASP_HAS_FILESYSTEM (ARDUINO_ARCH_ESP32 > 0 || ARDUINO_ARCH_ESP8266 > 0)
|
#define HASP_HAS_FILESYSTEM (ARDUINO_ARCH_ESP32 > 0 || ARDUINO_ARCH_ESP8266 > 0)
|
||||||
|
|
||||||
#ifndef HASP_USE_SPIFFS
|
#ifndef HASP_USE_SPIFFS
|
||||||
|
#ifndef HASP_USE_LITTLEFS
|
||||||
#define HASP_USE_SPIFFS (HASP_HAS_FILESYSTEM)
|
#define HASP_USE_SPIFFS (HASP_HAS_FILESYSTEM)
|
||||||
|
#else
|
||||||
|
#define HASP_USE_SPIFFS (HASP_USE_LITTLEFS <= 0)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HASP_USE_LITTLEFS
|
||||||
|
#define HASP_USE_LITTLEFS (HASP_USE_SPIFFS <= 0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HASP_USE_EEPROM
|
#ifndef HASP_USE_EEPROM
|
||||||
@ -91,12 +99,22 @@
|
|||||||
#include "SPIFFS.h"
|
#include "SPIFFS.h"
|
||||||
#endif
|
#endif
|
||||||
#include <FS.h> // Include the SPIFFS library
|
#include <FS.h> // Include the SPIFFS library
|
||||||
#include "hasp_spiffs.h"
|
#include "hasp_filesystem.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HASP_USE_LITTLEFS > 0
|
||||||
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
|
#include <LITTLEFS.h>
|
||||||
|
#endif
|
||||||
|
#include <FS.h> // Include the FS library
|
||||||
|
#include "hasp_filesystem.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||||
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
|
||||||
#include "lv_zifont.h"
|
#include "lv_zifont.h"
|
||||||
#endif
|
#endif
|
||||||
#endif // SPIFFS
|
#endif
|
||||||
|
|
||||||
#if HASP_USE_EEPROM > 0
|
#if HASP_USE_EEPROM > 0
|
||||||
#include "hasp_eeprom.h"
|
#include "hasp_eeprom.h"
|
||||||
@ -110,13 +128,13 @@
|
|||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
#include <ETH.h>
|
#include <ETH.h>
|
||||||
|
|
||||||
#define ETH_ADDR 0
|
#define ETH_ADDR 0
|
||||||
#define ETH_POWER_PIN -1
|
#define ETH_POWER_PIN -1
|
||||||
#define ETH_MDC_PIN 23
|
#define ETH_MDC_PIN 23
|
||||||
#define ETH_MDIO_PIN 18
|
#define ETH_MDIO_PIN 18
|
||||||
#define NRST 5
|
#define NRST 5
|
||||||
#define ETH_TYPE ETH_PHY_LAN8720
|
#define ETH_TYPE ETH_PHY_LAN8720
|
||||||
#define ETH_CLKMODE ETH_CLOCK_GPIO17_OUT
|
#define ETH_CLKMODE ETH_CLOCK_GPIO17_OUT
|
||||||
|
|
||||||
#include "hasp_ethernet_esp32.h"
|
#include "hasp_ethernet_esp32.h"
|
||||||
#warning Using ESP32 Ethernet LAN8720
|
#warning Using ESP32 Ethernet LAN8720
|
||||||
@ -142,6 +160,10 @@
|
|||||||
#include "hasp_mqtt.h"
|
#include "hasp_mqtt.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if HASP_USE_GPIO > 0
|
||||||
|
#include "hasp_gpio.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if HASP_USE_HTTP > 0
|
#if HASP_USE_HTTP > 0
|
||||||
#include "hasp_http.h"
|
#include "hasp_http.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -95,6 +95,7 @@ esp8266_flags=
|
|||||||
-D HASP_USE_SYSLOG=1
|
-D HASP_USE_SYSLOG=1
|
||||||
-D HASP_USE_TELNET=1
|
-D HASP_USE_TELNET=1
|
||||||
-D HASP_USE_SPIFFS=1
|
-D HASP_USE_SPIFFS=1
|
||||||
|
-D HASP_USE_LITTLEFS=0
|
||||||
-D HASP_USE_EEPROM=1
|
-D HASP_USE_EEPROM=1
|
||||||
-D HASP_USE_GPIO=1
|
-D HASP_USE_GPIO=1
|
||||||
-D HASP_USE_ETHERNET=0
|
-D HASP_USE_ETHERNET=0
|
||||||
@ -110,6 +111,7 @@ esp32_flags=
|
|||||||
-D HASP_USE_SYSLOG=1
|
-D HASP_USE_SYSLOG=1
|
||||||
-D HASP_USE_TELNET=1
|
-D HASP_USE_TELNET=1
|
||||||
-D HASP_USE_SPIFFS=1
|
-D HASP_USE_SPIFFS=1
|
||||||
|
-D HASP_USE_LITTLEFS=0
|
||||||
-D HASP_USE_EEPROM=1
|
-D HASP_USE_EEPROM=1
|
||||||
-D HASP_USE_GPIO=1
|
-D HASP_USE_GPIO=1
|
||||||
|
|
||||||
|
11
src/hasp.cpp
11
src/hasp.cpp
@ -15,6 +15,7 @@
|
|||||||
#include "hasp_debug.h"
|
#include "hasp_debug.h"
|
||||||
#include "hasp_config.h"
|
#include "hasp_config.h"
|
||||||
#include "hasp_dispatch.h"
|
#include "hasp_dispatch.h"
|
||||||
|
//#include "hasp_filesystem.h" included in hasp_conf.h
|
||||||
#include "hasp_wifi.h"
|
#include "hasp_wifi.h"
|
||||||
#include "hasp_gui.h"
|
#include "hasp_gui.h"
|
||||||
#include "hasp_tft.h"
|
#include "hasp_tft.h"
|
||||||
@ -404,7 +405,7 @@ void haspSetup()
|
|||||||
|
|
||||||
/* ********** Font Initializations ********** */
|
/* ********** Font Initializations ********** */
|
||||||
|
|
||||||
#if HASP_USE_SPIFFS > 0
|
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||||
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
|
||||||
lv_zifont_init();
|
lv_zifont_init();
|
||||||
|
|
||||||
@ -1006,22 +1007,22 @@ void haspNewObject(const JsonObject & config, uint8_t & saved_page_id)
|
|||||||
|
|
||||||
void haspLoadPage(const char * pages)
|
void haspLoadPage(const char * pages)
|
||||||
{
|
{
|
||||||
#if HASP_USE_SPIFFS > 0
|
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||||
if(pages[0] == '\0') return;
|
if(pages[0] == '\0') return;
|
||||||
|
|
||||||
if(!SPIFFS.begin()) {
|
if(!filesystemSetup()) {
|
||||||
Log.error(TAG_HASP, F("FS not mounted. Failed to load %s"), pages);
|
Log.error(TAG_HASP, F("FS not mounted. Failed to load %s"), pages);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!SPIFFS.exists(pages)) {
|
if(!HASP_FS.exists(pages)) {
|
||||||
Log.error(TAG_HASP, F("Non existing file %s"), pages);
|
Log.error(TAG_HASP, F("Non existing file %s"), pages);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.notice(TAG_HASP, F("Loading file %s"), pages);
|
Log.notice(TAG_HASP, F("Loading file %s"), pages);
|
||||||
|
|
||||||
File file = SPIFFS.open(pages, "r");
|
File file = HASP_FS.open(pages, "r");
|
||||||
dispatchParseJsonl(file);
|
dispatchParseJsonl(file);
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
|
@ -3,24 +3,20 @@
|
|||||||
#include "ArduinoJson.h"
|
#include "ArduinoJson.h"
|
||||||
#include "StreamUtils.h"
|
#include "StreamUtils.h"
|
||||||
|
|
||||||
|
#include "hasp_conf.h"
|
||||||
|
|
||||||
#include "hasp_config.h"
|
#include "hasp_config.h"
|
||||||
#include "hasp_debug.h"
|
#include "hasp_debug.h"
|
||||||
#include "hasp_gui.h"
|
#include "hasp_gui.h"
|
||||||
#include "hasp_ota.h"
|
|
||||||
#include "hasp_spiffs.h"
|
//#include "hasp_ota.h" included in conf
|
||||||
#include "hasp_telnet.h"
|
//#include "hasp_filesystem.h" included in conf
|
||||||
#include "hasp_gpio.h"
|
//#include "hasp_telnet.h" included in conf
|
||||||
|
//#include "hasp_gpio.h" included in conf
|
||||||
|
|
||||||
//#include "hasp_eeprom.h"
|
//#include "hasp_eeprom.h"
|
||||||
#include "hasp.h"
|
#include "hasp.h"
|
||||||
|
|
||||||
#include "hasp_conf.h"
|
|
||||||
|
|
||||||
#if HASP_USE_SPIFFS > 0
|
|
||||||
#include <FS.h> // Include the SPIFFS library
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
#include "SPIFFS.h"
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#if HASP_USE_EEPROM > 0
|
#if HASP_USE_EEPROM > 0
|
||||||
#include "EEPROM.h"
|
#include "EEPROM.h"
|
||||||
#endif
|
#endif
|
||||||
@ -74,13 +70,13 @@ void configStartDebug(bool setupdebug, String & configFile)
|
|||||||
{
|
{
|
||||||
if(setupdebug) {
|
if(setupdebug) {
|
||||||
debugStart(); // Debug started, now we can use it; HASP header sent
|
debugStart(); // Debug started, now we can use it; HASP header sent
|
||||||
#if HASP_USE_SPIFFS > 0
|
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||||
Log.notice(TAG_CONF, F("FILE: [SUCCESS] SPI flash FS mounted"));
|
Log.notice(TAG_CONF, F("[SUCCESS] SPI flash FS mounted"));
|
||||||
spiffsInfo();
|
filesystemInfo();
|
||||||
spiffsList();
|
filesystemList();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#if HASP_USE_SPIFFS > 0
|
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||||
Log.notice(TAG_CONF, F("Loading %s"), configFile.c_str());
|
Log.notice(TAG_CONF, F("Loading %s"), configFile.c_str());
|
||||||
#else
|
#else
|
||||||
Log.notice(TAG_CONF, F("reading EEPROM"));
|
Log.notice(TAG_CONF, F("reading EEPROM"));
|
||||||
@ -94,8 +90,8 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false)
|
|||||||
configFile = String(FPSTR(HASP_CONFIG_FILE));
|
configFile = String(FPSTR(HASP_CONFIG_FILE));
|
||||||
DeserializationError error;
|
DeserializationError error;
|
||||||
|
|
||||||
#if HASP_USE_SPIFFS > 0
|
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||||
File file = SPIFFS.open(configFile, "r");
|
File file = HASP_FS.open(configFile, "r");
|
||||||
|
|
||||||
if(file) {
|
if(file) {
|
||||||
size_t size = file.size();
|
size_t size = file.size();
|
||||||
@ -143,14 +139,14 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false)
|
|||||||
}
|
}
|
||||||
configStartDebug(setupdebug, configFile);
|
configStartDebug(setupdebug, configFile);
|
||||||
|
|
||||||
#if HASP_USE_SPIFFS > 0
|
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||||
Log.error(TAG_CONF, F("Failed to load %s"), configFile.c_str());
|
Log.error(TAG_CONF, F("Failed to load %s"), configFile.c_str());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
void configBackupToEeprom()
|
void configBackupToEeprom()
|
||||||
{
|
{
|
||||||
#if HASP_USE_SPIFFS>0
|
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||||
String configFile((char *)0);
|
String configFile((char *)0);
|
||||||
configFile.reserve(128);
|
configFile.reserve(128);
|
||||||
configFile = String(FPSTR(HASP_CONFIG_FILE));
|
configFile = String(FPSTR(HASP_CONFIG_FILE));
|
||||||
@ -159,7 +155,7 @@ void configBackupToEeprom()
|
|||||||
uint8_t buffer[128];
|
uint8_t buffer[128];
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
|
|
||||||
File file = SPIFFS.open(configFile, "r");
|
File file = HASP_FS.open(configFile, "r");
|
||||||
if(file) {
|
if(file) {
|
||||||
|
|
||||||
while(size_t count = file.read(buffer, sizeof(buffer)) > 0) {
|
while(size_t count = file.read(buffer, sizeof(buffer)) > 0) {
|
||||||
@ -281,8 +277,8 @@ void configWriteConfig()
|
|||||||
// changed |= otaGetConfig(settings[F("ota")].as<JsonObject>());
|
// changed |= otaGetConfig(settings[F("ota")].as<JsonObject>());
|
||||||
|
|
||||||
if(writefile) {
|
if(writefile) {
|
||||||
#if HASP_USE_SPIFFS > 0
|
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||||
File file = SPIFFS.open(configFile, "w");
|
File file = HASP_FS.open(configFile, "w");
|
||||||
if(file) {
|
if(file) {
|
||||||
Log.notice(TAG_CONF, F("Writing %s"), configFile.c_str());
|
Log.notice(TAG_CONF, F("Writing %s"), configFile.c_str());
|
||||||
size_t size = serializeJson(doc, file);
|
size_t size = serializeJson(doc, file);
|
||||||
@ -344,8 +340,8 @@ void configSetup()
|
|||||||
continue;
|
continue;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
#if HASP_USE_SPIFFS > 0
|
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||||
if(!SPIFFS.begin()) {
|
if(!filesystemSetup()) {
|
||||||
Log.error(TAG_CONF, F("FILE: SPI flash init failed. Unable to mount FS: Using default settings..."));
|
Log.error(TAG_CONF, F("FILE: SPI flash init failed. Unable to mount FS: Using default settings..."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -454,8 +450,8 @@ bool configClear()
|
|||||||
Log.error(TAG_CONF, F("Failed to clear to EEPROM"));
|
Log.error(TAG_CONF, F("Failed to clear to EEPROM"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#elif HASP_USE_SPIFFS > 0
|
#elif HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||||
return SPIFFS.format();
|
return HASP_FS.format();
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
@ -3,17 +3,16 @@
|
|||||||
#include "StringStream.h"
|
#include "StringStream.h"
|
||||||
#include "CharStream.h"
|
#include "CharStream.h"
|
||||||
|
|
||||||
|
#include "hasp_conf.h"
|
||||||
|
|
||||||
#include "hasp_dispatch.h"
|
#include "hasp_dispatch.h"
|
||||||
#include "hasp_config.h"
|
#include "hasp_config.h"
|
||||||
#include "hasp_debug.h"
|
#include "hasp_debug.h"
|
||||||
#include "hasp_gpio.h"
|
|
||||||
#include "hasp_gui.h"
|
#include "hasp_gui.h"
|
||||||
#include "hasp_oobe.h"
|
#include "hasp_oobe.h"
|
||||||
#include "hasp_hal.h"
|
#include "hasp_hal.h"
|
||||||
#include "hasp.h"
|
#include "hasp.h"
|
||||||
|
|
||||||
#include "hasp_conf.h"
|
|
||||||
|
|
||||||
inline bool isON(const char * payload)
|
inline bool isON(const char * payload)
|
||||||
{
|
{
|
||||||
return strcasecmp_P(payload, PSTR("ON")) == 0;
|
return strcasecmp_P(payload, PSTR("ON")) == 0;
|
||||||
@ -38,8 +37,8 @@ bool dispatch_factory_reset()
|
|||||||
{
|
{
|
||||||
bool formated, erased = true;
|
bool formated, erased = true;
|
||||||
|
|
||||||
#if HASP_USE_SPIFFS > 0
|
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||||
formated = SPIFFS.format();
|
formated = HASP_FS.format();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HASP_USE_EEPROM > 0
|
#if HASP_USE_EEPROM > 0
|
||||||
@ -209,12 +208,13 @@ void dispatchCommand(const char * topic, const char * payload)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
} else if(!strcmp_P(topic, PSTR("mqtthost")) || !strcmp_P(topic, PSTR("mqttport")) ||
|
} else if(!strcmp_P(topic, PSTR("mqtthost")) || !strcmp_P(topic, PSTR("mqttport")) ||
|
||||||
!strcmp_P(topic, PSTR("mqttuser")) || !strcmp_P(topic, PSTR("mqttpass"))) {
|
!strcmp_P(topic, PSTR("mqttport")) || !strcmp_P(topic, PSTR("mqttuser")) ||
|
||||||
char item[5];
|
!strcmp_P(topic, PSTR("hostname"))) {
|
||||||
memset(item, 0, sizeof(item));
|
// char item[5];
|
||||||
strncpy(item, topic + 4, 4);
|
// memset(item, 0, sizeof(item));
|
||||||
|
// strncpy(item, topic + 4, 4);
|
||||||
DynamicJsonDocument settings(45);
|
DynamicJsonDocument settings(45);
|
||||||
settings[item] = payload;
|
settings[topic + 4] = payload;
|
||||||
mqttSetConfig(settings.as<JsonObject>());
|
mqttSetConfig(settings.as<JsonObject>());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -4,16 +4,9 @@
|
|||||||
|
|
||||||
#include "hasp_conf.h"
|
#include "hasp_conf.h"
|
||||||
#include "hasp_debug.h"
|
#include "hasp_debug.h"
|
||||||
#include "hasp_spiffs.h"
|
#include "hasp_filesystem.h"
|
||||||
|
|
||||||
#if HASP_USE_SPIFFS > 0
|
void filesystemInfo()
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
#include "SPIFFS.h"
|
|
||||||
#endif
|
|
||||||
#include <FS.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void spiffsInfo()
|
|
||||||
{ // Get all information of your SPIFFS
|
{ // Get all information of your SPIFFS
|
||||||
#if 0
|
#if 0
|
||||||
FSInfo fs_info;
|
FSInfo fs_info;
|
||||||
@ -68,7 +61,7 @@ void spiffsInfo()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void spiffsList()
|
void filesystemList()
|
||||||
{
|
{
|
||||||
#if HASP_USE_SPIFFS > 0
|
#if HASP_USE_SPIFFS > 0
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
@ -76,42 +69,46 @@ void spiffsList()
|
|||||||
#else
|
#else
|
||||||
if(!SPIFFS.begin(true)) {
|
if(!SPIFFS.begin(true)) {
|
||||||
#endif
|
#endif
|
||||||
Log.error(TAG_FILE,F("Flash file system not mouted."));
|
Log.error(TAG_FILE, F("Flash file system not mouted."));
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
Log.verbose(TAG_FILE,F("Listing files on the internal flash:"));
|
Log.verbose(TAG_FILE, F("Listing files on the internal flash:"));
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
File root = SPIFFS.open("/");
|
File root = SPIFFS.open("/");
|
||||||
File file = root.openNextFile();
|
File file = root.openNextFile();
|
||||||
while(file) {
|
while(file) {
|
||||||
Log.verbose(TAG_FILE,F(" * %s (%u bytes)"), file.name(), (uint32_t)file.size());
|
Log.verbose(TAG_FILE, F(" * %s (%u bytes)"), file.name(), (uint32_t)file.size());
|
||||||
file = root.openNextFile();
|
file = root.openNextFile();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
Dir dir = SPIFFS.openDir("/");
|
Dir dir = SPIFFS.openDir("/");
|
||||||
while(dir.next()) {
|
while(dir.next()) {
|
||||||
Log.notice(TAG_FILE,F(" * %s (%u bytes)"), dir.fileName().c_str(), (uint32_t)dir.fileSize());
|
Log.notice(TAG_FILE, F(" * %s (%u bytes)"), dir.fileName().c_str(), (uint32_t)dir.fileSize());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void spiffsSetup()
|
bool filesystemSetup()
|
||||||
{
|
{
|
||||||
// no SPIFFS settings, as settings depend on SPIFFS
|
// no SPIFFS settings, as settings depend on SPIFFS
|
||||||
|
|
||||||
#if HASP_USE_SPIFFS > 0
|
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
if(!SPIFFS.begin()) {
|
if(!HASP_FS.begin()) {
|
||||||
#else
|
#else
|
||||||
if(!SPIFFS.begin(true)) {
|
if(!HASP_FS.begin(true)) {
|
||||||
#endif
|
#endif
|
||||||
Log.error(TAG_FILE,F("SPI flash init failed. Unable to mount FS."));
|
Log.error(TAG_FILE, F("SPI flash init failed. Unable to mount FS."));
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
Log.verbose(TAG_FILE,F("SPI Flash FS mounted"));
|
Log.verbose(TAG_FILE, F("SPI Flash FS mounted"));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
30
src/hasp_filesystem.h
Normal file
30
src/hasp_filesystem.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#ifndef HASP_FILESYSTEM_H
|
||||||
|
#define HASP_FILESYSTEM_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
bool filesystemSetup(void);
|
||||||
|
|
||||||
|
void filesystemList();
|
||||||
|
void filesystemInfo();
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
|
#include <FS.h>
|
||||||
|
#include <ESP.h>
|
||||||
|
|
||||||
|
#if HASP_USE_SPIFFS > 0
|
||||||
|
#include "SPIFFS.h"
|
||||||
|
extern FS * HASP_FS = &SPIFFS;
|
||||||
|
#elif HASP_USE_LITTLEFS > 0
|
||||||
|
#include "LittleFS.h"
|
||||||
|
#define HASP_FS LITTLEFS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||||
|
#include <FS.h>
|
||||||
|
#include <ESP.h>
|
||||||
|
#define HASP_FS SPIFFS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
//#include "lv_zifont.h"
|
//#include "lv_zifont.h"
|
||||||
|
|
||||||
|
#include "hasp_conf.h"
|
||||||
#include "hasp_debug.h"
|
#include "hasp_debug.h"
|
||||||
#include "hasp_config.h"
|
#include "hasp_config.h"
|
||||||
#include "hasp_dispatch.h"
|
#include "hasp_dispatch.h"
|
||||||
@ -39,16 +40,9 @@
|
|||||||
#define TOUCH_DRIVER 99
|
#define TOUCH_DRIVER 99
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HASP_USE_SPIFFS > 0
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
#include "SPIFFS.h"
|
|
||||||
#endif
|
|
||||||
#include <FS.h> // Include the SPIFFS library
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define BACKLIGHT_CHANNEL 15 // pwm channel 0-15
|
#define BACKLIGHT_CHANNEL 15 // pwm channel 0-15
|
||||||
|
|
||||||
#if HASP_USE_SPIFFS > 0
|
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||||
File pFileOut;
|
File pFileOut;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -609,8 +603,8 @@ void guiSetup()
|
|||||||
lv_obj_t * mouse_layer = lv_disp_get_layer_sys(NULL); // default display
|
lv_obj_t * mouse_layer = lv_disp_get_layer_sys(NULL); // default display
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
LV_IMG_DECLARE(mouse_cursor_icon); /*Declare the image file.*/
|
LV_IMG_DECLARE(mouse_cursor_icon); /*Declare the image file.*/
|
||||||
cursor = lv_img_create(mouse_layer, NULL); /*Create an image object for the cursor */
|
cursor = lv_img_create(mouse_layer, NULL); /*Create an image object for the cursor */
|
||||||
lv_img_set_src(cursor, &mouse_cursor_icon); /*Set the image source*/
|
lv_img_set_src(cursor, &mouse_cursor_icon); /*Set the image source*/
|
||||||
#else
|
#else
|
||||||
cursor = lv_obj_create(mouse_layer, NULL); // show cursor object on every page
|
cursor = lv_obj_create(mouse_layer, NULL); // show cursor object on every page
|
||||||
@ -822,7 +816,7 @@ bool guiSetConfig(const JsonObject & settings)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* **************************** SCREENSHOTS ************************************** */
|
/* **************************** SCREENSHOTS ************************************** */
|
||||||
#if HASP_USE_SPIFFS > 0 || HASP_USE_HTTP > 0
|
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 || HASP_USE_HTTP > 0
|
||||||
|
|
||||||
static void guiSetBmpHeader(uint8_t * buffer_p, int32_t data)
|
static void guiSetBmpHeader(uint8_t * buffer_p, int32_t data)
|
||||||
{
|
{
|
||||||
@ -887,9 +881,9 @@ void gui_flush_not_complete()
|
|||||||
{
|
{
|
||||||
Log.warning(TAG_GUI, F("GUI: Pixelbuffer not completely sent"));
|
Log.warning(TAG_GUI, F("GUI: Pixelbuffer not completely sent"));
|
||||||
}
|
}
|
||||||
#endif // HASP_USE_SPIFFS > 0 || HASP_USE_HTTP > 0
|
#endif // HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 || HASP_USE_HTTP > 0
|
||||||
|
|
||||||
#if HASP_USE_SPIFFS > 0
|
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||||
/* Flush VDB bytes to a file */
|
/* Flush VDB bytes to a file */
|
||||||
static void gui_screenshot_to_file(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p)
|
static void gui_screenshot_to_file(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p)
|
||||||
{
|
{
|
||||||
@ -914,7 +908,7 @@ void guiTakeScreenshot(const char * pFileName)
|
|||||||
uint8_t buffer[128];
|
uint8_t buffer[128];
|
||||||
gui_get_bitmap_header(buffer, sizeof(buffer));
|
gui_get_bitmap_header(buffer, sizeof(buffer));
|
||||||
|
|
||||||
pFileOut = SPIFFS.open(pFileName, "w");
|
pFileOut = HASP_FS.open(pFileName, "w");
|
||||||
if(pFileOut) {
|
if(pFileOut) {
|
||||||
|
|
||||||
size_t len = pFileOut.write(buffer, 122);
|
size_t len = pFileOut.write(buffer, 122);
|
||||||
|
@ -13,24 +13,11 @@
|
|||||||
|
|
||||||
#include "hasp_gui.h"
|
#include "hasp_gui.h"
|
||||||
#include "hasp_hal.h"
|
#include "hasp_hal.h"
|
||||||
#include "hasp_gpio.h"
|
|
||||||
#include "hasp_debug.h"
|
#include "hasp_debug.h"
|
||||||
#include "hasp_config.h"
|
#include "hasp_config.h"
|
||||||
#include "hasp_dispatch.h"
|
#include "hasp_dispatch.h"
|
||||||
#include "hasp.h"
|
#include "hasp.h"
|
||||||
|
|
||||||
#include "hasp_conf.h"
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
#include "SPIFFS.h"
|
|
||||||
#include <FS.h>
|
|
||||||
#include <FS.h>
|
|
||||||
#include <ESP.h>
|
|
||||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
|
||||||
#include <FS.h>
|
|
||||||
#include <ESP.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HASP_USE_HTTP > 0
|
#if HASP_USE_HTTP > 0
|
||||||
|
|
||||||
bool httpEnable = true;
|
bool httpEnable = true;
|
||||||
@ -38,7 +25,6 @@ bool webServerStarted = false;
|
|||||||
uint16_t httpPort = 80;
|
uint16_t httpPort = 80;
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||||
FS * filesystem = &SPIFFS;
|
|
||||||
File fsUploadFile;
|
File fsUploadFile;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -249,8 +235,8 @@ void webHandleRoot()
|
|||||||
httpMessage +=
|
httpMessage +=
|
||||||
F("<p><form method='get' action='firmware'><button type='submit'>Firmware Upgrade</button></form></p>");
|
F("<p><form method='get' action='firmware'><button type='submit'>Firmware Upgrade</button></form></p>");
|
||||||
|
|
||||||
#if HASP_USE_SPIFFS > 0
|
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||||
if(SPIFFS.exists(F("/edit.htm.gz"))) {
|
if(HASP_FS.exists(F("/edit.htm.gz"))) {
|
||||||
httpMessage += F("<p><form method='get' action='edit.htm.gz?path=/'><button type='submit'>File "
|
httpMessage += F("<p><form method='get' action='edit.htm.gz?path=/'><button type='submit'>File "
|
||||||
"Browser</button></form></p>");
|
"Browser</button></form></p>");
|
||||||
}
|
}
|
||||||
@ -447,6 +433,15 @@ void webHandleInfo()
|
|||||||
httpMessage += F("<br/><b>Memory Fragmentation: </b>");
|
httpMessage += F("<br/><b>Memory Fragmentation: </b>");
|
||||||
httpMessage += String(halGetHeapFragmentation());
|
httpMessage += String(halGetHeapFragmentation());
|
||||||
|
|
||||||
|
#if ARDUINO_ARCH_ESP32
|
||||||
|
if(psramFound()) {
|
||||||
|
httpMessage += F("<br/><b>Free PSRam: </b>");
|
||||||
|
httpMessage += halFormatBytes(ESP.getFreePsram());
|
||||||
|
httpMessage += F("<br/><b>PSRam Size: </b>");
|
||||||
|
httpMessage += halFormatBytes(ESP.getPsramSize());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* LVGL Stats */
|
/* LVGL Stats */
|
||||||
lv_mem_monitor_t mem_mon;
|
lv_mem_monitor_t mem_mon;
|
||||||
lv_mem_monitor(&mem_mon);
|
lv_mem_monitor(&mem_mon);
|
||||||
@ -696,7 +691,7 @@ void webHandleFirmwareUpdate()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HASP_USE_SPIFFS > 0
|
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||||
bool handleFileRead(String path)
|
bool handleFileRead(String path)
|
||||||
{
|
{
|
||||||
if(!httpIsAuthenticated(F("fileread"))) return false;
|
if(!httpIsAuthenticated(F("fileread"))) return false;
|
||||||
@ -706,10 +701,10 @@ bool handleFileRead(String path)
|
|||||||
path += F("index.htm");
|
path += F("index.htm");
|
||||||
}
|
}
|
||||||
String pathWithGz = path + F(".gz");
|
String pathWithGz = path + F(".gz");
|
||||||
if(filesystem->exists(pathWithGz) || filesystem->exists(path)) {
|
if(HASP_FS.exists(pathWithGz) || HASP_FS.exists(path)) {
|
||||||
if(filesystem->exists(pathWithGz)) path += F(".gz");
|
if(HASP_FS.exists(pathWithGz)) path += F(".gz");
|
||||||
|
|
||||||
File file = filesystem->open(path, "r");
|
File file = HASP_FS.open(path, "r");
|
||||||
String contentType = getContentType(path);
|
String contentType = getContentType(path);
|
||||||
if(path == F("/edit.htm.gz")) {
|
if(path == F("/edit.htm.gz")) {
|
||||||
contentType = F("text/html");
|
contentType = F("text/html");
|
||||||
@ -738,7 +733,7 @@ void handleFileUpload()
|
|||||||
filename += upload->filename;
|
filename += upload->filename;
|
||||||
}
|
}
|
||||||
if(filename.length() < 32) {
|
if(filename.length() < 32) {
|
||||||
fsUploadFile = filesystem->open(filename, "w");
|
fsUploadFile = HASP_FS.open(filename, "w");
|
||||||
Log.notice(TAG_HTTP, F("handleFileUpload Name: %s"), filename.c_str());
|
Log.notice(TAG_HTTP, F("handleFileUpload Name: %s"), filename.c_str());
|
||||||
haspProgressMsg(fsUploadFile.name());
|
haspProgressMsg(fsUploadFile.name());
|
||||||
} else {
|
} else {
|
||||||
@ -782,10 +777,10 @@ void handleFileDelete()
|
|||||||
if(path == "/") {
|
if(path == "/") {
|
||||||
return webServer.send_P(500, mimetype, PSTR("BAD PATH"));
|
return webServer.send_P(500, mimetype, PSTR("BAD PATH"));
|
||||||
}
|
}
|
||||||
if(!filesystem->exists(path)) {
|
if(!HASP_FS.exists(path)) {
|
||||||
return webServer.send_P(404, mimetype, PSTR("FileNotFound"));
|
return webServer.send_P(404, mimetype, PSTR("FileNotFound"));
|
||||||
}
|
}
|
||||||
filesystem->remove(path);
|
HASP_FS.remove(path);
|
||||||
webServer.send_P(200, mimetype, PSTR(""));
|
webServer.send_P(200, mimetype, PSTR(""));
|
||||||
// path.clear();
|
// path.clear();
|
||||||
}
|
}
|
||||||
@ -802,10 +797,10 @@ void handleFileCreate()
|
|||||||
if(path == "/") {
|
if(path == "/") {
|
||||||
return webServer.send(500, PSTR("text/plain"), PSTR("BAD PATH"));
|
return webServer.send(500, PSTR("text/plain"), PSTR("BAD PATH"));
|
||||||
}
|
}
|
||||||
if(filesystem->exists(path)) {
|
if(HASP_FS.exists(path)) {
|
||||||
return webServer.send(500, PSTR("text/plain"), PSTR("FILE EXISTS"));
|
return webServer.send(500, PSTR("text/plain"), PSTR("FILE EXISTS"));
|
||||||
}
|
}
|
||||||
File file = filesystem->open(path, "w");
|
File file = HASP_FS.open(path, "w");
|
||||||
if(file) {
|
if(file) {
|
||||||
file.close();
|
file.close();
|
||||||
} else {
|
} else {
|
||||||
@ -829,7 +824,7 @@ void handleFileList()
|
|||||||
path.clear();
|
path.clear();
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
File root = SPIFFS.open("/");
|
File root = HASP_FS.open("/", FILE_READ);
|
||||||
File file = root.openNextFile();
|
File file = root.openNextFile();
|
||||||
String output = "[";
|
String output = "[";
|
||||||
|
|
||||||
@ -854,7 +849,7 @@ void handleFileList()
|
|||||||
output += "]";
|
output += "]";
|
||||||
webServer.send(200, PSTR("text/json"), output);
|
webServer.send(200, PSTR("text/json"), output);
|
||||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||||
Dir dir = filesystem->openDir(path);
|
Dir dir = HASP_FS.openDir(path);
|
||||||
String output = "[";
|
String output = "[";
|
||||||
while(dir.next()) {
|
while(dir.next()) {
|
||||||
File entry = dir.openFile("r");
|
File entry = dir.openFile("r");
|
||||||
@ -1489,7 +1484,7 @@ void webHandleHaspConfig()
|
|||||||
httpMessage += F("<p><b>Default Font</b><select id='font' name='font'><option value=''>None</option>");
|
httpMessage += F("<p><b>Default Font</b><select id='font' name='font'><option value=''>None</option>");
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
File root = SPIFFS.open("/");
|
File root = HASP_FS.open("/");
|
||||||
File file = root.openNextFile();
|
File file = root.openNextFile();
|
||||||
|
|
||||||
while(file) {
|
while(file) {
|
||||||
@ -1500,7 +1495,7 @@ void webHandleHaspConfig()
|
|||||||
file = root.openNextFile();
|
file = root.openNextFile();
|
||||||
}
|
}
|
||||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||||
Dir dir = filesystem->openDir("/");
|
Dir dir = HASP_FS.openDir("/");
|
||||||
while(dir.next()) {
|
while(dir.next()) {
|
||||||
File file = dir.openFile("r");
|
File file = dir.openFile("r");
|
||||||
String filename = file.name();
|
String filename = file.name();
|
||||||
@ -1540,7 +1535,7 @@ void webHandleHaspConfig()
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
void httpHandleNotFound()
|
void httpHandleNotFound()
|
||||||
{ // webServer 404
|
{ // webServer 404
|
||||||
#if HASP_USE_SPIFFS > 0
|
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||||
if(handleFileRead(webServer.uri())) return;
|
if(handleFileRead(webServer.uri())) return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1730,7 +1725,7 @@ void httpSetup()
|
|||||||
haspSetPage(pageid.toInt());
|
haspSetPage(pageid.toInt());
|
||||||
});
|
});
|
||||||
|
|
||||||
#if HASP_USE_SPIFFS > 0
|
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||||
webServer.on(F("/list"), HTTP_GET, handleFileList);
|
webServer.on(F("/list"), HTTP_GET, handleFileList);
|
||||||
// load editor
|
// load editor
|
||||||
webServer.on(F("/edit"), HTTP_GET, []() {
|
webServer.on(F("/edit"), HTTP_GET, []() {
|
||||||
|
@ -13,14 +13,6 @@
|
|||||||
#include "hasp_config.h"
|
#include "hasp_config.h"
|
||||||
#include "hasp_debug.h"
|
#include "hasp_debug.h"
|
||||||
|
|
||||||
#include "hasp_conf.h"
|
|
||||||
#if HASP_USE_MQTT > 0
|
|
||||||
#include "hasp_mqtt.h"
|
|
||||||
#endif
|
|
||||||
#if HASP_USE_MDNS > 0
|
|
||||||
#include "hasp_mdns.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
uint8_t mdnsEnabled = true;
|
uint8_t mdnsEnabled = true;
|
||||||
|
|
||||||
void mdnsSetup()
|
void mdnsSetup()
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
#ifndef HASP_SPIFFS_H
|
|
||||||
#define HASP_SPIFFS_H
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
void spiffsSetup(void);
|
|
||||||
|
|
||||||
void spiffsList();
|
|
||||||
void spiffsInfo();
|
|
||||||
|
|
||||||
#endif
|
|
@ -23,6 +23,11 @@ build_flags =
|
|||||||
-D TFT_RST=-1 ; RST
|
-D TFT_RST=-1 ; RST
|
||||||
-D TFT_BCKL=-1 ; None, configurable via web UI (e.g. 21)
|
-D TFT_BCKL=-1 ; None, configurable via web UI (e.g. 21)
|
||||||
-D TOUCH_CS=17 ; (can also be 22 or 16)
|
-D TOUCH_CS=17 ; (can also be 22 or 16)
|
||||||
|
-D PIOENV=${PIOENV}
|
||||||
|
-D CONFIG_LITTLEFS_FOR_IDF_3_2
|
||||||
|
|
||||||
|
lib_deps =
|
||||||
|
LittleFS_esp32
|
||||||
|
|
||||||
lib_ignore =
|
lib_ignore =
|
||||||
GxTFT
|
GxTFT
|
||||||
|
Loading…
x
Reference in New Issue
Block a user