Parcourir la source

adjust button function (add scrolling)

Rory O Hayes il y a 3 ans
Parent
commit
7007db8d5a
2 fichiers modifiés avec 23 ajouts et 4 suppressions
  1. 11 2
      views/bt_mouse.c
  2. 12 2
      views/usb_mouse.c

+ 11 - 2
views/bt_mouse.c

@@ -46,6 +46,7 @@ struct BtMouse {
 
 #define MOUSE_MOVE_SHORT 5
 #define MOUSE_MOVE_LONG 20
+#define MOUSE_SCROLL 20
 
 static void bt_mouse_notify_event(BtMouse* bt_mouse) {
     FuriThreadId thread_id = furi_thread_get_id(bt_mouse->thread);
@@ -82,13 +83,13 @@ static void bt_mouse_process(BtMouse* bt_mouse, InputEvent* event) {
         void* model,
         {
             UNUSED(model);
-            if(event->key == InputKeyUp) {
+            if(event->key == InputKeyLeft) {
                 if(event->type == InputTypePress) {
                     bt_mouse_button_state(bt_mouse, HID_MOUSE_BTN_LEFT, true);
                 } else if(event->type == InputTypeRelease) {
                     bt_mouse_button_state(bt_mouse, HID_MOUSE_BTN_LEFT, false);
                 }
-            } else if(event->key == InputKeyDown) {
+            } else if(event->key == InputKeyRight) {
                 if(event->type == InputTypePress) {
                     bt_mouse_button_state(bt_mouse, HID_MOUSE_BTN_RIGHT, true);
                 } else if(event->type == InputTypeRelease) {
@@ -100,6 +101,14 @@ static void bt_mouse_process(BtMouse* bt_mouse, InputEvent* event) {
                 } else if(event->type == InputTypeRelease) {
                     bt_mouse_button_state(bt_mouse, HID_MOUSE_BTN_WHEEL, false);
                 }
+            } else if(event->key == InputKeyUp) {
+                if(event->type == InputTypePress) {
+                    bt_mouse->wheel = MOUSE_SCROLL;
+                }
+            } else if(event->key == InputKeyDown) {
+                if(event->type == InputTypePress) {
+                    bt_mouse->wheel = -MOUSE_SCROLL;
+                }
             }
         },
         true);

+ 12 - 2
views/usb_mouse.c

@@ -21,19 +21,21 @@ static void usb_mouse_draw_callback(Canvas* canvas, void* context) {
     canvas_draw_str(canvas, 0, 63, "Hold [back] to exit");
 }
 
+#define MOUSE_SCROLL 20
+
 static void usb_mouse_process(UsbMouse* usb_mouse, InputEvent* event) {
     with_view_model(
         usb_mouse->view,
         void* model,
         {
             UNUSED(model);
-            if(event->key == InputKeyUp) {
+            if(event->key == InputKeyLeft) {
                 if(event->type == InputTypePress) {
                     furi_hal_hid_mouse_press(HID_MOUSE_BTN_LEFT);
                 } else if(event->type == InputTypeRelease) {
                     furi_hal_hid_mouse_release(HID_MOUSE_BTN_LEFT);
                 }
-            } else if(event->key == InputKeyDown) {
+            } else if(event->key == InputKeyRight) {
                 if(event->type == InputTypePress) {
                     furi_hal_hid_mouse_press(HID_MOUSE_BTN_RIGHT);
                 } else if(event->type == InputTypeRelease) {
@@ -45,6 +47,14 @@ static void usb_mouse_process(UsbMouse* usb_mouse, InputEvent* event) {
                 } else if(event->type == InputTypeRelease) {
                     furi_hal_hid_mouse_release(HID_MOUSE_BTN_WHEEL);
                 }
+            } else if(event->key == InputKeyUp) {
+                if(event->type == InputTypePress) {
+                    furi_hal_hid_mouse_scroll(MOUSE_SCROLL);
+                }
+            } else if(event->key == InputKeyDown) {
+                if(event->type == InputTypePress) {
+                    furi_hal_hid_mouse_scroll(-MOUSE_SCROLL);
+                }
             }
         },
         true);