-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileSystemLFS.cpp
More file actions
86 lines (72 loc) · 1.95 KB
/
fileSystemLFS.cpp
File metadata and controls
86 lines (72 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <Arduino.h>
#include <ArduinoJson.h>
#include <LittleFS.h>
#include "constants.h"
#include "debug.h"
#include "fileSystemLFS.h"
#include "utilities.h"
fileSystemLFS::fileSystemLFS() {
}
void fileSystemLFS::loadConfigSim(JsonArray configs) {
#ifdef DEBUG_SIM
Serial.println(F("\nLoad config - simulation..."));
#endif
// Open the root directory
File file = LittleFS.open("/sim.json");
if (!file || file.isDirectory()) {
Serial.println(F("...failed to open the sim config."));
// results.success = false;
// return results;
return;
}
DynamicJsonDocument doc(4096);
deserializeJson(doc, file);
#ifdef DEBUG_SIM
// serializeJson(doc, Serial);
// Serial.println();
#endif
JsonArray array = doc.as<JsonArray>();
for (JsonObject obj : array) {
#ifdef DEBUG_SIM
Serial.println("obj...");
serializeJson(obj, Serial);
Serial.println();
#endif
configs.add(obj);
#ifdef DEBUG_SIM
Serial.println("configs...obj...");
serializeJson(configs, Serial);
#endif
}
#ifdef DEBUG_SIM
Serial.println("configs...");
serializeJson(configs, Serial);
Serial.println();
Serial.println(F("...config - simulation - load successful."));
#endif
}
bool fileSystemLFS::setup() {
Serial.println(F("\nSetup file system..."));
if (!LittleFS.begin(false)) {
Serial.println(F("\tLittleFS mount failed"));
Serial.println(F("\tDid not find filesystem; starting format"));
// format if begin fails
if (!LittleFS.begin(true)) {
#if defined(DEBUG) || defined(DEBUG_LOGGER)
Serial.println(F("\tLittleFS mount failed"));
Serial.println(F("\tFormatting not possible"));
#endif
Serial.println(F("...file system setup failed."));
return false;
}
Serial.println(F("Formatting"));
}
Serial.println(F("...file system setup successful."));
return true;
}
long fileSystemLFS::totalBytes() {
return LittleFS.totalBytes();
}
long fileSystemLFS::usedBytes() {
return LittleFS.usedBytes();
}