From 05c5f4527e7ad06a1161206f9c2c969ec84aa16d Mon Sep 17 00:00:00 2001 From: Ivan Podogov Date: Fri, 30 Dec 2022 22:24:38 +0000 Subject: [PATCH] Format and make scrolling more intuitive --- tracking/main_loop.h | 4 ++-- views/bt_mouse.c | 32 +++++++++++++++----------------- views/usb_mouse.c | 8 ++++---- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/tracking/main_loop.h b/tracking/main_loop.h index 26fd511ab87..cd592161f1e 100644 --- a/tracking/main_loop.h +++ b/tracking/main_loop.h @@ -6,14 +6,14 @@ extern "C" { #endif -typedef bool (*MouseMoveCallback)(int8_t x, int8_t y, void *context); +typedef bool (*MouseMoveCallback)(int8_t x, int8_t y, void* context); void calibration_begin(); bool calibration_step(); void calibration_end(); void tracking_begin(); -void tracking_step(MouseMoveCallback mouse_move, void *context); +void tracking_step(MouseMoveCallback mouse_move, void* context); void tracking_end(); #ifdef __cplusplus diff --git a/views/bt_mouse.c b/views/bt_mouse.c index 758036d0a55..7d9c0e6db67 100644 --- a/views/bt_mouse.c +++ b/views/bt_mouse.c @@ -44,9 +44,7 @@ struct BtMouse { #define BT_MOUSE_FLAG_KILL_THREAD (1UL << 1) #define BT_MOUSE_FLAG_ALL (BT_MOUSE_FLAG_INPUT_EVENT | BT_MOUSE_FLAG_KILL_THREAD) -#define MOUSE_MOVE_SHORT 5 -#define MOUSE_MOVE_LONG 20 -#define MOUSE_SCROLL 20 +#define MOUSE_SCROLL 2 static void bt_mouse_notify_event(BtMouse* bt_mouse) { FuriThreadId thread_id = furi_thread_get_id(bt_mouse->thread); @@ -68,7 +66,7 @@ static void bt_mouse_button_state(BtMouse* bt_mouse, int8_t button, bool state) event.button = button; event.state = state; - if (bt_mouse->connected) { + if(bt_mouse->connected) { furi_mutex_acquire(bt_mouse->mutex, FuriWaitForever); bt_mouse->queue[bt_mouse->qtail++] = event; bt_mouse->qtail %= BTN_EVT_QUEUE_SIZE; @@ -102,11 +100,11 @@ static void bt_mouse_process(BtMouse* bt_mouse, InputEvent* event) { bt_mouse_button_state(bt_mouse, HID_MOUSE_BTN_WHEEL, false); } } else if(event->key == InputKeyRight) { - if(event->type == InputTypePress) { + if(event->type == InputTypePress || event->type == InputTypeRepeat) { bt_mouse->wheel = MOUSE_SCROLL; } } else if(event->key == InputKeyLeft) { - if(event->type == InputTypePress) { + if(event->type == InputTypePress || event->type == InputTypeRepeat) { bt_mouse->wheel = -MOUSE_SCROLL; } } @@ -147,11 +145,11 @@ void bt_mouse_connection_status_changed_callback(BtStatus status, void* context) // bt_mouse->view, void * model, { model->connected = connected; }, true); } -bool bt_mouse_move(int8_t dx, int8_t dy, void *context) { +bool bt_mouse_move(int8_t dx, int8_t dy, void* context) { furi_assert(context); BtMouse* bt_mouse = context; - if (bt_mouse->connected) { + if(bt_mouse->connected) { furi_mutex_acquire(bt_mouse->mutex, FuriWaitForever); bt_mouse->dx += dx; bt_mouse->dy += dy; @@ -203,10 +201,9 @@ void bt_mouse_exit_callback(void* context) { } static int8_t clamp(int t) { - if (t < -128) { + if(t < -128) { return -128; - } - else if (t > 127) { + } else if(t > 127) { return 127; } return t; @@ -217,7 +214,8 @@ static int32_t bt_mouse_thread_callback(void* context) { BtMouse* bt_mouse = (BtMouse*)context; while(1) { - uint32_t flags = furi_thread_flags_wait(BT_MOUSE_FLAG_ALL, FuriFlagWaitAny, FuriWaitForever); + uint32_t flags = + furi_thread_flags_wait(BT_MOUSE_FLAG_ALL, FuriFlagWaitAny, FuriWaitForever); if(flags & BT_MOUSE_FLAG_KILL_THREAD) { break; } @@ -226,7 +224,7 @@ static int32_t bt_mouse_thread_callback(void* context) { ButtonEvent event; bool send_buttons = false; - if (bt_mouse->qhead != bt_mouse->qtail) { + if(bt_mouse->qhead != bt_mouse->qtail) { event = bt_mouse->queue[bt_mouse->qhead++]; bt_mouse->qhead %= BTN_EVT_QUEUE_SIZE; send_buttons = true; @@ -241,19 +239,19 @@ static int32_t bt_mouse_thread_callback(void* context) { furi_mutex_release(bt_mouse->mutex); - if (bt_mouse->connected && send_buttons) { - if (event.state) { + if(bt_mouse->connected && send_buttons) { + if(event.state) { furi_hal_bt_hid_mouse_press(event.button); } else { furi_hal_bt_hid_mouse_release(event.button); } } - if (bt_mouse->connected && (dx != 0 || dy != 0)) { + if(bt_mouse->connected && (dx != 0 || dy != 0)) { furi_hal_bt_hid_mouse_move(dx, dy); } - if (bt_mouse->connected && wheel != 0) { + if(bt_mouse->connected && wheel != 0) { furi_hal_bt_hid_mouse_scroll(wheel); } } diff --git a/views/usb_mouse.c b/views/usb_mouse.c index 75daac1c3d4..09075b56698 100644 --- a/views/usb_mouse.c +++ b/views/usb_mouse.c @@ -21,7 +21,7 @@ static void usb_mouse_draw_callback(Canvas* canvas, void* context) { canvas_draw_str(canvas, 0, 63, "Hold [back] to exit"); } -#define MOUSE_SCROLL 20 +#define MOUSE_SCROLL 2 static void usb_mouse_process(UsbMouse* usb_mouse, InputEvent* event) { with_view_model( @@ -48,11 +48,11 @@ static void usb_mouse_process(UsbMouse* usb_mouse, InputEvent* event) { furi_hal_hid_mouse_release(HID_MOUSE_BTN_WHEEL); } } else if(event->key == InputKeyRight) { - if(event->type == InputTypePress) { + if(event->type == InputTypePress || event->type == InputTypeRepeat) { furi_hal_hid_mouse_scroll(MOUSE_SCROLL); } } else if(event->key == InputKeyLeft) { - if(event->type == InputTypePress) { + if(event->type == InputTypePress || event->type == InputTypeRepeat) { furi_hal_hid_mouse_scroll(-MOUSE_SCROLL); } } @@ -88,7 +88,7 @@ void usb_mouse_enter_callback(void* context) { view_dispatcher_send_custom_event(usb_mouse->view_dispatcher, 0); } -bool usb_mouse_move(int8_t dx, int8_t dy, void *context) { +bool usb_mouse_move(int8_t dx, int8_t dy, void* context) { UNUSED(context); return furi_hal_hid_mouse_move(dx, dy); }