Make the ParserRunDry global. Separate TestConfig() and ApplyConfig()
This commit is contained in:
@@ -3,11 +3,13 @@
|
|||||||
static uint8_t hardwareConfig[HARDWARE_CONFIG_SIZE];
|
static uint8_t hardwareConfig[HARDWARE_CONFIG_SIZE];
|
||||||
config_buffer_t HardwareConfigBuffer = {hardwareConfig};
|
config_buffer_t HardwareConfigBuffer = {hardwareConfig};
|
||||||
|
|
||||||
static uint8_t userConfig1[USER_CONFIG_SIZE];
|
static uint8_t userConfig[USER_CONFIG_SIZE];
|
||||||
static uint8_t __attribute__((section (".m_data_2"))) userConfig2[USER_CONFIG_SIZE];
|
static uint8_t __attribute__((section (".m_data_2"))) stagingUserConfig[USER_CONFIG_SIZE];
|
||||||
|
|
||||||
config_buffer_t UserConfigBuffer = { userConfig1 };
|
config_buffer_t UserConfigBuffer = { userConfig };
|
||||||
config_buffer_t NewUserConfigBuffer = { userConfig2 };
|
config_buffer_t StagingUserConfigBuffer = { stagingUserConfig };
|
||||||
|
|
||||||
|
bool ParserRunDry;
|
||||||
|
|
||||||
uint8_t readUInt8(config_buffer_t *buffer) {
|
uint8_t readUInt8(config_buffer_t *buffer) {
|
||||||
return buffer->buffer[buffer->offset++];
|
return buffer->buffer[buffer->offset++];
|
||||||
|
|||||||
@@ -21,9 +21,10 @@
|
|||||||
|
|
||||||
// Variables:
|
// Variables:
|
||||||
|
|
||||||
|
extern bool ParserRunDry;
|
||||||
extern config_buffer_t HardwareConfigBuffer;
|
extern config_buffer_t HardwareConfigBuffer;
|
||||||
extern config_buffer_t UserConfigBuffer;
|
extern config_buffer_t UserConfigBuffer;
|
||||||
extern config_buffer_t NewUserConfigBuffer;
|
extern config_buffer_t StagingUserConfigBuffer;
|
||||||
|
|
||||||
// Functions:
|
// Functions:
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
#include "current_keymap.h"
|
#include "current_keymap.h"
|
||||||
#include "led_display.h"
|
#include "led_display.h"
|
||||||
|
|
||||||
static bool isDryRun;
|
|
||||||
|
|
||||||
static parser_error_t parseNoneAction(key_action_t *keyAction, config_buffer_t *buffer) {
|
static parser_error_t parseNoneAction(key_action_t *keyAction, config_buffer_t *buffer) {
|
||||||
keyAction->type = KeyActionType_None;
|
keyAction->type = KeyActionType_None;
|
||||||
return ParserError_Success;
|
return ParserError_Success;
|
||||||
@@ -146,7 +144,7 @@ static parser_error_t parseKeyActions(uint8_t targetLayer, config_buffer_t *buff
|
|||||||
return ParserError_InvalidActionCount;
|
return ParserError_InvalidActionCount;
|
||||||
}
|
}
|
||||||
for (uint16_t actionIdx = 0; actionIdx < actionCount; actionIdx++) {
|
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) {
|
if (errorCode != ParserError_Success) {
|
||||||
return errorCode;
|
return errorCode;
|
||||||
}
|
}
|
||||||
@@ -193,8 +191,7 @@ parser_error_t ParseKeymap(config_buffer_t *buffer) {;
|
|||||||
if (layerCount != LAYER_COUNT) {
|
if (layerCount != LAYER_COUNT) {
|
||||||
return ParserError_InvalidLayerCount;
|
return ParserError_InvalidLayerCount;
|
||||||
}
|
}
|
||||||
isDryRun = buffer == &NewUserConfigBuffer || !isDefault;
|
if (!ParserRunDry) {
|
||||||
if (!isDryRun) {
|
|
||||||
LedDisplay_SetText(abbreviationLen, abbreviation);
|
LedDisplay_SetText(abbreviationLen, abbreviation);
|
||||||
}
|
}
|
||||||
for (uint16_t layerIdx = 0; layerIdx < layerCount; layerIdx++) {
|
for (uint16_t layerIdx = 0; layerIdx < layerCount; layerIdx++) {
|
||||||
|
|||||||
@@ -83,21 +83,25 @@ void readMergeSensor(void)
|
|||||||
SetResponseByte(MERGE_SENSOR_IS_MERGED);
|
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)
|
void applyConfig(void)
|
||||||
{
|
{
|
||||||
uint8_t *temp;
|
TestConfig(); // This line will be removed. TestConfig will be called by Agent separately.
|
||||||
|
memcpy(&UserConfigBuffer, &StagingUserConfigBuffer, USER_CONFIG_SIZE);
|
||||||
NewUserConfigBuffer.offset = 0;
|
ParserRunDry = false;
|
||||||
GenericHidOutBuffer[0] = ParseConfig(&NewUserConfigBuffer);
|
UserConfigBuffer.offset = 0;
|
||||||
GenericHidOutBuffer[1] = NewUserConfigBuffer.offset;
|
GenericHidOutBuffer[0] = ParseConfig(&UserConfigBuffer);
|
||||||
GenericHidOutBuffer[2] = NewUserConfigBuffer.offset >> 8;
|
GenericHidOutBuffer[1] = UserConfigBuffer.offset;
|
||||||
if (GenericHidOutBuffer[0] == ParserError_Success) {
|
GenericHidOutBuffer[2] = UserConfigBuffer.offset >> 8;
|
||||||
temp = UserConfigBuffer.buffer;
|
|
||||||
UserConfigBuffer.buffer = NewUserConfigBuffer.buffer;
|
|
||||||
NewUserConfigBuffer.buffer = temp;
|
|
||||||
UserConfigBuffer.offset = 0;
|
|
||||||
ParseConfig(&UserConfigBuffer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLedPwm(void)
|
void setLedPwm(void)
|
||||||
@@ -153,7 +157,7 @@ void writeConfiguration(bool isHardware)
|
|||||||
return;
|
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;
|
uint16_t bufferLength = isHardware ? HARDWARE_CONFIG_SIZE : USER_CONFIG_SIZE;
|
||||||
|
|
||||||
if (offset + length > bufferLength) {
|
if (offset + length > bufferLength) {
|
||||||
|
|||||||
Reference in New Issue
Block a user