Skip to content

Commit

Permalink
feat: add serial input to update keyconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
DriftKingTW committed Dec 17, 2024
1 parent ffef3be commit 306dd44
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,39 @@ 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

0 comments on commit 306dd44

Please sign in to comment.