diff --git a/src/main.cpp b/src/main.cpp index 11987d1..520d998 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -349,40 +349,7 @@ void generalTask(void *pvParameters) { while (true) { checkBattery(); - - // Accept Serial input for keyconfig.json - if (Serial.available() > 0) { - String jsonString = Serial.readString(); - Serial.println("Received JSON:"); - Serial.println(jsonString); - - // Parse JSON - DynamicJsonDocument doc(jsonDocSize); - deserializeJson(doc, jsonString); - - // Check if JSON overflowed - if (doc.overflowed() || doc.isNull()) { - Serial.println("JSON overflowed or empty"); - } else { - // Save JSON to SPIFFS as keyconfig.json - File configFile = SPIFFS.open("/keyconfig.json", "w"); - if (!configFile) { - Serial.println("Failed to open config file for writing"); - } - if (!serializeJson(doc, configFile)) { - Serial.println("Failed to write to config file"); - } - configFile.close(); - - // Reload keymaps - keymapsNeedsUpdate = true; - - // Show config updated message - configUpdated = true; - Serial.println("Config updated!"); - } - } - + // if (isDetectingLastConnectedDevice && bleKeyboard.isConnected() && // bleKeyboard.getCounnectedCount() > 1) { // isDetectingLastConnectedDevice = false; @@ -905,6 +872,39 @@ void loop() { return; } + // Accept Serial input for keyconfig.json + if (Serial.available() > 0) { + String jsonString = Serial.readString(); + Serial.println("Received JSON:"); + Serial.println(jsonString); + + // Parse JSON + DynamicJsonDocument doc(jsonDocSize); + deserializeJson(doc, jsonString); + + // Check if JSON overflowed + if (doc.overflowed() || doc.isNull()) { + Serial.println("JSON overflowed or empty"); + } else { + // Save JSON to SPIFFS as keyconfig.json + File configFile = SPIFFS.open("/keyconfig.json", "w"); + if (!configFile) { + Serial.println("Failed to open config file for writing"); + } + if (!serializeJson(doc, configFile)) { + Serial.println("Failed to write to config file"); + } + configFile.close(); + + // Reload keymaps + keymapsNeedsUpdate = true; + + // Show config updated message + configUpdated = true; + Serial.println("Config updated!"); + } + } + // Keypad scan for (int r = 0; r < ROWS; r++) { digitalWrite(outputs[r], LOW); // Setting one row low