From f67680d5b004a72419550a8268802030a8421643 Mon Sep 17 00:00:00 2001 From: Leeroy Date: Sun, 22 Oct 2023 20:43:44 +1100 Subject: [PATCH] Accelerated Mouse Pointer. Screen Nav is easy now! --- .../external/hid_app/views/hid_mouse.c | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/applications/external/hid_app/views/hid_mouse.c b/applications/external/hid_app/views/hid_mouse.c index f7de93d6324b..7db5e9c44e30 100644 --- a/applications/external/hid_app/views/hid_mouse.c +++ b/applications/external/hid_app/views/hid_mouse.c @@ -23,6 +23,8 @@ typedef struct { HidTransport transport; } HidMouseModel; +static uint32_t button_press_repeat_count; + static void hid_mouse_draw_callback(Canvas* canvas, void* context) { furi_assert(context); HidMouseModel* model = context; @@ -117,6 +119,17 @@ static void hid_mouse_process(HidMouse* hid_mouse, InputEvent* event) { hid_mouse->view, HidMouseModel * model, { + //Save a repeat counter for the acceleration of the mouse pointer... + if(event->type == InputTypeRelease) { + button_press_repeat_count = 0; + } else if(event->type == InputTypePress) { + button_press_repeat_count = 2; + } else if(event->type == InputTypeRepeat) { + button_press_repeat_count = + (button_press_repeat_count > 10) ? 10 : button_press_repeat_count + 1; + } + + //Process the button presses. if(event->key == InputKeyBack) { if(event->type == InputTypeShort) { hid_hal_mouse_press(hid_mouse->hid, HID_MOUSE_BTN_RIGHT); @@ -148,7 +161,9 @@ static void hid_mouse_process(HidMouse* hid_mouse, InputEvent* event) { model->right_pressed = true; hid_hal_mouse_move(hid_mouse->hid, MOUSE_MOVE_SHORT, 0); } else if(event->type == InputTypeRepeat) { - hid_hal_mouse_move(hid_mouse->hid, MOUSE_MOVE_LONG, 0); + //Accelerated + for(int32_t i = button_press_repeat_count; i > 1; i = i - 2) + hid_hal_mouse_move(hid_mouse->hid, MOUSE_MOVE_LONG, 0); } else if(event->type == InputTypeRelease) { model->right_pressed = false; } @@ -157,7 +172,9 @@ static void hid_mouse_process(HidMouse* hid_mouse, InputEvent* event) { model->left_pressed = true; hid_hal_mouse_move(hid_mouse->hid, -MOUSE_MOVE_SHORT, 0); } else if(event->type == InputTypeRepeat) { - hid_hal_mouse_move(hid_mouse->hid, -MOUSE_MOVE_LONG, 0); + //Accelerated + for(int32_t i = button_press_repeat_count; i > 1; i = i - 2) + hid_hal_mouse_move(hid_mouse->hid, -MOUSE_MOVE_LONG, 0); } else if(event->type == InputTypeRelease) { model->left_pressed = false; } @@ -166,7 +183,9 @@ static void hid_mouse_process(HidMouse* hid_mouse, InputEvent* event) { model->down_pressed = true; hid_hal_mouse_move(hid_mouse->hid, 0, MOUSE_MOVE_SHORT); } else if(event->type == InputTypeRepeat) { - hid_hal_mouse_move(hid_mouse->hid, 0, MOUSE_MOVE_LONG); + //Accelerated + for(int32_t i = button_press_repeat_count; i > 1; i = i - 2) + hid_hal_mouse_move(hid_mouse->hid, 0, MOUSE_MOVE_LONG); } else if(event->type == InputTypeRelease) { model->down_pressed = false; } @@ -175,7 +194,9 @@ static void hid_mouse_process(HidMouse* hid_mouse, InputEvent* event) { model->up_pressed = true; hid_hal_mouse_move(hid_mouse->hid, 0, -MOUSE_MOVE_SHORT); } else if(event->type == InputTypeRepeat) { - hid_hal_mouse_move(hid_mouse->hid, 0, -MOUSE_MOVE_LONG); + //Accelerated + for(int32_t i = button_press_repeat_count; i > 1; i = i - 2) + hid_hal_mouse_move(hid_mouse->hid, 0, -MOUSE_MOVE_LONG); } else if(event->type == InputTypeRelease) { model->up_pressed = false; }