[FL-2932] TikTok: reset cursor after enter and reconnect #1921
Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
parent
d530238fae
commit
7d2d2b3dd9
@ -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,11 +89,19 @@ 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);
|
||||||
|
furi_delay_ms(50);
|
||||||
|
}
|
||||||
|
// Move cursor from the corner
|
||||||
|
furi_hal_bt_hid_mouse_move(20, 120);
|
||||||
|
furi_delay_ms(50);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void bt_hid_tiktok_process_press(BtHidTikTokModel* model, InputEvent* event) {
|
||||||
if(event->key == InputKeyUp) {
|
if(event->key == InputKeyUp) {
|
||||||
model->up_pressed = true;
|
model->up_pressed = true;
|
||||||
} else if(event->key == InputKeyDown) {
|
} else if(event->key == InputKeyDown) {
|
||||||
@ -106,15 +115,9 @@ static void bt_hid_tiktok_process_press(BtHidTikTok* bt_hid_tiktok, InputEvent*
|
|||||||
} else if(event->key == InputKeyOk) {
|
} else if(event->key == InputKeyOk) {
|
||||||
model->ok_pressed = true;
|
model->ok_pressed = true;
|
||||||
}
|
}
|
||||||
},
|
|
||||||
true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bt_hid_tiktok_process_release(BtHidTikTok* bt_hid_tiktok, InputEvent* event) {
|
static void bt_hid_tiktok_process_release(BtHidTikTokModel* model, InputEvent* event) {
|
||||||
with_view_model(
|
|
||||||
bt_hid_tiktok->view,
|
|
||||||
BtHidTikTokModel * model,
|
|
||||||
{
|
|
||||||
if(event->key == InputKeyUp) {
|
if(event->key == InputKeyUp) {
|
||||||
model->up_pressed = false;
|
model->up_pressed = false;
|
||||||
} else if(event->key == InputKeyDown) {
|
} else if(event->key == InputKeyDown) {
|
||||||
@ -128,8 +131,6 @@ static void bt_hid_tiktok_process_release(BtHidTikTok* bt_hid_tiktok, InputEvent
|
|||||||
} else if(event->key == InputKeyOk) {
|
} else if(event->key == InputKeyOk) {
|
||||||
model->ok_pressed = false;
|
model->ok_pressed = false;
|
||||||
}
|
}
|
||||||
},
|
|
||||||
true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool bt_hid_tiktok_input_callback(InputEvent* event, void* context) {
|
static bool bt_hid_tiktok_input_callback(InputEvent* event, void* context) {
|
||||||
@ -137,11 +138,19 @@ 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;
|
||||||
|
|
||||||
|
with_view_model(
|
||||||
|
bt_hid_tiktok->view,
|
||||||
|
BtHidTikTokModel * model,
|
||||||
|
{
|
||||||
if(event->type == InputTypePress) {
|
if(event->type == InputTypePress) {
|
||||||
bt_hid_tiktok_process_press(bt_hid_tiktok, event);
|
bt_hid_tiktok_process_press(model, event);
|
||||||
|
if(model->connected && !model->is_cursor_set) {
|
||||||
|
bt_hid_tiktok_reset_cursor();
|
||||||
|
model->is_cursor_set = true;
|
||||||
|
}
|
||||||
consumed = true;
|
consumed = true;
|
||||||
} else if(event->type == InputTypeRelease) {
|
} else if(event->type == InputTypeRelease) {
|
||||||
bt_hid_tiktok_process_release(bt_hid_tiktok, event);
|
bt_hid_tiktok_process_release(model, event);
|
||||||
consumed = true;
|
consumed = true;
|
||||||
} else if(event->type == InputTypeShort) {
|
} else if(event->type == InputTypeShort) {
|
||||||
if(event->key == InputKeyOk) {
|
if(event->key == InputKeyOk) {
|
||||||
@ -173,7 +182,15 @@ static bool bt_hid_tiktok_input_callback(InputEvent* event, void* context) {
|
|||||||
furi_hal_bt_hid_consumer_key_release_all();
|
furi_hal_bt_hid_consumer_key_release_all();
|
||||||
consumed = true;
|
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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user