Merge pull request #55 from UltimateHackingKeyboard/configuration-parser
Verify a new configuration before applying it
This commit is contained in:
@@ -214,7 +214,14 @@ SECTIONS
|
|||||||
__bss_end__ = .;
|
__bss_end__ = .;
|
||||||
__END_BSS = .;
|
__END_BSS = .;
|
||||||
} > m_data
|
} > m_data
|
||||||
|
|
||||||
|
.m_data_2 :
|
||||||
|
{
|
||||||
|
. = ALIGN(4);
|
||||||
|
*(.m_data_2) /* This is an User defined section */
|
||||||
|
. = ALIGN(4);
|
||||||
|
} > m_data_2
|
||||||
|
|
||||||
.heap :
|
.heap :
|
||||||
{
|
{
|
||||||
. = ALIGN(8);
|
. = ALIGN(8);
|
||||||
|
|||||||
@@ -3,8 +3,12 @@
|
|||||||
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 userConfig[USER_CONFIG_SIZE];
|
static uint8_t userConfig1[USER_CONFIG_SIZE];
|
||||||
config_buffer_t UserConfigBuffer = {userConfig};
|
static uint8_t __attribute__((section (".m_data_2"))) userConfig2[USER_CONFIG_SIZE];
|
||||||
|
config_buffer_t UserConfigBuffer = { userConfig1 };
|
||||||
|
config_buffer_t StagingUserConfigBuffer = { userConfig2 };
|
||||||
|
|
||||||
|
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,8 +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 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;
|
||||||
}
|
}
|
||||||
@@ -187,22 +185,28 @@ parser_error_t ParseKeymap(config_buffer_t *buffer) {;
|
|||||||
const char *name = readString(buffer, &nameLen);
|
const char *name = readString(buffer, &nameLen);
|
||||||
const char *description = readString(buffer, &descriptionLen);
|
const char *description = readString(buffer, &descriptionLen);
|
||||||
uint16_t layerCount = readCompactLength(buffer);
|
uint16_t layerCount = readCompactLength(buffer);
|
||||||
|
bool temp;
|
||||||
|
|
||||||
(void)name;
|
(void)name;
|
||||||
(void)description;
|
(void)description;
|
||||||
if (layerCount != LAYER_COUNT) {
|
if (layerCount != LAYER_COUNT) {
|
||||||
return ParserError_InvalidLayerCount;
|
return ParserError_InvalidLayerCount;
|
||||||
}
|
}
|
||||||
isDryRun = !isDefault;
|
temp = ParserRunDry;
|
||||||
if (!isDryRun) {
|
if (!isDefault) {
|
||||||
|
ParserRunDry = true;
|
||||||
|
}
|
||||||
|
if (!ParserRunDry) {
|
||||||
LedDisplay_SetText(abbreviationLen, abbreviation);
|
LedDisplay_SetText(abbreviationLen, abbreviation);
|
||||||
}
|
}
|
||||||
for (uint16_t layerIdx = 0; layerIdx < layerCount; layerIdx++) {
|
for (uint16_t layerIdx = 0; layerIdx < layerCount; layerIdx++) {
|
||||||
errorCode = parseLayer(buffer, layerIdx);
|
errorCode = parseLayer(buffer, layerIdx);
|
||||||
if (errorCode != ParserError_Success) {
|
if (errorCode != ParserError_Success) {
|
||||||
|
ParserRunDry = temp;
|
||||||
return errorCode;
|
return errorCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ParserRunDry = temp;
|
||||||
return ParserError_Success;
|
return ParserError_Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,10 +85,26 @@ void readMergeSensor(void)
|
|||||||
|
|
||||||
void applyConfig(void)
|
void applyConfig(void)
|
||||||
{
|
{
|
||||||
|
uint8_t *temp;
|
||||||
|
|
||||||
|
ParserRunDry = true;
|
||||||
|
StagingUserConfigBuffer.offset = 0;
|
||||||
|
GenericHidOutBuffer[0] = ParseConfig(&StagingUserConfigBuffer);
|
||||||
|
GenericHidOutBuffer[1] = StagingUserConfigBuffer.offset;
|
||||||
|
GenericHidOutBuffer[2] = StagingUserConfigBuffer.offset >> 8;
|
||||||
|
GenericHidOutBuffer[3] = 0;
|
||||||
|
if (GenericHidOutBuffer[0]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ParserRunDry = false;
|
||||||
|
temp = UserConfigBuffer.buffer;
|
||||||
|
UserConfigBuffer.buffer = StagingUserConfigBuffer.buffer;
|
||||||
|
StagingUserConfigBuffer.buffer = temp;
|
||||||
UserConfigBuffer.offset = 0;
|
UserConfigBuffer.offset = 0;
|
||||||
GenericHidOutBuffer[0] = ParseConfig(&UserConfigBuffer);
|
GenericHidOutBuffer[0] = ParseConfig(&UserConfigBuffer);
|
||||||
GenericHidOutBuffer[1] = UserConfigBuffer.offset;
|
GenericHidOutBuffer[1] = UserConfigBuffer.offset;
|
||||||
GenericHidOutBuffer[2] = UserConfigBuffer.offset >> 8;
|
GenericHidOutBuffer[2] = UserConfigBuffer.offset >> 8;
|
||||||
|
GenericHidOutBuffer[3] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLedPwm(void)
|
void setLedPwm(void)
|
||||||
@@ -144,7 +160,7 @@ void writeConfiguration(bool isHardware)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *buffer = isHardware ? HardwareConfigBuffer.buffer : UserConfigBuffer.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