MCPcopy Create free account
hub / github.com/BruceDevices/firmware / fromFile

Method fromFile

src/core/config.cpp:88–439  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86}
87
88void BruceConfig::fromFile(bool checkFS) {
89 FS *fs;
90 if (checkFS) {
91 if (!getFsStorage(fs)) {
92 log_i("Fail getting filesystem for config");
93 return;
94 }
95 } else {
96 if (checkLittleFsSize()) fs = &LittleFS;
97 else return;
98 }
99
100 if (!fs->exists(filepath)) {
101 log_i("Config file not found. Creating default config");
102 return saveFile();
103 }
104
105 File file;
106 file = fs->open(filepath, FILE_READ);
107 if (!file) {
108 log_i("Config file not found. Using default values");
109 return;
110 }
111
112 // Deserialize the JSON document
113 JsonDocument jsonDoc;
114 if (deserializeJson(jsonDoc, file)) {
115 Serial.println("Failed to read config file, using default configuration");
116 return;
117 }
118 file.close();
119
120 JsonObject setting = jsonDoc.as<JsonObject>();
121 int count = 0;
122
123 if (!setting["priColor"].isNull()) {
124 priColor = strtoul(setting["priColor"], nullptr, 16);
125 } else {
126 count++;
127 log_e("Fail");
128 }
129 if (!setting["secColor"].isNull()) {
130 secColor = strtoul(setting["secColor"], nullptr, 16);
131 } else {
132 count++;
133 log_e("Fail");
134 }
135 if (!setting["bgColor"].isNull()) {
136 bgColor = strtoul(setting["bgColor"], nullptr, 16);
137 } else {
138 count++;
139 log_e("Fail");
140 }
141
142 if (!setting["themeFile"].isNull()) {
143 themePath = setting["themeFile"].as<String>();
144 } else {
145 count++;

Callers 2

begin_storageFunction · 0.45
viewFileFunction · 0.45

Calls 5

getFsStorageFunction · 0.85
checkLittleFsSizeFunction · 0.85
closeMethod · 0.80
printlnMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected