Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hid app merge fix #753

Merged
merged 4 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
130 changes: 12 additions & 118 deletions applications/system/hid_app/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,9 @@
#include "views.h"
#include <notification/notification_messages.h>
#include <dolphin/dolphin.h>
#include "hid_icons.h"

#define TAG "HidApp"

enum HidDebugSubmenuIndex {
HidSubmenuIndexKeynote,
HidSubmenuIndexKeynoteVertical,
HidSubmenuIndexKeyboard,
HidSubmenuIndexNumpad,
HidSubmenuIndexMedia,
HidSubmenuIndexMusicMacOs,
HidSubmenuIndexMovie,
HidSubmenuIndexTikTok,
HidSubmenuIndexMouse,
HidSubmenuIndexMouseClicker,
HidSubmenuIndexMouseJiggler,
HidSubmenuIndexMouseJigglerStealth,
HidSubmenuIndexPushToTalk,
HidSubmenuIndexRemovePairing,
};

bool hid_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
Hid* app = context;
Expand All @@ -34,9 +16,7 @@ bool hid_custom_event_callback(void* context, uint32_t event) {
bool hid_back_event_callback(void* context) {
furi_assert(context);
Hid* app = context;
FURI_LOG_D("HID", "Back event");
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewSubmenu);
return true;
return scene_manager_handle_back_event(app->scene_manager);
}

void bt_hid_remove_pairing(Hid* app) {
Expand All @@ -53,53 +33,12 @@ void bt_hid_remove_pairing(Hid* app) {
furi_hal_bt_start_advertising();
}

static void hid_submenu_callback(void* context, uint32_t index) {
furi_assert(context);
Hid* app = context;
if(index == HidSubmenuIndexKeynote) {
hid_keynote_set_orientation(app->hid_keynote, false);
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewKeynote);
} else if(index == HidSubmenuIndexKeynoteVertical) {
hid_keynote_set_orientation(app->hid_keynote, true);
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewKeynote);
} else if(index == HidSubmenuIndexKeyboard) {
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewKeyboard);
} else if(index == HidSubmenuIndexNumpad) {
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewNumpad);
} else if(index == HidSubmenuIndexMedia) {
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewMedia);
} else if(index == HidSubmenuIndexMusicMacOs) {
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewMusicMacOs);
} else if(index == HidSubmenuIndexMovie) {
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewMovie);
} else if(index == HidSubmenuIndexMouse) {
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewMouse);
} else if(index == HidSubmenuIndexTikTok) {
view_dispatcher_switch_to_view(app->view_dispatcher, BtHidViewTikTok);
} else if(index == HidSubmenuIndexMouseClicker) {
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewMouseClicker);
} else if(index == HidSubmenuIndexMouseJiggler) {
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewMouseJiggler);
} else if(index == HidSubmenuIndexMouseJigglerStealth) {
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewMouseJigglerStealth);
} else if(index == HidSubmenuIndexPushToTalk) {
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewPushToTalkMenu);
} else if(index == HidSubmenuIndexRemovePairing) {
scene_manager_next_scene(app->scene_manager, HidSceneUnpair);
}
}

static void bt_hid_connection_status_changed_callback(BtStatus status, void* context) {
furi_assert(context);
Hid* hid = context;
bool connected = (status == BtStatusConnected);
#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
const bool connected = (status == BtStatusConnected);
notification_internal_message(
hid->notifications, connected ? &sequence_set_blue_255 : &sequence_reset_blue);
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);
Expand All @@ -114,17 +53,12 @@ static void bt_hid_connection_status_changed_callback(BtStatus status, void* con
hid_tiktok_set_connected_status(hid->hid_tiktok, connected);
}

static uint32_t hid_exit(void* context) {
UNUSED(context);
return VIEW_NONE;
}

static uint32_t hid_ptt_menu_view(void* context) {
UNUSED(context);
return HidViewPushToTalkMenu;
}

Hid* hid_alloc(void) {
Hid* hid_alloc() {
Hid* app = malloc(sizeof(Hid));

// Gui
Expand All @@ -139,55 +73,18 @@ Hid* hid_alloc(void) {
// View dispatcher
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);
view_dispatcher_set_custom_event_callback(app->view_dispatcher, hid_custom_event_callback);
view_dispatcher_set_navigation_event_callback(app->view_dispatcher, hid_back_event_callback);
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);

// Scene Manager
app->scene_manager = scene_manager_alloc(&hid_scene_handlers, app);

// Device Type Submenu view
app->submenu = submenu_alloc();
submenu_add_item(app->submenu, "Keynote", HidSubmenuIndexKeynote, hid_submenu_callback, app);
submenu_add_item(
app->submenu,
"Keynote Vertical",
HidSubmenuIndexKeynoteVertical,
hid_submenu_callback,
app);
submenu_add_item(app->submenu, "Keyboard", HidSubmenuIndexKeyboard, hid_submenu_callback, app);
submenu_add_item(app->submenu, "Numpad", HidSubmenuIndexNumpad, hid_submenu_callback, app);
submenu_add_item(app->submenu, "Media", HidSubmenuIndexMedia, hid_submenu_callback, app);
submenu_add_item(
app->submenu, "Apple Music macOS", HidSubmenuIndexMusicMacOs, hid_submenu_callback, app);
submenu_add_item(app->submenu, "Movie", HidSubmenuIndexMovie, hid_submenu_callback, app);
submenu_add_item(app->submenu, "Mouse", HidSubmenuIndexMouse, hid_submenu_callback, app);
submenu_add_item(
app->submenu, "TikTok / YT Shorts", HidSubmenuIndexTikTok, hid_submenu_callback, app);
submenu_add_item(
app->submenu, "Mouse Clicker", HidSubmenuIndexMouseClicker, hid_submenu_callback, app);
submenu_add_item(
app->submenu, "Mouse Jiggler", HidSubmenuIndexMouseJiggler, hid_submenu_callback, app);
submenu_add_item(
app->submenu,
"Mouse Jiggler Stealth",
HidSubmenuIndexMouseJigglerStealth,
hid_submenu_callback,
app);
submenu_add_item(
app->submenu, "PushToTalk", HidSubmenuIndexPushToTalk, hid_submenu_callback, app);
#ifdef HID_TRANSPORT_BLE
submenu_add_item(
app->submenu, "Remove Pairing", HidSubmenuIndexRemovePairing, hid_submenu_callback, app);
#endif
view_set_previous_callback(submenu_get_view(app->submenu), hid_exit);
view_dispatcher_add_view(app->view_dispatcher, HidViewSubmenu, submenu_get_view(app->submenu));
return app;
}

Hid* hid_app_alloc_view(void* context) {
furi_assert(context);
Hid* app = context;
view_dispatcher_add_view(app->view_dispatcher, HidViewSubmenu, submenu_get_view(app->submenu));

// Dialog view
app->dialog = dialog_ex_alloc();
Expand Down Expand Up @@ -327,18 +224,16 @@ void hid_free(Hid* app) {
int32_t hid_usb_app(void* p) {
UNUSED(p);
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);

bt_hid_connection_status_changed_callback(BtStatusConnected, app);

dolphin_deed(DolphinDeedPluginStart);

scene_manager_next_scene(app->scene_manager, HidSceneMain);
scene_manager_next_scene(app->scene_manager, HidSceneStart);

view_dispatcher_run(app->view_dispatcher);

Expand All @@ -352,7 +247,6 @@ int32_t hid_usb_app(void* p) {
int32_t hid_ble_app(void* p) {
UNUSED(p);
Hid* app = hid_alloc();
app = hid_app_alloc_view(app);

FURI_LOG_D("HID", "Starting as BLE app");

Expand Down Expand Up @@ -382,7 +276,7 @@ int32_t hid_ble_app(void* p) {

dolphin_deed(DolphinDeedPluginStart);

scene_manager_next_scene(app->scene_manager, HidSceneMain);
scene_manager_next_scene(app->scene_manager, HidSceneStart);

view_dispatcher_run(app->view_dispatcher);

Expand Down
3 changes: 2 additions & 1 deletion applications/system/hid_app/hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct Hid {
HidPushToTalk* hid_ptt;
HidPushToTalkMenu* hid_ptt_menu;
};

void bt_hid_remove_pairing(Hid* app);

void hid_hal_keyboard_press(Hid* instance, uint16_t event);
Expand All @@ -76,4 +77,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);
3 changes: 2 additions & 1 deletion applications/system/hid_app/scenes/hid_scene_config.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ADD_SCENE(hid, start, Start)
ADD_SCENE(hid, main, Main)
ADD_SCENE(hid, unpair, Unpair)
ADD_SCENE(hid, unpair, Unpair)
1 change: 0 additions & 1 deletion applications/system/hid_app/scenes/hid_scene_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

void hid_scene_main_on_enter(void* context) {
Hid* app = context;

view_dispatcher_switch_to_view(
app->view_dispatcher, scene_manager_get_scene_state(app->scene_manager, HidSceneMain));
}
Expand Down
Loading