Skip to content

Commit

Permalink
app: hid: select transport based on #define
Browse files Browse the repository at this point in the history
  • Loading branch information
hedger committed Dec 6, 2023
1 parent 5a04bef commit ed1b927
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 108 deletions.
2 changes: 2 additions & 0 deletions applications/system/hid_app/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ App(
apptype=FlipperAppType.EXTERNAL,
entry_point="hid_usb_app",
stack_size=1 * 1024,
cdefines=["HID_TRANSPORT_USB"],
fap_description="Use Flipper as a HID remote control over USB",
fap_version="1.0",
fap_category="USB",
Expand All @@ -19,6 +20,7 @@ App(
apptype=FlipperAppType.EXTERNAL,
entry_point="hid_ble_app",
stack_size=1 * 1024,
cdefines=["HID_TRANSPORT_BLE"],
fap_libs=["ble_profile"],
fap_description="Use Flipper as a HID remote control over Bluetooth",
fap_version="1.0",
Expand Down
214 changes: 106 additions & 108 deletions applications/system/hid_app/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,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_media_set_connected_status(hid->hid_media, connected);
Expand Down Expand Up @@ -108,9 +108,8 @@ static uint32_t hid_exit(void* context) {
return VIEW_NONE;
}

Hid* hid_alloc(HidTransport transport) {
Hid* hid_alloc() {
Hid* app = malloc(sizeof(Hid));
app->transport = transport;

// Gui
app->gui = furi_record_open(RECORD_GUI);
Expand Down Expand Up @@ -141,14 +140,14 @@ Hid* hid_alloc(HidTransport transport) {
app->device_type_submenu, "Media", HidSubmenuIndexMedia, 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 Controller",
HidSubmenuIndexTikTok,
hid_submenu_callback,
app);
}
#ifdef HID_TRANSPORT_BLE
submenu_add_item(
app->device_type_submenu,
"TikTok Controller",
HidSubmenuIndexTikTok,
hid_submenu_callback,
app);
#endif
submenu_add_item(
app->device_type_submenu,
"Mouse Clicker",
Expand All @@ -161,14 +160,14 @@ Hid* hid_alloc(HidTransport transport) {
HidSubmenuIndexMouseJiggler,
hid_submenu_callback,
app);
if(transport == HidTransportBle) {
submenu_add_item(
app->device_type_submenu,
"Remove Pairing",
HidSubmenuIndexRemovePairing,
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));
Expand Down Expand Up @@ -246,10 +245,9 @@ 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);
Expand Down Expand Up @@ -285,129 +283,129 @@ void hid_free(Hid* app) {

void hid_hal_keyboard_press(Hid* instance, uint16_t event) {
furi_assert(instance);
if(instance->transport == HidTransportBle) {
ble_profile_hid_kb_press(instance->ble_hid_profile, event);
} else if(instance->transport == HidTransportUsb) {
furi_hal_hid_kb_press(event);
} else {
furi_crash();
}
#ifdef HID_TRANSPORT_BLE
ble_profile_hid_kb_press(instance->ble_hid_profile, event);
#elif HID_TRANSPORT_USB
furi_hal_hid_kb_press(event);
#else
furi_crash();
#endif
}

void hid_hal_keyboard_release(Hid* instance, uint16_t event) {
furi_assert(instance);
if(instance->transport == HidTransportBle) {
ble_profile_hid_kb_release(instance->ble_hid_profile, event);
} else if(instance->transport == HidTransportUsb) {
furi_hal_hid_kb_release(event);
} else {
furi_crash();
}
#ifdef HID_TRANSPORT_BLE
ble_profile_hid_kb_release(instance->ble_hid_profile, event);
#elif HID_TRANSPORT_USB
furi_hal_hid_kb_release(event);
#else
furi_crash();
#endif
}

void hid_hal_keyboard_release_all(Hid* instance) {
furi_assert(instance);
if(instance->transport == HidTransportBle) {
ble_profile_hid_kb_release_all(instance->ble_hid_profile);
} else if(instance->transport == HidTransportUsb) {
furi_hal_hid_kb_release_all();
} else {
furi_crash();
}
#ifdef HID_TRANSPORT_BLE
ble_profile_hid_kb_release_all(instance->ble_hid_profile);
#elif HID_TRANSPORT_USB
furi_hal_hid_kb_release_all();
#else
furi_crash();
#endif
}

void hid_hal_consumer_key_press(Hid* instance, uint16_t event) {
furi_assert(instance);
if(instance->transport == HidTransportBle) {
ble_profile_hid_consumer_key_press(instance->ble_hid_profile, event);
} else if(instance->transport == HidTransportUsb) {
furi_hal_hid_consumer_key_press(event);
} else {
furi_crash();
}
#ifdef HID_TRANSPORT_BLE
ble_profile_hid_consumer_key_press(instance->ble_hid_profile, event);
#elif HID_TRANSPORT_USB
furi_hal_hid_consumer_key_press(event);
#else
furi_crash();
#endif
}

void hid_hal_consumer_key_release(Hid* instance, uint16_t event) {
furi_assert(instance);
if(instance->transport == HidTransportBle) {
ble_profile_hid_consumer_key_release(instance->ble_hid_profile, event);
} else if(instance->transport == HidTransportUsb) {
furi_hal_hid_consumer_key_release(event);
} else {
furi_crash();
}
#ifdef HID_TRANSPORT_BLE
ble_profile_hid_consumer_key_release(instance->ble_hid_profile, event);
#elif HID_TRANSPORT_USB
furi_hal_hid_consumer_key_release(event);
#else
furi_crash();
#endif
}

void hid_hal_consumer_key_release_all(Hid* instance) {
furi_assert(instance);
if(instance->transport == HidTransportBle) {
ble_profile_hid_consumer_key_release_all(instance->ble_hid_profile);
} else if(instance->transport == HidTransportUsb) {
furi_hal_hid_kb_release_all();
} else {
furi_crash();
}
#ifdef HID_TRANSPORT_BLE
ble_profile_hid_consumer_key_release_all(instance->ble_hid_profile);
#elif HID_TRANSPORT_USB
furi_hal_hid_kb_release_all();
#else
furi_crash();
#endif
}

void hid_hal_mouse_move(Hid* instance, int8_t dx, int8_t dy) {
furi_assert(instance);
if(instance->transport == HidTransportBle) {
ble_profile_hid_mouse_move(instance->ble_hid_profile, dx, dy);
} else if(instance->transport == HidTransportUsb) {
furi_hal_hid_mouse_move(dx, dy);
} else {
furi_crash();
}
#ifdef HID_TRANSPORT_BLE
ble_profile_hid_mouse_move(instance->ble_hid_profile, dx, dy);
#elif HID_TRANSPORT_USB
furi_hal_hid_mouse_move(dx, dy);
#else
furi_crash();
#endif
}

void hid_hal_mouse_scroll(Hid* instance, int8_t delta) {
furi_assert(instance);
if(instance->transport == HidTransportBle) {
ble_profile_hid_mouse_scroll(instance->ble_hid_profile, delta);
} else if(instance->transport == HidTransportUsb) {
furi_hal_hid_mouse_scroll(delta);
} else {
furi_crash();
}
#ifdef HID_TRANSPORT_BLE
ble_profile_hid_mouse_scroll(instance->ble_hid_profile, delta);
#elif HID_TRANSPORT_USB
furi_hal_hid_mouse_scroll(delta);
#else
furi_crash();
#endif
}

void hid_hal_mouse_press(Hid* instance, uint16_t event) {
furi_assert(instance);
if(instance->transport == HidTransportBle) {
ble_profile_hid_mouse_press(instance->ble_hid_profile, event);
} else if(instance->transport == HidTransportUsb) {
furi_hal_hid_mouse_press(event);
} else {
furi_crash();
}
#ifdef HID_TRANSPORT_BLE
ble_profile_hid_mouse_press(instance->ble_hid_profile, event);
#elif HID_TRANSPORT_USB
furi_hal_hid_mouse_press(event);
#else
furi_crash();
#endif
}

void hid_hal_mouse_release(Hid* instance, uint16_t event) {
furi_assert(instance);
if(instance->transport == HidTransportBle) {
ble_profile_hid_mouse_release(instance->ble_hid_profile, event);
} else if(instance->transport == HidTransportUsb) {
furi_hal_hid_mouse_release(event);
} else {
furi_crash();
}
#ifdef HID_TRANSPORT_BLE
ble_profile_hid_mouse_release(instance->ble_hid_profile, event);
#elif HID_TRANSPORT_USB
furi_hal_hid_mouse_release(event);
#else
furi_crash();
#endif
}

void hid_hal_mouse_release_all(Hid* instance) {
furi_assert(instance);
if(instance->transport == HidTransportBle) {
ble_profile_hid_mouse_release_all(instance->ble_hid_profile);
} 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();
}
#ifdef HID_TRANSPORT_BLE
ble_profile_hid_mouse_release_all(instance->ble_hid_profile);
#elif HID_TRANSPORT_USB
furi_hal_hid_mouse_release(HID_MOUSE_BTN_LEFT);
furi_hal_hid_mouse_release(HID_MOUSE_BTN_RIGHT);
#else
furi_crash();
#endif
}

int32_t hid_usb_app(void* p) {
UNUSED(p);
Hid* app = hid_alloc(HidTransportUsb);
Hid* app = hid_alloc();
app = hid_app_alloc_view(app);
FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config();
furi_hal_usb_unlock();
Expand All @@ -428,7 +426,7 @@ 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);

bt_disconnect(app->bt);
Expand Down

0 comments on commit ed1b927

Please sign in to comment.