Rename a lot of variables within parse_keymap.c
This commit is contained in:
@@ -36,153 +36,152 @@ static const char *readString(serialized_buffer_t *buffer, uint16_t *len) {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void parseNoneAction(key_action_t *action, serialized_buffer_t *buffer) {
|
static void parseNoneAction(key_action_t *keyAction, serialized_buffer_t *buffer) {
|
||||||
action->type = KeyActionType_None;
|
keyAction->type = KeyActionType_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseKeyStrokeAction(key_action_t *action, uint8_t actionType, serialized_buffer_t *buffer) {
|
static void parseKeyStrokeAction(key_action_t *keyAction, uint8_t actionType, serialized_buffer_t *buffer) {
|
||||||
uint8_t flags = actionType - 1;
|
uint8_t flags = actionType - 1;
|
||||||
|
|
||||||
action->type = KeyActionType_Keystroke;
|
keyAction->type = KeyActionType_Keystroke;
|
||||||
|
|
||||||
uint8_t keystrokeType = (SERIALIZED_KEYSTROKE_TYPE_MASK_KEYSTROKE_TYPE & flags) >> SERIALIZED_KEYSTROKE_TYPE_OFFSET_KEYSTROKE_TYPE;
|
uint8_t keystrokeType = (SERIALIZED_KEYSTROKE_TYPE_MASK_KEYSTROKE_TYPE & flags) >> SERIALIZED_KEYSTROKE_TYPE_OFFSET_KEYSTROKE_TYPE;
|
||||||
switch (keystrokeType) {
|
switch (keystrokeType) {
|
||||||
case SerializedKeystrokeType_Basic:
|
case SerializedKeystrokeType_Basic:
|
||||||
action->keystroke.keystrokeType = KeystrokeType_Basic;
|
keyAction->keystroke.keystrokeType = KeystrokeType_Basic;
|
||||||
break;
|
break;
|
||||||
case SerializedKeystrokeType_ShortMedia:
|
case SerializedKeystrokeType_ShortMedia:
|
||||||
case SerializedKeystrokeType_LongMedia:
|
case SerializedKeystrokeType_LongMedia:
|
||||||
action->keystroke.keystrokeType = KeystrokeType_Media;
|
keyAction->keystroke.keystrokeType = KeystrokeType_Media;
|
||||||
break;
|
break;
|
||||||
case SerializedKeystrokeType_System:
|
case SerializedKeystrokeType_System:
|
||||||
action->keystroke.keystrokeType = KeystrokeType_System;
|
keyAction->keystroke.keystrokeType = KeystrokeType_System;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (flags & SERIALIZED_KEYSTROKE_TYPE_MASK_HAS_SCANCODE) {
|
if (flags & SERIALIZED_KEYSTROKE_TYPE_MASK_HAS_SCANCODE) {
|
||||||
action->keystroke.scancode = keystrokeType == SerializedKeystrokeType_LongMedia ? readUInt16(buffer) : readUInt8(buffer);
|
keyAction->keystroke.scancode = keystrokeType == SerializedKeystrokeType_LongMedia ? readUInt16(buffer) : readUInt8(buffer);
|
||||||
}
|
}
|
||||||
if (flags & SERIALIZED_KEYSTROKE_TYPE_MASK_HAS_MODIFIERS) {
|
if (flags & SERIALIZED_KEYSTROKE_TYPE_MASK_HAS_MODIFIERS) {
|
||||||
action->keystroke.modifiers = readUInt8(buffer);
|
keyAction->keystroke.modifiers = readUInt8(buffer);
|
||||||
}
|
}
|
||||||
if (flags & SERIALIZED_KEYSTROKE_TYPE_MASK_HAS_LONGPRESS) {
|
if (flags & SERIALIZED_KEYSTROKE_TYPE_MASK_HAS_LONGPRESS) {
|
||||||
action->keystroke.longPressAction = readUInt8(buffer);
|
keyAction->keystroke.longPressAction = readUInt8(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseSwitchLayerAction(key_action_t *action, serialized_buffer_t *buffer) {
|
static void parseSwitchLayerAction(key_action_t *KeyAction, serialized_buffer_t *buffer) {
|
||||||
uint8_t layer = readUInt8(buffer) + 1;
|
uint8_t layer = readUInt8(buffer) + 1;
|
||||||
bool isToggle = readBool(buffer);
|
bool isToggle = readBool(buffer);
|
||||||
|
|
||||||
action->type = KeyActionType_SwitchLayer;
|
KeyAction->type = KeyActionType_SwitchLayer;
|
||||||
action->switchLayer.layer = layer;
|
KeyAction->switchLayer.layer = layer;
|
||||||
action->switchLayer.isToggle = isToggle;
|
KeyAction->switchLayer.isToggle = isToggle;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseSwitchKeymapAction(key_action_t *action, serialized_buffer_t *buffer) {
|
static void parseSwitchKeymapAction(key_action_t *keyAction, serialized_buffer_t *buffer) {
|
||||||
// uint16_t len;
|
// uint16_t len;
|
||||||
// const char *keymap = readString(buffer, &len);
|
// const char *keymap = readString(buffer, &len);
|
||||||
|
|
||||||
action->type = KeyActionType_SwitchKeymap;
|
keyAction->type = KeyActionType_SwitchKeymap;
|
||||||
|
|
||||||
// TODO: Implement this
|
// TODO: Implement this
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseMouseAction(key_action_t *action, serialized_buffer_t *buffer) {
|
static void parseMouseAction(key_action_t *keyAction, serialized_buffer_t *buffer) {
|
||||||
uint8_t mouseAction = readUInt8(buffer);
|
uint8_t mouseAction = readUInt8(buffer);
|
||||||
|
|
||||||
action->type = KeyActionType_Mouse;
|
keyAction->type = KeyActionType_Mouse;
|
||||||
switch (mouseAction) {
|
switch (mouseAction) {
|
||||||
case 0: // leftClick
|
case 0: // leftClick
|
||||||
action->mouse.buttonActions |= MouseButton_Left;
|
keyAction->mouse.buttonActions |= MouseButton_Left;
|
||||||
break;
|
break;
|
||||||
case 1: // middleClick
|
case 1: // middleClick
|
||||||
action->mouse.buttonActions |= MouseButton_Middle;
|
keyAction->mouse.buttonActions |= MouseButton_Middle;
|
||||||
break;
|
break;
|
||||||
case 2: // rightClick
|
case 2: // rightClick
|
||||||
action->mouse.buttonActions |= MouseButton_Right;
|
keyAction->mouse.buttonActions |= MouseButton_Right;
|
||||||
break;
|
break;
|
||||||
case 3: // moveUp
|
case 3: // moveUp
|
||||||
action->mouse.moveActions |= MouseMove_Up;
|
keyAction->mouse.moveActions |= MouseMove_Up;
|
||||||
break;
|
break;
|
||||||
case 4: // moveDown
|
case 4: // moveDown
|
||||||
action->mouse.moveActions |= MouseMove_Down;
|
keyAction->mouse.moveActions |= MouseMove_Down;
|
||||||
break;
|
break;
|
||||||
case 5: // moveLeft
|
case 5: // moveLeft
|
||||||
action->mouse.moveActions |= MouseMove_Left;
|
keyAction->mouse.moveActions |= MouseMove_Left;
|
||||||
break;
|
break;
|
||||||
case 6: // moveRight
|
case 6: // moveRight
|
||||||
action->mouse.moveActions |= MouseMove_Right;
|
keyAction->mouse.moveActions |= MouseMove_Right;
|
||||||
break;
|
break;
|
||||||
case 7: // scrollUp
|
case 7: // scrollUp
|
||||||
action->mouse.scrollActions |= MouseScroll_Up;
|
keyAction->mouse.scrollActions |= MouseScroll_Up;
|
||||||
break;
|
break;
|
||||||
case 8: // scrollDown
|
case 8: // scrollDown
|
||||||
action->mouse.scrollActions |= MouseScroll_Down;
|
keyAction->mouse.scrollActions |= MouseScroll_Down;
|
||||||
break;
|
break;
|
||||||
case 9: // scrollLeft
|
case 9: // scrollLeft
|
||||||
action->mouse.scrollActions |= MouseScroll_Left;
|
keyAction->mouse.scrollActions |= MouseScroll_Left;
|
||||||
break;
|
break;
|
||||||
case 10: // scrollRight
|
case 10: // scrollRight
|
||||||
action->mouse.scrollActions |= MouseScroll_Right;
|
keyAction->mouse.scrollActions |= MouseScroll_Right;
|
||||||
break;
|
break;
|
||||||
case 11: // accelerate
|
case 11: // accelerate
|
||||||
action->mouse.moveActions |= MouseMove_Accelerate;
|
keyAction->mouse.moveActions |= MouseMove_Accelerate;
|
||||||
break;
|
break;
|
||||||
case 12: // decelerate
|
case 12: // decelerate
|
||||||
action->mouse.moveActions |= MouseMove_Decelerate;
|
keyAction->mouse.moveActions |= MouseMove_Decelerate;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseKeyAction(key_action_t *action, serialized_buffer_t *buffer) {
|
static void parseKeyAction(key_action_t *keyAction, serialized_buffer_t *buffer) {
|
||||||
uint8_t actionType = readUInt8(buffer);
|
uint8_t actionType = readUInt8(buffer);
|
||||||
|
|
||||||
switch (actionType) {
|
switch (actionType) {
|
||||||
case SerializedKeyActionType_None:
|
case SerializedKeyActionType_None:
|
||||||
return parseNoneAction(action, buffer);
|
return parseNoneAction(keyAction, buffer);
|
||||||
case SerializedKeyActionType_KeyStroke ... SerializedKeyActionType_LastKeyStroke:
|
case SerializedKeyActionType_KeyStroke ... SerializedKeyActionType_LastKeyStroke:
|
||||||
return parseKeyStrokeAction(action, actionType, buffer);
|
return parseKeyStrokeAction(keyAction, actionType, buffer);
|
||||||
case SerializedKeyActionType_SwitchLayer:
|
case SerializedKeyActionType_SwitchLayer:
|
||||||
return parseSwitchLayerAction(action, buffer);
|
return parseSwitchLayerAction(keyAction, buffer);
|
||||||
case SerializedKeyActionType_SwitchKeymap:
|
case SerializedKeyActionType_SwitchKeymap:
|
||||||
return parseSwitchKeymapAction(action, buffer);
|
return parseSwitchKeymapAction(keyAction, buffer);
|
||||||
case SerializedKeyActionType_Mouse:
|
case SerializedKeyActionType_Mouse:
|
||||||
return parseMouseAction(action, buffer);
|
return parseMouseAction(keyAction, buffer);
|
||||||
default:
|
default:
|
||||||
// TODO: Handle the case where the actionType is unknown
|
// TODO: Handle the case where the actionType is unknown.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseKeyActions(uint8_t targetLayer, serialized_buffer_t *buffer, uint8_t moduleID, uint8_t pointerRole) {
|
static void parseKeyActions(uint8_t targetLayer, serialized_buffer_t *buffer, uint8_t moduleId, uint8_t pointerRole) {
|
||||||
uint8_t actionCount = readCompactLength(buffer);
|
uint8_t actionCount = readCompactLength(buffer);
|
||||||
|
|
||||||
for (uint8_t actionIdx = 0; actionIdx < actionCount; actionIdx++) {
|
for (uint8_t actionIdx = 0; actionIdx < actionCount; actionIdx++) {
|
||||||
key_action_t *action = &(CurrentKeymap[targetLayer][moduleID][actionIdx]);
|
key_action_t *keyAction = &(CurrentKeymap[targetLayer][moduleId][actionIdx]);
|
||||||
parseKeyAction(action, buffer);
|
parseKeyAction(keyAction, buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseModule(serialized_buffer_t *buffer, uint8_t targetLayer) {
|
static void parseModule(serialized_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);
|
||||||
parseKeyActions(targetLayer, buffer, moduleID, pointerRole);
|
parseKeyActions(layer, buffer, moduleId, pointerRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void clearModule(uint8_t targetLayer, uint8_t moduleID) {
|
static void clearModule(uint8_t layer, uint8_t moduleId) {
|
||||||
memset(&CurrentKeymap[targetLayer][moduleID], 0, MAX_KEY_COUNT_PER_MODULE * sizeof(key_action_t));
|
memset(&CurrentKeymap[layer][moduleId], 0, MAX_KEY_COUNT_PER_MODULE * sizeof(key_action_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParseLayer(const uint8_t *data, uint8_t targetLayer) {
|
void ParseLayer(const uint8_t *data, uint8_t layer) {
|
||||||
serialized_buffer_t buffer;
|
serialized_buffer_t buffer;
|
||||||
|
|
||||||
buffer.buffer = data;
|
buffer.buffer = data;
|
||||||
buffer.offset = 0;
|
buffer.offset = 0;
|
||||||
|
|
||||||
uint8_t moduleCount = readCompactLength(&buffer);
|
uint8_t moduleCount = readCompactLength(&buffer);
|
||||||
|
|
||||||
for (uint8_t modIdx = 0; modIdx < moduleCount; modIdx++) {
|
for (uint8_t moduleIdx = 0; moduleIdx < moduleCount; moduleIdx++) {
|
||||||
clearModule(targetLayer, modIdx);
|
clearModule(layer, moduleIdx);
|
||||||
parseModule(&buffer, targetLayer);
|
parseModule(&buffer, layer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user