Handle secondary role modifiers.
This commit is contained in:
@@ -40,7 +40,7 @@ static parser_error_t parseKeyStrokeAction(key_action_t *keyAction, uint8_t keyS
|
|||||||
? 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)
|
? readUInt8(buffer) + 1
|
||||||
: 0;
|
: 0;
|
||||||
return ParserError_Success;
|
return ParserError_Success;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#include "main.h"
|
|
||||||
#include "key_action.h"
|
#include "key_action.h"
|
||||||
#include "led_display.h"
|
#include "led_display.h"
|
||||||
#include "layer.h"
|
#include "layer.h"
|
||||||
@@ -7,80 +6,127 @@
|
|||||||
#include "peripherals/test_led.h"
|
#include "peripherals/test_led.h"
|
||||||
#include "slave_drivers/is31fl3731_driver.h"
|
#include "slave_drivers/is31fl3731_driver.h"
|
||||||
#include "slave_drivers/uhk_module_driver.h"
|
#include "slave_drivers/uhk_module_driver.h"
|
||||||
#include "led_pwm.h"
|
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
#include "key_states.h"
|
#include "key_states.h"
|
||||||
#include "right_key_matrix.h"
|
#include "right_key_matrix.h"
|
||||||
#include "layer.h"
|
#include "layer.h"
|
||||||
|
#include "usb_report_updater.h"
|
||||||
|
|
||||||
static uint8_t mouseWheelDivisorCounter = 0;
|
static uint8_t mouseWheelDivisorCounter = 0;
|
||||||
static uint8_t mouseSpeedAccelDivisorCounter = 0;
|
static uint8_t mouseSpeedAccelDivisorCounter = 0;
|
||||||
static uint8_t mouseSpeed = 3;
|
static uint8_t mouseSpeed = 3;
|
||||||
static bool wasPreviousMouseActionWheelAction = false;
|
static bool wasPreviousMouseActionWheelAction = false;
|
||||||
|
|
||||||
void processMouseAction(key_action_t action)
|
void processMouseAction(key_action_t *action)
|
||||||
{
|
{
|
||||||
bool isWheelAction = action.mouse.scrollActions && !action.mouse.moveActions && !action.mouse.buttonActions;
|
bool isWheelAction = action->mouse.scrollActions && !action->mouse.moveActions && !action->mouse.buttonActions;
|
||||||
|
|
||||||
if (isWheelAction && wasPreviousMouseActionWheelAction) {
|
if (isWheelAction && wasPreviousMouseActionWheelAction) {
|
||||||
mouseWheelDivisorCounter++;
|
mouseWheelDivisorCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 & MouseScroll_Up) {
|
if (action->mouse.scrollActions & MouseScroll_Up) {
|
||||||
ActiveUsbMouseReport->wheelX = 1;
|
ActiveUsbMouseReport->wheelX = 1;
|
||||||
}
|
}
|
||||||
if (action.mouse.scrollActions & MouseScroll_Down) {
|
if (action->mouse.scrollActions & MouseScroll_Down) {
|
||||||
ActiveUsbMouseReport->wheelX = -1;
|
ActiveUsbMouseReport->wheelX = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.mouse.moveActions & MouseMove_Accelerate || action.mouse.moveActions & MouseMove_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 & MouseMove_Accelerate) {
|
if (action->mouse.moveActions & MouseMove_Accelerate) {
|
||||||
if (mouseSpeed < MOUSE_MAX_SPEED) {
|
if (mouseSpeed < MOUSE_MAX_SPEED) {
|
||||||
mouseSpeed++;
|
mouseSpeed++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (action.mouse.moveActions & MouseMove_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 & MouseMove_Left) {
|
if (action->mouse.moveActions & MouseMove_Left) {
|
||||||
ActiveUsbMouseReport->x = -mouseSpeed;
|
ActiveUsbMouseReport->x = -mouseSpeed;
|
||||||
}
|
}
|
||||||
if (action.mouse.moveActions & MouseMove_Right) {
|
if (action->mouse.moveActions & MouseMove_Right) {
|
||||||
ActiveUsbMouseReport->x = mouseSpeed;
|
ActiveUsbMouseReport->x = mouseSpeed;
|
||||||
}
|
}
|
||||||
if (action.mouse.moveActions & MouseMove_Up) {
|
if (action->mouse.moveActions & MouseMove_Up) {
|
||||||
ActiveUsbMouseReport->y = -mouseSpeed;
|
ActiveUsbMouseReport->y = -mouseSpeed;
|
||||||
}
|
}
|
||||||
if (action.mouse.moveActions & MouseMove_Down) {
|
if (action->mouse.moveActions & MouseMove_Down) {
|
||||||
ActiveUsbMouseReport->y = mouseSpeed;
|
ActiveUsbMouseReport->y = mouseSpeed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ActiveUsbMouseReport->buttons |= action.mouse.buttonActions;
|
ActiveUsbMouseReport->buttons |= action->mouse.buttonActions;
|
||||||
|
|
||||||
wasPreviousMouseActionWheelAction = isWheelAction;
|
wasPreviousMouseActionWheelAction = isWheelAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t basicScancodeIndex = 0;
|
||||||
|
uint8_t mediaScancodeIndex = 0;
|
||||||
|
uint8_t systemScancodeIndex = 0;
|
||||||
|
|
||||||
|
void applyKeyAction(key_state_t *keyState, key_action_t *action)
|
||||||
|
{
|
||||||
|
switch (action->type) {
|
||||||
|
case KeyActionType_Keystroke:
|
||||||
|
ActiveUsbBasicKeyboardReport->modifiers |= action->keystroke.modifiers;
|
||||||
|
|
||||||
|
switch (action->keystroke.keystrokeType) {
|
||||||
|
case KeystrokeType_Basic:
|
||||||
|
if (basicScancodeIndex >= USB_BASIC_KEYBOARD_MAX_KEYS || action->keystroke.scancode == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ActiveUsbBasicKeyboardReport->scancodes[basicScancodeIndex++] = action->keystroke.scancode;
|
||||||
|
break;
|
||||||
|
case KeystrokeType_Media:
|
||||||
|
if (mediaScancodeIndex >= USB_MEDIA_KEYBOARD_MAX_KEYS) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ActiveUsbMediaKeyboardReport->scancodes[mediaScancodeIndex++] = action->keystroke.scancode;
|
||||||
|
break;
|
||||||
|
case KeystrokeType_System:
|
||||||
|
if (systemScancodeIndex >= USB_SYSTEM_KEYBOARD_MAX_KEYS) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ActiveUsbSystemKeyboardReport->scancodes[systemScancodeIndex++] = action->keystroke.scancode;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case KeyActionType_Mouse:
|
||||||
|
processMouseAction(action);
|
||||||
|
break;
|
||||||
|
case KeyActionType_SwitchKeymap:
|
||||||
|
if (!keyState->previous && keyState->current) {
|
||||||
|
SwitchKeymap(action->switchKeymap.keymapId);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t secondaryRoleState = SecondaryRoleState_Released;
|
||||||
|
uint8_t secondaryRoleSlotId;
|
||||||
|
uint8_t secondaryRoleKeyId;
|
||||||
|
secondary_role_t secondaryRole;
|
||||||
|
|
||||||
void UpdateActiveUsbReports(void)
|
void UpdateActiveUsbReports(void)
|
||||||
{
|
{
|
||||||
static uint8_t previousModifiers = 0;
|
static uint8_t previousModifiers = 0;
|
||||||
uint8_t basicScancodeIndex = 0;
|
basicScancodeIndex = 0;
|
||||||
uint8_t mediaScancodeIndex = 0;
|
mediaScancodeIndex = 0;
|
||||||
uint8_t systemScancodeIndex = 0;
|
systemScancodeIndex = 0;
|
||||||
|
|
||||||
for (uint8_t keyId=0; keyId < RIGHT_KEY_MATRIX_KEY_COUNT; keyId++) {
|
for (uint8_t keyId=0; keyId < RIGHT_KEY_MATRIX_KEY_COUNT; keyId++) {
|
||||||
KeyStates[SlotId_RightKeyboardHalf][keyId].current = RightKeyMatrix.keyStates[keyId];
|
KeyStates[SlotId_RightKeyboardHalf][keyId].current = RightKeyMatrix.keyStates[keyId];
|
||||||
@@ -101,42 +147,25 @@ void UpdateActiveUsbReports(void)
|
|||||||
for (uint8_t slotId=0; slotId<SLOT_COUNT; slotId++) {
|
for (uint8_t slotId=0; slotId<SLOT_COUNT; slotId++) {
|
||||||
for (uint8_t keyId=0; keyId<MAX_KEY_COUNT_PER_MODULE; keyId++) {
|
for (uint8_t keyId=0; keyId<MAX_KEY_COUNT_PER_MODULE; keyId++) {
|
||||||
key_state_t *keyState = &KeyStates[slotId][keyId];
|
key_state_t *keyState = &KeyStates[slotId][keyId];
|
||||||
if (keyState->current) {
|
key_action_t *action = &CurrentKeymap[activeLayer][slotId][keyId];
|
||||||
key_action_t action = CurrentKeymap[activeLayer][slotId][keyId];
|
|
||||||
switch (action.type) {
|
|
||||||
case KeyActionType_Keystroke:
|
|
||||||
ActiveUsbBasicKeyboardReport->modifiers |= action.keystroke.modifiers;
|
|
||||||
|
|
||||||
switch (action.keystroke.keystrokeType) {
|
if (action->type == KeyActionType_Keystroke && action->keystroke.secondaryRole) {
|
||||||
case KeystrokeType_Basic:
|
if (!keyState->previous && keyState->current && secondaryRoleState == SecondaryRoleState_Released) {
|
||||||
if (basicScancodeIndex >= USB_BASIC_KEYBOARD_MAX_KEYS || action.keystroke.scancode == 0) {
|
secondaryRoleState = SecondaryRoleState_Pressed;
|
||||||
break;
|
secondaryRoleSlotId = slotId;
|
||||||
}
|
secondaryRoleKeyId = keyId;
|
||||||
ActiveUsbBasicKeyboardReport->scancodes[basicScancodeIndex++] = action.keystroke.scancode;
|
secondaryRole = action->keystroke.secondaryRole;
|
||||||
break;
|
} else if (keyState->previous && !keyState->current && secondaryRoleSlotId == slotId && secondaryRoleKeyId == keyId) {
|
||||||
case KeystrokeType_Media:
|
if (secondaryRoleState == SecondaryRoleState_Pressed) {
|
||||||
if (mediaScancodeIndex >= USB_MEDIA_KEYBOARD_MAX_KEYS) {
|
applyKeyAction(keyState, action);
|
||||||
break;
|
}
|
||||||
}
|
secondaryRoleState = SecondaryRoleState_Released;
|
||||||
ActiveUsbMediaKeyboardReport->scancodes[mediaScancodeIndex++] = action.keystroke.scancode;
|
|
||||||
break;
|
|
||||||
case KeystrokeType_System:
|
|
||||||
if (systemScancodeIndex >= USB_SYSTEM_KEYBOARD_MAX_KEYS) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ActiveUsbSystemKeyboardReport->scancodes[systemScancodeIndex++] = action.keystroke.scancode;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case KeyActionType_Mouse:
|
|
||||||
processMouseAction(action);
|
|
||||||
break;
|
|
||||||
case KeyActionType_SwitchKeymap:
|
|
||||||
if (!keyState->previous && keyState->current) {
|
|
||||||
SwitchKeymap(action.switchKeymap.keymapId);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
} else if (keyState->current) {
|
||||||
|
if (!keyState->previous && secondaryRoleState == SecondaryRoleState_Pressed) {
|
||||||
|
secondaryRoleState = SecondaryRoleState_Triggered;
|
||||||
|
}
|
||||||
|
applyKeyAction(keyState, action);
|
||||||
}
|
}
|
||||||
keyState->previous = keyState->current;
|
keyState->previous = keyState->current;
|
||||||
}
|
}
|
||||||
@@ -149,5 +178,9 @@ void UpdateActiveUsbReports(void)
|
|||||||
ActiveUsbBasicKeyboardReport->modifiers |= previousModifiers;
|
ActiveUsbBasicKeyboardReport->modifiers |= previousModifiers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (secondaryRoleState == SecondaryRoleState_Triggered && IS_SECONDARY_ROLE_MODIFIER(secondaryRole)) {
|
||||||
|
ActiveUsbBasicKeyboardReport->modifiers |= SECONDARY_ROLE_MODIFIER_TO_HID_MODIFIER(secondaryRole);
|
||||||
|
}
|
||||||
|
|
||||||
previousModifiers = ActiveUsbBasicKeyboardReport->modifiers;
|
previousModifiers = ActiveUsbBasicKeyboardReport->modifiers;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
#ifndef __USB_REPORT_UPDATER_H__
|
||||||
|
#define __USB_REPORT_UPDATER_H__
|
||||||
|
|
||||||
|
// Macros:
|
||||||
|
|
||||||
|
#define IS_SECONDARY_ROLE_MODIFIER(secondaryRole) (SecondaryRole_LeftCtrl <= (secondaryRole) && (secondaryRole) <= SecondaryRole_RightSuper)
|
||||||
|
#define IS_SECONDARY_ROLE_LAYER_SWITCHER(secondaryRole) (SecondaryRole_Mod <= (secondaryRole) && (secondaryRole) <= SecondaryRole_Mouse)
|
||||||
|
#define SECONDARY_ROLE_MODIFIER_TO_HID_MODIFIER(secondaryRoleModifier) (1 << ((secondaryRoleModifier) - 1))
|
||||||
|
|
||||||
|
// Typedefs:
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
SecondaryRoleState_Released,
|
||||||
|
SecondaryRoleState_Pressed,
|
||||||
|
SecondaryRoleState_Triggered,
|
||||||
|
} secondary_role_state_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
SecondaryRole_LeftCtrl = 1,
|
||||||
|
SecondaryRole_LeftShift,
|
||||||
|
SecondaryRole_LeftAlt,
|
||||||
|
SecondaryRole_LeftSuper,
|
||||||
|
SecondaryRole_RightCtrl,
|
||||||
|
SecondaryRole_RightShift,
|
||||||
|
SecondaryRole_RightAlt,
|
||||||
|
SecondaryRole_RightSuper,
|
||||||
|
SecondaryRole_Mod,
|
||||||
|
SecondaryRole_Fn,
|
||||||
|
SecondaryRole_Mouse
|
||||||
|
} secondary_role_t;
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user