From 2d32ea68fe749b19854b528dcc94d7c13809c7d0 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Mon, 19 Feb 2024 04:33:36 +0300 Subject: [PATCH] hid app merge fixes + changes by Willy-JL --- .../hid_app/assets/Like_pressed_17x17.png | Bin 3643 -> 0 bytes .../assets/Pin_back_arrow_rotated_8x10.png | Bin 959 -> 0 bytes .../assets/RoundButtonPressed_16x16.png | Bin 320 -> 0 bytes applications/system/hid_app/hid.c | 275 +++++++----------- applications/system/hid_app/hid.h | 16 +- .../system/hid_app/scenes/hid_scene.c | 30 ++ .../system/hid_app/scenes/hid_scene.h | 29 ++ .../system/hid_app/scenes/hid_scene_config.h | 3 + .../hid_app/scenes/hid_scene_exit_confirm.c | 45 +++ .../system/hid_app/scenes/hid_scene_main.c | 22 ++ .../system/hid_app/scenes/hid_scene_unpair.c | 63 ++++ applications/system/hid_app/transport_ble.c | 60 ++++ applications/system/hid_app/transport_usb.c | 61 ++++ applications/system/hid_app/views.h | 6 +- .../system/hid_app/views/hid_keynote.c | 4 +- applications/system/hid_app/views/hid_media.c | 2 +- applications/system/hid_app/views/hid_movie.c | 2 +- .../system/hid_app/views/hid_music_macos.c | 2 +- .../system/hid_app/views/hid_tikshorts.h | 14 - .../views/{hid_tikshorts.c => hid_tiktok.c} | 137 +++++---- .../system/hid_app/views/hid_tiktok.h | 14 + 21 files changed, 515 insertions(+), 270 deletions(-) delete mode 100644 applications/system/hid_app/assets/Like_pressed_17x17.png delete mode 100644 applications/system/hid_app/assets/Pin_back_arrow_rotated_8x10.png delete mode 100644 applications/system/hid_app/assets/RoundButtonPressed_16x16.png create mode 100644 applications/system/hid_app/scenes/hid_scene.c create mode 100644 applications/system/hid_app/scenes/hid_scene.h create mode 100644 applications/system/hid_app/scenes/hid_scene_config.h create mode 100644 applications/system/hid_app/scenes/hid_scene_exit_confirm.c create mode 100644 applications/system/hid_app/scenes/hid_scene_main.c create mode 100644 applications/system/hid_app/scenes/hid_scene_unpair.c create mode 100644 applications/system/hid_app/transport_ble.c create mode 100644 applications/system/hid_app/transport_usb.c delete mode 100644 applications/system/hid_app/views/hid_tikshorts.h rename applications/system/hid_app/views/{hid_tikshorts.c => hid_tiktok.c} (61%) create mode 100644 applications/system/hid_app/views/hid_tiktok.h diff --git a/applications/system/hid_app/assets/Like_pressed_17x17.png b/applications/system/hid_app/assets/Like_pressed_17x17.png deleted file mode 100644 index f5bf276f31a716a4b419995bd0631b2778f99ee9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3643 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 +#include #include "views.h" #include #include +#include "hid_icons.h" #define TAG "HidApp" @@ -13,13 +16,43 @@ enum HidDebugSubmenuIndex { HidSubmenuIndexMedia, HidSubmenuIndexMusicMacOs, HidSubmenuIndexMovie, - HidSubmenuIndexTikShorts, + HidSubmenuIndexTikTok, HidSubmenuIndexMouse, HidSubmenuIndexMouseClicker, HidSubmenuIndexMouseJiggler, HidSubmenuIndexPushToTalk, + HidSubmenuIndexRemovePairing, }; +bool hid_custom_event_callback(void* context, uint32_t event) { + furi_assert(context); + Hid* app = context; + return scene_manager_handle_custom_event(app->scene_manager, event); +} + +bool hid_back_event_callback(void* context) { + furi_assert(context); + Hid* app = context; + FURI_LOG_D("HID", "Back event"); + app->view_id = HidViewSubmenu; + view_dispatcher_switch_to_view(app->view_dispatcher, HidViewSubmenu); + return true; +} + +void bt_hid_remove_pairing(Hid* app) { + Bt* bt = app->bt; + bt_disconnect(bt); + + // Wait 2nd core to update nvm storage + furi_delay_ms(200); + + furi_hal_bt_stop_advertising(); + + bt_forget_bonded_devices(bt); + + furi_hal_bt_start_advertising(); +} + static void hid_submenu_callback(void* context, uint32_t index) { furi_assert(context); Hid* app = context; @@ -49,9 +82,9 @@ static void hid_submenu_callback(void* context, uint32_t index) { } else if(index == HidSubmenuIndexMouse) { app->view_id = HidViewMouse; view_dispatcher_switch_to_view(app->view_dispatcher, HidViewMouse); - } else if(index == HidSubmenuIndexTikShorts) { - app->view_id = BtHidViewTikShorts; - view_dispatcher_switch_to_view(app->view_dispatcher, BtHidViewTikShorts); + } else if(index == HidSubmenuIndexTikTok) { + app->view_id = BtHidViewTikTok; + view_dispatcher_switch_to_view(app->view_dispatcher, BtHidViewTikTok); } else if(index == HidSubmenuIndexMouseClicker) { app->view_id = HidViewMouseClicker; view_dispatcher_switch_to_view(app->view_dispatcher, HidViewMouseClicker); @@ -61,6 +94,8 @@ static void hid_submenu_callback(void* context, uint32_t index) { } else if(index == HidSubmenuIndexPushToTalk) { app->view_id = HidViewPushToTalkMenu; view_dispatcher_switch_to_view(app->view_dispatcher, HidViewPushToTalkMenu); + } else if(index == HidSubmenuIndexRemovePairing) { + scene_manager_next_scene(app->scene_manager, HidSceneUnpair); } } @@ -68,13 +103,13 @@ static void bt_hid_connection_status_changed_callback(BtStatus status, void* con furi_assert(context); Hid* hid = context; bool connected = (status == BtStatusConnected); - if(hid->transport == HidTransportBle) { - if(connected) { - notification_internal_message(hid->notifications, &sequence_set_blue_255); - } else { - notification_internal_message(hid->notifications, &sequence_reset_blue); - } +#ifdef HID_TRANSPORT_BLE + if(connected) { + notification_internal_message(hid->notifications, &sequence_set_blue_255); + } else { + notification_internal_message(hid->notifications, &sequence_reset_blue); } +#endif hid_keynote_set_connected_status(hid->hid_keynote, connected); hid_keyboard_set_connected_status(hid->hid_keyboard, connected); hid_numpad_set_connected_status(hid->hid_numpad, connected); @@ -85,12 +120,7 @@ static void bt_hid_connection_status_changed_callback(BtStatus status, void* con hid_mouse_clicker_set_connected_status(hid->hid_mouse_clicker, connected); hid_mouse_jiggler_set_connected_status(hid->hid_mouse_jiggler, connected); hid_ptt_set_connected_status(hid->hid_ptt, connected); - hid_tikshorts_set_connected_status(hid->hid_tikshorts, connected); -} - -static uint32_t hid_menu_view(void* context) { - UNUSED(context); - return HidViewSubmenu; + hid_tiktok_set_connected_status(hid->hid_tiktok, connected); } static uint32_t hid_exit(void* context) { @@ -103,9 +133,8 @@ static uint32_t hid_ptt_menu_view(void* context) { return HidViewPushToTalkMenu; } -Hid* hid_alloc(HidTransport transport) { +Hid* hid_alloc() { Hid* app = malloc(sizeof(Hid)); - app->transport = transport; // Gui app->gui = furi_record_open(RECORD_GUI); @@ -120,6 +149,12 @@ Hid* hid_alloc(HidTransport transport) { app->view_dispatcher = view_dispatcher_alloc(); view_dispatcher_enable_queue(app->view_dispatcher); view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen); + view_dispatcher_set_navigation_event_callback(app->view_dispatcher, hid_back_event_callback); + view_dispatcher_set_event_callback_context(app->view_dispatcher, app); + + // Scene Manager + app->scene_manager = scene_manager_alloc(&hid_scene_handlers, app); + // Device Type Submenu view app->device_type_submenu = submenu_alloc(); submenu_add_item( @@ -146,14 +181,12 @@ Hid* hid_alloc(HidTransport transport) { app->device_type_submenu, "Movie", HidSubmenuIndexMovie, hid_submenu_callback, app); submenu_add_item( app->device_type_submenu, "Mouse", HidSubmenuIndexMouse, hid_submenu_callback, app); - if(app->transport == HidTransportBle) { - submenu_add_item( - app->device_type_submenu, - "TikTok / YT Shorts", - HidSubmenuIndexTikShorts, - hid_submenu_callback, - app); - } + submenu_add_item( + app->device_type_submenu, + "TikTok / YT Shorts", + HidSubmenuIndexTikTok, + hid_submenu_callback, + app); submenu_add_item( app->device_type_submenu, "Mouse Clicker", @@ -172,11 +205,18 @@ Hid* hid_alloc(HidTransport transport) { HidSubmenuIndexPushToTalk, hid_submenu_callback, app); +#ifdef HID_TRANSPORT_BLE + submenu_add_item( + app->device_type_submenu, + "Remove Pairing", + HidSubmenuIndexRemovePairing, + hid_submenu_callback, + app); +#endif view_set_previous_callback(submenu_get_view(app->device_type_submenu), hid_exit); view_dispatcher_add_view( app->view_dispatcher, HidViewSubmenu, submenu_get_view(app->device_type_submenu)); app->view_id = HidViewSubmenu; - view_dispatcher_switch_to_view(app->view_dispatcher, app->view_id); return app; } @@ -184,57 +224,56 @@ Hid* hid_app_alloc_view(void* context) { furi_assert(context); Hid* app = context; + // Dialog view + app->dialog = dialog_ex_alloc(); + view_dispatcher_add_view(app->view_dispatcher, HidViewDialog, dialog_ex_get_view(app->dialog)); + + // Popup view + app->popup = popup_alloc(); + view_dispatcher_add_view(app->view_dispatcher, HidViewPopup, popup_get_view(app->popup)); + // Keynote view app->hid_keynote = hid_keynote_alloc(app); - view_set_previous_callback(hid_keynote_get_view(app->hid_keynote), hid_menu_view); view_dispatcher_add_view( app->view_dispatcher, HidViewKeynote, hid_keynote_get_view(app->hid_keynote)); // Keyboard view app->hid_keyboard = hid_keyboard_alloc(app); - view_set_previous_callback(hid_keyboard_get_view(app->hid_keyboard), hid_menu_view); view_dispatcher_add_view( app->view_dispatcher, HidViewKeyboard, hid_keyboard_get_view(app->hid_keyboard)); //Numpad keyboard view app->hid_numpad = hid_numpad_alloc(app); - view_set_previous_callback(hid_numpad_get_view(app->hid_numpad), hid_menu_view); view_dispatcher_add_view( app->view_dispatcher, HidViewNumpad, hid_numpad_get_view(app->hid_numpad)); // Media view app->hid_media = hid_media_alloc(app); - view_set_previous_callback(hid_media_get_view(app->hid_media), hid_menu_view); view_dispatcher_add_view( app->view_dispatcher, HidViewMedia, hid_media_get_view(app->hid_media)); // Music MacOs view app->hid_music_macos = hid_music_macos_alloc(app); - view_set_previous_callback(hid_music_macos_get_view(app->hid_music_macos), hid_menu_view); view_dispatcher_add_view( app->view_dispatcher, HidViewMusicMacOs, hid_music_macos_get_view(app->hid_music_macos)); // Movie view app->hid_movie = hid_movie_alloc(app); - view_set_previous_callback(hid_movie_get_view(app->hid_movie), hid_menu_view); view_dispatcher_add_view( app->view_dispatcher, HidViewMovie, hid_movie_get_view(app->hid_movie)); - // TikTok / YT Shorts view - app->hid_tikshorts = hid_tikshorts_alloc(app); - view_set_previous_callback(hid_tikshorts_get_view(app->hid_tikshorts), hid_menu_view); + // TikTok view + app->hid_tiktok = hid_tiktok_alloc(app); view_dispatcher_add_view( - app->view_dispatcher, BtHidViewTikShorts, hid_tikshorts_get_view(app->hid_tikshorts)); + app->view_dispatcher, BtHidViewTikTok, hid_tiktok_get_view(app->hid_tiktok)); // Mouse view app->hid_mouse = hid_mouse_alloc(app); - view_set_previous_callback(hid_mouse_get_view(app->hid_mouse), hid_menu_view); view_dispatcher_add_view( app->view_dispatcher, HidViewMouse, hid_mouse_get_view(app->hid_mouse)); // Mouse clicker view app->hid_mouse_clicker = hid_mouse_clicker_alloc(app); - view_set_previous_callback(hid_mouse_clicker_get_view(app->hid_mouse_clicker), hid_menu_view); view_dispatcher_add_view( app->view_dispatcher, HidViewMouseClicker, @@ -242,7 +281,6 @@ Hid* hid_app_alloc_view(void* context) { // Mouse jiggler view app->hid_mouse_jiggler = hid_mouse_jiggler_alloc(app); - view_set_previous_callback(hid_mouse_jiggler_get_view(app->hid_mouse_jiggler), hid_menu_view); view_dispatcher_add_view( app->view_dispatcher, HidViewMouseJiggler, @@ -250,7 +288,6 @@ Hid* hid_app_alloc_view(void* context) { // PushToTalk view app->hid_ptt_menu = hid_ptt_menu_alloc(app); - view_set_previous_callback(hid_ptt_menu_get_view(app->hid_ptt_menu), hid_menu_view); view_dispatcher_add_view( app->view_dispatcher, HidViewPushToTalkMenu, hid_ptt_menu_get_view(app->hid_ptt_menu)); app->hid_ptt = hid_ptt_alloc(app); @@ -265,13 +302,16 @@ void hid_free(Hid* app) { furi_assert(app); // Reset notification - if(app->transport == HidTransportBle) { - notification_internal_message(app->notifications, &sequence_reset_blue); - } - +#ifdef HID_TRANSPORT_BLE + notification_internal_message(app->notifications, &sequence_reset_blue); +#endif // Free views view_dispatcher_remove_view(app->view_dispatcher, HidViewSubmenu); submenu_free(app->device_type_submenu); + view_dispatcher_remove_view(app->view_dispatcher, HidViewDialog); + dialog_ex_free(app->dialog); + view_dispatcher_remove_view(app->view_dispatcher, HidViewPopup); + popup_free(app->popup); view_dispatcher_remove_view(app->view_dispatcher, HidViewKeynote); hid_keynote_free(app->hid_keynote); view_dispatcher_remove_view(app->view_dispatcher, HidViewKeyboard); @@ -294,8 +334,9 @@ void hid_free(Hid* app) { hid_ptt_menu_free(app->hid_ptt_menu); view_dispatcher_remove_view(app->view_dispatcher, HidViewPushToTalk); hid_ptt_free(app->hid_ptt); - view_dispatcher_remove_view(app->view_dispatcher, BtHidViewTikShorts); - hid_tikshorts_free(app->hid_tikshorts); + view_dispatcher_remove_view(app->view_dispatcher, BtHidViewTikTok); + hid_tiktok_free(app->hid_tiktok); + scene_manager_free(app->scene_manager); view_dispatcher_free(app->view_dispatcher); // Close records @@ -310,132 +351,12 @@ void hid_free(Hid* app) { free(app); } -void hid_hal_keyboard_press(Hid* instance, uint16_t event) { - furi_assert(instance); - if(instance->transport == HidTransportBle) { - furi_hal_bt_hid_kb_press(event); - } else if(instance->transport == HidTransportUsb) { - furi_hal_hid_kb_press(event); - } else { - furi_crash(); - } -} - -void hid_hal_keyboard_release(Hid* instance, uint16_t event) { - furi_assert(instance); - if(instance->transport == HidTransportBle) { - furi_hal_bt_hid_kb_release(event); - } else if(instance->transport == HidTransportUsb) { - furi_hal_hid_kb_release(event); - } else { - furi_crash(); - } -} - -void hid_hal_keyboard_release_all(Hid* instance) { - furi_assert(instance); - if(instance->transport == HidTransportBle) { - furi_hal_bt_hid_kb_release_all(); - } else if(instance->transport == HidTransportUsb) { - furi_hal_hid_kb_release_all(); - } else { - furi_crash(); - } -} - -void hid_hal_consumer_key_press(Hid* instance, uint16_t event) { - furi_assert(instance); - if(instance->transport == HidTransportBle) { - furi_hal_bt_hid_consumer_key_press(event); - } else if(instance->transport == HidTransportUsb) { - furi_hal_hid_consumer_key_press(event); - } else { - furi_crash(); - } -} - -void hid_hal_consumer_key_release(Hid* instance, uint16_t event) { - furi_assert(instance); - if(instance->transport == HidTransportBle) { - furi_hal_bt_hid_consumer_key_release(event); - } else if(instance->transport == HidTransportUsb) { - furi_hal_hid_consumer_key_release(event); - } else { - furi_crash(); - } -} - -void hid_hal_consumer_key_release_all(Hid* instance) { - furi_assert(instance); - if(instance->transport == HidTransportBle) { - furi_hal_bt_hid_consumer_key_release_all(); - } else if(instance->transport == HidTransportUsb) { - furi_hal_hid_kb_release_all(); - } else { - furi_crash(); - } -} - -void hid_hal_mouse_move(Hid* instance, int8_t dx, int8_t dy) { - furi_assert(instance); - if(instance->transport == HidTransportBle) { - furi_hal_bt_hid_mouse_move(dx, dy); - } else if(instance->transport == HidTransportUsb) { - furi_hal_hid_mouse_move(dx, dy); - } else { - furi_crash(); - } -} - -void hid_hal_mouse_scroll(Hid* instance, int8_t delta) { - furi_assert(instance); - if(instance->transport == HidTransportBle) { - furi_hal_bt_hid_mouse_scroll(delta); - } else if(instance->transport == HidTransportUsb) { - furi_hal_hid_mouse_scroll(delta); - } else { - furi_crash(); - } -} - -void hid_hal_mouse_press(Hid* instance, uint16_t event) { - furi_assert(instance); - if(instance->transport == HidTransportBle) { - furi_hal_bt_hid_mouse_press(event); - } else if(instance->transport == HidTransportUsb) { - furi_hal_hid_mouse_press(event); - } else { - furi_crash(); - } -} - -void hid_hal_mouse_release(Hid* instance, uint16_t event) { - furi_assert(instance); - if(instance->transport == HidTransportBle) { - furi_hal_bt_hid_mouse_release(event); - } else if(instance->transport == HidTransportUsb) { - furi_hal_hid_mouse_release(event); - } else { - furi_crash(); - } -} - -void hid_hal_mouse_release_all(Hid* instance) { - furi_assert(instance); - if(instance->transport == HidTransportBle) { - furi_hal_bt_hid_mouse_release_all(); - } else if(instance->transport == HidTransportUsb) { - furi_hal_hid_mouse_release(HID_MOUSE_BTN_LEFT); - furi_hal_hid_mouse_release(HID_MOUSE_BTN_RIGHT); - } else { - furi_crash(); - } -} - int32_t hid_usb_app(void* p) { UNUSED(p); - Hid* app = hid_alloc(HidTransportUsb); + Hid* app = hid_alloc(); app = hid_app_alloc_view(app); + FURI_LOG_D("HID", "Starting as USB app"); + FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config(); furi_hal_usb_unlock(); furi_check(furi_hal_usb_set_config(&usb_hid, NULL) == true); @@ -444,6 +365,8 @@ int32_t hid_usb_app(void* p) { dolphin_deed(DolphinDeedPluginStart); + scene_manager_next_scene(app->scene_manager, HidSceneMain); + view_dispatcher_run(app->view_dispatcher); furi_hal_usb_set_config(usb_mode_prev, NULL); @@ -455,9 +378,11 @@ int32_t hid_usb_app(void* p) { int32_t hid_ble_app(void* p) { UNUSED(p); - Hid* app = hid_alloc(HidTransportBle); + Hid* app = hid_alloc(); app = hid_app_alloc_view(app); + FURI_LOG_D("HID", "Starting as BLE app"); + bt_disconnect(app->bt); // Wait 2nd core to update nvm storage @@ -475,13 +400,17 @@ int32_t hid_ble_app(void* p) { furi_record_close(RECORD_STORAGE); - furi_check(bt_set_profile(app->bt, BtProfileHidKeyboard)); + app->ble_hid_profile = bt_profile_start(app->bt, ble_profile_hid, NULL); + + furi_check(app->ble_hid_profile); furi_hal_bt_start_advertising(); bt_set_status_changed_callback(app->bt, bt_hid_connection_status_changed_callback, app); dolphin_deed(DolphinDeedPluginStart); + scene_manager_next_scene(app->scene_manager, HidSceneMain); + view_dispatcher_run(app->view_dispatcher); bt_set_status_changed_callback(app->bt, NULL, NULL); @@ -493,7 +422,7 @@ int32_t hid_ble_app(void* p) { bt_keys_storage_set_default_path(app->bt); - furi_check(bt_set_profile(app->bt, BtProfileSerial)); + furi_check(bt_profile_restore_default(app->bt)); hid_free(app); diff --git a/applications/system/hid_app/hid.h b/applications/system/hid_app/hid.h index 3c0f0ae79..70a73e2ec 100644 --- a/applications/system/hid_app/hid.h +++ b/applications/system/hid_app/hid.h @@ -2,14 +2,16 @@ #include #include -#include #include #include +#include + #include #include #include #include +#include #include #include @@ -25,10 +27,12 @@ #include "views/hid_mouse.h" #include "views/hid_mouse_clicker.h" #include "views/hid_mouse_jiggler.h" -#include "views/hid_tikshorts.h" +#include "views/hid_tiktok.h" #include "views/hid_ptt.h" #include "views/hid_ptt_menu.h" +#include "scenes/hid_scene.h" + #define HID_BT_KEYS_STORAGE_NAME ".bt_hid.keys" typedef enum { @@ -39,12 +43,15 @@ typedef enum { typedef struct Hid Hid; struct Hid { + FuriHalBleProfileBase* ble_hid_profile; Bt* bt; Gui* gui; NotificationApp* notifications; ViewDispatcher* view_dispatcher; + SceneManager* scene_manager; Submenu* device_type_submenu; DialogEx* dialog; + Popup* popup; HidKeynote* hid_keynote; HidKeyboard* hid_keyboard; HidNumpad* hid_numpad; @@ -54,13 +61,14 @@ struct Hid { HidMouse* hid_mouse; HidMouseClicker* hid_mouse_clicker; HidMouseJiggler* hid_mouse_jiggler; - HidTikShorts* hid_tikshorts; + HidTikTok* hid_tiktok; HidPushToTalk* hid_ptt; HidPushToTalkMenu* hid_ptt_menu; HidTransport transport; uint32_t view_id; }; +void bt_hid_remove_pairing(Hid* app); void hid_hal_keyboard_press(Hid* instance, uint16_t event); void hid_hal_keyboard_release(Hid* instance, uint16_t event); @@ -74,4 +82,4 @@ void hid_hal_mouse_move(Hid* instance, int8_t dx, int8_t dy); void hid_hal_mouse_scroll(Hid* instance, int8_t delta); void hid_hal_mouse_press(Hid* instance, uint16_t event); void hid_hal_mouse_release(Hid* instance, uint16_t event); -void hid_hal_mouse_release_all(Hid* instance); +void hid_hal_mouse_release_all(Hid* instance); \ No newline at end of file diff --git a/applications/system/hid_app/scenes/hid_scene.c b/applications/system/hid_app/scenes/hid_scene.c new file mode 100644 index 000000000..89399a809 --- /dev/null +++ b/applications/system/hid_app/scenes/hid_scene.c @@ -0,0 +1,30 @@ +#include "hid_scene.h" + +// Generate scene on_enter handlers array +#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter, +void (*const hid_on_enter_handlers[])(void*) = { +#include "hid_scene_config.h" +}; +#undef ADD_SCENE + +// Generate scene on_event handlers array +#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event, +bool (*const hid_on_event_handlers[])(void* context, SceneManagerEvent event) = { +#include "hid_scene_config.h" +}; +#undef ADD_SCENE + +// Generate scene on_exit handlers array +#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit, +void (*const hid_on_exit_handlers[])(void* context) = { +#include "hid_scene_config.h" +}; +#undef ADD_SCENE + +// Initialize scene handlers configuration structure +const SceneManagerHandlers hid_scene_handlers = { + .on_enter_handlers = hid_on_enter_handlers, + .on_event_handlers = hid_on_event_handlers, + .on_exit_handlers = hid_on_exit_handlers, + .scene_num = HidSceneNum, +}; diff --git a/applications/system/hid_app/scenes/hid_scene.h b/applications/system/hid_app/scenes/hid_scene.h new file mode 100644 index 000000000..9a2e6bb32 --- /dev/null +++ b/applications/system/hid_app/scenes/hid_scene.h @@ -0,0 +1,29 @@ +#pragma once + +#include + +// Generate scene id and total number +#define ADD_SCENE(prefix, name, id) HidScene##id, +typedef enum { +#include "hid_scene_config.h" + HidSceneNum, +} HidScene; +#undef ADD_SCENE + +extern const SceneManagerHandlers hid_scene_handlers; + +// Generate scene on_enter handlers declaration +#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*); +#include "hid_scene_config.h" +#undef ADD_SCENE + +// Generate scene on_event handlers declaration +#define ADD_SCENE(prefix, name, id) \ + bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event); +#include "hid_scene_config.h" +#undef ADD_SCENE + +// Generate scene on_exit handlers declaration +#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context); +#include "hid_scene_config.h" +#undef ADD_SCENE diff --git a/applications/system/hid_app/scenes/hid_scene_config.h b/applications/system/hid_app/scenes/hid_scene_config.h new file mode 100644 index 000000000..8f3a788d1 --- /dev/null +++ b/applications/system/hid_app/scenes/hid_scene_config.h @@ -0,0 +1,3 @@ +ADD_SCENE(hid, main, Main) +ADD_SCENE(hid, unpair, Unpair) +ADD_SCENE(hid, exit_confirm, ExitConfirm) \ No newline at end of file diff --git a/applications/system/hid_app/scenes/hid_scene_exit_confirm.c b/applications/system/hid_app/scenes/hid_scene_exit_confirm.c new file mode 100644 index 000000000..94e783e93 --- /dev/null +++ b/applications/system/hid_app/scenes/hid_scene_exit_confirm.c @@ -0,0 +1,45 @@ +#include "../hid.h" +#include "../views.h" + +static void hid_scene_exit_confirm_dialog_callback(DialogExResult result, void* context) { + furi_assert(context); + Hid* app = context; + if(result == DialogExResultLeft) { + view_dispatcher_stop(app->view_dispatcher); + } else if(result == DialogExResultRight) { + scene_manager_previous_scene(app->scene_manager); + } else if(result == DialogExResultCenter) { + scene_manager_search_and_switch_to_previous_scene(app->scene_manager, HidSceneMain); + view_dispatcher_switch_to_view(app->view_dispatcher, HidViewSubmenu); + } +} + +void hid_scene_exit_confirm_on_enter(void* context) { + Hid* app = context; + + // Exit dialog view + dialog_ex_reset(app->dialog); + dialog_ex_set_result_callback(app->dialog, hid_scene_exit_confirm_dialog_callback); + dialog_ex_set_context(app->dialog, app); + dialog_ex_set_left_button_text(app->dialog, "Exit"); + dialog_ex_set_right_button_text(app->dialog, "Stay"); + dialog_ex_set_center_button_text(app->dialog, "Menu"); + dialog_ex_set_header(app->dialog, "Close Current App?", 16, 12, AlignLeft, AlignTop); + + view_dispatcher_switch_to_view(app->view_dispatcher, HidViewDialog); +} + +bool hid_scene_exit_confirm_on_event(void* context, SceneManagerEvent event) { + Hid* app = context; + bool consumed = false; + UNUSED(app); + UNUSED(event); + + return consumed; +} + +void hid_scene_exit_confirm_on_exit(void* context) { + Hid* app = context; + + dialog_ex_reset(app->dialog); +} diff --git a/applications/system/hid_app/scenes/hid_scene_main.c b/applications/system/hid_app/scenes/hid_scene_main.c new file mode 100644 index 000000000..6c4a11682 --- /dev/null +++ b/applications/system/hid_app/scenes/hid_scene_main.c @@ -0,0 +1,22 @@ +#include "../hid.h" +#include "../views.h" + +void hid_scene_main_on_enter(void* context) { + Hid* app = context; + + view_dispatcher_switch_to_view(app->view_dispatcher, app->view_id); +} + +bool hid_scene_main_on_event(void* context, SceneManagerEvent event) { + Hid* app = context; + bool consumed = false; + UNUSED(app); + UNUSED(event); + + return consumed; +} + +void hid_scene_main_on_exit(void* context) { + Hid* app = context; + UNUSED(app); +} diff --git a/applications/system/hid_app/scenes/hid_scene_unpair.c b/applications/system/hid_app/scenes/hid_scene_unpair.c new file mode 100644 index 000000000..7b0bbd9e6 --- /dev/null +++ b/applications/system/hid_app/scenes/hid_scene_unpair.c @@ -0,0 +1,63 @@ +#include "../hid.h" +#include "../views.h" +#include "hid_icons.h" + +static void hid_scene_unpair_dialog_callback(DialogExResult result, void* context) { + Hid* app = context; + + if(result == DialogExResultRight) { + // Unpair all devices + bt_hid_remove_pairing(app); + + // Show popup + view_dispatcher_switch_to_view(app->view_dispatcher, HidViewPopup); + } else if(result == DialogExResultLeft) { + scene_manager_previous_scene(app->scene_manager); + } +} + +void hid_scene_unpair_popup_callback(void* context) { + Hid* app = context; + + scene_manager_previous_scene(app->scene_manager); +} + +void hid_scene_unpair_on_enter(void* context) { + Hid* app = context; + + // Un-pair dialog view + dialog_ex_reset(app->dialog); + dialog_ex_set_result_callback(app->dialog, hid_scene_unpair_dialog_callback); + dialog_ex_set_context(app->dialog, app); + dialog_ex_set_header(app->dialog, "Unpair All Devices?", 64, 3, AlignCenter, AlignTop); + dialog_ex_set_text( + app->dialog, "All previous pairings\nwill be lost!", 64, 22, AlignCenter, AlignTop); + dialog_ex_set_left_button_text(app->dialog, "Back"); + dialog_ex_set_right_button_text(app->dialog, "Unpair"); + + // Un-pair success popup view + popup_set_icon(app->popup, 32, 5, &I_DolphinNice_96x59); + popup_set_header(app->popup, "Done", 14, 15, AlignLeft, AlignTop); + popup_set_timeout(app->popup, 1500); + popup_set_context(app->popup, app); + popup_set_callback(app->popup, hid_scene_unpair_popup_callback); + popup_enable_timeout(app->popup); + + view_dispatcher_switch_to_view(app->view_dispatcher, HidViewDialog); +} + +bool hid_scene_unpair_on_event(void* context, SceneManagerEvent event) { + Hid* app = context; + bool consumed = false; + UNUSED(app); + UNUSED(event); + + return consumed; +} + +void hid_scene_unpair_on_exit(void* context) { + Hid* app = context; + + dialog_ex_reset(app->dialog); + popup_reset(app->popup); +} diff --git a/applications/system/hid_app/transport_ble.c b/applications/system/hid_app/transport_ble.c new file mode 100644 index 000000000..92a260add --- /dev/null +++ b/applications/system/hid_app/transport_ble.c @@ -0,0 +1,60 @@ +#include "hid.h" + +#ifndef HID_TRANSPORT_BLE +#error "HID_TRANSPORT_BLE must be defined" +#endif + +void hid_hal_keyboard_press(Hid* instance, uint16_t event) { + furi_assert(instance); + ble_profile_hid_kb_press(instance->ble_hid_profile, event); +} + +void hid_hal_keyboard_release(Hid* instance, uint16_t event) { + furi_assert(instance); + ble_profile_hid_kb_release(instance->ble_hid_profile, event); +} + +void hid_hal_keyboard_release_all(Hid* instance) { + furi_assert(instance); + ble_profile_hid_kb_release_all(instance->ble_hid_profile); +} + +void hid_hal_consumer_key_press(Hid* instance, uint16_t event) { + furi_assert(instance); + ble_profile_hid_consumer_key_press(instance->ble_hid_profile, event); +} + +void hid_hal_consumer_key_release(Hid* instance, uint16_t event) { + furi_assert(instance); + ble_profile_hid_consumer_key_release(instance->ble_hid_profile, event); +} + +void hid_hal_consumer_key_release_all(Hid* instance) { + furi_assert(instance); + ble_profile_hid_consumer_key_release_all(instance->ble_hid_profile); +} + +void hid_hal_mouse_move(Hid* instance, int8_t dx, int8_t dy) { + furi_assert(instance); + ble_profile_hid_mouse_move(instance->ble_hid_profile, dx, dy); +} + +void hid_hal_mouse_scroll(Hid* instance, int8_t delta) { + furi_assert(instance); + ble_profile_hid_mouse_scroll(instance->ble_hid_profile, delta); +} + +void hid_hal_mouse_press(Hid* instance, uint16_t event) { + furi_assert(instance); + ble_profile_hid_mouse_press(instance->ble_hid_profile, event); +} + +void hid_hal_mouse_release(Hid* instance, uint16_t event) { + furi_assert(instance); + ble_profile_hid_mouse_release(instance->ble_hid_profile, event); +} + +void hid_hal_mouse_release_all(Hid* instance) { + furi_assert(instance); + ble_profile_hid_mouse_release_all(instance->ble_hid_profile); +} diff --git a/applications/system/hid_app/transport_usb.c b/applications/system/hid_app/transport_usb.c new file mode 100644 index 000000000..882a715a5 --- /dev/null +++ b/applications/system/hid_app/transport_usb.c @@ -0,0 +1,61 @@ +#include "hid.h" + +#ifndef HID_TRANSPORT_USB +#error "HID_TRANSPORT_USB must be defined" +#endif + +void hid_hal_keyboard_press(Hid* instance, uint16_t event) { + furi_assert(instance); + furi_hal_hid_kb_press(event); +} + +void hid_hal_keyboard_release(Hid* instance, uint16_t event) { + furi_assert(instance); + furi_hal_hid_kb_release(event); +} + +void hid_hal_keyboard_release_all(Hid* instance) { + furi_assert(instance); + furi_hal_hid_kb_release_all(); +} + +void hid_hal_consumer_key_press(Hid* instance, uint16_t event) { + furi_assert(instance); + furi_hal_hid_consumer_key_press(event); +} + +void hid_hal_consumer_key_release(Hid* instance, uint16_t event) { + furi_assert(instance); + furi_hal_hid_consumer_key_release(event); +} + +void hid_hal_consumer_key_release_all(Hid* instance) { + furi_assert(instance); + furi_hal_hid_kb_release_all(); +} + +void hid_hal_mouse_move(Hid* instance, int8_t dx, int8_t dy) { + furi_assert(instance); + furi_hal_hid_mouse_move(dx, dy); +} + +void hid_hal_mouse_scroll(Hid* instance, int8_t delta) { + furi_assert(instance); + furi_hal_hid_mouse_scroll(delta); +} + +void hid_hal_mouse_press(Hid* instance, uint16_t event) { + furi_assert(instance); + furi_hal_hid_mouse_press(event); +} + +void hid_hal_mouse_release(Hid* instance, uint16_t event) { + furi_assert(instance); + furi_hal_hid_mouse_release(event); +} + +void hid_hal_mouse_release_all(Hid* instance) { + furi_assert(instance); + furi_hal_hid_mouse_release(HID_MOUSE_BTN_LEFT); + furi_hal_hid_mouse_release(HID_MOUSE_BTN_RIGHT); +} diff --git a/applications/system/hid_app/views.h b/applications/system/hid_app/views.h index 583ddb4b9..6fc8531ae 100644 --- a/applications/system/hid_app/views.h +++ b/applications/system/hid_app/views.h @@ -9,8 +9,10 @@ typedef enum { HidViewMouse, HidViewMouseClicker, HidViewMouseJiggler, - BtHidViewTikShorts, + BtHidViewTikTok, HidViewPushToTalk, HidViewPushToTalkMenu, HidViewPushToTalkHelp, -} HidView; + HidViewDialog, + HidViewPopup, +} HidView; \ No newline at end of file diff --git a/applications/system/hid_app/views/hid_keynote.c b/applications/system/hid_app/views/hid_keynote.c index 7d0e125d7..543363bf6 100644 --- a/applications/system/hid_app/views/hid_keynote.c +++ b/applications/system/hid_app/views/hid_keynote.c @@ -116,16 +116,16 @@ static void hid_keynote_draw_vertical_callback(Canvas* canvas, void* context) { HidKeynoteModel* model = context; // Header - canvas_set_font(canvas, FontPrimary); if(model->transport == HidTransportBle) { if(model->connected) { canvas_draw_icon(canvas, 0, 0, &I_Ble_connected_15x15); } else { canvas_draw_icon(canvas, 0, 0, &I_Ble_disconnected_15x15); } - + canvas_set_font(canvas, FontPrimary); elements_multiline_text_aligned(canvas, 20, 3, AlignLeft, AlignTop, "Keynote"); } else { + canvas_set_font(canvas, FontPrimary); elements_multiline_text_aligned(canvas, 12, 3, AlignLeft, AlignTop, "Keynote"); } diff --git a/applications/system/hid_app/views/hid_media.c b/applications/system/hid_app/views/hid_media.c index 849c511d9..af213eb03 100644 --- a/applications/system/hid_app/views/hid_media.c +++ b/applications/system/hid_app/views/hid_media.c @@ -1,7 +1,7 @@ #include "hid_media.h" #include -#include #include +#include #include #include "../hid.h" diff --git a/applications/system/hid_app/views/hid_movie.c b/applications/system/hid_app/views/hid_movie.c index 229f7299a..0a91b7f3b 100644 --- a/applications/system/hid_app/views/hid_movie.c +++ b/applications/system/hid_app/views/hid_movie.c @@ -1,7 +1,7 @@ #include "hid_movie.h" #include -#include #include +#include #include #include "../hid.h" diff --git a/applications/system/hid_app/views/hid_music_macos.c b/applications/system/hid_app/views/hid_music_macos.c index d5dd4dab3..68d738fd7 100644 --- a/applications/system/hid_app/views/hid_music_macos.c +++ b/applications/system/hid_app/views/hid_music_macos.c @@ -1,7 +1,7 @@ #include "hid_music_macos.h" #include -#include #include +#include #include #include "../hid.h" diff --git a/applications/system/hid_app/views/hid_tikshorts.h b/applications/system/hid_app/views/hid_tikshorts.h deleted file mode 100644 index 5604962ee..000000000 --- a/applications/system/hid_app/views/hid_tikshorts.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include - -typedef struct Hid Hid; -typedef struct HidTikShorts HidTikShorts; - -HidTikShorts* hid_tikshorts_alloc(Hid* bt_hid); - -void hid_tikshorts_free(HidTikShorts* hid_tikshorts); - -View* hid_tikshorts_get_view(HidTikShorts* hid_tikshorts); - -void hid_tikshorts_set_connected_status(HidTikShorts* hid_tikshorts, bool connected); diff --git a/applications/system/hid_app/views/hid_tikshorts.c b/applications/system/hid_app/views/hid_tiktok.c similarity index 61% rename from applications/system/hid_app/views/hid_tikshorts.c rename to applications/system/hid_app/views/hid_tiktok.c index 6965c1331..e9198791d 100644 --- a/applications/system/hid_app/views/hid_tikshorts.c +++ b/applications/system/hid_app/views/hid_tiktok.c @@ -1,12 +1,12 @@ -#include "hid_tikshorts.h" +#include "hid_tiktok.h" #include "../hid.h" #include #include "hid_icons.h" -#define TAG "HidTikShorts" +#define TAG "HidTikTok" -struct HidTikShorts { +struct HidTikTok { View* view; Hid* hid; }; @@ -21,11 +21,11 @@ typedef struct { bool is_cursor_set; bool back_mouse_pressed; HidTransport transport; -} HidTikShortsModel; +} HidTikTokModel; -static void hid_tikshorts_draw_callback(Canvas* canvas, void* context) { +static void hid_tiktok_draw_callback(Canvas* canvas, void* context) { furi_assert(context); - HidTikShortsModel* model = context; + HidTikTokModel* model = context; // Header if(model->transport == HidTransportBle) { @@ -110,32 +110,30 @@ static void hid_tikshorts_draw_callback(Canvas* canvas, void* context) { elements_multiline_text_aligned(canvas, 13, 62, AlignLeft, AlignBottom, "Hold to exit"); } -static void hid_tikshorts_reset_cursor(HidTikShorts* hid_tikshorts) { +static void hid_tiktok_reset_cursor(HidTikTok* hid_tiktok) { // Set cursor to the phone's left up corner // Delays to guarantee one packet per connection interval for(size_t i = 0; i < 8; i++) { - hid_hal_mouse_move(hid_tikshorts->hid, -127, -127); + hid_hal_mouse_move(hid_tiktok->hid, -127, -127); furi_delay_ms(50); } // Move cursor from the corner - hid_hal_mouse_move(hid_tikshorts->hid, 20, 120); + hid_hal_mouse_move(hid_tiktok->hid, 20, 120); furi_delay_ms(50); } -static void hid_tikshorts_process_press( - HidTikShorts* hid_tikshorts, - HidTikShortsModel* model, - InputEvent* event) { +static void + hid_tiktok_process_press(HidTikTok* hid_tiktok, HidTikTokModel* model, InputEvent* event) { if(event->key == InputKeyUp) { model->up_pressed = true; } else if(event->key == InputKeyDown) { model->down_pressed = true; } else if(event->key == InputKeyLeft) { model->left_pressed = true; - hid_hal_consumer_key_press(hid_tikshorts->hid, HID_CONSUMER_VOLUME_DECREMENT); + hid_hal_consumer_key_press(hid_tiktok->hid, HID_CONSUMER_VOLUME_DECREMENT); } else if(event->key == InputKeyRight) { model->right_pressed = true; - hid_hal_consumer_key_press(hid_tikshorts->hid, HID_CONSUMER_VOLUME_INCREMENT); + hid_hal_consumer_key_press(hid_tiktok->hid, HID_CONSUMER_VOLUME_INCREMENT); } else if(event->key == InputKeyOk) { model->ok_pressed = true; } else if(event->key == InputKeyBack) { @@ -143,20 +141,18 @@ static void hid_tikshorts_process_press( } } -static void hid_tikshorts_process_release( - HidTikShorts* hid_tikshorts, - HidTikShortsModel* model, - InputEvent* event) { +static void + hid_tiktok_process_release(HidTikTok* hid_tiktok, HidTikTokModel* model, InputEvent* event) { if(event->key == InputKeyUp) { model->up_pressed = false; } else if(event->key == InputKeyDown) { model->down_pressed = false; } else if(event->key == InputKeyLeft) { model->left_pressed = false; - hid_hal_consumer_key_release(hid_tikshorts->hid, HID_CONSUMER_VOLUME_DECREMENT); + hid_hal_consumer_key_release(hid_tiktok->hid, HID_CONSUMER_VOLUME_DECREMENT); } else if(event->key == InputKeyRight) { model->right_pressed = false; - hid_hal_consumer_key_release(hid_tikshorts->hid, HID_CONSUMER_VOLUME_INCREMENT); + hid_hal_consumer_key_release(hid_tiktok->hid, HID_CONSUMER_VOLUME_INCREMENT); } else if(event->key == InputKeyOk) { model->ok_pressed = false; } else if(event->key == InputKeyBack) { @@ -164,61 +160,61 @@ static void hid_tikshorts_process_release( } } -static bool hid_tikshorts_input_callback(InputEvent* event, void* context) { +static bool hid_tiktok_input_callback(InputEvent* event, void* context) { furi_assert(context); - HidTikShorts* hid_tikshorts = context; + HidTikTok* hid_tiktok = context; bool consumed = false; with_view_model( - hid_tikshorts->view, - HidTikShortsModel * model, + hid_tiktok->view, + HidTikTokModel * model, { if(event->type == InputTypePress) { - hid_tikshorts_process_press(hid_tikshorts, model, event); + hid_tiktok_process_press(hid_tiktok, model, event); if(model->connected && !model->is_cursor_set) { - hid_tikshorts_reset_cursor(hid_tikshorts); + hid_tiktok_reset_cursor(hid_tiktok); model->is_cursor_set = true; } consumed = true; } else if(event->type == InputTypeRelease) { - hid_tikshorts_process_release(hid_tikshorts, model, event); + hid_tiktok_process_release(hid_tiktok, model, event); consumed = true; } else if(event->type == InputTypeShort) { if(event->key == InputKeyOk) { - hid_hal_mouse_press(hid_tikshorts->hid, HID_MOUSE_BTN_LEFT); + hid_hal_mouse_press(hid_tiktok->hid, HID_MOUSE_BTN_LEFT); furi_delay_ms(25); - hid_hal_mouse_release(hid_tikshorts->hid, HID_MOUSE_BTN_LEFT); + hid_hal_mouse_release(hid_tiktok->hid, HID_MOUSE_BTN_LEFT); furi_delay_ms(100); - hid_hal_mouse_press(hid_tikshorts->hid, HID_MOUSE_BTN_LEFT); + hid_hal_mouse_press(hid_tiktok->hid, HID_MOUSE_BTN_LEFT); furi_delay_ms(25); - hid_hal_mouse_release(hid_tikshorts->hid, HID_MOUSE_BTN_LEFT); - consumed = true; - } else if(event->key == InputKeyDown) { - // Swipe to next video - hid_hal_mouse_scroll(hid_tikshorts->hid, 6); - hid_hal_mouse_scroll(hid_tikshorts->hid, 8); - hid_hal_mouse_scroll(hid_tikshorts->hid, 10); - hid_hal_mouse_scroll(hid_tikshorts->hid, 8); - hid_hal_mouse_scroll(hid_tikshorts->hid, 6); + hid_hal_mouse_release(hid_tiktok->hid, HID_MOUSE_BTN_LEFT); consumed = true; } else if(event->key == InputKeyUp) { // Swipe to previous video - hid_hal_mouse_scroll(hid_tikshorts->hid, -6); - hid_hal_mouse_scroll(hid_tikshorts->hid, -8); - hid_hal_mouse_scroll(hid_tikshorts->hid, -10); - hid_hal_mouse_scroll(hid_tikshorts->hid, -8); - hid_hal_mouse_scroll(hid_tikshorts->hid, -6); + hid_hal_mouse_scroll(hid_tiktok->hid, -6); + hid_hal_mouse_scroll(hid_tiktok->hid, -8); + hid_hal_mouse_scroll(hid_tiktok->hid, -10); + hid_hal_mouse_scroll(hid_tiktok->hid, -8); + hid_hal_mouse_scroll(hid_tiktok->hid, -6); + consumed = true; + } else if(event->key == InputKeyDown) { + // Swipe to next video + hid_hal_mouse_scroll(hid_tiktok->hid, 6); + hid_hal_mouse_scroll(hid_tiktok->hid, 8); + hid_hal_mouse_scroll(hid_tiktok->hid, 10); + hid_hal_mouse_scroll(hid_tiktok->hid, 8); + hid_hal_mouse_scroll(hid_tiktok->hid, 6); consumed = true; } else if(event->key == InputKeyBack) { // Pause - hid_hal_mouse_press(hid_tikshorts->hid, HID_MOUSE_BTN_LEFT); + hid_hal_mouse_press(hid_tiktok->hid, HID_MOUSE_BTN_LEFT); furi_delay_ms(50); - hid_hal_mouse_release(hid_tikshorts->hid, HID_MOUSE_BTN_LEFT); + hid_hal_mouse_release(hid_tiktok->hid, HID_MOUSE_BTN_LEFT); consumed = true; } } else if(event->type == InputTypeLong) { if(event->key == InputKeyBack) { - hid_hal_consumer_key_release_all(hid_tikshorts->hid); + hid_hal_consumer_key_release_all(hid_tiktok->hid); model->is_cursor_set = false; consumed = false; } @@ -229,40 +225,37 @@ static bool hid_tikshorts_input_callback(InputEvent* event, void* context) { return consumed; } -HidTikShorts* hid_tikshorts_alloc(Hid* bt_hid) { - HidTikShorts* hid_tikshorts = malloc(sizeof(HidTikShorts)); - hid_tikshorts->hid = bt_hid; - hid_tikshorts->view = view_alloc(); - view_set_context(hid_tikshorts->view, hid_tikshorts); - view_allocate_model(hid_tikshorts->view, ViewModelTypeLocking, sizeof(HidTikShortsModel)); - view_set_draw_callback(hid_tikshorts->view, hid_tikshorts_draw_callback); - view_set_input_callback(hid_tikshorts->view, hid_tikshorts_input_callback); +HidTikTok* hid_tiktok_alloc(Hid* bt_hid) { + HidTikTok* hid_tiktok = malloc(sizeof(HidTikTok)); + hid_tiktok->hid = bt_hid; + hid_tiktok->view = view_alloc(); + view_set_context(hid_tiktok->view, hid_tiktok); + view_allocate_model(hid_tiktok->view, ViewModelTypeLocking, sizeof(HidTikTokModel)); + view_set_draw_callback(hid_tiktok->view, hid_tiktok_draw_callback); + view_set_input_callback(hid_tiktok->view, hid_tiktok_input_callback); with_view_model( - hid_tikshorts->view, - HidTikShortsModel * model, - { model->transport = bt_hid->transport; }, - true); + hid_tiktok->view, HidTikTokModel * model, { model->transport = bt_hid->transport; }, true); - return hid_tikshorts; + return hid_tiktok; } -void hid_tikshorts_free(HidTikShorts* hid_tikshorts) { - furi_assert(hid_tikshorts); - view_free(hid_tikshorts->view); - free(hid_tikshorts); +void hid_tiktok_free(HidTikTok* hid_tiktok) { + furi_assert(hid_tiktok); + view_free(hid_tiktok->view); + free(hid_tiktok); } -View* hid_tikshorts_get_view(HidTikShorts* hid_tikshorts) { - furi_assert(hid_tikshorts); - return hid_tikshorts->view; +View* hid_tiktok_get_view(HidTikTok* hid_tiktok) { + furi_assert(hid_tiktok); + return hid_tiktok->view; } -void hid_tikshorts_set_connected_status(HidTikShorts* hid_tikshorts, bool connected) { - furi_assert(hid_tikshorts); +void hid_tiktok_set_connected_status(HidTikTok* hid_tiktok, bool connected) { + furi_assert(hid_tiktok); with_view_model( - hid_tikshorts->view, - HidTikShortsModel * model, + hid_tiktok->view, + HidTikTokModel * model, { model->connected = connected; model->is_cursor_set = false; diff --git a/applications/system/hid_app/views/hid_tiktok.h b/applications/system/hid_app/views/hid_tiktok.h new file mode 100644 index 000000000..b2efc3692 --- /dev/null +++ b/applications/system/hid_app/views/hid_tiktok.h @@ -0,0 +1,14 @@ +#pragma once + +#include + +typedef struct Hid Hid; +typedef struct HidTikTok HidTikTok; + +HidTikTok* hid_tiktok_alloc(Hid* bt_hid); + +void hid_tiktok_free(HidTikTok* hid_tiktok); + +View* hid_tiktok_get_view(HidTikTok* hid_tiktok); + +void hid_tiktok_set_connected_status(HidTikTok* hid_tiktok, bool connected);