Rename key action related enums and values to be easier to read.

This commit is contained in:
László Monda
2017-06-15 19:14:05 +02:00
parent 480b184ab5
commit 976444b5fe
4 changed files with 352 additions and 352 deletions

View File

@@ -9,46 +9,46 @@
#include "module.h" #include "module.h"
typedef enum { typedef enum {
KEY_ACTION_NONE, KeyActionType_None,
KEY_ACTION_KEYSTROKE, KeyActionType_Keystroke,
KEY_ACTION_MOUSE, KeyActionType_Mouse,
KEY_ACTION_SWITCH_LAYER, KeyActionType_SwitchLayer,
KEY_ACTION_SWITCH_KEYMAP, KeyActionType_SwitchKeymap,
KEY_ACTION_PLAY_MACRO, KeyActionType_PlayMacro,
KEY_ACTION_TEST, KeyActionType_Test,
} key_action_type_t; } key_action_type_t;
typedef enum { typedef enum {
KEYSTROKE_BASIC, KeystrokeType_Basic,
KEYSTROKE_MEDIA, KeystrokeType_Media,
KEYSTROKE_SYSTEM, KeystrokeType_System,
} keystroke_type_t; } keystroke_type_t;
enum { typedef enum {
MOUSE_BUTTON_LEFT = (1 << 0), MouseButton_Left = 1 << 0,
MOUSE_BUTTON_RIGHT = (1 << 1), MouseButton_Right = 1 << 1,
MOUSE_BUTTON_MIDDLE = (1 << 2), MouseButton_Middle = 1 << 2,
MOUSE_BUTTON_4 = (1 << 3), MouseButton_4 = 1 << 3,
MOUSE_BUTTON_5 = (1 << 4), MouseButton_5 = 1 << 4,
MOUSE_BUTTON_6 = (1 << 5), MouseButton_t = 1 << 5,
}; } mouse_button_t;
enum { typedef enum {
MOUSE_MOVE_UP = (1 << 0), MouseMove_Up = 1 << 0,
MOUSE_MOVE_DOWN = (1 << 1), MouseMove_Down = 1 << 1,
MOUSE_MOVE_LEFT = (1 << 2), MouseMove_Left = 1 << 2,
MOUSE_MOVE_RIGHT = (1 << 3), MouseMove_Right = 1 << 3,
MOUSE_ACCELERATE = (1 << 4), MouseMove_Accelerate = 1 << 4,
MOUSE_DECELERATE = (1 << 5), MouseMove_Decelerate = 1 << 5,
}; } mouse_move_action_t;
enum { typedef enum {
MOUSE_SCROLL_UP = (1 << 0), MouseScroll_Up = 1 << 0,
MOUSE_SCROLL_DOWN = (1 << 1), MouseScroll_Down = 1 << 1,
MOUSE_SCROLL_LEFT = (1 << 2), MouseScroll_Left = 1 << 2,
MOUSE_SCROLL_RIGHT = (1 << 3), MouseScroll_Right = 1 << 3,
}; } mouse_scroll_t;
typedef enum { typedef enum {
TestAction_DisableUsb, TestAction_DisableUsb,
@@ -75,9 +75,9 @@ typedef struct {
uint16_t scancode; uint16_t scancode;
} __attribute__ ((packed)) keystroke; } __attribute__ ((packed)) keystroke;
struct { struct {
uint8_t buttonActions; mouse_button_t buttonActions;
uint8_t scrollActions; mouse_scroll_t scrollActions;
uint8_t moveActions; mouse_move_action_t moveActions;
} __attribute__ ((packed)) mouse; } __attribute__ ((packed)) mouse;
struct { struct {
bool isToggle; bool isToggle;

View File

@@ -39,25 +39,25 @@ 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 *action, serialized_buffer_t *buffer) {
action->type = KEY_ACTION_NONE; action->type = KeyActionType_None;
} }
static void parseKeyStrokeAction(key_action_t *action, uint8_t actionType, serialized_buffer_t *buffer) { static void parseKeyStrokeAction(key_action_t *action, uint8_t actionType, serialized_buffer_t *buffer) {
uint8_t flags = actionType - 1; uint8_t flags = actionType - 1;
action->type = KEY_ACTION_KEYSTROKE; action->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 = KEYSTROKE_BASIC; action->keystroke.keystrokeType = KeystrokeType_Basic;
break; break;
case SerializedKeystrokeType_ShortMedia: case SerializedKeystrokeType_ShortMedia:
case SerializedKeystrokeType_LongMedia: case SerializedKeystrokeType_LongMedia:
action->keystroke.keystrokeType = KEYSTROKE_MEDIA; action->keystroke.keystrokeType = KeystrokeType_Media;
break; break;
case SerializedKeystrokeType_System: case SerializedKeystrokeType_System:
action->keystroke.keystrokeType = KEYSTROKE_SYSTEM; action->keystroke.keystrokeType = KeystrokeType_System;
break; break;
} }
if (flags & SERIALIZED_KEYSTROKE_TYPE_MASK_HAS_SCANCODE) { if (flags & SERIALIZED_KEYSTROKE_TYPE_MASK_HAS_SCANCODE) {
@@ -75,7 +75,7 @@ static void parseSwitchLayerAction(key_action_t *action, serialized_buffer_t *bu
uint8_t layer = readUInt8(buffer) + 1; uint8_t layer = readUInt8(buffer) + 1;
bool isToggle = readBool(buffer); bool isToggle = readBool(buffer);
action->type = KEY_ACTION_SWITCH_LAYER; action->type = KeyActionType_SwitchLayer;
action->switchLayer.layer = layer; action->switchLayer.layer = layer;
action->switchLayer.isToggle = isToggle; action->switchLayer.isToggle = isToggle;
} }
@@ -84,7 +84,7 @@ static void parseSwitchKeymapAction(key_action_t *action, serialized_buffer_t *b
// uint16_t len; // uint16_t len;
// const char *keymap = readString(buffer, &len); // const char *keymap = readString(buffer, &len);
action->type = KEY_ACTION_SWITCH_KEYMAP; action->type = KeyActionType_SwitchKeymap;
// TODO: Implement this // TODO: Implement this
} }
@@ -92,46 +92,46 @@ static void parseSwitchKeymapAction(key_action_t *action, serialized_buffer_t *b
static void parseMouseAction(key_action_t *action, serialized_buffer_t *buffer) { static void parseMouseAction(key_action_t *action, serialized_buffer_t *buffer) {
uint8_t mouseAction = readUInt8(buffer); uint8_t mouseAction = readUInt8(buffer);
action->type = KEY_ACTION_MOUSE; action->type = KeyActionType_Mouse;
switch (mouseAction) { switch (mouseAction) {
case 0: // leftClick case 0: // leftClick
action->mouse.buttonActions |= MOUSE_BUTTON_LEFT; action->mouse.buttonActions |= MouseButton_Left;
break; break;
case 1: // middleClick case 1: // middleClick
action->mouse.buttonActions |= MOUSE_BUTTON_MIDDLE; action->mouse.buttonActions |= MouseButton_Middle;
break; break;
case 2: // rightClick case 2: // rightClick
action->mouse.buttonActions |= MOUSE_BUTTON_RIGHT; action->mouse.buttonActions |= MouseButton_Right;
break; break;
case 3: // moveUp case 3: // moveUp
action->mouse.moveActions |= MOUSE_MOVE_UP; action->mouse.moveActions |= MouseMove_Up;
break; break;
case 4: // moveDown case 4: // moveDown
action->mouse.moveActions |= MOUSE_MOVE_DOWN; action->mouse.moveActions |= MouseMove_Down;
break; break;
case 5: // moveLeft case 5: // moveLeft
action->mouse.moveActions |= MOUSE_MOVE_LEFT; action->mouse.moveActions |= MouseMove_Left;
break; break;
case 6: // moveRight case 6: // moveRight
action->mouse.moveActions |= MOUSE_MOVE_RIGHT; action->mouse.moveActions |= MouseMove_Right;
break; break;
case 7: // scrollUp case 7: // scrollUp
action->mouse.scrollActions |= MOUSE_SCROLL_UP; action->mouse.scrollActions |= MouseScroll_Up;
break; break;
case 8: // scrollDown case 8: // scrollDown
action->mouse.scrollActions |= MOUSE_SCROLL_DOWN; action->mouse.scrollActions |= MouseScroll_Down;
break; break;
case 9: // scrollLeft case 9: // scrollLeft
action->mouse.scrollActions |= MOUSE_SCROLL_LEFT; action->mouse.scrollActions |= MouseScroll_Left;
break; break;
case 10: // scrollRight case 10: // scrollRight
action->mouse.scrollActions |= MOUSE_SCROLL_RIGHT; action->mouse.scrollActions |= MouseScroll_Right;
break; break;
case 11: // accelerate case 11: // accelerate
action->mouse.moveActions |= MOUSE_ACCELERATE; action->mouse.moveActions |= MouseMove_Accelerate;
break; break;
case 12: // decelerate case 12: // decelerate
action->mouse.moveActions |= MOUSE_DECELERATE; action->mouse.moveActions |= MouseMove_Decelerate;
break; break;
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -28,43 +28,43 @@ void processMouseAction(key_action_t action)
if (action.mouse.scrollActions) { if (action.mouse.scrollActions) {
if (mouseWheelDivisorCounter == MOUSE_WHEEL_DIVISOR) { if (mouseWheelDivisorCounter == MOUSE_WHEEL_DIVISOR) {
mouseWheelDivisorCounter = 0; mouseWheelDivisorCounter = 0;
if (action.mouse.scrollActions & MOUSE_SCROLL_UP) { if (action.mouse.scrollActions & MouseScroll_Up) {
UsbMouseReport.wheelX = 1; UsbMouseReport.wheelX = 1;
} }
if (action.mouse.scrollActions & MOUSE_SCROLL_DOWN) { if (action.mouse.scrollActions & MouseScroll_Down) {
UsbMouseReport.wheelX = -1; UsbMouseReport.wheelX = -1;
} }
} }
} }
if (action.mouse.moveActions & MOUSE_ACCELERATE || action.mouse.moveActions & MOUSE_DECELERATE) { if (action.mouse.moveActions & MouseMove_Accelerate || action.mouse.moveActions & MouseMove_Decelerate) {
mouseSpeedAccelDivisorCounter++; mouseSpeedAccelDivisorCounter++;
if (mouseSpeedAccelDivisorCounter == MOUSE_SPEED_ACCEL_DIVISOR) { if (mouseSpeedAccelDivisorCounter == MOUSE_SPEED_ACCEL_DIVISOR) {
mouseSpeedAccelDivisorCounter = 0; mouseSpeedAccelDivisorCounter = 0;
if (action.mouse.moveActions & MOUSE_ACCELERATE) { if (action.mouse.moveActions & MouseMove_Accelerate) {
if (mouseSpeed < MOUSE_MAX_SPEED) { if (mouseSpeed < MOUSE_MAX_SPEED) {
mouseSpeed++; mouseSpeed++;
} }
} }
if (action.mouse.moveActions & MOUSE_DECELERATE) { if (action.mouse.moveActions & MouseMove_Decelerate) {
if (mouseSpeed > 1) { if (mouseSpeed > 1) {
mouseSpeed--; mouseSpeed--;
} }
} }
} }
} else if (action.mouse.moveActions) { } else if (action.mouse.moveActions) {
if (action.mouse.moveActions & MOUSE_MOVE_LEFT) { if (action.mouse.moveActions & MouseMove_Left) {
UsbMouseReport.x = -mouseSpeed; UsbMouseReport.x = -mouseSpeed;
} }
if (action.mouse.moveActions & MOUSE_MOVE_RIGHT) { if (action.mouse.moveActions & MouseMove_Right) {
UsbMouseReport.x = mouseSpeed; UsbMouseReport.x = mouseSpeed;
} }
if (action.mouse.moveActions & MOUSE_MOVE_UP) { if (action.mouse.moveActions & MouseMove_Up) {
UsbMouseReport.y = -mouseSpeed; UsbMouseReport.y = -mouseSpeed;
} }
if (action.mouse.moveActions & MOUSE_MOVE_DOWN) { if (action.mouse.moveActions & MouseMove_Down) {
UsbMouseReport.y = mouseSpeed; UsbMouseReport.y = mouseSpeed;
} }
} }
@@ -120,7 +120,7 @@ void UpdateActiveUsbReports() {
for (uint8_t keyId=0; keyId<MAX_KEY_COUNT_PER_MODULE; keyId++) { for (uint8_t keyId=0; keyId<MAX_KEY_COUNT_PER_MODULE; keyId++) {
if (CurrentKeyStates[slotId][keyId]) { if (CurrentKeyStates[slotId][keyId]) {
key_action_t action = CurrentKeymap[LAYER_ID_BASE][slotId][keyId]; key_action_t action = CurrentKeymap[LAYER_ID_BASE][slotId][keyId];
if (action.type == KEY_ACTION_SWITCH_LAYER) { if (action.type == KeyActionType_SwitchLayer) {
activeLayer = action.switchLayer.layer; activeLayer = action.switchLayer.layer;
} }
} }
@@ -136,23 +136,23 @@ void UpdateActiveUsbReports() {
key_action_t action = CurrentKeymap[activeLayer][slotId][keyId]; key_action_t action = CurrentKeymap[activeLayer][slotId][keyId];
switch (action.type) { switch (action.type) {
case KEY_ACTION_KEYSTROKE: case KeyActionType_Keystroke:
ActiveUsbBasicKeyboardReport->modifiers |= action.keystroke.modifiers; ActiveUsbBasicKeyboardReport->modifiers |= action.keystroke.modifiers;
switch (action.keystroke.keystrokeType) { switch (action.keystroke.keystrokeType) {
case KEYSTROKE_BASIC: case KeystrokeType_Basic:
if (basicScancodeIndex >= USB_BASIC_KEYBOARD_MAX_KEYS) { if (basicScancodeIndex >= USB_BASIC_KEYBOARD_MAX_KEYS) {
break; break;
} }
ActiveUsbBasicKeyboardReport->scancodes[basicScancodeIndex++] = action.keystroke.scancode; ActiveUsbBasicKeyboardReport->scancodes[basicScancodeIndex++] = action.keystroke.scancode;
break; break;
case KEYSTROKE_MEDIA: case KeystrokeType_Media:
if (mediaScancodeIndex >= USB_MEDIA_KEYBOARD_MAX_KEYS) { if (mediaScancodeIndex >= USB_MEDIA_KEYBOARD_MAX_KEYS) {
break; break;
} }
ActiveUsbMediaKeyboardReport->scancodes[mediaScancodeIndex++] = action.keystroke.scancode; ActiveUsbMediaKeyboardReport->scancodes[mediaScancodeIndex++] = action.keystroke.scancode;
break; break;
case KEYSTROKE_SYSTEM: case KeystrokeType_System:
if (systemScancodeIndex >= USB_SYSTEM_KEYBOARD_MAX_KEYS) { if (systemScancodeIndex >= USB_SYSTEM_KEYBOARD_MAX_KEYS) {
break; break;
} }
@@ -160,10 +160,10 @@ void UpdateActiveUsbReports() {
break; break;
} }
break; break;
case KEY_ACTION_MOUSE: case KeyActionType_Mouse:
processMouseAction(action); processMouseAction(action);
break; break;
case KEY_ACTION_TEST: case KeyActionType_Test:
processTestAction(action); processTestAction(action);
break; break;
} }