Merge pull request #420 from krolchonok/fix-hid_ble

refactoring HID_BLE
This commit is contained in:
MX 2023-04-14 02:19:13 +03:00 committed by GitHub
commit bd199c63ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 23 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -93,17 +93,23 @@ static void hid_mouse_draw_callback(Canvas* canvas, void* context) {
// Ok // Ok
if(model->left_mouse_pressed) { if(model->left_mouse_pressed) {
canvas_draw_icon(canvas, 81, 25, &I_Ok_btn_pressed_13x13); canvas_set_bitmap_mode(canvas, 1);
} else { canvas_draw_icon(canvas, 81, 25, &I_Pressed_Button_13x13);
canvas_draw_icon(canvas, 83, 27, &I_Left_mouse_icon_9x9); canvas_set_bitmap_mode(canvas, 0);
canvas_set_color(canvas, ColorWhite);
} }
canvas_draw_icon(canvas, 83, 27, &I_Left_mouse_icon_9x9);
canvas_set_color(canvas, ColorBlack);
// Back // Back
if(model->right_mouse_pressed) { if(model->right_mouse_pressed) {
canvas_draw_icon(canvas, 108, 48, &I_Ok_btn_pressed_13x13); canvas_set_bitmap_mode(canvas, 1);
} else { canvas_draw_icon(canvas, 108, 48, &I_Pressed_Button_13x13);
canvas_draw_icon(canvas, 110, 50, &I_Right_mouse_icon_9x9); canvas_set_bitmap_mode(canvas, 0);
canvas_set_color(canvas, ColorWhite);
} }
canvas_draw_icon(canvas, 110, 50, &I_Right_mouse_icon_9x9);
canvas_set_color(canvas, ColorBlack);
} }
static void hid_mouse_process(HidMouse* hid_mouse, InputEvent* event) { static void hid_mouse_process(HidMouse* hid_mouse, InputEvent* event) {

View File

@ -19,6 +19,7 @@ typedef struct {
bool ok_pressed; bool ok_pressed;
bool connected; bool connected;
bool is_cursor_set; bool is_cursor_set;
bool back_mouse_pressed;
HidTransport transport; HidTransport transport;
} HidTikTokModel; } HidTikTokModel;
@ -40,53 +41,63 @@ static void hid_tiktok_draw_callback(Canvas* canvas, void* context) {
canvas_set_font(canvas, FontSecondary); canvas_set_font(canvas, FontSecondary);
// Keypad circles // Keypad circles
canvas_draw_icon(canvas, 76, 8, &I_Circles_47x47); canvas_draw_icon(canvas, 66, 8, &I_Circles_47x47);
// Pause
if(model->back_mouse_pressed) {
canvas_set_bitmap_mode(canvas, 1);
canvas_draw_icon(canvas, 106, 46, &I_Pressed_Button_13x13);
canvas_set_bitmap_mode(canvas, 0);
canvas_set_color(canvas, ColorWhite);
}
canvas_draw_icon(canvas, 108, 48, &I_Pause_icon_9x9);
canvas_set_color(canvas, ColorBlack);
// Up // Up
if(model->up_pressed) { if(model->up_pressed) {
canvas_set_bitmap_mode(canvas, 1); canvas_set_bitmap_mode(canvas, 1);
canvas_draw_icon(canvas, 93, 9, &I_Pressed_Button_13x13); canvas_draw_icon(canvas, 83, 9, &I_Pressed_Button_13x13);
canvas_set_bitmap_mode(canvas, 0); canvas_set_bitmap_mode(canvas, 0);
canvas_set_color(canvas, ColorWhite); canvas_set_color(canvas, ColorWhite);
} }
canvas_draw_icon(canvas, 96, 11, &I_Arr_up_7x9); canvas_draw_icon(canvas, 86, 11, &I_Arr_up_7x9);
canvas_set_color(canvas, ColorBlack); canvas_set_color(canvas, ColorBlack);
// Down // Down
if(model->down_pressed) { if(model->down_pressed) {
canvas_set_bitmap_mode(canvas, 1); canvas_set_bitmap_mode(canvas, 1);
canvas_draw_icon(canvas, 93, 41, &I_Pressed_Button_13x13); canvas_draw_icon(canvas, 83, 41, &I_Pressed_Button_13x13);
canvas_set_bitmap_mode(canvas, 0); canvas_set_bitmap_mode(canvas, 0);
canvas_set_color(canvas, ColorWhite); canvas_set_color(canvas, ColorWhite);
} }
canvas_draw_icon(canvas, 96, 44, &I_Arr_dwn_7x9); canvas_draw_icon(canvas, 86, 44, &I_Arr_dwn_7x9);
canvas_set_color(canvas, ColorBlack); canvas_set_color(canvas, ColorBlack);
// Left // Left
if(model->left_pressed) { if(model->left_pressed) {
canvas_set_bitmap_mode(canvas, 1); canvas_set_bitmap_mode(canvas, 1);
canvas_draw_icon(canvas, 77, 25, &I_Pressed_Button_13x13); canvas_draw_icon(canvas, 67, 25, &I_Pressed_Button_13x13);
canvas_set_bitmap_mode(canvas, 0); canvas_set_bitmap_mode(canvas, 0);
canvas_set_color(canvas, ColorWhite); canvas_set_color(canvas, ColorWhite);
} }
canvas_draw_icon(canvas, 81, 29, &I_Voldwn_6x6); canvas_draw_icon(canvas, 71, 29, &I_Voldwn_6x6);
canvas_set_color(canvas, ColorBlack); canvas_set_color(canvas, ColorBlack);
// Right // Right
if(model->right_pressed) { if(model->right_pressed) {
canvas_set_bitmap_mode(canvas, 1); canvas_set_bitmap_mode(canvas, 1);
canvas_draw_icon(canvas, 109, 25, &I_Pressed_Button_13x13); canvas_draw_icon(canvas, 99, 25, &I_Pressed_Button_13x13);
canvas_set_bitmap_mode(canvas, 0); canvas_set_bitmap_mode(canvas, 0);
canvas_set_color(canvas, ColorWhite); canvas_set_color(canvas, ColorWhite);
} }
canvas_draw_icon(canvas, 111, 29, &I_Volup_8x6); canvas_draw_icon(canvas, 101, 29, &I_Volup_8x6);
canvas_set_color(canvas, ColorBlack); canvas_set_color(canvas, ColorBlack);
// Ok // Ok
if(model->ok_pressed) { if(model->ok_pressed) {
canvas_draw_icon(canvas, 91, 23, &I_Like_pressed_17x17); canvas_draw_icon(canvas, 81, 23, &I_Like_pressed_17x17);
} else { } else {
canvas_draw_icon(canvas, 94, 27, &I_Like_def_11x9); canvas_draw_icon(canvas, 84, 27, &I_Like_def_11x9);
} }
// Exit // Exit
canvas_draw_icon(canvas, 0, 54, &I_Pin_back_arrow_10x8); canvas_draw_icon(canvas, 0, 54, &I_Pin_back_arrow_10x8);
@ -102,7 +113,8 @@ static void hid_tiktok_reset_cursor(HidTikTok* hid_tiktok) {
furi_delay_ms(50); furi_delay_ms(50);
} }
// Move cursor from the corner // Move cursor from the corner
hid_hal_mouse_move(hid_tiktok->hid, 20, 120); hid_hal_mouse_move(hid_tiktok->hid, 40, 120);
hid_hal_mouse_move(hid_tiktok->hid, 0, 120);
furi_delay_ms(50); furi_delay_ms(50);
} }
@ -120,6 +132,8 @@ static void
hid_hal_consumer_key_press(hid_tiktok->hid, HID_CONSUMER_VOLUME_INCREMENT); hid_hal_consumer_key_press(hid_tiktok->hid, HID_CONSUMER_VOLUME_INCREMENT);
} else if(event->key == InputKeyOk) { } else if(event->key == InputKeyOk) {
model->ok_pressed = true; model->ok_pressed = true;
} else if(event->key == InputKeyBack) {
model->back_mouse_pressed = true;
} }
} }
@ -137,6 +151,8 @@ static void
hid_hal_consumer_key_release(hid_tiktok->hid, HID_CONSUMER_VOLUME_INCREMENT); hid_hal_consumer_key_release(hid_tiktok->hid, HID_CONSUMER_VOLUME_INCREMENT);
} else if(event->key == InputKeyOk) { } else if(event->key == InputKeyOk) {
model->ok_pressed = false; model->ok_pressed = false;
} else if(event->key == InputKeyBack) {
model->back_mouse_pressed = false;
} }
} }
@ -169,16 +185,16 @@ static bool hid_tiktok_input_callback(InputEvent* event, void* context) {
furi_delay_ms(50); furi_delay_ms(50);
hid_hal_mouse_release(hid_tiktok->hid, HID_MOUSE_BTN_LEFT); hid_hal_mouse_release(hid_tiktok->hid, HID_MOUSE_BTN_LEFT);
consumed = true; consumed = true;
} else if(event->key == InputKeyUp) { } else if(event->key == InputKeyDown) {
// Emulate up swipe // Swipe to new video
hid_hal_mouse_scroll(hid_tiktok->hid, -6); hid_hal_mouse_scroll(hid_tiktok->hid, -6);
hid_hal_mouse_scroll(hid_tiktok->hid, -12); hid_hal_mouse_scroll(hid_tiktok->hid, -12);
hid_hal_mouse_scroll(hid_tiktok->hid, -19); hid_hal_mouse_scroll(hid_tiktok->hid, -19);
hid_hal_mouse_scroll(hid_tiktok->hid, -12); hid_hal_mouse_scroll(hid_tiktok->hid, -12);
hid_hal_mouse_scroll(hid_tiktok->hid, -6); hid_hal_mouse_scroll(hid_tiktok->hid, -6);
consumed = true; consumed = true;
} else if(event->key == InputKeyDown) { } else if(event->key == InputKeyUp) {
// Emulate down swipe // Swipe to previous video
hid_hal_mouse_scroll(hid_tiktok->hid, 6); hid_hal_mouse_scroll(hid_tiktok->hid, 6);
hid_hal_mouse_scroll(hid_tiktok->hid, 12); hid_hal_mouse_scroll(hid_tiktok->hid, 12);
hid_hal_mouse_scroll(hid_tiktok->hid, 19); hid_hal_mouse_scroll(hid_tiktok->hid, 19);
@ -186,7 +202,9 @@ static bool hid_tiktok_input_callback(InputEvent* event, void* context) {
hid_hal_mouse_scroll(hid_tiktok->hid, 6); hid_hal_mouse_scroll(hid_tiktok->hid, 6);
consumed = true; consumed = true;
} else if(event->key == InputKeyBack) { } else if(event->key == InputKeyBack) {
hid_hal_consumer_key_release_all(hid_tiktok->hid); // Pause
hid_hal_mouse_press(hid_tiktok->hid, HID_MOUSE_BTN_RIGHT);
hid_hal_mouse_release(hid_tiktok->hid, HID_MOUSE_BTN_RIGHT);
consumed = true; consumed = true;
} }
} else if(event->type == InputTypeLong) { } else if(event->type == InputTypeLong) {