[FL-2932] TikTok: reset cursor after enter and reconnect #1921

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
gornekich 2022-10-26 02:57:06 +04:00 committed by GitHub
parent d530238fae
commit 7d2d2b3dd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,6 +17,7 @@ typedef struct {
bool down_pressed; bool down_pressed;
bool ok_pressed; bool ok_pressed;
bool connected; bool connected;
bool is_cursor_set;
} BtHidTikTokModel; } BtHidTikTokModel;
static void bt_hid_tiktok_draw_callback(Canvas* canvas, void* context) { static void bt_hid_tiktok_draw_callback(Canvas* canvas, void* context) {
@ -88,48 +89,48 @@ static void bt_hid_tiktok_draw_callback(Canvas* canvas, void* context) {
elements_multiline_text_aligned(canvas, 13, 62, AlignLeft, AlignBottom, "Hold to exit"); elements_multiline_text_aligned(canvas, 13, 62, AlignLeft, AlignBottom, "Hold to exit");
} }
static void bt_hid_tiktok_process_press(BtHidTikTok* bt_hid_tiktok, InputEvent* event) { static void bt_hid_tiktok_reset_cursor() {
with_view_model( // Set cursor to the phone's left up corner
bt_hid_tiktok->view, // Delays to guarantee one packet per connection interval
BtHidTikTokModel * model, for(size_t i = 0; i < 8; i++) {
{ furi_hal_bt_hid_mouse_move(-127, -127);
if(event->key == InputKeyUp) { furi_delay_ms(50);
model->up_pressed = true; }
} else if(event->key == InputKeyDown) { // Move cursor from the corner
model->down_pressed = true; furi_hal_bt_hid_mouse_move(20, 120);
} else if(event->key == InputKeyLeft) { furi_delay_ms(50);
model->left_pressed = true;
furi_hal_bt_hid_consumer_key_press(HID_CONSUMER_VOLUME_DECREMENT);
} else if(event->key == InputKeyRight) {
model->right_pressed = true;
furi_hal_bt_hid_consumer_key_press(HID_CONSUMER_VOLUME_INCREMENT);
} else if(event->key == InputKeyOk) {
model->ok_pressed = true;
}
},
true);
} }
static void bt_hid_tiktok_process_release(BtHidTikTok* bt_hid_tiktok, InputEvent* event) { static void bt_hid_tiktok_process_press(BtHidTikTokModel* model, InputEvent* event) {
with_view_model( if(event->key == InputKeyUp) {
bt_hid_tiktok->view, model->up_pressed = true;
BtHidTikTokModel * model, } else if(event->key == InputKeyDown) {
{ model->down_pressed = true;
if(event->key == InputKeyUp) { } else if(event->key == InputKeyLeft) {
model->up_pressed = false; model->left_pressed = true;
} else if(event->key == InputKeyDown) { furi_hal_bt_hid_consumer_key_press(HID_CONSUMER_VOLUME_DECREMENT);
model->down_pressed = false; } else if(event->key == InputKeyRight) {
} else if(event->key == InputKeyLeft) { model->right_pressed = true;
model->left_pressed = false; furi_hal_bt_hid_consumer_key_press(HID_CONSUMER_VOLUME_INCREMENT);
furi_hal_bt_hid_consumer_key_release(HID_CONSUMER_VOLUME_DECREMENT); } else if(event->key == InputKeyOk) {
} else if(event->key == InputKeyRight) { model->ok_pressed = true;
model->right_pressed = false; }
furi_hal_bt_hid_consumer_key_release(HID_CONSUMER_VOLUME_INCREMENT); }
} else if(event->key == InputKeyOk) {
model->ok_pressed = false; static void bt_hid_tiktok_process_release(BtHidTikTokModel* model, InputEvent* event) {
} if(event->key == InputKeyUp) {
}, model->up_pressed = false;
true); } else if(event->key == InputKeyDown) {
model->down_pressed = false;
} else if(event->key == InputKeyLeft) {
model->left_pressed = false;
furi_hal_bt_hid_consumer_key_release(HID_CONSUMER_VOLUME_DECREMENT);
} else if(event->key == InputKeyRight) {
model->right_pressed = false;
furi_hal_bt_hid_consumer_key_release(HID_CONSUMER_VOLUME_INCREMENT);
} else if(event->key == InputKeyOk) {
model->ok_pressed = false;
}
} }
static bool bt_hid_tiktok_input_callback(InputEvent* event, void* context) { static bool bt_hid_tiktok_input_callback(InputEvent* event, void* context) {
@ -137,43 +138,59 @@ static bool bt_hid_tiktok_input_callback(InputEvent* event, void* context) {
BtHidTikTok* bt_hid_tiktok = context; BtHidTikTok* bt_hid_tiktok = context;
bool consumed = false; bool consumed = false;
if(event->type == InputTypePress) { with_view_model(
bt_hid_tiktok_process_press(bt_hid_tiktok, event); bt_hid_tiktok->view,
consumed = true; BtHidTikTokModel * model,
} else if(event->type == InputTypeRelease) { {
bt_hid_tiktok_process_release(bt_hid_tiktok, event); if(event->type == InputTypePress) {
consumed = true; bt_hid_tiktok_process_press(model, event);
} else if(event->type == InputTypeShort) { if(model->connected && !model->is_cursor_set) {
if(event->key == InputKeyOk) { bt_hid_tiktok_reset_cursor();
furi_hal_bt_hid_mouse_press(HID_MOUSE_BTN_LEFT); model->is_cursor_set = true;
furi_delay_ms(50); }
furi_hal_bt_hid_mouse_release(HID_MOUSE_BTN_LEFT); consumed = true;
furi_delay_ms(50); } else if(event->type == InputTypeRelease) {
furi_hal_bt_hid_mouse_press(HID_MOUSE_BTN_LEFT); bt_hid_tiktok_process_release(model, event);
furi_delay_ms(50); consumed = true;
furi_hal_bt_hid_mouse_release(HID_MOUSE_BTN_LEFT); } else if(event->type == InputTypeShort) {
consumed = true; if(event->key == InputKeyOk) {
} else if(event->key == InputKeyUp) { furi_hal_bt_hid_mouse_press(HID_MOUSE_BTN_LEFT);
// Emulate up swipe furi_delay_ms(50);
furi_hal_bt_hid_mouse_scroll(-6); furi_hal_bt_hid_mouse_release(HID_MOUSE_BTN_LEFT);
furi_hal_bt_hid_mouse_scroll(-12); furi_delay_ms(50);
furi_hal_bt_hid_mouse_scroll(-19); furi_hal_bt_hid_mouse_press(HID_MOUSE_BTN_LEFT);
furi_hal_bt_hid_mouse_scroll(-12); furi_delay_ms(50);
furi_hal_bt_hid_mouse_scroll(-6); furi_hal_bt_hid_mouse_release(HID_MOUSE_BTN_LEFT);
consumed = true; consumed = true;
} else if(event->key == InputKeyDown) { } else if(event->key == InputKeyUp) {
// Emulate down swipe // Emulate up swipe
furi_hal_bt_hid_mouse_scroll(6); furi_hal_bt_hid_mouse_scroll(-6);
furi_hal_bt_hid_mouse_scroll(12); furi_hal_bt_hid_mouse_scroll(-12);
furi_hal_bt_hid_mouse_scroll(19); furi_hal_bt_hid_mouse_scroll(-19);
furi_hal_bt_hid_mouse_scroll(12); furi_hal_bt_hid_mouse_scroll(-12);
furi_hal_bt_hid_mouse_scroll(6); furi_hal_bt_hid_mouse_scroll(-6);
consumed = true; consumed = true;
} else if(event->key == InputKeyBack) { } else if(event->key == InputKeyDown) {
furi_hal_bt_hid_consumer_key_release_all(); // Emulate down swipe
consumed = true; furi_hal_bt_hid_mouse_scroll(6);
} furi_hal_bt_hid_mouse_scroll(12);
} furi_hal_bt_hid_mouse_scroll(19);
furi_hal_bt_hid_mouse_scroll(12);
furi_hal_bt_hid_mouse_scroll(6);
consumed = true;
} else if(event->key == InputKeyBack) {
furi_hal_bt_hid_consumer_key_release_all();
consumed = true;
}
} else if(event->type == InputTypeLong) {
if(event->key == InputKeyBack) {
furi_hal_bt_hid_consumer_key_release_all();
model->is_cursor_set = false;
consumed = false;
}
}
},
true);
return consumed; return consumed;
} }
@ -203,5 +220,11 @@ View* bt_hid_tiktok_get_view(BtHidTikTok* bt_hid_tiktok) {
void bt_hid_tiktok_set_connected_status(BtHidTikTok* bt_hid_tiktok, bool connected) { void bt_hid_tiktok_set_connected_status(BtHidTikTok* bt_hid_tiktok, bool connected) {
furi_assert(bt_hid_tiktok); furi_assert(bt_hid_tiktok);
with_view_model( with_view_model(
bt_hid_tiktok->view, BtHidTikTokModel * model, { model->connected = connected; }, true); bt_hid_tiktok->view,
BtHidTikTokModel * model,
{
model->connected = connected;
model->is_cursor_set = false;
},
true);
} }