Skip to content

Commit 501ce25

Browse files
committed
started with LittleFS support
1 parent 9f46927 commit 501ce25

File tree

5 files changed

+84
-16
lines changed

5 files changed

+84
-16
lines changed

src/Homie/Config.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,11 @@ using namespace HomieInternals;
44

55
Config::Config()
66
: _configStruct()
7-
, _spiffsBegan(false)
87
, _valid(false) {
98
}
109

1110
bool Config::_spiffsBegin() {
12-
if (!_spiffsBegan) {
13-
#ifdef ESP32
14-
_spiffsBegan = SPIFFS.begin(true);
15-
#elif defined(ESP8266)
16-
_spiffsBegan = SPIFFS.begin();
17-
#endif
18-
if (!_spiffsBegan) Interface::get().getLogger() << F("✖ Cannot mount filesystem") << endl;
19-
}
20-
21-
return _spiffsBegan;
11+
return _fs._fsBegin();
2212
}
2313

2414
bool Config::load() {

src/Homie/Config.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
#include "Arduino.h"
44

55
#include <ArduinoJson.h>
6-
#ifdef ESP32
7-
#include <SPIFFS.h>
8-
#endif // ESP32
9-
#include "FS.h"
6+
#include "FS.hpp"
107
#include "Datatypes/Interface.hpp"
118
#include "Datatypes/ConfigStruct.hpp"
129
#include "Utils/DeviceId.hpp"
@@ -34,7 +31,7 @@ class Config {
3431

3532
private:
3633
ConfigStruct _configStruct;
37-
bool _spiffsBegan;
34+
FS _fs;
3835
bool _valid;
3936

4037
bool _spiffsBegin();

src/Homie/Constants.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,26 @@
1010
#define HOMIE_CONFIG 1
1111
#endif
1212

13+
// config mode requires SPIFFS as ESP Async Webserver only works with SPIFFS
14+
#if HOMIE_CONFIG
15+
#define HOMIE_SPIFFS
16+
#endif
17+
18+
// default should be SPIFFS, except using LittleFS is explicitely defined
19+
#ifndef HOMIE_LITTLEFS
20+
#ifndef HOMIE_SPIFFS
21+
#define HOMIE_SPIFFS
22+
#endif
23+
#endif
24+
25+
// fail if none or both are defined
26+
#if defined(HOMIE_SPIFFS) && defined(HOMIE_LITTLEFS)
27+
#error "Only one of HOMIE_SPIFFS and HOMIE_LITTLEFS must be defined. HOMIE_CONFIG requires HOMIE_SPIFFS."
28+
#endif
29+
#if !(defined(HOMIE_SPIFFS) || defined(HOMIE_LITTLEFS))
30+
#error "At least one of HOMIE_SPIFFS or HOMIE_LITTLEFS needs to be defined."
31+
#endif
32+
1333
namespace HomieInternals {
1434
const char HOMIE_VERSION[] = "3.0.1";
1535
const char HOMIE_ESP8266_VERSION[] = "3.0.0";

src/Homie/FS.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "FS.hpp"
2+
#include "Datatypes/Interface.hpp"
3+
4+
HomieInternals::FS::FS()
5+
: _fsBegan(false) {
6+
}
7+
8+
bool HomieInternals::FS::_fsBegin() {
9+
if (!_fsBegan) {
10+
#ifdef ESP32
11+
#ifdef HOMIE_SPIFFS
12+
_fsBegan = SPIFFS.begin(true);
13+
#elif defined(HOMIE_LITTLEFS)
14+
_fsBegan = LittleFS.begin();
15+
#endif
16+
#elif defined(ESP8266)
17+
#ifdef HOMIE_SPIFFS
18+
_fsBegan = SPIFFS.begin();
19+
#elif defined(HOMIE_LITTLEFS)
20+
_fsBegan = LittleFS.begin();
21+
#endif
22+
#endif
23+
if (!_fsBegan) Interface::get().getLogger() << F("✖ Cannot mount filesystem") << endl;
24+
}
25+
26+
return _fsBegan;
27+
}
28+
29+
void HomieInternals::FS::doSomething() {
30+
bool lala = false;
31+
}

src/Homie/FS.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#pragma once
2+
3+
#include "Constants.hpp"
4+
5+
#ifdef ESP32
6+
#ifdef HOMIE_SPIFFS
7+
#include <SPIFFS.h>
8+
#endif
9+
#ifdef HOMIE_LITTLEFS
10+
#include <LITTLEFS.h>
11+
#endif
12+
#elif defined(ESP8266)
13+
#ifdef HOMIE_SPIFFS
14+
#include "FS.h"
15+
#elif defined(HOMIE_LITTLEFS)
16+
#include "LittleFS.h"
17+
#endif
18+
#endif // ESP32
19+
20+
namespace HomieInternals {
21+
class FS {
22+
public:
23+
FS();
24+
bool _fsBegin();
25+
static void doSomething();
26+
27+
private:
28+
bool _fsBegan;
29+
};
30+
} // namespace HomieInternals

0 commit comments

Comments
 (0)