Uppercamelcase read*() config parser functions since they're not local.
This commit is contained in:
@@ -1,40 +1,40 @@
|
|||||||
#include "basic_types.h"
|
#include "basic_types.h"
|
||||||
|
|
||||||
uint8_t readUInt8(config_buffer_t *buffer)
|
uint8_t ReadUInt8(config_buffer_t *buffer)
|
||||||
{
|
{
|
||||||
return buffer->buffer[buffer->offset++];
|
return buffer->buffer[buffer->offset++];
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t readUInt16(config_buffer_t *buffer)
|
uint16_t ReadUInt16(config_buffer_t *buffer)
|
||||||
{
|
{
|
||||||
uint16_t uInt16 = readUInt8(buffer);
|
uint16_t uInt16 = ReadUInt8(buffer);
|
||||||
|
|
||||||
uInt16 |= readUInt8(buffer) << 8;
|
uInt16 |= ReadUInt8(buffer) << 8;
|
||||||
return uInt16;
|
return uInt16;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t readInt16(config_buffer_t *buffer)
|
int16_t ReadInt16(config_buffer_t *buffer)
|
||||||
{
|
{
|
||||||
return readUInt16(buffer);
|
return ReadUInt16(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool readBool(config_buffer_t *buffer)
|
bool ReadBool(config_buffer_t *buffer)
|
||||||
{
|
{
|
||||||
return readUInt8(buffer);
|
return ReadUInt8(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t readCompactLength(config_buffer_t *buffer)
|
uint16_t ReadCompactLength(config_buffer_t *buffer)
|
||||||
{
|
{
|
||||||
uint16_t compactLength = readUInt8(buffer);
|
uint16_t compactLength = ReadUInt8(buffer);
|
||||||
|
|
||||||
return compactLength == 0xFF ? readUInt16(buffer) : compactLength;
|
return compactLength == 0xFF ? ReadUInt16(buffer) : compactLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *readString(config_buffer_t *buffer, uint16_t *len)
|
const char *ReadString(config_buffer_t *buffer, uint16_t *len)
|
||||||
{
|
{
|
||||||
const char *string;
|
const char *string;
|
||||||
|
|
||||||
*len = readCompactLength(buffer);
|
*len = ReadCompactLength(buffer);
|
||||||
string = (const char *)(buffer->buffer + buffer->offset);
|
string = (const char *)(buffer->buffer + buffer->offset);
|
||||||
buffer->offset += *len;
|
buffer->offset += *len;
|
||||||
return string;
|
return string;
|
||||||
|
|||||||
@@ -14,11 +14,11 @@
|
|||||||
|
|
||||||
// Functions:
|
// Functions:
|
||||||
|
|
||||||
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);
|
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);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -7,10 +7,10 @@
|
|||||||
|
|
||||||
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);
|
||||||
uint8_t initialPointerSpeed = readUInt8(buffer);
|
uint8_t initialPointerSpeed = ReadUInt8(buffer);
|
||||||
uint8_t pointerAcceleration = readUInt8(buffer);
|
uint8_t pointerAcceleration = ReadUInt8(buffer);
|
||||||
uint8_t maxPointerSpeed = readUInt8(buffer);
|
uint8_t maxPointerSpeed = ReadUInt8(buffer);
|
||||||
|
|
||||||
(void)id;
|
(void)id;
|
||||||
(void)initialPointerSpeed;
|
(void)initialPointerSpeed;
|
||||||
@@ -26,11 +26,11 @@ parser_error_t ParseConfig(config_buffer_t *buffer)
|
|||||||
uint16_t keymapCount;
|
uint16_t keymapCount;
|
||||||
parser_error_t errorCode;
|
parser_error_t errorCode;
|
||||||
|
|
||||||
uint16_t dataModelVersion = readUInt16(buffer);
|
uint16_t dataModelVersion = ReadUInt16(buffer);
|
||||||
uint16_t userConfigLength = readUInt16(buffer);
|
uint16_t userConfigLength = ReadUInt16(buffer);
|
||||||
(void)userConfigLength;
|
(void)userConfigLength;
|
||||||
readString(buffer, &len); // Ignore device name
|
ReadString(buffer, &len); // Ignore device name
|
||||||
uint16_t moduleConfigurationCount = readCompactLength(buffer);
|
uint16_t moduleConfigurationCount = ReadCompactLength(buffer);
|
||||||
|
|
||||||
(void)dataModelVersion;
|
(void)dataModelVersion;
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ parser_error_t ParseConfig(config_buffer_t *buffer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macroCount = readCompactLength(buffer);
|
macroCount = ReadCompactLength(buffer);
|
||||||
if (macroCount > MAX_MACRO_NUM) {
|
if (macroCount > MAX_MACRO_NUM) {
|
||||||
return ParserError_InvalidMacroCount;
|
return ParserError_InvalidMacroCount;
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,7 @@ parser_error_t ParseConfig(config_buffer_t *buffer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
keymapCount = readCompactLength(buffer);
|
keymapCount = ReadCompactLength(buffer);
|
||||||
if (keymapCount == 0 || keymapCount > MAX_KEYMAP_NUM) {
|
if (keymapCount == 0 || keymapCount > MAX_KEYMAP_NUM) {
|
||||||
return ParserError_InvalidKeymapCount;
|
return ParserError_InvalidKeymapCount;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,21 +34,21 @@ static parser_error_t parseKeyStrokeAction(key_action_t *keyAction, uint8_t keyS
|
|||||||
return ParserError_InvalidSerializedKeystrokeType;
|
return ParserError_InvalidSerializedKeystrokeType;
|
||||||
}
|
}
|
||||||
keyAction->keystroke.scancode = keyStrokeAction & SERIALIZED_KEYSTROKE_TYPE_MASK_HAS_SCANCODE
|
keyAction->keystroke.scancode = keyStrokeAction & SERIALIZED_KEYSTROKE_TYPE_MASK_HAS_SCANCODE
|
||||||
? keystrokeType == SerializedKeystrokeType_LongMedia ? readUInt16(buffer) : readUInt8(buffer)
|
? keystrokeType == SerializedKeystrokeType_LongMedia ? ReadUInt16(buffer) : ReadUInt8(buffer)
|
||||||
: 0;
|
: 0;
|
||||||
keyAction->keystroke.modifiers = keyStrokeAction & SERIALIZED_KEYSTROKE_TYPE_MASK_HAS_MODIFIERS
|
keyAction->keystroke.modifiers = keyStrokeAction & SERIALIZED_KEYSTROKE_TYPE_MASK_HAS_MODIFIERS
|
||||||
? readUInt8(buffer)
|
? ReadUInt8(buffer)
|
||||||
: 0;
|
: 0;
|
||||||
keyAction->keystroke.secondaryRole = keyStrokeAction & SERIALIZED_KEYSTROKE_TYPE_MASK_HAS_LONGPRESS
|
keyAction->keystroke.secondaryRole = keyStrokeAction & SERIALIZED_KEYSTROKE_TYPE_MASK_HAS_LONGPRESS
|
||||||
? readUInt8(buffer) + 1
|
? ReadUInt8(buffer) + 1
|
||||||
: 0;
|
: 0;
|
||||||
return ParserError_Success;
|
return ParserError_Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
static parser_error_t parseSwitchLayerAction(key_action_t *KeyAction, config_buffer_t *buffer)
|
static parser_error_t parseSwitchLayerAction(key_action_t *KeyAction, config_buffer_t *buffer)
|
||||||
{
|
{
|
||||||
uint8_t layer = readUInt8(buffer) + 1;
|
uint8_t layer = ReadUInt8(buffer) + 1;
|
||||||
bool isToggle = readBool(buffer);
|
bool isToggle = ReadBool(buffer);
|
||||||
|
|
||||||
KeyAction->type = KeyActionType_SwitchLayer;
|
KeyAction->type = KeyActionType_SwitchLayer;
|
||||||
KeyAction->switchLayer.layer = layer;
|
KeyAction->switchLayer.layer = layer;
|
||||||
@@ -58,7 +58,7 @@ static parser_error_t parseSwitchLayerAction(key_action_t *KeyAction, config_buf
|
|||||||
|
|
||||||
static parser_error_t parseSwitchKeymapAction(key_action_t *keyAction, config_buffer_t *buffer)
|
static parser_error_t parseSwitchKeymapAction(key_action_t *keyAction, config_buffer_t *buffer)
|
||||||
{
|
{
|
||||||
uint8_t keymapIndex = readUInt8(buffer);
|
uint8_t keymapIndex = ReadUInt8(buffer);
|
||||||
|
|
||||||
if (keymapIndex >= tempKeymapCount) {
|
if (keymapIndex >= tempKeymapCount) {
|
||||||
return ParserError_InvalidSerializedSwitchKeymapAction;
|
return ParserError_InvalidSerializedSwitchKeymapAction;
|
||||||
@@ -70,7 +70,7 @@ static parser_error_t parseSwitchKeymapAction(key_action_t *keyAction, config_bu
|
|||||||
|
|
||||||
static parser_error_t parsePlayMacroAction(key_action_t *keyAction, config_buffer_t *buffer)
|
static parser_error_t parsePlayMacroAction(key_action_t *keyAction, config_buffer_t *buffer)
|
||||||
{
|
{
|
||||||
uint8_t macroIndex = readUInt8(buffer);
|
uint8_t macroIndex = ReadUInt8(buffer);
|
||||||
|
|
||||||
if (macroIndex >= tempMacroCount) {
|
if (macroIndex >= tempMacroCount) {
|
||||||
return ParserError_InvalidSerializedPlayMacroAction;
|
return ParserError_InvalidSerializedPlayMacroAction;
|
||||||
@@ -82,7 +82,7 @@ static parser_error_t parsePlayMacroAction(key_action_t *keyAction, config_buffe
|
|||||||
|
|
||||||
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);
|
||||||
|
|
||||||
keyAction->type = KeyActionType_Mouse;
|
keyAction->type = KeyActionType_Mouse;
|
||||||
memset(&keyAction->mouse, 0, sizeof keyAction->mouse);
|
memset(&keyAction->mouse, 0, sizeof keyAction->mouse);
|
||||||
@@ -134,7 +134,7 @@ static parser_error_t parseMouseAction(key_action_t *keyAction, config_buffer_t
|
|||||||
|
|
||||||
static parser_error_t parseKeyAction(key_action_t *keyAction, config_buffer_t *buffer)
|
static parser_error_t parseKeyAction(key_action_t *keyAction, config_buffer_t *buffer)
|
||||||
{
|
{
|
||||||
uint8_t keyActionType = readUInt8(buffer);
|
uint8_t keyActionType = ReadUInt8(buffer);
|
||||||
|
|
||||||
switch (keyActionType) {
|
switch (keyActionType) {
|
||||||
case SerializedKeyActionType_None:
|
case SerializedKeyActionType_None:
|
||||||
@@ -156,7 +156,7 @@ static parser_error_t parseKeyAction(key_action_t *keyAction, config_buffer_t *b
|
|||||||
static parser_error_t parseKeyActions(uint8_t targetLayer, config_buffer_t *buffer, uint8_t moduleId, uint8_t pointerRole)
|
static parser_error_t parseKeyActions(uint8_t targetLayer, config_buffer_t *buffer, uint8_t moduleId, uint8_t pointerRole)
|
||||||
{
|
{
|
||||||
parser_error_t errorCode;
|
parser_error_t errorCode;
|
||||||
uint16_t actionCount = readCompactLength(buffer);
|
uint16_t actionCount = ReadCompactLength(buffer);
|
||||||
key_action_t dummyKeyAction;
|
key_action_t dummyKeyAction;
|
||||||
|
|
||||||
if (actionCount > MAX_KEY_COUNT_PER_MODULE) {
|
if (actionCount > MAX_KEY_COUNT_PER_MODULE) {
|
||||||
@@ -173,8 +173,8 @@ static parser_error_t parseKeyActions(uint8_t targetLayer, config_buffer_t *buff
|
|||||||
|
|
||||||
static parser_error_t parseModule(config_buffer_t *buffer, uint8_t layer)
|
static parser_error_t parseModule(config_buffer_t *buffer, uint8_t layer)
|
||||||
{
|
{
|
||||||
uint8_t moduleId = readUInt8(buffer);
|
uint8_t moduleId = ReadUInt8(buffer);
|
||||||
uint8_t pointerRole = readUInt8(buffer);
|
uint8_t pointerRole = ReadUInt8(buffer);
|
||||||
|
|
||||||
return parseKeyActions(layer, buffer, moduleId, pointerRole);
|
return parseKeyActions(layer, buffer, moduleId, pointerRole);
|
||||||
}
|
}
|
||||||
@@ -182,7 +182,7 @@ static parser_error_t parseModule(config_buffer_t *buffer, uint8_t layer)
|
|||||||
static parser_error_t parseLayer(config_buffer_t *buffer, uint8_t layer)
|
static parser_error_t parseLayer(config_buffer_t *buffer, uint8_t layer)
|
||||||
{
|
{
|
||||||
parser_error_t errorCode;
|
parser_error_t errorCode;
|
||||||
uint16_t moduleCount = readCompactLength(buffer);
|
uint16_t moduleCount = ReadCompactLength(buffer);
|
||||||
|
|
||||||
if (moduleCount > SLOT_COUNT) {
|
if (moduleCount > SLOT_COUNT) {
|
||||||
return ParserError_InvalidModuleCount;
|
return ParserError_InvalidModuleCount;
|
||||||
@@ -203,11 +203,11 @@ parser_error_t ParseKeymap(config_buffer_t *buffer, uint8_t keymapIdx, uint8_t k
|
|||||||
uint16_t abbreviationLen;
|
uint16_t abbreviationLen;
|
||||||
uint16_t nameLen;
|
uint16_t nameLen;
|
||||||
uint16_t descriptionLen;
|
uint16_t descriptionLen;
|
||||||
const char *abbreviation = readString(buffer, &abbreviationLen);
|
const char *abbreviation = ReadString(buffer, &abbreviationLen);
|
||||||
bool isDefault = readBool(buffer);
|
bool isDefault = ReadBool(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);
|
||||||
|
|
||||||
(void)name;
|
(void)name;
|
||||||
(void)description;
|
(void)description;
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ parser_error_t parseKeyMacroAction(config_buffer_t *buffer, macro_action_t *macr
|
|||||||
keyMacroType >>= 2;
|
keyMacroType >>= 2;
|
||||||
type = keyMacroType & 0b11;
|
type = keyMacroType & 0b11;
|
||||||
keyMacroType >>= 2;
|
keyMacroType >>= 2;
|
||||||
scancode = keyMacroType & 0b10 ? readUInt8(buffer) : 0;
|
scancode = keyMacroType & 0b10 ? ReadUInt8(buffer) : 0;
|
||||||
modifierMask = keyMacroType & 0b01 ? readUInt8(buffer) : 0;
|
modifierMask = keyMacroType & 0b01 ? ReadUInt8(buffer) : 0;
|
||||||
macroAction->type = MacroActionType_Key;
|
macroAction->type = MacroActionType_Key;
|
||||||
macroAction->key.action = action;
|
macroAction->key.action = action;
|
||||||
macroAction->key.type = type;
|
macroAction->key.type = type;
|
||||||
@@ -26,7 +26,7 @@ parser_error_t parseKeyMacroAction(config_buffer_t *buffer, macro_action_t *macr
|
|||||||
parser_error_t parseMouseButtonMacroAction(config_buffer_t *buffer, macro_action_t *macroAction, serialized_macro_action_type_t macroActionType)
|
parser_error_t parseMouseButtonMacroAction(config_buffer_t *buffer, macro_action_t *macroAction, serialized_macro_action_type_t macroActionType)
|
||||||
{
|
{
|
||||||
uint8_t action = macroActionType - SerializedMacroActionType_MouseButtonMacroAction;
|
uint8_t action = macroActionType - SerializedMacroActionType_MouseButtonMacroAction;
|
||||||
uint8_t mouseButtonsMask = readUInt8(buffer);
|
uint8_t mouseButtonsMask = ReadUInt8(buffer);
|
||||||
|
|
||||||
macroAction->type = MacroActionType_MouseButton;
|
macroAction->type = MacroActionType_MouseButton;
|
||||||
macroAction->mouseButton.action = action;
|
macroAction->mouseButton.action = action;
|
||||||
@@ -36,8 +36,8 @@ parser_error_t parseMouseButtonMacroAction(config_buffer_t *buffer, macro_action
|
|||||||
|
|
||||||
parser_error_t parseMoveMouseMacroAction(config_buffer_t *buffer, macro_action_t *macroAction)
|
parser_error_t parseMoveMouseMacroAction(config_buffer_t *buffer, macro_action_t *macroAction)
|
||||||
{
|
{
|
||||||
int16_t x = readInt16(buffer);
|
int16_t x = ReadInt16(buffer);
|
||||||
int16_t y = readInt16(buffer);
|
int16_t y = ReadInt16(buffer);
|
||||||
|
|
||||||
macroAction->type = MacroActionType_MoveMouse;
|
macroAction->type = MacroActionType_MoveMouse;
|
||||||
macroAction->moveMouse.x = x;
|
macroAction->moveMouse.x = x;
|
||||||
@@ -47,8 +47,8 @@ parser_error_t parseMoveMouseMacroAction(config_buffer_t *buffer, macro_action_t
|
|||||||
|
|
||||||
parser_error_t parseScrollMouseMacroAction(config_buffer_t *buffer, macro_action_t *macroAction)
|
parser_error_t parseScrollMouseMacroAction(config_buffer_t *buffer, macro_action_t *macroAction)
|
||||||
{
|
{
|
||||||
int16_t x = readInt16(buffer);
|
int16_t x = ReadInt16(buffer);
|
||||||
int16_t y = readInt16(buffer);
|
int16_t y = ReadInt16(buffer);
|
||||||
|
|
||||||
macroAction->type = MacroActionType_ScrollMouse;
|
macroAction->type = MacroActionType_ScrollMouse;
|
||||||
macroAction->scrollMouse.x = x;
|
macroAction->scrollMouse.x = x;
|
||||||
@@ -58,7 +58,7 @@ parser_error_t parseScrollMouseMacroAction(config_buffer_t *buffer, macro_action
|
|||||||
|
|
||||||
parser_error_t parseDelayMacroAction(config_buffer_t *buffer, macro_action_t *macroAction)
|
parser_error_t parseDelayMacroAction(config_buffer_t *buffer, macro_action_t *macroAction)
|
||||||
{
|
{
|
||||||
int16_t delay = readInt16(buffer);
|
int16_t delay = ReadInt16(buffer);
|
||||||
|
|
||||||
macroAction->type = MacroActionType_Delay;
|
macroAction->type = MacroActionType_Delay;
|
||||||
macroAction->delay.delay = delay;
|
macroAction->delay.delay = delay;
|
||||||
@@ -68,7 +68,7 @@ parser_error_t parseDelayMacroAction(config_buffer_t *buffer, macro_action_t *ma
|
|||||||
parser_error_t parseTextMacroAction(config_buffer_t *buffer, macro_action_t *macroAction)
|
parser_error_t parseTextMacroAction(config_buffer_t *buffer, macro_action_t *macroAction)
|
||||||
{
|
{
|
||||||
uint16_t textLen;
|
uint16_t textLen;
|
||||||
const char *text = readString(buffer, &textLen);
|
const char *text = ReadString(buffer, &textLen);
|
||||||
|
|
||||||
macroAction->type = MacroActionType_Text;
|
macroAction->type = MacroActionType_Text;
|
||||||
macroAction->text.text = text;
|
macroAction->text.text = text;
|
||||||
@@ -78,7 +78,7 @@ parser_error_t parseTextMacroAction(config_buffer_t *buffer, macro_action_t *mac
|
|||||||
|
|
||||||
parser_error_t ParseMacroAction(config_buffer_t *buffer, macro_action_t *macroAction)
|
parser_error_t ParseMacroAction(config_buffer_t *buffer, macro_action_t *macroAction)
|
||||||
{
|
{
|
||||||
uint8_t macroActionType = readUInt8(buffer);
|
uint8_t macroActionType = ReadUInt8(buffer);
|
||||||
|
|
||||||
switch (macroActionType) {
|
switch (macroActionType) {
|
||||||
case SerializedMacroActionType_KeyMacroAction ... SerializedMacroActionType_LastKeyMacroAction:
|
case SerializedMacroActionType_KeyMacroAction ... SerializedMacroActionType_LastKeyMacroAction:
|
||||||
@@ -101,10 +101,10 @@ parser_error_t ParseMacro(config_buffer_t *buffer, uint8_t macroIdx)
|
|||||||
{
|
{
|
||||||
parser_error_t errorCode;
|
parser_error_t errorCode;
|
||||||
uint16_t nameLen;
|
uint16_t nameLen;
|
||||||
bool isLooped = readBool(buffer);
|
bool isLooped = ReadBool(buffer);
|
||||||
bool isPrivate = readBool(buffer);
|
bool isPrivate = ReadBool(buffer);
|
||||||
const char *name = readString(buffer, &nameLen);
|
const char *name = ReadString(buffer, &nameLen);
|
||||||
uint16_t macroActionsCount = readCompactLength(buffer);
|
uint16_t macroActionsCount = ReadCompactLength(buffer);
|
||||||
uint16_t firstMacroActionOffset = buffer->offset;
|
uint16_t firstMacroActionOffset = buffer->offset;
|
||||||
macro_action_t dummyMacroAction;
|
macro_action_t dummyMacroAction;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user