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"
typedef enum {
KEY_ACTION_NONE,
KEY_ACTION_KEYSTROKE,
KEY_ACTION_MOUSE,
KEY_ACTION_SWITCH_LAYER,
KEY_ACTION_SWITCH_KEYMAP,
KEY_ACTION_PLAY_MACRO,
KEY_ACTION_TEST,
KeyActionType_None,
KeyActionType_Keystroke,
KeyActionType_Mouse,
KeyActionType_SwitchLayer,
KeyActionType_SwitchKeymap,
KeyActionType_PlayMacro,
KeyActionType_Test,
} key_action_type_t;
typedef enum {
KEYSTROKE_BASIC,
KEYSTROKE_MEDIA,
KEYSTROKE_SYSTEM,
KeystrokeType_Basic,
KeystrokeType_Media,
KeystrokeType_System,
} keystroke_type_t;
enum {
MOUSE_BUTTON_LEFT = (1 << 0),
MOUSE_BUTTON_RIGHT = (1 << 1),
MOUSE_BUTTON_MIDDLE = (1 << 2),
MOUSE_BUTTON_4 = (1 << 3),
MOUSE_BUTTON_5 = (1 << 4),
MOUSE_BUTTON_6 = (1 << 5),
};
typedef enum {
MouseButton_Left = 1 << 0,
MouseButton_Right = 1 << 1,
MouseButton_Middle = 1 << 2,
MouseButton_4 = 1 << 3,
MouseButton_5 = 1 << 4,
MouseButton_t = 1 << 5,
} mouse_button_t;
enum {
MOUSE_MOVE_UP = (1 << 0),
MOUSE_MOVE_DOWN = (1 << 1),
MOUSE_MOVE_LEFT = (1 << 2),
MOUSE_MOVE_RIGHT = (1 << 3),
typedef enum {
MouseMove_Up = 1 << 0,
MouseMove_Down = 1 << 1,
MouseMove_Left = 1 << 2,
MouseMove_Right = 1 << 3,
MOUSE_ACCELERATE = (1 << 4),
MOUSE_DECELERATE = (1 << 5),
};
MouseMove_Accelerate = 1 << 4,
MouseMove_Decelerate = 1 << 5,
} mouse_move_action_t;
enum {
MOUSE_SCROLL_UP = (1 << 0),
MOUSE_SCROLL_DOWN = (1 << 1),
MOUSE_SCROLL_LEFT = (1 << 2),
MOUSE_SCROLL_RIGHT = (1 << 3),
};
typedef enum {
MouseScroll_Up = 1 << 0,
MouseScroll_Down = 1 << 1,
MouseScroll_Left = 1 << 2,
MouseScroll_Right = 1 << 3,
} mouse_scroll_t;
typedef enum {
TestAction_DisableUsb,
@@ -75,9 +75,9 @@ typedef struct {
uint16_t scancode;
} __attribute__ ((packed)) keystroke;
struct {
uint8_t buttonActions;
uint8_t scrollActions;
uint8_t moveActions;
mouse_button_t buttonActions;
mouse_scroll_t scrollActions;
mouse_move_action_t moveActions;
} __attribute__ ((packed)) mouse;
struct {
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) {
action->type = KEY_ACTION_NONE;
action->type = KeyActionType_None;
}
static void parseKeyStrokeAction(key_action_t *action, uint8_t actionType, serialized_buffer_t *buffer) {
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;
switch (keystrokeType) {
case SerializedKeystrokeType_Basic:
action->keystroke.keystrokeType = KEYSTROKE_BASIC;
action->keystroke.keystrokeType = KeystrokeType_Basic;
break;
case SerializedKeystrokeType_ShortMedia:
case SerializedKeystrokeType_LongMedia:
action->keystroke.keystrokeType = KEYSTROKE_MEDIA;
action->keystroke.keystrokeType = KeystrokeType_Media;
break;
case SerializedKeystrokeType_System:
action->keystroke.keystrokeType = KEYSTROKE_SYSTEM;
action->keystroke.keystrokeType = KeystrokeType_System;
break;
}
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;
bool isToggle = readBool(buffer);
action->type = KEY_ACTION_SWITCH_LAYER;
action->type = KeyActionType_SwitchLayer;
action->switchLayer.layer = layer;
action->switchLayer.isToggle = isToggle;
}
@@ -84,7 +84,7 @@ static void parseSwitchKeymapAction(key_action_t *action, serialized_buffer_t *b
// uint16_t len;
// const char *keymap = readString(buffer, &len);
action->type = KEY_ACTION_SWITCH_KEYMAP;
action->type = KeyActionType_SwitchKeymap;
// 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) {
uint8_t mouseAction = readUInt8(buffer);
action->type = KEY_ACTION_MOUSE;
action->type = KeyActionType_Mouse;
switch (mouseAction) {
case 0: // leftClick
action->mouse.buttonActions |= MOUSE_BUTTON_LEFT;
action->mouse.buttonActions |= MouseButton_Left;
break;
case 1: // middleClick
action->mouse.buttonActions |= MOUSE_BUTTON_MIDDLE;
action->mouse.buttonActions |= MouseButton_Middle;
break;
case 2: // rightClick
action->mouse.buttonActions |= MOUSE_BUTTON_RIGHT;
action->mouse.buttonActions |= MouseButton_Right;
break;
case 3: // moveUp
action->mouse.moveActions |= MOUSE_MOVE_UP;
action->mouse.moveActions |= MouseMove_Up;
break;
case 4: // moveDown
action->mouse.moveActions |= MOUSE_MOVE_DOWN;
action->mouse.moveActions |= MouseMove_Down;
break;
case 5: // moveLeft
action->mouse.moveActions |= MOUSE_MOVE_LEFT;
action->mouse.moveActions |= MouseMove_Left;
break;
case 6: // moveRight
action->mouse.moveActions |= MOUSE_MOVE_RIGHT;
action->mouse.moveActions |= MouseMove_Right;
break;
case 7: // scrollUp
action->mouse.scrollActions |= MOUSE_SCROLL_UP;
action->mouse.scrollActions |= MouseScroll_Up;
break;
case 8: // scrollDown
action->mouse.scrollActions |= MOUSE_SCROLL_DOWN;
action->mouse.scrollActions |= MouseScroll_Down;
break;
case 9: // scrollLeft
action->mouse.scrollActions |= MOUSE_SCROLL_LEFT;
action->mouse.scrollActions |= MouseScroll_Left;
break;
case 10: // scrollRight
action->mouse.scrollActions |= MOUSE_SCROLL_RIGHT;
action->mouse.scrollActions |= MouseScroll_Right;
break;
case 11: // accelerate
action->mouse.moveActions |= MOUSE_ACCELERATE;
action->mouse.moveActions |= MouseMove_Accelerate;
break;
case 12: // decelerate
action->mouse.moveActions |= MOUSE_DECELERATE;
action->mouse.moveActions |= MouseMove_Decelerate;
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 (mouseWheelDivisorCounter == MOUSE_WHEEL_DIVISOR) {
mouseWheelDivisorCounter = 0;
if (action.mouse.scrollActions & MOUSE_SCROLL_UP) {
if (action.mouse.scrollActions & MouseScroll_Up) {
UsbMouseReport.wheelX = 1;
}
if (action.mouse.scrollActions & MOUSE_SCROLL_DOWN) {
if (action.mouse.scrollActions & MouseScroll_Down) {
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++;
if (mouseSpeedAccelDivisorCounter == MOUSE_SPEED_ACCEL_DIVISOR) {
mouseSpeedAccelDivisorCounter = 0;
if (action.mouse.moveActions & MOUSE_ACCELERATE) {
if (action.mouse.moveActions & MouseMove_Accelerate) {
if (mouseSpeed < MOUSE_MAX_SPEED) {
mouseSpeed++;
}
}
if (action.mouse.moveActions & MOUSE_DECELERATE) {
if (action.mouse.moveActions & MouseMove_Decelerate) {
if (mouseSpeed > 1) {
mouseSpeed--;
}
}
}
} else if (action.mouse.moveActions) {
if (action.mouse.moveActions & MOUSE_MOVE_LEFT) {
if (action.mouse.moveActions & MouseMove_Left) {
UsbMouseReport.x = -mouseSpeed;
}
if (action.mouse.moveActions & MOUSE_MOVE_RIGHT) {
if (action.mouse.moveActions & MouseMove_Right) {
UsbMouseReport.x = mouseSpeed;
}
if (action.mouse.moveActions & MOUSE_MOVE_UP) {
if (action.mouse.moveActions & MouseMove_Up) {
UsbMouseReport.y = -mouseSpeed;
}
if (action.mouse.moveActions & MOUSE_MOVE_DOWN) {
if (action.mouse.moveActions & MouseMove_Down) {
UsbMouseReport.y = mouseSpeed;
}
}
@@ -120,7 +120,7 @@ void UpdateActiveUsbReports() {
for (uint8_t keyId=0; keyId<MAX_KEY_COUNT_PER_MODULE; keyId++) {
if (CurrentKeyStates[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;
}
}
@@ -136,23 +136,23 @@ void UpdateActiveUsbReports() {
key_action_t action = CurrentKeymap[activeLayer][slotId][keyId];
switch (action.type) {
case KEY_ACTION_KEYSTROKE:
case KeyActionType_Keystroke:
ActiveUsbBasicKeyboardReport->modifiers |= action.keystroke.modifiers;
switch (action.keystroke.keystrokeType) {
case KEYSTROKE_BASIC:
case KeystrokeType_Basic:
if (basicScancodeIndex >= USB_BASIC_KEYBOARD_MAX_KEYS) {
break;
}
ActiveUsbBasicKeyboardReport->scancodes[basicScancodeIndex++] = action.keystroke.scancode;
break;
case KEYSTROKE_MEDIA:
case KeystrokeType_Media:
if (mediaScancodeIndex >= USB_MEDIA_KEYBOARD_MAX_KEYS) {
break;
}
ActiveUsbMediaKeyboardReport->scancodes[mediaScancodeIndex++] = action.keystroke.scancode;
break;
case KEYSTROKE_SYSTEM:
case KeystrokeType_System:
if (systemScancodeIndex >= USB_SYSTEM_KEYBOARD_MAX_KEYS) {
break;
}
@@ -160,10 +160,10 @@ void UpdateActiveUsbReports() {
break;
}
break;
case KEY_ACTION_MOUSE:
case KeyActionType_Mouse:
processMouseAction(action);
break;
case KEY_ACTION_TEST:
case KeyActionType_Test:
processTestAction(action);
break;
}