Initial implementation of mouse actions
This implements the mouse action handling. There is no acceleration while holding the mouse movement keys yet, though, that will be a separate step. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#include "keyboard_layout.h"
|
#include "keyboard_layout.h"
|
||||||
#include "led_display.h"
|
#include "led_display.h"
|
||||||
#include "layer.h"
|
#include "layer.h"
|
||||||
|
#include "usb_interface_mouse.h"
|
||||||
|
|
||||||
static uint8_t keyMasks[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE];
|
static uint8_t keyMasks[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE];
|
||||||
|
|
||||||
@@ -85,12 +86,89 @@ bool handleKey(uhk_key_t key, int scancodeIdx, usb_keyboard_report_t *report, co
|
|||||||
LedDisplay_SetLayerLed(ActiveLayer);
|
LedDisplay_SetLayerLed(ActiveLayer);
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
|
case UHK_KEY_MOUSE:
|
||||||
|
fillMouseReport(key, prevKeyStates, currKeyStates, keyId);
|
||||||
|
return false;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define MOUSE_WHEEL_SPEED 1
|
||||||
|
#define MOUSE_WHEEL_DIVISOR 4
|
||||||
|
|
||||||
|
#define MOUSE_MAX_SPEED 10
|
||||||
|
#define MOUSE_SPEED_ACCEL_DIVISOR 50
|
||||||
|
|
||||||
|
static uint8_t mouseWheelDivisorCounter = 0;
|
||||||
|
static uint8_t mouseSpeedAccelDivisorCounter = 0;
|
||||||
|
static uint8_t mouseSpeed = 3;
|
||||||
|
static bool wasPreviousMouseActionWheelAction = false;
|
||||||
|
|
||||||
|
void HandleMouseKey(usb_mouse_report_t *report, uhk_key_t key, const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId)
|
||||||
|
{
|
||||||
|
bool isWheelAction;
|
||||||
|
|
||||||
|
if (!key_is_pressed(prevKeyStates, currKeyStates, keyId))
|
||||||
|
return;
|
||||||
|
|
||||||
|
isWheelAction = !!(key.mouse.scrollActions) && !(key.mouse.moveActions) && !(key.mouse.buttonActions);
|
||||||
|
|
||||||
|
if (isWheelAction && wasPreviousMouseActionWheelAction) {
|
||||||
|
mouseWheelDivisorCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key.mouse.scrollActions) {
|
||||||
|
if (mouseWheelDivisorCounter == MOUSE_WHEEL_DIVISOR) {
|
||||||
|
mouseWheelDivisorCounter = 0;
|
||||||
|
if (key.mouse.scrollActions & UHK_MOUSE_SCROLL_UP) {
|
||||||
|
report->wheelX = 1;
|
||||||
|
}
|
||||||
|
if (key.mouse.scrollActions & UHK_MOUSE_SCROLL_DOWN) {
|
||||||
|
report->wheelX = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key.mouse.moveActions & UHK_MOUSE_ACCELERATE || key.mouse.moveActions & UHK_MOUSE_DECELERATE) {
|
||||||
|
mouseSpeedAccelDivisorCounter++;
|
||||||
|
|
||||||
|
if (mouseSpeedAccelDivisorCounter == MOUSE_SPEED_ACCEL_DIVISOR) {
|
||||||
|
mouseSpeedAccelDivisorCounter = 0;
|
||||||
|
|
||||||
|
if (key.mouse.moveActions & UHK_MOUSE_ACCELERATE) {
|
||||||
|
if (mouseSpeed < MOUSE_MAX_SPEED) {
|
||||||
|
mouseSpeed++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (key.mouse.moveActions & UHK_MOUSE_DECELERATE) {
|
||||||
|
if (mouseSpeed > 1) {
|
||||||
|
mouseSpeed--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (key.mouse.moveActions) {
|
||||||
|
if (key.mouse.moveActions & UHK_MOUSE_MOVE_LEFT) {
|
||||||
|
report->x = -mouseSpeed;
|
||||||
|
}
|
||||||
|
if (key.mouse.moveActions & UHK_MOUSE_MOVE_RIGHT) {
|
||||||
|
report->x = mouseSpeed;
|
||||||
|
}
|
||||||
|
if (key.mouse.moveActions & UHK_MOUSE_MOVE_UP) {
|
||||||
|
report->y = -mouseSpeed;
|
||||||
|
}
|
||||||
|
if (key.mouse.moveActions & UHK_MOUSE_MOVE_DOWN) {
|
||||||
|
report->y = mouseSpeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
report->buttons |= key.mouse.buttonActions;
|
||||||
|
|
||||||
|
wasPreviousMouseActionWheelAction = isWheelAction;
|
||||||
|
}
|
||||||
|
|
||||||
void fillKeyboardReport(usb_keyboard_report_t *report, const uint8_t *leftKeyStates, const uint8_t *rightKeyStates) {
|
void fillKeyboardReport(usb_keyboard_report_t *report, const uint8_t *leftKeyStates, const uint8_t *rightKeyStates) {
|
||||||
int scancodeIdx = 0;
|
int scancodeIdx = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -101,5 +101,7 @@ 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 uhk_key_t CurrentKeymap[LAYER_COUNT][SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE];
|
||||||
|
|
||||||
void fillKeyboardReport(usb_keyboard_report_t *report, const uint8_t *leftKeyStates, const uint8_t *rightKeyStates);
|
void fillKeyboardReport(usb_keyboard_report_t *report, const uint8_t *leftKeyStates, const uint8_t *rightKeyStates);
|
||||||
|
void HandleMouseKey(usb_mouse_report_t *report, uhk_key_t key, const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId);
|
||||||
|
extern void fillMouseReport(uhk_key_t key, const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "fsl_i2c.h"
|
#include "fsl_i2c.h"
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "reset_button.h"
|
#include "reset_button.h"
|
||||||
|
#include "keyboard_layout.h"
|
||||||
|
|
||||||
static usb_device_endpoint_struct_t UsbMouseEndpoints[USB_MOUSE_ENDPOINT_COUNT] = {{
|
static usb_device_endpoint_struct_t UsbMouseEndpoints[USB_MOUSE_ENDPOINT_COUNT] = {{
|
||||||
USB_MOUSE_ENDPOINT_INDEX | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
|
USB_MOUSE_ENDPOINT_INDEX | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
|
||||||
@@ -38,23 +39,23 @@ usb_device_class_struct_t UsbMouseClass = {
|
|||||||
|
|
||||||
static usb_mouse_report_t UsbMouseReport;
|
static usb_mouse_report_t UsbMouseReport;
|
||||||
|
|
||||||
static uint8_t scrollCounter = 0;
|
|
||||||
static volatile usb_status_t UsbMouseAction(void)
|
static volatile usb_status_t UsbMouseAction(void)
|
||||||
{
|
{
|
||||||
|
usb_status_t ret;
|
||||||
|
ret = USB_DeviceHidSend(UsbCompositeDevice.mouseHandle, USB_MOUSE_ENDPOINT_INDEX,
|
||||||
|
(uint8_t*)&UsbMouseReport, USB_MOUSE_REPORT_LENGTH);
|
||||||
UsbMouseReport.buttons = 0;
|
UsbMouseReport.buttons = 0;
|
||||||
UsbMouseReport.x = 0;
|
UsbMouseReport.x = 0;
|
||||||
UsbMouseReport.y = 0;
|
UsbMouseReport.y = 0;
|
||||||
UsbMouseReport.wheelX = 0;
|
UsbMouseReport.wheelX = 0;
|
||||||
UsbMouseReport.wheelY = 0;
|
UsbMouseReport.wheelY = 0;
|
||||||
|
|
||||||
if (RESET_BUTTON_IS_PRESSED) {
|
return ret;
|
||||||
if (!(scrollCounter % 10)) {
|
}
|
||||||
UsbMouseReport.wheelX = -1;
|
|
||||||
}
|
void fillMouseReport(uhk_key_t key, const uint8_t *prevKeyStates, const uint8_t *currKeyStates, uint8_t keyId)
|
||||||
}
|
{
|
||||||
scrollCounter++;
|
HandleMouseKey(&UsbMouseReport, key, prevKeyStates, currKeyStates, keyId);
|
||||||
return USB_DeviceHidSend(UsbCompositeDevice.mouseHandle, USB_MOUSE_ENDPOINT_INDEX,
|
|
||||||
(uint8_t*)&UsbMouseReport, USB_MOUSE_REPORT_LENGTH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
usb_status_t UsbMouseCallback(class_handle_t handle, uint32_t event, void *param)
|
usb_status_t UsbMouseCallback(class_handle_t handle, uint32_t event, void *param)
|
||||||
|
|||||||
Reference in New Issue
Block a user