Rename a couple of key action related type names and enum values.
This commit is contained in:
@@ -8,20 +8,20 @@ static uint8_t keyMasks[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE];
|
|||||||
static uint8_t ActiveLayer = LAYER_ID_BASE;
|
static uint8_t ActiveLayer = LAYER_ID_BASE;
|
||||||
uint8_t prevKeyStates[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE];
|
uint8_t prevKeyStates[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE];
|
||||||
|
|
||||||
static inline __attribute__((always_inline)) uhk_key_t getKeycode(uint8_t slotId, uint8_t keyId)
|
static inline __attribute__((always_inline)) key_action_t getKeycode(uint8_t slotId, uint8_t keyId)
|
||||||
{
|
{
|
||||||
if (keyId < MAX_KEY_COUNT_PER_MODULE) {
|
if (keyId < MAX_KEY_COUNT_PER_MODULE) {
|
||||||
if (keyMasks[slotId][keyId]!=0 && keyMasks[slotId][keyId]!=ActiveLayer) {
|
if (keyMasks[slotId][keyId]!=0 && keyMasks[slotId][keyId]!=ActiveLayer) {
|
||||||
// Mask out key presses after releasing modifier keys
|
// Mask out key presses after releasing modifier keys
|
||||||
return (uhk_key_t){.type = UHK_KEY_NONE};
|
return (key_action_t){.type = KEY_ACTION_NONE};
|
||||||
}
|
}
|
||||||
|
|
||||||
uhk_key_t key = CurrentKeymap[ActiveLayer][slotId][keyId];
|
key_action_t key = CurrentKeymap[ActiveLayer][slotId][keyId];
|
||||||
keyMasks[slotId][keyId] = ActiveLayer;
|
keyMasks[slotId][keyId] = ActiveLayer;
|
||||||
|
|
||||||
return key;
|
return key;
|
||||||
} else {
|
} else {
|
||||||
return (uhk_key_t){.type = UHK_KEY_NONE};
|
return (key_action_t){.type = KEY_ACTION_NONE};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,8 +38,8 @@ static void clearKeymasks(const uint8_t *leftKeyStates, const uint8_t *rightKeyS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool pressKey(uhk_key_t key, int scancodeIdx, usb_keyboard_report_t *report) {
|
static bool pressKey(key_action_t key, int scancodeIdx, usb_keyboard_report_t *report) {
|
||||||
if (key.type != UHK_KEY_SIMPLE) {
|
if (key.type != KEY_ACTION_KEYSTROKE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,14 +69,14 @@ static bool hasKeyReleased(const uint8_t *prevKeyStates, const uint8_t *currKeyS
|
|||||||
return (!currKeyStates[keyId]) && prevKeyStates[keyId];
|
return (!currKeyStates[keyId]) && prevKeyStates[keyId];
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool handleKey(uhk_key_t key, int scancodeIdx, usb_keyboard_report_t *report, const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId) {
|
static bool handleKey(key_action_t key, int scancodeIdx, usb_keyboard_report_t *report, const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId) {
|
||||||
switch (key.type) {
|
switch (key.type) {
|
||||||
case UHK_KEY_SIMPLE:
|
case KEY_ACTION_KEYSTROKE:
|
||||||
if (isKeyPressed(prevKeyStates, currKeyStates, keyId)) {
|
if (isKeyPressed(prevKeyStates, currKeyStates, keyId)) {
|
||||||
return pressKey(key, scancodeIdx, report);
|
return pressKey(key, scancodeIdx, report);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case UHK_KEY_LAYER:
|
case KEY_ACTION_SWITCH_LAYER:
|
||||||
if (hasKeyPressed(prevKeyStates, currKeyStates, keyId)) {
|
if (hasKeyPressed(prevKeyStates, currKeyStates, keyId)) {
|
||||||
ActiveLayer = key.layer.target;
|
ActiveLayer = key.layer.target;
|
||||||
}
|
}
|
||||||
@@ -97,7 +97,7 @@ static uint8_t mouseSpeedAccelDivisorCounter = 0;
|
|||||||
static uint8_t mouseSpeed = 3;
|
static uint8_t mouseSpeed = 3;
|
||||||
static bool wasPreviousMouseActionWheelAction = false;
|
static bool wasPreviousMouseActionWheelAction = false;
|
||||||
|
|
||||||
static void handleMouseKey(usb_mouse_report_t *report, uhk_key_t key, const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId)
|
static void handleMouseKey(usb_mouse_report_t *report, key_action_t key, const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId)
|
||||||
{
|
{
|
||||||
if (!isKeyPressed(prevKeyStates, currKeyStates, keyId)) {
|
if (!isKeyPressed(prevKeyStates, currKeyStates, keyId)) {
|
||||||
return;
|
return;
|
||||||
@@ -112,43 +112,43 @@ static void handleMouseKey(usb_mouse_report_t *report, uhk_key_t key, const uint
|
|||||||
if (key.mouse.scrollActions) {
|
if (key.mouse.scrollActions) {
|
||||||
if (mouseWheelDivisorCounter == MOUSE_WHEEL_DIVISOR) {
|
if (mouseWheelDivisorCounter == MOUSE_WHEEL_DIVISOR) {
|
||||||
mouseWheelDivisorCounter = 0;
|
mouseWheelDivisorCounter = 0;
|
||||||
if (key.mouse.scrollActions & UHK_MOUSE_SCROLL_UP) {
|
if (key.mouse.scrollActions & MOUSE_SCROLL_UP) {
|
||||||
report->wheelX = 1;
|
report->wheelX = 1;
|
||||||
}
|
}
|
||||||
if (key.mouse.scrollActions & UHK_MOUSE_SCROLL_DOWN) {
|
if (key.mouse.scrollActions & MOUSE_SCROLL_DOWN) {
|
||||||
report->wheelX = -1;
|
report->wheelX = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key.mouse.moveActions & UHK_MOUSE_ACCELERATE || key.mouse.moveActions & UHK_MOUSE_DECELERATE) {
|
if (key.mouse.moveActions & MOUSE_ACCELERATE || key.mouse.moveActions & MOUSE_DECELERATE) {
|
||||||
mouseSpeedAccelDivisorCounter++;
|
mouseSpeedAccelDivisorCounter++;
|
||||||
|
|
||||||
if (mouseSpeedAccelDivisorCounter == MOUSE_SPEED_ACCEL_DIVISOR) {
|
if (mouseSpeedAccelDivisorCounter == MOUSE_SPEED_ACCEL_DIVISOR) {
|
||||||
mouseSpeedAccelDivisorCounter = 0;
|
mouseSpeedAccelDivisorCounter = 0;
|
||||||
|
|
||||||
if (key.mouse.moveActions & UHK_MOUSE_ACCELERATE) {
|
if (key.mouse.moveActions & MOUSE_ACCELERATE) {
|
||||||
if (mouseSpeed < MOUSE_MAX_SPEED) {
|
if (mouseSpeed < MOUSE_MAX_SPEED) {
|
||||||
mouseSpeed++;
|
mouseSpeed++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (key.mouse.moveActions & UHK_MOUSE_DECELERATE) {
|
if (key.mouse.moveActions & MOUSE_DECELERATE) {
|
||||||
if (mouseSpeed > 1) {
|
if (mouseSpeed > 1) {
|
||||||
mouseSpeed--;
|
mouseSpeed--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (key.mouse.moveActions) {
|
} else if (key.mouse.moveActions) {
|
||||||
if (key.mouse.moveActions & UHK_MOUSE_MOVE_LEFT) {
|
if (key.mouse.moveActions & MOUSE_MOVE_LEFT) {
|
||||||
report->x = -mouseSpeed;
|
report->x = -mouseSpeed;
|
||||||
}
|
}
|
||||||
if (key.mouse.moveActions & UHK_MOUSE_MOVE_RIGHT) {
|
if (key.mouse.moveActions & MOUSE_MOVE_RIGHT) {
|
||||||
report->x = mouseSpeed;
|
report->x = mouseSpeed;
|
||||||
}
|
}
|
||||||
if (key.mouse.moveActions & UHK_MOUSE_MOVE_UP) {
|
if (key.mouse.moveActions & MOUSE_MOVE_UP) {
|
||||||
report->y = -mouseSpeed;
|
report->y = -mouseSpeed;
|
||||||
}
|
}
|
||||||
if (key.mouse.moveActions & UHK_MOUSE_MOVE_DOWN) {
|
if (key.mouse.moveActions & MOUSE_MOVE_DOWN) {
|
||||||
report->y = mouseSpeed;
|
report->y = mouseSpeed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -168,9 +168,9 @@ void HandleKeyboardEvents(usb_keyboard_report_t *keyboardReport, usb_mouse_repor
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
uhk_key_t code = getKeycode(SLOT_ID_RIGHT_KEYBOARD_HALF, keyId);
|
key_action_t code = getKeycode(SLOT_ID_RIGHT_KEYBOARD_HALF, keyId);
|
||||||
|
|
||||||
if (code.type == UHK_KEY_MOUSE) {
|
if (code.type == KEY_ACTION_MOUSE) {
|
||||||
handleMouseKey(mouseReport, code, prevKeyStates[SLOT_ID_RIGHT_KEYBOARD_HALF], rightKeyStates, keyId);
|
handleMouseKey(mouseReport, code, prevKeyStates[SLOT_ID_RIGHT_KEYBOARD_HALF], rightKeyStates, keyId);
|
||||||
} else {
|
} else {
|
||||||
if (handleKey(code, scancodeIdx, keyboardReport, prevKeyStates[SLOT_ID_RIGHT_KEYBOARD_HALF], rightKeyStates, keyId)) {
|
if (handleKey(code, scancodeIdx, keyboardReport, prevKeyStates[SLOT_ID_RIGHT_KEYBOARD_HALF], rightKeyStates, keyId)) {
|
||||||
@@ -184,9 +184,9 @@ void HandleKeyboardEvents(usb_keyboard_report_t *keyboardReport, usb_mouse_repor
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
uhk_key_t code = getKeycode(SLOT_ID_LEFT_KEYBOARD_HALF, keyId);
|
key_action_t code = getKeycode(SLOT_ID_LEFT_KEYBOARD_HALF, keyId);
|
||||||
|
|
||||||
if (code.type == UHK_KEY_MOUSE) {
|
if (code.type == KEY_ACTION_MOUSE) {
|
||||||
handleMouseKey(mouseReport, code, prevKeyStates[SLOT_ID_LEFT_KEYBOARD_HALF], leftKeyStates, keyId);
|
handleMouseKey(mouseReport, code, prevKeyStates[SLOT_ID_LEFT_KEYBOARD_HALF], leftKeyStates, keyId);
|
||||||
} else {
|
} else {
|
||||||
if (handleKey(code, scancodeIdx, keyboardReport, prevKeyStates[SLOT_ID_LEFT_KEYBOARD_HALF], leftKeyStates, keyId)) {
|
if (handleKey(code, scancodeIdx, keyboardReport, prevKeyStates[SLOT_ID_LEFT_KEYBOARD_HALF], leftKeyStates, keyId)) {
|
||||||
|
|||||||
@@ -22,41 +22,38 @@
|
|||||||
#define KEY_STATE_COUNT (5*7)
|
#define KEY_STATE_COUNT (5*7)
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
UHK_KEY_NONE,
|
KEY_ACTION_NONE,
|
||||||
UHK_KEY_SIMPLE,
|
KEY_ACTION_KEYSTROKE,
|
||||||
UHK_KEY_MOUSE,
|
KEY_ACTION_MOUSE,
|
||||||
UHK_KEY_LAYER,
|
KEY_ACTION_SWITCH_LAYER,
|
||||||
UHK_KEY_LAYER_TOGGLE,
|
KEY_ACTION_SWITCH_KEYMAP,
|
||||||
UHK_KEY_KEYMAP,
|
KEY_ACTION_PLAY_MACRO,
|
||||||
UHK_KEY_MACRO,
|
} key_action_type_t;
|
||||||
UHK_KEY_LPRESSMOD,
|
|
||||||
UHK_KEY_LPRESSLAYER,
|
|
||||||
} uhk_key_type_t;
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
UHK_MOUSE_BUTTON_LEFT = (1 << 0),
|
MOUSE_BUTTON_LEFT = (1 << 0),
|
||||||
UHK_MOUSE_BUTTON_RIGHT = (1 << 1),
|
MOUSE_BUTTON_RIGHT = (1 << 1),
|
||||||
UHK_MOUSE_BUTTON_MIDDLE = (1 << 2),
|
MOUSE_BUTTON_MIDDLE = (1 << 2),
|
||||||
UHK_MOUSE_BUTTON_4 = (1 << 3),
|
MOUSE_BUTTON_4 = (1 << 3),
|
||||||
UHK_MOUSE_BUTTON_5 = (1 << 4),
|
MOUSE_BUTTON_5 = (1 << 4),
|
||||||
UHK_MOUSE_BUTTON_6 = (1 << 5),
|
MOUSE_BUTTON_6 = (1 << 5),
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
UHK_MOUSE_MOVE_UP = (1 << 0),
|
MOUSE_MOVE_UP = (1 << 0),
|
||||||
UHK_MOUSE_MOVE_DOWN = (1 << 1),
|
MOUSE_MOVE_DOWN = (1 << 1),
|
||||||
UHK_MOUSE_MOVE_LEFT = (1 << 2),
|
MOUSE_MOVE_LEFT = (1 << 2),
|
||||||
UHK_MOUSE_MOVE_RIGHT = (1 << 3),
|
MOUSE_MOVE_RIGHT = (1 << 3),
|
||||||
|
|
||||||
UHK_MOUSE_ACCELERATE = (1 << 4),
|
MOUSE_ACCELERATE = (1 << 4),
|
||||||
UHK_MOUSE_DECELERATE = (1 << 5),
|
MOUSE_DECELERATE = (1 << 5),
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
UHK_MOUSE_SCROLL_UP = (1 << 0),
|
MOUSE_SCROLL_UP = (1 << 0),
|
||||||
UHK_MOUSE_SCROLL_DOWN = (1 << 1),
|
MOUSE_SCROLL_DOWN = (1 << 1),
|
||||||
UHK_MOUSE_SCROLL_LEFT = (1 << 2),
|
MOUSE_SCROLL_LEFT = (1 << 2),
|
||||||
UHK_MOUSE_SCROLL_RIGHT = (1 << 3),
|
MOUSE_SCROLL_RIGHT = (1 << 3),
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MOUSE_WHEEL_SPEED 1
|
#define MOUSE_WHEEL_SPEED 1
|
||||||
@@ -101,10 +98,10 @@ typedef struct {
|
|||||||
uint8_t key;
|
uint8_t key;
|
||||||
} __attribute__ ((packed)) longpressLayer;
|
} __attribute__ ((packed)) longpressLayer;
|
||||||
};
|
};
|
||||||
} __attribute__ ((packed)) uhk_key_t;
|
} __attribute__ ((packed)) key_action_t;
|
||||||
|
|
||||||
extern uint8_t prevKeyStates[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE];
|
extern uint8_t prevKeyStates[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE];
|
||||||
extern uhk_key_t CurrentKeymap[LAYER_COUNT][SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE];
|
extern key_action_t CurrentKeymap[LAYER_COUNT][SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE];
|
||||||
|
|
||||||
void HandleKeyboardEvents(usb_keyboard_report_t *keyboardReport, usb_mouse_report_t *mouseReport, const uint8_t *leftKeyStates, const uint8_t *rightKeyStates);
|
void HandleKeyboardEvents(usb_keyboard_report_t *keyboardReport, usb_mouse_report_t *mouseReport, const uint8_t *leftKeyStates, const uint8_t *rightKeyStates);
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -53,7 +53,7 @@ static volatile usb_status_t UsbMouseAction(void)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fillMouseReport(uhk_key_t key, const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId)
|
void fillMouseReport(key_action_t key, const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId)
|
||||||
{
|
{
|
||||||
HandleMouseKey(&UsbMouseReport, key, prevKeyStates, currKeyStates, keyId);
|
HandleMouseKey(&UsbMouseReport, key, prevKeyStates, currKeyStates, keyId);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user