Skip to content

Commit

Permalink
started with LittleFS support
Browse files Browse the repository at this point in the history
  • Loading branch information
kleini committed Dec 28, 2020
1 parent 9f46927 commit 501ce25
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 16 deletions.
12 changes: 1 addition & 11 deletions src/Homie/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,11 @@ using namespace HomieInternals;

Config::Config()
: _configStruct()
, _spiffsBegan(false)
, _valid(false) {
}

bool Config::_spiffsBegin() {
if (!_spiffsBegan) {
#ifdef ESP32
_spiffsBegan = SPIFFS.begin(true);
#elif defined(ESP8266)
_spiffsBegan = SPIFFS.begin();
#endif
if (!_spiffsBegan) Interface::get().getLogger() << F("✖ Cannot mount filesystem") << endl;
}

return _spiffsBegan;
return _fs._fsBegin();
}

bool Config::load() {
Expand Down
7 changes: 2 additions & 5 deletions src/Homie/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
#include "Arduino.h"

#include <ArduinoJson.h>
#ifdef ESP32
#include <SPIFFS.h>
#endif // ESP32
#include "FS.h"
#include "FS.hpp"
#include "Datatypes/Interface.hpp"
#include "Datatypes/ConfigStruct.hpp"
#include "Utils/DeviceId.hpp"
Expand Down Expand Up @@ -34,7 +31,7 @@ class Config {

private:
ConfigStruct _configStruct;
bool _spiffsBegan;
FS _fs;
bool _valid;

bool _spiffsBegin();
Expand Down
20 changes: 20 additions & 0 deletions src/Homie/Constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@
#define HOMIE_CONFIG 1
#endif

// config mode requires SPIFFS as ESP Async Webserver only works with SPIFFS
#if HOMIE_CONFIG
#define HOMIE_SPIFFS
#endif

// default should be SPIFFS, except using LittleFS is explicitely defined
#ifndef HOMIE_LITTLEFS
#ifndef HOMIE_SPIFFS
#define HOMIE_SPIFFS
#endif
#endif

// fail if none or both are defined
#if defined(HOMIE_SPIFFS) && defined(HOMIE_LITTLEFS)
#error "Only one of HOMIE_SPIFFS and HOMIE_LITTLEFS must be defined. HOMIE_CONFIG requires HOMIE_SPIFFS."
#endif
#if !(defined(HOMIE_SPIFFS) || defined(HOMIE_LITTLEFS))
#error "At least one of HOMIE_SPIFFS or HOMIE_LITTLEFS needs to be defined."
#endif

namespace HomieInternals {
const char HOMIE_VERSION[] = "3.0.1";
const char HOMIE_ESP8266_VERSION[] = "3.0.0";
Expand Down
31 changes: 31 additions & 0 deletions src/Homie/FS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "FS.hpp"
#include "Datatypes/Interface.hpp"

HomieInternals::FS::FS()
: _fsBegan(false) {
}

bool HomieInternals::FS::_fsBegin() {
if (!_fsBegan) {
#ifdef ESP32
#ifdef HOMIE_SPIFFS
_fsBegan = SPIFFS.begin(true);
#elif defined(HOMIE_LITTLEFS)
_fsBegan = LittleFS.begin();
#endif
#elif defined(ESP8266)
#ifdef HOMIE_SPIFFS
_fsBegan = SPIFFS.begin();
#elif defined(HOMIE_LITTLEFS)
_fsBegan = LittleFS.begin();
#endif
#endif
if (!_fsBegan) Interface::get().getLogger() << F("✖ Cannot mount filesystem") << endl;
}

return _fsBegan;
}

void HomieInternals::FS::doSomething() {
bool lala = false;
}
30 changes: 30 additions & 0 deletions src/Homie/FS.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "Constants.hpp"

#ifdef ESP32
#ifdef HOMIE_SPIFFS
#include <SPIFFS.h>
#endif
#ifdef HOMIE_LITTLEFS
#include <LITTLEFS.h>
#endif
#elif defined(ESP8266)
#ifdef HOMIE_SPIFFS
#include "FS.h"
#elif defined(HOMIE_LITTLEFS)
#include "LittleFS.h"
#endif
#endif // ESP32

namespace HomieInternals {
class FS {
public:
FS();
bool _fsBegin();
static void doSomething();

private:
bool _fsBegan;
};
} // namespace HomieInternals

0 comments on commit 501ce25

Please sign in to comment.