Merge pull request #55 from UltimateHackingKeyboard/configuration-parser

Verify a new configuration before applying it
This commit is contained in:
László Monda
2017-08-08 20:49:08 +02:00
committed by GitHub
5 changed files with 42 additions and 9 deletions

View File

@@ -214,7 +214,14 @@ SECTIONS
__bss_end__ = .;
__END_BSS = .;
} > m_data
.m_data_2 :
{
. = ALIGN(4);
*(.m_data_2) /* This is an User defined section */
. = ALIGN(4);
} > m_data_2
.heap :
{
. = ALIGN(8);

View File

@@ -3,8 +3,12 @@
static uint8_t hardwareConfig[HARDWARE_CONFIG_SIZE];
config_buffer_t HardwareConfigBuffer = {hardwareConfig};
static uint8_t userConfig[USER_CONFIG_SIZE];
config_buffer_t UserConfigBuffer = {userConfig};
static uint8_t userConfig1[USER_CONFIG_SIZE];
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) {
return buffer->buffer[buffer->offset++];

View File

@@ -21,8 +21,10 @@
// Variables:
extern bool ParserRunDry;
extern config_buffer_t HardwareConfigBuffer;
extern config_buffer_t UserConfigBuffer;
extern config_buffer_t StagingUserConfigBuffer;
// Functions:

View File

@@ -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;
}
@@ -187,22 +185,28 @@ parser_error_t ParseKeymap(config_buffer_t *buffer) {;
const char *name = readString(buffer, &nameLen);
const char *description = readString(buffer, &descriptionLen);
uint16_t layerCount = readCompactLength(buffer);
bool temp;
(void)name;
(void)description;
if (layerCount != LAYER_COUNT) {
return ParserError_InvalidLayerCount;
}
isDryRun = !isDefault;
if (!isDryRun) {
temp = ParserRunDry;
if (!isDefault) {
ParserRunDry = true;
}
if (!ParserRunDry) {
LedDisplay_SetText(abbreviationLen, abbreviation);
}
for (uint16_t layerIdx = 0; layerIdx < layerCount; layerIdx++) {
errorCode = parseLayer(buffer, layerIdx);
if (errorCode != ParserError_Success) {
ParserRunDry = temp;
return errorCode;
}
}
ParserRunDry = temp;
return ParserError_Success;
}

View File

@@ -85,10 +85,26 @@ void readMergeSensor(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;
GenericHidOutBuffer[0] = ParseConfig(&UserConfigBuffer);
GenericHidOutBuffer[1] = UserConfigBuffer.offset;
GenericHidOutBuffer[2] = UserConfigBuffer.offset >> 8;
GenericHidOutBuffer[3] = 1;
}
void setLedPwm(void)
@@ -144,7 +160,7 @@ void writeConfiguration(bool isHardware)
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;
if (offset + length > bufferLength) {