From 31dcc2485bfd2fe2b602961665b84d6f8dde8fdb Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Thu, 4 Jun 2020 17:32:23 +0900 Subject: [PATCH] Support LittleFS --- src/AutoConnectDefs.h | 23 ++++++++++++++++++----- src/AutoConnectElementBasisImpl.h | 14 +++++++++++--- src/AutoConnectUploadImpl.h | 8 ++++++-- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/AutoConnectDefs.h b/src/AutoConnectDefs.h index 511c8ce..1c97091 100644 --- a/src/AutoConnectDefs.h +++ b/src/AutoConnectDefs.h @@ -3,7 +3,7 @@ * @file AutoConnectDefs.h * @author hieromon@gmail.com * @version 1.2.0 - * @date 2020-04-23 + * @date 2020-05-29 * @copyright MIT license. */ @@ -18,11 +18,11 @@ #define AC_DEBUG_PORT Serial #endif // !AC_DEBUG_PORT #ifdef AC_DEBUG -#define AC_DBG_DUMB(fmt, ...) do {AC_DEBUG_PORT.printf(PSTR(fmt), ## __VA_ARGS__ );} while (0) -#define AC_DBG(fmt, ...) do {AC_DEBUG_PORT.printf(PSTR("[AC] " fmt), ## __VA_ARGS__ );} while (0) +#define AC_DBG_DUMB(fmt, ...) do {AC_DEBUG_PORT.printf_P((PGM_P)PSTR(fmt), ## __VA_ARGS__ );} while (0) +#define AC_DBG(fmt, ...) do {AC_DEBUG_PORT.printf_P((PGM_P)PSTR("[AC] " fmt), ## __VA_ARGS__ );} while (0) #else -#define AC_DBG(...) do {} while(0) -#define AC_DBG_DUMB(...) do {} while(0) +#define AC_DBG(...) do {(void)0;} while(0) +#define AC_DBG_DUMB(...) do {(void)0;} while(0) #endif // !AC_DEBUG // Indicator to specify that AutoConnectAux handles elements with JSON. @@ -34,6 +34,19 @@ #define AUTOCONNECT_USE_UPDATE #endif +// SPIFFS has deprecated on EP8266 core. This flag indicates that +// the migration to LittleFS has not completed. +//#define AC_USE_SPIFFS + +// Deploys SPIFFS usage flag to the global. +#if defined(ARDUINO_ARCH_ESP8266) +#ifdef AC_USE_SPIFFS +#define AUTOCONNECT_USE_SPIFFS +#endif +#elif defined(ARDUINO_ARCH_ESP32) +#define AUTOCONNECT_USE_SPIFFS +#endif + // Predefined parameters // SSID that Captive portal started. #ifndef AUTOCONNECT_APID diff --git a/src/AutoConnectElementBasisImpl.h b/src/AutoConnectElementBasisImpl.h index 63f7ae3..8f5978c 100644 --- a/src/AutoConnectElementBasisImpl.h +++ b/src/AutoConnectElementBasisImpl.h @@ -2,8 +2,8 @@ * Implementation of AutoConnectElementBasis classes. * @file AutoConnectElementBasisImpl.h * @author hieromon@gmail.com - * @version 0.9.11 - * @date 2019-06-25 + * @version 1.2.0 + * @date 2029-05-29 * @copyright MIT license. */ @@ -19,6 +19,14 @@ #endif #include "AutoConnectElementBasis.h" +// Preserve a valid global Filesystem instance. +// It allows the interface to the actual filesystem for migration to LittleFS. +#ifdef AUTOCONNECT_USE_SPIFFS +namespace AutoConnectFS { SPIFFST& FLASHFS = SPIFFS; }; +#else +namespace AutoConnectFS { SPIFFST& FLASHFS = LittleFS; }; +#endif + /** * Append post-tag accoring by the post attribute. * @param s An original string @@ -111,7 +119,7 @@ bool AutoConnectFileBasis::attach(const ACFile_t store) { // Classify a handler type and create the corresponding handler switch (store) { case AC_File_FS: - handlerFS = new AutoConnectUploadFS(SPIFFS); + handlerFS = new AutoConnectUploadFS(AutoConnectFS::FLASHFS); _upload.reset(reinterpret_cast(handlerFS)); break; case AC_File_SD: diff --git a/src/AutoConnectUploadImpl.h b/src/AutoConnectUploadImpl.h index 4e4276f..205fa23 100644 --- a/src/AutoConnectUploadImpl.h +++ b/src/AutoConnectUploadImpl.h @@ -2,8 +2,8 @@ * The default upload handler implementation. * @file AutoConnectUploadImpl.h * @author hieromon@gmail.com - * @version 0.9.9 - * @date 2019-05-25 + * @version 1.2.0 + * @date 2020-05-29 * @copyright MIT license. */ @@ -20,7 +20,11 @@ #include #include #define FS_NO_GLOBALS +#ifdef AUTOCONNECT_USE_SPIFFS #include +#else +#include +#endif // Types branching to be code commonly for the file system classes with // ESP8266 and ESP32.