diff --git a/right/src/config_parser/parse_config.c b/right/src/config_parser/parse_config.c index 7b871a5..a2b6304 100644 --- a/right/src/config_parser/parse_config.c +++ b/right/src/config_parser/parse_config.c @@ -52,13 +52,14 @@ parser_error_t ParseConfig(config_buffer_t *buffer) return ParserError_InvalidKeymapCount; } for (uint8_t keymapIdx = 0; keymapIdx < keymapCount; keymapIdx++) { - errorCode = ParseKeymap(buffer, keymapIdx, keymapCount); + errorCode = ParseKeymap(buffer, keymapIdx, keymapCount, macroCount); if (errorCode != ParserError_Success) { return errorCode; } } if (!ParserRunDry) { AllKeymapsCount = keymapCount; + AllMacrosCount = macroCount; } return ParserError_Success; } diff --git a/right/src/config_parser/parse_config.h b/right/src/config_parser/parse_config.h index 850e42f..213ce83 100644 --- a/right/src/config_parser/parse_config.h +++ b/right/src/config_parser/parse_config.h @@ -21,6 +21,7 @@ ParserError_InvalidKeymapCount, ParserError_InvalidAbbreviationLen, ParserError_InvalidMacroCount, + ParserError_InvalidSerializedPlayMacroAction, } parser_error_t; // Functions: diff --git a/right/src/config_parser/parse_keymap.c b/right/src/config_parser/parse_keymap.c index fb274ca..d83564a 100644 --- a/right/src/config_parser/parse_keymap.c +++ b/right/src/config_parser/parse_keymap.c @@ -5,7 +5,8 @@ #include "keymaps.h" #include "led_display.h" -uint8_t tempKeymapCount; +static uint8_t tempKeymapCount; +static uint8_t tempMacroCount; static parser_error_t parseNoneAction(key_action_t *keyAction, config_buffer_t *buffer) { @@ -71,6 +72,9 @@ static parser_error_t parsePlayMacroAction(key_action_t *keyAction, config_buffe { uint8_t macroIndex = readUInt8(buffer); + if (macroIndex >= tempMacroCount) { + return ParserError_InvalidSerializedPlayMacroAction; + } keyAction->type = KeyActionType_SwitchKeymap; keyAction->playMacro.macroId = macroIndex; return ParserError_Success; @@ -192,7 +196,7 @@ static parser_error_t parseLayer(config_buffer_t *buffer, uint8_t layer) return ParserError_Success; } -parser_error_t ParseKeymap(config_buffer_t *buffer, uint8_t keymapIdx, uint8_t keymapCount) +parser_error_t ParseKeymap(config_buffer_t *buffer, uint8_t keymapIdx, uint8_t keymapCount, uint8_t macroCount) { uint16_t offset = buffer->offset; parser_error_t errorCode; @@ -222,6 +226,7 @@ parser_error_t ParseKeymap(config_buffer_t *buffer, uint8_t keymapIdx, uint8_t k } } tempKeymapCount = keymapCount; + tempMacroCount = macroCount; for (uint8_t layerIdx = 0; layerIdx < layerCount; layerIdx++) { errorCode = parseLayer(buffer, layerIdx); if (errorCode != ParserError_Success) { diff --git a/right/src/config_parser/parse_keymap.h b/right/src/config_parser/parse_keymap.h index f0ad4ab..0a738c6 100644 --- a/right/src/config_parser/parse_keymap.h +++ b/right/src/config_parser/parse_keymap.h @@ -52,6 +52,6 @@ // Functions: - parser_error_t ParseKeymap(config_buffer_t *buffer, uint8_t keymapIdx, uint8_t keymapCount); + parser_error_t ParseKeymap(config_buffer_t *buffer, uint8_t keymapIdx, uint8_t keymapCount, uint8_t macroCount); #endif diff --git a/right/src/keymaps.c b/right/src/keymaps.c index 0aded45..95daa89 100644 --- a/right/src/keymaps.c +++ b/right/src/keymaps.c @@ -4,6 +4,7 @@ #include "led_display.h" #include "config_parser/parse_keymap.h" #include "config_parser/config_globals.h" +#include "macros.h" // TODO: Restore Ctrl and Super keys and Mod+N. @@ -16,7 +17,7 @@ void Keymaps_Switch(uint8_t index) { CurrentKeymapIndex = index; UserConfigBuffer.offset = AllKeymaps[index].offset; - ParseKeymap(&UserConfigBuffer, index, AllKeymapsCount); + ParseKeymap(&UserConfigBuffer, index, AllKeymapsCount, AllMacrosCount); LedDisplay_SetText(AllKeymaps[index].abbreviationLen, AllKeymaps[index].abbreviation); } diff --git a/right/src/macros.c b/right/src/macros.c index cd17f7f..64b934c 100644 --- a/right/src/macros.c +++ b/right/src/macros.c @@ -1,3 +1,4 @@ #include "macros.h" macro_reference_t AllMacros[MAX_MACRO_NUM]; +uint8_t AllMacrosCount; diff --git a/right/src/macros.h b/right/src/macros.h index fd1c08f..a303287 100644 --- a/right/src/macros.h +++ b/right/src/macros.h @@ -19,5 +19,6 @@ // Variables: extern macro_reference_t AllMacros[MAX_MACRO_NUM]; + extern uint8_t AllMacrosCount; #endif