mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-11-27 05:42:16 +03:00
hid app merge fixes
+ changes by Willy-JL
This commit is contained in:
parent
66c60e65aa
commit
2d32ea68fe
Binary file not shown.
Before Width: | Height: | Size: 3.6 KiB |
Binary file not shown.
Before Width: | Height: | Size: 959 B |
Binary file not shown.
Before Width: | Height: | Size: 320 B |
@ -1,7 +1,10 @@
|
||||
#include "hid.h"
|
||||
#include <extra_profiles/hid_profile.h>
|
||||
#include <profiles/serial_profile.h>
|
||||
#include "views.h"
|
||||
#include <notification/notification_messages.h>
|
||||
#include <dolphin/dolphin.h>
|
||||
#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) {
|
||||
#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,
|
||||
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) {
|
||||
#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);
|
||||
|
||||
|
@ -2,14 +2,16 @@
|
||||
|
||||
#include <furi.h>
|
||||
#include <furi_hal_bt.h>
|
||||
#include <furi_hal_bt_hid.h>
|
||||
#include <furi_hal_usb.h>
|
||||
#include <furi_hal_usb_hid.h>
|
||||
|
||||
#include <extra_profiles/hid_profile.h>
|
||||
|
||||
#include <bt/bt_service/bt.h>
|
||||
#include <gui/gui.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/scene_manager.h>
|
||||
#include <notification/notification.h>
|
||||
#include <storage/storage.h>
|
||||
|
||||
@ -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);
|
||||
|
30
applications/system/hid_app/scenes/hid_scene.c
Normal file
30
applications/system/hid_app/scenes/hid_scene.c
Normal file
@ -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,
|
||||
};
|
29
applications/system/hid_app/scenes/hid_scene.h
Normal file
29
applications/system/hid_app/scenes/hid_scene.h
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/scene_manager.h>
|
||||
|
||||
// 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
|
3
applications/system/hid_app/scenes/hid_scene_config.h
Normal file
3
applications/system/hid_app/scenes/hid_scene_config.h
Normal file
@ -0,0 +1,3 @@
|
||||
ADD_SCENE(hid, main, Main)
|
||||
ADD_SCENE(hid, unpair, Unpair)
|
||||
ADD_SCENE(hid, exit_confirm, ExitConfirm)
|
45
applications/system/hid_app/scenes/hid_scene_exit_confirm.c
Normal file
45
applications/system/hid_app/scenes/hid_scene_exit_confirm.c
Normal file
@ -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);
|
||||
}
|
22
applications/system/hid_app/scenes/hid_scene_main.c
Normal file
22
applications/system/hid_app/scenes/hid_scene_main.c
Normal file
@ -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);
|
||||
}
|
63
applications/system/hid_app/scenes/hid_scene_unpair.c
Normal file
63
applications/system/hid_app/scenes/hid_scene_unpair.c
Normal file
@ -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);
|
||||
}
|
60
applications/system/hid_app/transport_ble.c
Normal file
60
applications/system/hid_app/transport_ble.c
Normal file
@ -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);
|
||||
}
|
61
applications/system/hid_app/transport_usb.c
Normal file
61
applications/system/hid_app/transport_usb.c
Normal file
@ -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);
|
||||
}
|
@ -9,8 +9,10 @@ typedef enum {
|
||||
HidViewMouse,
|
||||
HidViewMouseClicker,
|
||||
HidViewMouseJiggler,
|
||||
BtHidViewTikShorts,
|
||||
BtHidViewTikTok,
|
||||
HidViewPushToTalk,
|
||||
HidViewPushToTalkMenu,
|
||||
HidViewPushToTalkHelp,
|
||||
HidViewDialog,
|
||||
HidViewPopup,
|
||||
} HidView;
|
@ -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");
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "hid_media.h"
|
||||
#include <furi.h>
|
||||
#include <furi_hal_bt_hid.h>
|
||||
#include <furi_hal_usb_hid.h>
|
||||
#include <extra_profiles/hid_profile.h>
|
||||
#include <gui/elements.h>
|
||||
#include "../hid.h"
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "hid_movie.h"
|
||||
#include <furi.h>
|
||||
#include <furi_hal_bt_hid.h>
|
||||
#include <furi_hal_usb_hid.h>
|
||||
#include <extra_profiles/hid_profile.h>
|
||||
#include <gui/elements.h>
|
||||
#include "../hid.h"
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "hid_music_macos.h"
|
||||
#include <furi.h>
|
||||
#include <furi_hal_bt_hid.h>
|
||||
#include <furi_hal_usb_hid.h>
|
||||
#include <extra_profiles/hid_profile.h>
|
||||
#include <gui/elements.h>
|
||||
#include "../hid.h"
|
||||
|
||||
|
@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
|
||||
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);
|
@ -1,12 +1,12 @@
|
||||
#include "hid_tikshorts.h"
|
||||
#include "hid_tiktok.h"
|
||||
#include "../hid.h"
|
||||
#include <gui/elements.h>
|
||||
|
||||
#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;
|
14
applications/system/hid_app/views/hid_tiktok.h
Normal file
14
applications/system/hid_app/views/hid_tiktok.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
|
||||
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);
|
Loading…
Reference in New Issue
Block a user