diff --git a/right/src/config_parser/config_state.c b/right/src/config_parser/config_state.c index 2912750..0a299b9 100644 --- a/right/src/config_parser/config_state.c +++ b/right/src/config_parser/config_state.c @@ -3,11 +3,13 @@ static uint8_t hardwareConfig[HARDWARE_CONFIG_SIZE]; config_buffer_t HardwareConfigBuffer = {hardwareConfig}; -static uint8_t userConfig1[USER_CONFIG_SIZE]; -static uint8_t __attribute__((section (".m_data_2"))) userConfig2[USER_CONFIG_SIZE]; +static uint8_t userConfig[USER_CONFIG_SIZE]; +static uint8_t __attribute__((section (".m_data_2"))) stagingUserConfig[USER_CONFIG_SIZE]; -config_buffer_t UserConfigBuffer = { userConfig1 }; -config_buffer_t NewUserConfigBuffer = { userConfig2 }; +config_buffer_t UserConfigBuffer = { userConfig }; +config_buffer_t StagingUserConfigBuffer = { stagingUserConfig }; + +bool ParserRunDry; uint8_t readUInt8(config_buffer_t *buffer) { return buffer->buffer[buffer->offset++]; diff --git a/right/src/config_parser/config_state.h b/right/src/config_parser/config_state.h index f92630d..84dfd00 100644 --- a/right/src/config_parser/config_state.h +++ b/right/src/config_parser/config_state.h @@ -21,9 +21,10 @@ // Variables: + extern bool ParserRunDry; extern config_buffer_t HardwareConfigBuffer; extern config_buffer_t UserConfigBuffer; - extern config_buffer_t NewUserConfigBuffer; + extern config_buffer_t StagingUserConfigBuffer; // Functions: diff --git a/right/src/config_parser/parse_keymap.c b/right/src/config_parser/parse_keymap.c index 1ae18ef..455ba26 100644 --- a/right/src/config_parser/parse_keymap.c +++ b/right/src/config_parser/parse_keymap.c @@ -3,8 +3,6 @@ #include "current_keymap.h" #include "led_display.h" -static bool isDryRun; - static parser_error_t parseNoneAction(key_action_t *keyAction, config_buffer_t *buffer) { keyAction->type = KeyActionType_None; return ParserError_Success; @@ -146,7 +144,7 @@ static parser_error_t parseKeyActions(uint8_t targetLayer, config_buffer_t *buff return ParserError_InvalidActionCount; } for (uint16_t actionIdx = 0; actionIdx < actionCount; actionIdx++) { - errorCode = parseKeyAction(isDryRun ? &dummyKeyAction : &CurrentKeymap[targetLayer][moduleId][actionIdx], buffer); + errorCode = parseKeyAction(ParserRunDry ? &dummyKeyAction : &CurrentKeymap[targetLayer][moduleId][actionIdx], buffer); if (errorCode != ParserError_Success) { return errorCode; } @@ -193,8 +191,7 @@ parser_error_t ParseKeymap(config_buffer_t *buffer) {; if (layerCount != LAYER_COUNT) { return ParserError_InvalidLayerCount; } - isDryRun = buffer == &NewUserConfigBuffer || !isDefault; - if (!isDryRun) { + if (!ParserRunDry) { LedDisplay_SetText(abbreviationLen, abbreviation); } for (uint16_t layerIdx = 0; layerIdx < layerCount; layerIdx++) { diff --git a/right/src/usb_protocol_handler.c b/right/src/usb_protocol_handler.c index 1d12f29..b2b5917 100644 --- a/right/src/usb_protocol_handler.c +++ b/right/src/usb_protocol_handler.c @@ -83,21 +83,25 @@ void readMergeSensor(void) SetResponseByte(MERGE_SENSOR_IS_MERGED); } +// TODO: Expose this as a separate USB command and make Agent call it and check its output before calling applyConfig. +void TestConfig(void) +{ + ParserRunDry = true; + StagingUserConfigBuffer.offset = 0; + GenericHidOutBuffer[0] = ParseConfig(&StagingUserConfigBuffer); + GenericHidOutBuffer[1] = StagingUserConfigBuffer.offset; + GenericHidOutBuffer[2] = StagingUserConfigBuffer.offset >> 8; +} + void applyConfig(void) { - uint8_t *temp; - - NewUserConfigBuffer.offset = 0; - GenericHidOutBuffer[0] = ParseConfig(&NewUserConfigBuffer); - GenericHidOutBuffer[1] = NewUserConfigBuffer.offset; - GenericHidOutBuffer[2] = NewUserConfigBuffer.offset >> 8; - if (GenericHidOutBuffer[0] == ParserError_Success) { - temp = UserConfigBuffer.buffer; - UserConfigBuffer.buffer = NewUserConfigBuffer.buffer; - NewUserConfigBuffer.buffer = temp; - UserConfigBuffer.offset = 0; - ParseConfig(&UserConfigBuffer); - } + TestConfig(); // This line will be removed. TestConfig will be called by Agent separately. + memcpy(&UserConfigBuffer, &StagingUserConfigBuffer, USER_CONFIG_SIZE); + ParserRunDry = false; + UserConfigBuffer.offset = 0; + GenericHidOutBuffer[0] = ParseConfig(&UserConfigBuffer); + GenericHidOutBuffer[1] = UserConfigBuffer.offset; + GenericHidOutBuffer[2] = UserConfigBuffer.offset >> 8; } void setLedPwm(void) @@ -153,7 +157,7 @@ void writeConfiguration(bool isHardware) return; } - uint8_t *buffer = isHardware ? HardwareConfigBuffer.buffer : NewUserConfigBuffer.buffer; + uint8_t *buffer = isHardware ? HardwareConfigBuffer.buffer : StagingUserConfigBuffer.buffer; uint16_t bufferLength = isHardware ? HARDWARE_CONFIG_SIZE : USER_CONFIG_SIZE; if (offset + length > bufferLength) {