From 5d091365da0219b268b40900945ca66576865680 Mon Sep 17 00:00:00 2001 From: Carl Date: Sun, 6 Oct 2024 12:39:50 -0400 Subject: [PATCH 1/3] Added AHK mode. Send generic key strokes to cap --- code/JCPM2-experimental.ino | 147 +++++++++++++++++++++++++++++++++++- 1 file changed, 146 insertions(+), 1 deletion(-) diff --git a/code/JCPM2-experimental.ino b/code/JCPM2-experimental.ino index 2c0c657..952093c 100644 --- a/code/JCPM2-experimental.ino +++ b/code/JCPM2-experimental.ino @@ -47,7 +47,7 @@ long oldPulseTime = 0; int fanRPM = 0; char toneNote; -int modeArray[] = {0, 1, 3, 7}; //adjust this array to modify sequence of modes - as written, change to {0, 1, 2, 3, 4, 5} to access all modes +int modeArray[] = {0, 1, 3, 7, 8}; //adjust this array to modify sequence of modes - as written, change to {0, 1, 2, 3, 4, 5} to access all modes int inputModeIndex = 0; int modeArrayLength = (sizeof(modeArray) / sizeof(modeArray[0])); @@ -224,6 +224,10 @@ if (inputMode == 7) { KiCad(); } +if (inputMode == 8) { // AHK Mode + ahkMode(); +} + //Serial.println(inputMode); } @@ -716,6 +720,133 @@ void KiCad(){ screenKiCad(); } +void ahkMode() { + setLightsGreen(); + // Handle encoder movement for increment/decrement + if (increment == 1) { + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F1); + Keyboard.releaseAll(); + increment = 0; + setLightsGreen(); // Reset all lights to green after releasing + } + + if (decrement == 1) { + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F2); + Keyboard.releaseAll(); + decrement = 0; + setLightsGreen(); // Reset all lights to green after releasing + } + + // Handle button presses for SW1 to SW9 + if (SW1 == 0) { + setLightsRed(0); // Turn the first LED red when pressed + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F3); + Keyboard.releaseAll(); + delay(100); + setLightsGreen(); // Reset all lights to green after releasing + } + + if (SW2 == 0) { + setLightsRed(0); + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F4); + Keyboard.releaseAll(); + delay(100); + setLightsGreen(); // Reset all lights to green after releasing + } + + if (SW3 == 0) { + setLightsRed(1); + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F5); + Keyboard.releaseAll(); + delay(100); + setLightsGreen(); // Reset all lights to green after releasing + } + + if (SW4 == 0) { + setLightsRed(2); + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F6); + Keyboard.releaseAll(); + delay(100); + setLightsGreen(); // Reset all lights to green after releasing + } + + if (SW5 == 0) { + setLightsRed(3); + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F7); + Keyboard.releaseAll(); + delay(100); + setLightsGreen(); // Reset all lights to green after releasing + } + + if (SW6 == 0) { + setLightsRed(4); + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F8); + Keyboard.releaseAll(); + delay(100); + setLightsGreen(); // Reset all lights to green after releasing + } + + if (SW7 == 0) { + setLightsRed(5); + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F9); + Keyboard.releaseAll(); + delay(100); + setLightsGreen(); // Reset all lights to green after releasing + } + + if (SW8 == 0) { + setLightsRed(6); + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F10); + Keyboard.releaseAll(); + delay(100); + setLightsGreen(); // Reset all lights to green after releasing + } + + + + if (SW9 == 0) { + setLightsRed(7); // Turn the ninth LED red when pressed + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press(KEY_F11); + Keyboard.releaseAll(); + delay(100); + setLightsGreen(); // Reset all lights to green after releasing + } +} + + //======================.96" oled screen======================= void screenVolume(){ @@ -853,3 +984,17 @@ void topPixelsClear(){ } pixels.show(); // Show results } + +// Function to set all lights to green +void setLightsGreen() { + for (int i = 0; i < NUMPIXELS; i++) { + pixels.setPixelColor(i, pixels.Color(0, 255, 0)); // Set green color + } + pixels.show(); +} + +// Function to set a specific light red when a button is pressed +void setLightsRed(int index) { + pixels.setPixelColor(index, pixels.Color(255, 0, 0)); // Set red color + pixels.show(); +} \ No newline at end of file From 60fe2e789f8d2e3937b33fcfca8f0c5bd007364e Mon Sep 17 00:00:00 2001 From: Carl Date: Sun, 6 Oct 2024 18:36:06 -0400 Subject: [PATCH 2/3] JSON version. Web Browser accessible --- code/JCPM-json/JCPM-json.ino | Bin 0 -> 2678 bytes code/JCPM-json/buttons.ino | 93 +++++++++++++++++++++++++++++++++++ code/JCPM-json/neopixels.ino | 23 +++++++++ code/JCPM-json/profiles.ino | 48 ++++++++++++++++++ code/JCPM-json/serial.ino | Bin 0 -> 6245 bytes 5 files changed, 164 insertions(+) create mode 100644 code/JCPM-json/JCPM-json.ino create mode 100644 code/JCPM-json/buttons.ino create mode 100644 code/JCPM-json/neopixels.ino create mode 100644 code/JCPM-json/profiles.ino create mode 100644 code/JCPM-json/serial.ino diff --git a/code/JCPM-json/JCPM-json.ino b/code/JCPM-json/JCPM-json.ino new file mode 100644 index 0000000000000000000000000000000000000000..335787dccf08c3fd5b18fbbf2581e33b087da94d GIT binary patch literal 2678 zcmb7GZBN@s5bkIHim5C09F#%=g)8MaiSlx#B@mHA_aUIjvB$|4XV=%~zu6ZP zM>y3T;zKg~%ri63&d%f=<4Ino2!DJ%Kl#v?;s+*rbNVOvzpX7e6B6!mF&42*A?7K} zM5z!64_V0*%><8grWe7x7p~LO{`FO_Mq}ALm(oHqK7mB=j7>@z8wOSLK9Xt4xcH_7 zuTgmKB9_W{e;Zs~{(>TnGg&e{xfAyFaM5W~3CTJYc0Y8HXAc=%#Zk8O?c6aXaCSVC;&8t&a4R2EWJ4ZEGC zVJ1?RF_db!YmJP8J+@(CJj~}rbLMj%(?s8 zs_0gPF_gsCtHgo`Hz%8I2#>YQDUWb4Wtk3Jfl*_%CSSg*Pz|^54h++!{hPl>{hN!6n|{lX4F2gtQL3pEhi=99 zn)`0l%_9B22EEtF{b>!l zS(E){^ruGZZl{KZ4`x6qh!xFv+6ijTbTSR-8mO_)In#^={ZG@ml0LP~3TWGnP)$@q z4(!?H7$=NJ`+J>E%M7mhlv)X*x9*hM2(~t09y4v5*YTODz?MNaw&2->_JjrP3>}3} zx1rLpF4b-L`8GV0h%m#MkPDhXHqr__qw}6Uj#{rya~_4a;j?k0Ff^C!hVz+Qbk8ih zy1~AJs#p~{PtxW>#A%iL^8K5=2ALEy@cR&E^paUYO8CbGsw@g2HSLv|c)*nM$cf6m z$ushFjy_PmG?VBAe`-eC`SOXp_HA0@QJ5FOAyYs-1*W1=k+{!p|y>4C<{nMO}B06eS z(c$nAI&MaTCGmJT^uYIq*&AE*+MWA*@^|^!u73v1>G$0eMfg7~RT7TFWhiNDkaD%C K2PEj5H~#{kA7okp literal 0 HcmV?d00001 diff --git a/code/JCPM-json/buttons.ino b/code/JCPM-json/buttons.ino new file mode 100644 index 0000000..7cd586b --- /dev/null +++ b/code/JCPM-json/buttons.ino @@ -0,0 +1,93 @@ +// Define buttons and button states (inverted logic for LOW = pressed) +bool SW1 = HIGH; +bool SW2 = HIGH; +bool SW3 = HIGH; +bool SW4 = HIGH; +bool SW5 = HIGH; +bool SW6 = HIGH; +bool SW7 = HIGH; +bool SW8 = HIGH; +bool SW9 = HIGH; + +// Define states to track when buttons are held or released +bool buttonHeld[9] = {false, false, false, false, false, false, false, false, false}; + +//Encoder vars +int16_t encoderPosition = 0; // Tracks position change + + +// Encoder setup +Encoder myEnc(1, 0); // Pin 1 and 0 for the encoder (adjust if needed) + +// Check button actions +// Function to check and update button states +void checkButtonActions() { + int buttonPins[9] = {4, 15, A0, A1, A2, A3, 14, 16, 10}; // Array of button pin numbers + + for (int i = 0; i < sizeof(buttonPins) / sizeof(buttonPins[0]); i++) { + int currentState = digitalRead(buttonPins[i]); // Read the current state of each button + + // Button press detected (LOW state and not already held) + if (currentState == LOW && !buttonHeld[i]) { + buttonHeld[i] = true; // Mark button as held + Serial.print("{\"button\":"); + Serial.print(i + 1); // JSON output for button press + Serial.println(", \"event\":\"pressed\"}"); + + executeButtonAction(i); // Execute the button action when pressed + } + + // Button release detected (HIGH state and was previously held) + if (currentState == HIGH && buttonHeld[i]) { + buttonHeld[i] = false; // Reset button held state + Serial.print("{\"button\":"); + Serial.print(i + 1); // JSON output for button release + Serial.println(", \"event\":\"released\"}"); + } + } +} + +void checkEncoderActions() { + int16_t newPosition = myEnc.read(); // Read the encoder position + + // Detect if the encoder has moved forward + if (newPosition > encoderPosition) { + Serial.println("{\"encoder\":\"increment\"}"); // Send JSON output for increment + encoderPosition = newPosition; // Update the last known position + } + + // Detect if the encoder has moved backward + if (newPosition < encoderPosition) { + Serial.println("{\"encoder\":\"decrement\"}"); // Send JSON output for decrement + encoderPosition = newPosition; // Update the last known position + } + + delay(50); // Small delay to allow more frequent checks and avoid missing pulses +} + +// Define the executeButtonAction function +void executeButtonAction(int buttonIndex) { + ButtonConfig config = buttonConfigs[buttonIndex]; + + // Set the LED color to "press" color + setPixelColor(buttonIndex, config.colorOnPress[0], config.colorOnPress[1], config.colorOnPress[2]); + + // Execute the HID action + if (strcmp(config.action, "key") == 0) { + // Handle key presses with modifiers + if (strstr(config.modifiers, "Ctrl")) Keyboard.press(KEY_LEFT_CTRL); + if (strstr(config.modifiers, "Shift")) Keyboard.press(KEY_LEFT_SHIFT); + + for (int i = 0; i < strlen(config.keys); i++) { + Keyboard.press(config.keys[i]); + } + delay(100); + Keyboard.releaseAll(); + } else if (strcmp(config.action, "mouse_move") == 0) { + // Handle mouse movement + Mouse.move(config.x, config.y); + } + + // Reset the LED color to default after the action + setPixelColor(buttonIndex, config.color[0], config.color[1], config.color[2]); +} diff --git a/code/JCPM-json/neopixels.ino b/code/JCPM-json/neopixels.ino new file mode 100644 index 0000000..ad3f546 --- /dev/null +++ b/code/JCPM-json/neopixels.ino @@ -0,0 +1,23 @@ +#include + +#define PIN 5 // NeoPixel data pin +#define NUMPIXELS 11 // Total number of NeoPixel LEDs +Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); + +void setupNeoPixels() { + pixels.begin(); + resetAllPixels(); // Set all pixels to off initially +} + +void setPixelColor(int pixel, int r, int g, int b) { + if (pixel >= 0 && pixel < pixels.numPixels()) { + pixels.setPixelColor(pixel, pixels.Color(r, g, b)); + pixels.show(); // Update to show the change + } +} + +void resetAllPixels() { + for (int i = 0; i < NUMPIXELS; i++) { + setPixelColor(i, 0, 0, 0); // Turn off all LEDs + } +} diff --git a/code/JCPM-json/profiles.ino b/code/JCPM-json/profiles.ino new file mode 100644 index 0000000..a117ea4 --- /dev/null +++ b/code/JCPM-json/profiles.ino @@ -0,0 +1,48 @@ +#include +#include + +// Load configuration from EEPROM +void loadConfigFromEEPROM() { + int configOffset = 0; + EEPROM.get(configOffset, generalConfig); + EEPROM.get(configOffset + sizeof(GeneralConfig), buttonConfigs); + + // Output loaded configuration for debugging + Serial.println("{\"status\":\"Loaded configuration from EEPROM.\"}"); + + Serial.print("{\"buttons\":["); + for (int i = 0; i < 9; i++) { + Serial.print("{\"button\":"); + Serial.print(i); + Serial.print(",\"action\":\""); + Serial.print(buttonConfigs[i].action); + Serial.print("\"}"); + + if (i < 8) { + Serial.print(","); // Add a comma after each button except the last one + } + } + + Serial.println("]}"); // Close the JSON array and object +} + +// Save configuration to EEPROM +void saveConfigToEEPROM() { + int configOffset = 0; + EEPROM.put(configOffset, generalConfig); + EEPROM.put(configOffset + sizeof(GeneralConfig), buttonConfigs); + + Serial.println("{\"response\":\"Configuration saved to EEPROM.\"}"); +} + +void resetEEPROM() { + int eepromSize = EEPROM.length(); + + for (int i = 0; i < eepromSize; i++) { + EEPROM.write(i, 0); // Write zeros to the entire EEPROM + } + + Serial.println("{\"response\":\"EEPROM reset completed\"}"); + + asm volatile ("jmp 0"); // Inline assembly to jump to address 0 (reset vector) +} diff --git a/code/JCPM-json/serial.ino b/code/JCPM-json/serial.ino new file mode 100644 index 0000000000000000000000000000000000000000..f53cc68fda7543208f14da040eb3fd6f683d2a74 GIT binary patch literal 6245 zcmb_g+iu%95bbk-`~#r^t%GKr%VHn4O#-xud)u}ylJ?0l3PqwFZDh*OC9zxN-}elM zlqt!w(rx`>NSrxy;mqMsk0TYtMJUD5%QP$^mAuaq)xSR3-g;cF3JWXJdM;;M5H2)g^^69AM(mql}B;!>7{zQ^Fj!Ca*ibd119unHQ-tkN4I${i%F^R~olRLdZoXb=OGP;!^1MTg( z=C$#V0JQOQBg*!li_&~eO9NZis%sRGb=+DMr<@a?vl1pjF_S766C`Kury2HuMK5wc zj{>T~Gb3~K*TLb5fClgRnVeu}gfFrgk}cC+F^Lv3{3DCLo0MB{Yr7F`1{+1D!+o7f ziNwv4blD#31VSIR42spHzboW3ndv=_z9XJQ4RjfBF&vAqT$B`P4<7Gw!U>-Jre4wV z)gl`fIdz9_zPSvdNfbD6+Lo!gNO7)_;+dZ_XtnZcbystlVVtbgl(lpH;9HibtF%;Q z+)ALH6ljE&5;mmby&Zh`F!U^=tWtp#jXc9M-k7@2h$1}}fpUK5i-1ym(A1hn*pR3WmU zCK2r()@*xQ8Mms}g_#ur$P87!Vvu#Q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FhCV OV~jHTf{p)2kNyMQG*vSI literal 0 HcmV?d00001 From 00b3d7ed6dcedc9eef73215ac386b2ff14f5044c Mon Sep 17 00:00:00 2001 From: Carl Date: Sun, 6 Oct 2024 22:14:06 -0400 Subject: [PATCH 3/3] Added debug, fixed encoder --- code/JCPM-json/JCPM-json.ino | Bin 2678 -> 2675 bytes code/JCPM-json/buttons.ino | 167 ++++++++++++++++++----------------- code/JCPM-json/profiles.ino | 46 +++++++++- code/JCPM-json/serial.ino | Bin 6245 -> 8562 bytes 4 files changed, 130 insertions(+), 83 deletions(-) diff --git a/code/JCPM-json/JCPM-json.ino b/code/JCPM-json/JCPM-json.ino index 335787dccf08c3fd5b18fbbf2581e33b087da94d..a495e9141e9d0823ff6a3b7622283094d29fa2a2 100644 GIT binary patch delta 7 Ocmew+@>yg encoderPosition) { - Serial.println("{\"encoder\":\"increment\"}"); // Send JSON output for increment - encoderPosition = newPosition; // Update the last known position - } - - // Detect if the encoder has moved backward - if (newPosition < encoderPosition) { - Serial.println("{\"encoder\":\"decrement\"}"); // Send JSON output for decrement - encoderPosition = newPosition; // Update the last known position - } + int16_t newPosition = myEnc.read(); + if (newPosition > encoderPosition) { + Serial.println("{\"encoder\":\"increment\"}"); // JSON output for increment action + executeEncoderAction(encoderConfigs[0]); + encoderPosition = newPosition; + } + if (newPosition < encoderPosition) { + Serial.println("{\"encoder\":\"decrement\"}"); // JSON output for decrement action + executeEncoderAction(encoderConfigs[1]); + encoderPosition = newPosition; + } + delay(50); +} - delay(50); // Small delay to allow more frequent checks and avoid missing pulses +void executeHIDAction(const char* action, const char* keys, const char* modifiers, int x = 0, int y = 0, bool hasMouseAction = false) { + // Check if the action type is "constant" and map string to HID keycode + if (strcmp(action, "const") == 0) { + if (strcmp(keys, "UpArrow") == 0) { + Keyboard.press(HID_KEYBOARD_UPARROW); + } else if (strcmp(keys, "DownArrow") == 0) { + Keyboard.press(HID_KEYBOARD_DOWNARROW); + } else if (strcmp(keys, "LeftArrow") == 0) { + Keyboard.press(HID_KEYBOARD_LEFTARROW); + } else if (strcmp(keys, "RightArrow") == 0) { + Keyboard.press(HID_KEYBOARD_RIGHTARROW); + } else if (strcmp(keys, "Enter") == 0) { + Keyboard.press(KEY_ENTER); + } else { + Serial.print("{\"error\":\"Invalid constant: "); + Serial.print(keys); + Serial.println("\"}"); + return; + } + delay(100); // Short delay for key press + Keyboard.releaseAll(); + } + // Handle "key" action to press any key provided in the config + else if (strcmp(action, "key") == 0) { + // Handle modifiers if any + if (strstr(modifiers, "Ctrl")) Keyboard.press(KEY_LEFT_CTRL); + if (strstr(modifiers, "Shift")) Keyboard.press(KEY_LEFT_SHIFT); + if (strstr(modifiers, "Alt")) Keyboard.press(KEY_LEFT_ALT); + + // Directly press the specified key as a character + // Loop over each character in keys and press it + for (int i = 0; i < strlen(keys); i++) { + Keyboard.press(keys[i]); // Press each character in the string + delay(50); // Optional small delay between each key press + } + delay(100); // Short delay for key press + Keyboard.releaseAll(); + } + // Handle mouse actions if needed + else if (hasMouseAction && strcmp(action, "mouse") == 0) { + Mouse.move(x, y); + } } -// Define the executeButtonAction function void executeButtonAction(int buttonIndex) { - ButtonConfig config = buttonConfigs[buttonIndex]; - - // Set the LED color to "press" color - setPixelColor(buttonIndex, config.colorOnPress[0], config.colorOnPress[1], config.colorOnPress[2]); - - // Execute the HID action - if (strcmp(config.action, "key") == 0) { - // Handle key presses with modifiers - if (strstr(config.modifiers, "Ctrl")) Keyboard.press(KEY_LEFT_CTRL); - if (strstr(config.modifiers, "Shift")) Keyboard.press(KEY_LEFT_SHIFT); - - for (int i = 0; i < strlen(config.keys); i++) { - Keyboard.press(config.keys[i]); - } - delay(100); - Keyboard.releaseAll(); - } else if (strcmp(config.action, "mouse_move") == 0) { - // Handle mouse movement - Mouse.move(config.x, config.y); - } + ButtonConfig config = buttonConfigs[buttonIndex]; + executeHIDAction(config.action, config.keys, config.modifiers, config.x, config.y, true); +} - // Reset the LED color to default after the action - setPixelColor(buttonIndex, config.color[0], config.color[1], config.color[2]); +void executeEncoderAction(const EncoderConfig &config) { + executeHIDAction(config.action, config.keys, config.modifiers); } diff --git a/code/JCPM-json/profiles.ino b/code/JCPM-json/profiles.ino index a117ea4..3aa05f1 100644 --- a/code/JCPM-json/profiles.ino +++ b/code/JCPM-json/profiles.ino @@ -4,8 +4,17 @@ // Load configuration from EEPROM void loadConfigFromEEPROM() { int configOffset = 0; + + // Load general configuration EEPROM.get(configOffset, generalConfig); - EEPROM.get(configOffset + sizeof(GeneralConfig), buttonConfigs); + configOffset += sizeof(GeneralConfig); + + // Load button configurations + EEPROM.get(configOffset, buttonConfigs); + configOffset += sizeof(buttonConfigs); + + // Load encoder configurations + EEPROM.get(configOffset, encoderConfigs); // Output loaded configuration for debugging Serial.println("{\"status\":\"Loaded configuration from EEPROM.\"}"); @@ -18,19 +27,50 @@ void loadConfigFromEEPROM() { Serial.print(buttonConfigs[i].action); Serial.print("\"}"); + // Set the button's color if it has a color configured + setPixelColor(i - 1, buttonConfigs[i].color[0], buttonConfigs[i].color[1], buttonConfigs[i].color[2]); + + if (i < 8) { Serial.print(","); // Add a comma after each button except the last one } } Serial.println("]}"); // Close the JSON array and object + + // Print encoder configurations + Serial.print("{\"encoder\":{\"increment\":{"); + Serial.print("\"action\":\""); + Serial.print(encoderConfigs[0].action); + Serial.print("\",\"keys\":\""); + Serial.print(encoderConfigs[0].keys); + Serial.print("\",\"modifiers\":\""); + Serial.print(encoderConfigs[0].modifiers); + Serial.print("\"},\"decrement\":{"); + + Serial.print("\"action\":\""); + Serial.print(encoderConfigs[1].action); + Serial.print("\",\"keys\":\""); + Serial.print(encoderConfigs[1].keys); + Serial.print("\",\"modifiers\":\""); + Serial.print(encoderConfigs[1].modifiers); + Serial.println("\"}}}"); } // Save configuration to EEPROM void saveConfigToEEPROM() { int configOffset = 0; + + // Save general configuration EEPROM.put(configOffset, generalConfig); - EEPROM.put(configOffset + sizeof(GeneralConfig), buttonConfigs); + configOffset += sizeof(GeneralConfig); + + // Save button configurations + EEPROM.put(configOffset, buttonConfigs); + configOffset += sizeof(buttonConfigs); + + // Save encoder configurations + EEPROM.put(configOffset, encoderConfigs); Serial.println("{\"response\":\"Configuration saved to EEPROM.\"}"); } @@ -43,6 +83,4 @@ void resetEEPROM() { } Serial.println("{\"response\":\"EEPROM reset completed\"}"); - - asm volatile ("jmp 0"); // Inline assembly to jump to address 0 (reset vector) } diff --git a/code/JCPM-json/serial.ino b/code/JCPM-json/serial.ino index f53cc68fda7543208f14da040eb3fd6f683d2a74..18479c7997335b7d11af46b4811948e8a1686235 100644 GIT binary patch literal 8562 zcmbtaYj4}e68-L9v0#BpMs)pZbI~>rAhuOEZ4w1`@<}!dT3X4xkw}3L+iKwde$UM8 zlDia1$*8{w_!SSmk5@(B-&f!Fl!|7mFK-XR`!HIB zw+r3hmocTT@-&L)Dk25-Mj63Whf^8(8t2iX-@A@``>&LO8J8F`;CMU>iI$31m}@mpJ+6q)wGA zcKXZV)$q&TQqFuU^di$-p&Cr_w5oNxx&TV~D>q`Yc8re;Mvp`b9vBWtg8Jcal1 zETZMYkj>y7{mY68$`r!6tPh(`l8a}f52MS{L(aQTI{A#;S!6s_m%kN2Xh0aqw7CM^0|Yt{vI+7Fj0(tw;RIi@C;GM3dvLu31G| zhbBi`UDJs#Qbml7V)WdorBW$I@n=*#)S8)!a-|=mET_W5+c9*U~v_Yhz_~#$Od7A){V8voi*!b>{GZMYm?0i%iX|G zS?hKEnQqsaq1wbN^*j2a+i>!Y&M7f}H zDGvyCbF6n(xC3bF)SQ+_La(beIUk;Wy(pU#(|{UAad4!Y0tqVFf}0luO^1y3@j!#LL|vC|IivIDIel|FDq%{wc%A;6_r zwy%?yFQsB%nwz5*VXnnT(!92a@V3(_Vzwcf8O0flXV9%RTtqRY7eDX_|1y+^~ zVcB*{Pn_7_Mk!>?TAemi3IT^wRB_X5ZEO3bWzCFs?TXD+a9K+2s_e3yA^r{r*)MsPV2HYPLU0l zIHD#?bh%-cMf2DeaXz^+8yQt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