Skip to content

Commit cf24f96

Browse files
committed
fix: macro config loading error
1 parent 0938e17 commit cf24f96

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

src/main.cpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ RotaryEncoder rotaryExtEncoder1;
4444
Key rotaryExtKeyMap[3] = {rotaryExtKey1, rotaryExtKey2, rotaryExtKey3};
4545
RotaryEncoder rotaryExtRotaryEncoderMap[1] = {rotaryExtEncoder1};
4646

47-
String keyMapJSON = "", macroMapJSON = "";
47+
String keyConfigJSON = "", macroMapJSON = "";
4848
String currentKeyInfo = "";
4949
bool updateKeyInfo = false;
5050
bool isFnKeyPressed = false;
@@ -172,8 +172,7 @@ void setup() {
172172
Serial.println(listFiles());
173173

174174
Serial.println("Loading config files from SPIFFS...");
175-
keyMapJSON = loadJSONFileAsString("keyconfig");
176-
macroMapJSON = loadJSONFileAsString("macros");
175+
keyConfigJSON = loadJSONFileAsString("keyconfig");
177176

178177
StaticJsonDocument<256> doc;
179178
String configJSON = loadJSONFileAsString("config");
@@ -680,7 +679,7 @@ void initKeys() {
680679

681680
DynamicJsonDocument doc(jsonDocSize);
682681
DeserializationError err = deserializeJson(
683-
doc, keyMapJSON, DeserializationOption::NestingLimit(5));
682+
doc, keyConfigJSON, DeserializationOption::NestingLimit(5));
684683
if (err) {
685684
Serial.print(F("deserializeJson() failed: "));
686685
Serial.println(err.c_str());
@@ -763,20 +762,20 @@ void initKeys() {
763762
void initMacros() {
764763
DynamicJsonDocument doc(jsonDocSize);
765764
DeserializationError err = deserializeJson(
766-
doc, macroMapJSON, DeserializationOption::NestingLimit(5));
765+
doc, keyConfigJSON, DeserializationOption::NestingLimit(5));
767766
if (err) {
768767
Serial.print(F("deserializeJson() failed: "));
769768
Serial.println(err.c_str());
770769
}
771-
size_t macrosLength = doc.size();
770+
size_t macrosLength = doc["macros"].size();
772771
for (size_t i = 0; i < macrosLength; i++) {
773772
uint8_t macroLayout[] = {0, 0, 0, 0, 0, 0};
774-
String macroNameStr = doc[i]["name"];
775-
String macroStringContent = doc[i]["stringContent"];
776-
macroMap[i].type = doc[i]["type"];
773+
String macroNameStr = doc["macros"][i]["name"];
774+
String macroStringContent = doc["macros"][i]["stringContent"];
775+
macroMap[i].type = doc["macros"][i]["type"];
777776
macroMap[i].macroInfo = macroNameStr;
778777
macroMap[i].stringContent = macroStringContent;
779-
copyArray(doc[i]["keyStrokes"], macroLayout);
778+
copyArray(doc["macros"][i]["keyStrokes"], macroLayout);
780779
std::copy(std::begin(macroLayout), std::end(macroLayout),
781780
std::begin(macroMap[i].keyStrokes));
782781
}
@@ -789,12 +788,10 @@ void initMacros() {
789788
void updateKeymaps() {
790789
resetIdle();
791790

792-
keyMapJSON = "";
793-
macroMapJSON = "";
791+
keyConfigJSON = "";
794792

795793
Serial.println("Loading config files from SPIFFS...");
796-
keyMapJSON = loadJSONFileAsString("keyconfig");
797-
macroMapJSON = loadJSONFileAsString("macros");
794+
keyConfigJSON = loadJSONFileAsString("keyconfig");
798795

799796
initKeys();
800797
initMacros();
@@ -908,7 +905,7 @@ void switchLayout(int layoutIndex) {
908905
int findLayoutIndex(String layoutName) {
909906
DynamicJsonDocument doc(jsonDocSize);
910907
DeserializationError err = deserializeJson(
911-
doc, keyMapJSON, DeserializationOption::NestingLimit(5));
908+
doc, keyConfigJSON, DeserializationOption::NestingLimit(5));
912909
if (err) {
913910
Serial.print(F("deserializeJson() failed: "));
914911
Serial.println(err.c_str());
@@ -1323,13 +1320,13 @@ void initWebServer() {
13231320

13241321
Serial.println("Reading key configuration from \"" + filename +
13251322
".json\"...");
1326-
String keyconfigJSON = "";
1323+
String keyConfigJSON = "";
13271324
while (file.available()) {
1328-
keyconfigJSON += (char)file.read();
1325+
keyConfigJSON += (char)file.read();
13291326
}
13301327
file.close();
13311328

1332-
deserializeJson(doc, keyconfigJSON);
1329+
deserializeJson(doc, keyConfigJSON);
13331330
res["message"] = "success";
13341331
res["config"] = doc;
13351332
serializeJson(res, buffer);

0 commit comments

Comments
 (0)