Skip to content

Commit

Permalink
fix: serial update config conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
DriftKingTW committed Dec 17, 2024
1 parent a16d617 commit 4941c57
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4941c57

Please sign in to comment.