Просмотр исходного кода

Format and make scrolling more intuitive

Ivan Podogov 3 лет назад
Родитель
Сommit
05c5f4527e
3 измененных файлов с 21 добавлено и 23 удалено
  1. 2 2
      tracking/main_loop.h
  2. 15 17
      views/bt_mouse.c
  3. 4 4
      views/usb_mouse.c

+ 2 - 2
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

+ 15 - 17
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);
             }
         }

+ 4 - 4
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);
 }