Skip to content

Commit

Permalink
adjust button function (add scrolling)
Browse files Browse the repository at this point in the history
  • Loading branch information
rorosaurus authored Dec 23, 2022
1 parent 971a8f6 commit 7007db8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
13 changes: 11 additions & 2 deletions views/bt_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
14 changes: 12 additions & 2 deletions views/usb_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit 7007db8

Please sign in to comment.