Merge pull request #53 from UltimateHackingKeyboard/configuration-parser
Add the macro parser
This commit is contained in:
@@ -13,6 +13,10 @@ uint16_t readUInt16(config_buffer_t *buffer) {
|
|||||||
return uInt16;
|
return uInt16;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int16_t readInt16(config_buffer_t *buffer) {
|
||||||
|
return readUInt16(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
bool readBool(config_buffer_t *buffer) {
|
bool readBool(config_buffer_t *buffer) {
|
||||||
return readUInt8(buffer);
|
return readUInt8(buffer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
uint8_t readUInt8(config_buffer_t *buffer);
|
uint8_t readUInt8(config_buffer_t *buffer);
|
||||||
uint16_t readUInt16(config_buffer_t *buffer);
|
uint16_t readUInt16(config_buffer_t *buffer);
|
||||||
|
int16_t readInt16(config_buffer_t *buffer);
|
||||||
bool readBool(config_buffer_t *buffer);
|
bool readBool(config_buffer_t *buffer);
|
||||||
uint16_t readCompactLength(config_buffer_t *buffer);
|
uint16_t readCompactLength(config_buffer_t *buffer);
|
||||||
const char *readString(config_buffer_t *buffer, uint16_t *len);
|
const char *readString(config_buffer_t *buffer, uint16_t *len);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "parse_config.h"
|
#include "parse_config.h"
|
||||||
#include "parse_keymap.h"
|
#include "parse_keymap.h"
|
||||||
|
#include "parse_macro.h"
|
||||||
|
|
||||||
static parser_error_t parseModuleConfiguration(config_buffer_t *buffer) {
|
static parser_error_t parseModuleConfiguration(config_buffer_t *buffer) {
|
||||||
uint8_t id = readUInt8(buffer);
|
uint8_t id = readUInt8(buffer);
|
||||||
@@ -30,10 +31,10 @@ parser_error_t ParseConfig(config_buffer_t *buffer) {
|
|||||||
}
|
}
|
||||||
macroCount = readCompactLength(buffer);
|
macroCount = readCompactLength(buffer);
|
||||||
for (uint16_t macroIdx = 0; macroIdx < macroCount; macroIdx++) {
|
for (uint16_t macroIdx = 0; macroIdx < macroCount; macroIdx++) {
|
||||||
// errorCode = ParseMacro(buffer);
|
errorCode = ParseMacro(buffer);
|
||||||
// if (errorCode != ParserError_Success) {
|
if (errorCode != ParserError_Success) {
|
||||||
// return errorCode;
|
return errorCode;
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
keymapCount = readCompactLength(buffer);
|
keymapCount = readCompactLength(buffer);
|
||||||
for (uint16_t keymapIdx = 0; keymapIdx < keymapCount; keymapIdx++) {
|
for (uint16_t keymapIdx = 0; keymapIdx < keymapCount; keymapIdx++) {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
ParserError_InvalidLayerCount,
|
ParserError_InvalidLayerCount,
|
||||||
ParserError_InvalidModuleCount,
|
ParserError_InvalidModuleCount,
|
||||||
ParserError_InvalidActionCount,
|
ParserError_InvalidActionCount,
|
||||||
|
ParserError_InvalidSerializedMacroActionType,
|
||||||
} parser_error_t;
|
} parser_error_t;
|
||||||
|
|
||||||
// Functions:
|
// Functions:
|
||||||
|
|||||||
@@ -60,6 +60,13 @@ static parser_error_t parseSwitchKeymapAction(key_action_t *keyAction, config_bu
|
|||||||
return ParserError_Success;
|
return ParserError_Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static parser_error_t parsePlayMacroAction(key_action_t *keyAction, config_buffer_t *buffer) {
|
||||||
|
uint8_t macroIndex = readUInt8(buffer);
|
||||||
|
|
||||||
|
(void)macroIndex;
|
||||||
|
return ParserError_Success;
|
||||||
|
}
|
||||||
|
|
||||||
static parser_error_t parseMouseAction(key_action_t *keyAction, config_buffer_t *buffer) {
|
static parser_error_t parseMouseAction(key_action_t *keyAction, config_buffer_t *buffer) {
|
||||||
uint8_t mouseAction = readUInt8(buffer);
|
uint8_t mouseAction = readUInt8(buffer);
|
||||||
|
|
||||||
@@ -125,6 +132,8 @@ static parser_error_t parseKeyAction(key_action_t *keyAction, config_buffer_t *b
|
|||||||
return parseSwitchKeymapAction(keyAction, buffer);
|
return parseSwitchKeymapAction(keyAction, buffer);
|
||||||
case SerializedKeyActionType_Mouse:
|
case SerializedKeyActionType_Mouse:
|
||||||
return parseMouseAction(keyAction, buffer);
|
return parseMouseAction(keyAction, buffer);
|
||||||
|
case SerializedKeyActionType_PlayMacro:
|
||||||
|
return parsePlayMacroAction(keyAction, buffer);
|
||||||
default:
|
default:
|
||||||
return ParserError_InvalidSerializedKeyActionType;
|
return ParserError_InvalidSerializedKeyActionType;
|
||||||
}
|
}
|
||||||
|
|||||||
106
right/src/config/parse_macro.c
Normal file
106
right/src/config/parse_macro.c
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
#include "parse_macro.h"
|
||||||
|
|
||||||
|
parser_error_t parseKeyMacroAction(config_buffer_t *buffer, serialized_macro_action_type_t macroActionType) {
|
||||||
|
uint8_t keyMacroType = macroActionType - SerializedMacroActionType_KeyMacroAction;
|
||||||
|
uint8_t action = keyMacroType & 0b11;
|
||||||
|
uint8_t type;
|
||||||
|
uint8_t scancode;
|
||||||
|
uint8_t modifierMask;
|
||||||
|
|
||||||
|
keyMacroType >>= 2;
|
||||||
|
type = keyMacroType & 0b11;
|
||||||
|
keyMacroType >>= 2;
|
||||||
|
if (keyMacroType & 0b10) {
|
||||||
|
scancode = readUInt8(buffer);
|
||||||
|
}
|
||||||
|
if (keyMacroType & 0b01) {
|
||||||
|
modifierMask = readUInt8(buffer);
|
||||||
|
}
|
||||||
|
(void)action;
|
||||||
|
(void)type;
|
||||||
|
(void)scancode;
|
||||||
|
(void)modifierMask;
|
||||||
|
return ParserError_Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
parser_error_t parseMouseButtonMacroAction(config_buffer_t *buffer, serialized_macro_action_type_t macroActionType) {
|
||||||
|
uint8_t action = macroActionType - SerializedMacroActionType_MouseButtonMacroAction;
|
||||||
|
uint8_t mouseButtonsMask = readUInt8(buffer);
|
||||||
|
|
||||||
|
(void)action;
|
||||||
|
(void)mouseButtonsMask;
|
||||||
|
return ParserError_Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
parser_error_t parseMoveMouseMacroAction(config_buffer_t *buffer) {
|
||||||
|
int16_t x = readInt16(buffer);
|
||||||
|
int16_t y = readInt16(buffer);
|
||||||
|
|
||||||
|
(void)x;
|
||||||
|
(void)y;
|
||||||
|
return ParserError_Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
parser_error_t parseScrollMouseMacroAction(config_buffer_t *buffer) {
|
||||||
|
int16_t x = readInt16(buffer);
|
||||||
|
int16_t y = readInt16(buffer);
|
||||||
|
|
||||||
|
(void)x;
|
||||||
|
(void)y;
|
||||||
|
return ParserError_Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
parser_error_t parseDelayMacroAction(config_buffer_t *buffer) {
|
||||||
|
int16_t delay = readInt16(buffer);
|
||||||
|
|
||||||
|
(void)delay;
|
||||||
|
return ParserError_Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
parser_error_t parseTextMacroAction(config_buffer_t *buffer) {
|
||||||
|
uint16_t textLen;
|
||||||
|
const char *text = readString(buffer, &textLen);
|
||||||
|
|
||||||
|
(void)text;
|
||||||
|
return ParserError_Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
parser_error_t parseMacroAction(config_buffer_t *buffer) {
|
||||||
|
uint8_t macroActionType = readUInt8(buffer);
|
||||||
|
|
||||||
|
switch (macroActionType) {
|
||||||
|
case SerializedMacroActionType_KeyMacroAction ... SerializedMacroActionType_LastKeyMacroAction:
|
||||||
|
return parseKeyMacroAction(buffer, macroActionType);
|
||||||
|
case SerializedMacroActionType_MouseButtonMacroAction ... SerializedMacroActionType_LastMouseButtonMacroAction:
|
||||||
|
return parseMouseButtonMacroAction(buffer, macroActionType);
|
||||||
|
case SerializedMacroActionType_MoveMouseMacroAction:
|
||||||
|
return parseMoveMouseMacroAction(buffer);
|
||||||
|
case SerializedMacroActionType_ScrollMouseMacroAction:
|
||||||
|
return parseScrollMouseMacroAction(buffer);
|
||||||
|
case SerializedMacroActionType_DelayMacroAction:
|
||||||
|
return parseDelayMacroAction(buffer);
|
||||||
|
case SerializedMacroActionType_TextMacroAction:
|
||||||
|
return parseTextMacroAction(buffer);
|
||||||
|
}
|
||||||
|
return ParserError_InvalidSerializedMacroActionType;
|
||||||
|
}
|
||||||
|
|
||||||
|
parser_error_t ParseMacro(config_buffer_t *buffer) {
|
||||||
|
parser_error_t errorCode;
|
||||||
|
uint16_t nameLen;
|
||||||
|
bool isLooped = readBool(buffer);
|
||||||
|
bool isPrivate = readBool(buffer);
|
||||||
|
const char *name = readString(buffer, &nameLen);
|
||||||
|
uint16_t macroActionsCount = readCompactLength(buffer);
|
||||||
|
|
||||||
|
(void)isLooped;
|
||||||
|
(void)isPrivate;
|
||||||
|
(void)name;
|
||||||
|
for (uint16_t i = 0; i < macroActionsCount; i++) {
|
||||||
|
errorCode = parseMacroAction(buffer);
|
||||||
|
if (errorCode != ParserError_Success) {
|
||||||
|
return errorCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ParserError_Success;
|
||||||
|
}
|
||||||
25
right/src/config/parse_macro.h
Normal file
25
right/src/config/parse_macro.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef __PARSE_MACRO_H__
|
||||||
|
#define __PARSE_MACRO_H__
|
||||||
|
|
||||||
|
// Includes:
|
||||||
|
|
||||||
|
#include "parse_config.h"
|
||||||
|
|
||||||
|
// Typedefs:
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
SerializedMacroActionType_KeyMacroAction = 0,
|
||||||
|
SerializedMacroActionType_LastKeyMacroAction = 63,
|
||||||
|
SerializedMacroActionType_MouseButtonMacroAction,
|
||||||
|
SerializedMacroActionType_LastMouseButtonMacroAction = 66,
|
||||||
|
SerializedMacroActionType_MoveMouseMacroAction,
|
||||||
|
SerializedMacroActionType_ScrollMouseMacroAction,
|
||||||
|
SerializedMacroActionType_DelayMacroAction,
|
||||||
|
SerializedMacroActionType_TextMacroAction
|
||||||
|
} serialized_macro_action_type_t;
|
||||||
|
|
||||||
|
// Functions:
|
||||||
|
|
||||||
|
parser_error_t ParseMacro(config_buffer_t *buffer);
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user