From d453cfe1ae67b44433d937216d834ffdf05bb503 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Wed, 20 Mar 2024 13:35:23 +0300 Subject: [PATCH] upd airmouse --- non_catalog_apps/airmouse/air_mouse.c | 9 +++++ non_catalog_apps/airmouse/application.fam | 4 +-- non_catalog_apps/airmouse/views/bt_mouse.c | 38 +++++++++++++++++++++- non_catalog_apps/airmouse/views/bt_mouse.h | 2 ++ 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/non_catalog_apps/airmouse/air_mouse.c b/non_catalog_apps/airmouse/air_mouse.c index 64b2274abb6..54a6e80273b 100644 --- a/non_catalog_apps/airmouse/air_mouse.c +++ b/non_catalog_apps/airmouse/air_mouse.c @@ -10,6 +10,7 @@ enum AirMouseSubmenuIndex { AirMouseSubmenuIndexBtMouse, AirMouseSubmenuIndexUsbMouse, AirMouseSubmenuIndexCalibration, + AirMouseSubmenuIndexRemovePairing, }; void air_mouse_submenu_callback(void* context, uint32_t index) { @@ -24,6 +25,8 @@ void air_mouse_submenu_callback(void* context, uint32_t index) { } else if(index == AirMouseSubmenuIndexCalibration) { app->view_id = AirMouseViewCalibration; view_dispatcher_switch_to_view(app->view_dispatcher, AirMouseViewCalibration); + } else if(index == AirMouseSubmenuIndexRemovePairing) { + bt_mouse_remove_pairing(); } } @@ -78,6 +81,12 @@ AirMouse* air_mouse_app_alloc() { AirMouseSubmenuIndexCalibration, air_mouse_submenu_callback, app); + submenu_add_item( + app->submenu, + "Clear Bluetooth Pairings", + AirMouseSubmenuIndexRemovePairing, + air_mouse_submenu_callback, + app); view_set_previous_callback(submenu_get_view(app->submenu), air_mouse_exit); view_dispatcher_add_view( app->view_dispatcher, AirMouseViewSubmenu, submenu_get_view(app->submenu)); diff --git a/non_catalog_apps/airmouse/application.fam b/non_catalog_apps/airmouse/application.fam index 82b77950314..61cf1edbd4c 100644 --- a/non_catalog_apps/airmouse/application.fam +++ b/non_catalog_apps/airmouse/application.fam @@ -6,7 +6,7 @@ App( stack_size=10 * 1024, fap_category="GPIO", fap_icon="mouse_10px.png", - fap_version="1.0", - sources=["*.c", "*.cc"], + fap_version="1.1", fap_libs=["ble_profile"], + sources=["*.c", "*.cc"], ) diff --git a/non_catalog_apps/airmouse/views/bt_mouse.c b/non_catalog_apps/airmouse/views/bt_mouse.c index 3c4d9a6d8dd..78d438eb583 100644 --- a/non_catalog_apps/airmouse/views/bt_mouse.c +++ b/non_catalog_apps/airmouse/views/bt_mouse.c @@ -10,6 +10,7 @@ #include #include #include +#include typedef struct ButtonEvent { int8_t button; @@ -42,12 +43,19 @@ struct BtMouse { ButtonEvent queue[BTN_EVT_QUEUE_SIZE]; }; +static const BleProfileHidParams ble_hid_params = { + .device_name_prefix = "AirMouse", + .mac_xor = 0x0001, +}; + #define BT_MOUSE_FLAG_INPUT_EVENT (1UL << 0) #define BT_MOUSE_FLAG_KILL_THREAD (1UL << 1) #define BT_MOUSE_FLAG_ALL (BT_MOUSE_FLAG_INPUT_EVENT | BT_MOUSE_FLAG_KILL_THREAD) #define MOUSE_SCROLL 2 +#define HID_BT_KEYS_STORAGE_NAME ".bt_hid.keys" + static void bt_mouse_notify_event(BtMouse* bt_mouse) { FuriThreadId thread_id = furi_thread_get_id(bt_mouse->thread); furi_assert(thread_id); @@ -252,15 +260,37 @@ void bt_mouse_enter_callback(void* context) { BtMouse* bt_mouse = context; bt_mouse->bt = furi_record_open(RECORD_BT); + bt_disconnect(bt_mouse->bt); + + furi_delay_ms(200); + bt_keys_storage_set_storage_path(bt_mouse->bt, APP_DATA_PATH(HID_BT_KEYS_STORAGE_NAME)); + bt_mouse->notifications = furi_record_open(RECORD_NOTIFICATION); bt_set_status_changed_callback( bt_mouse->bt, bt_mouse_connection_status_changed_callback, bt_mouse); - bt_mouse->hid = bt_profile_start(bt_mouse->bt, ble_profile_hid, NULL); + bt_mouse->hid = bt_profile_start(bt_mouse->bt, ble_profile_hid, (void*)&ble_hid_params); furi_assert(bt_mouse->hid); furi_hal_bt_start_advertising(); bt_mouse_thread_start(bt_mouse); } +void bt_mouse_remove_pairing(void) { + Bt* bt = furi_record_open(RECORD_BT); + bt_disconnect(bt); + + furi_delay_ms(200); + furi_hal_bt_stop_advertising(); + + bt_keys_storage_set_storage_path(bt, APP_DATA_PATH(HID_BT_KEYS_STORAGE_NAME)); + bt_forget_bonded_devices(bt); + + furi_delay_ms(200); + bt_keys_storage_set_default_path(bt); + + furi_check(bt_profile_restore_default(bt)); + furi_record_close(RECORD_BT); +} + bool bt_mouse_custom_callback(uint32_t event, void* context) { UNUSED(event); furi_assert(context); @@ -281,6 +311,12 @@ void bt_mouse_exit_callback(void* context) { tracking_end(); notification_internal_message(bt_mouse->notifications, &sequence_reset_blue); + bt_set_status_changed_callback(bt_mouse->bt, NULL, NULL); + bt_disconnect(bt_mouse->bt); + + furi_delay_ms(200); + bt_keys_storage_set_default_path(bt_mouse->bt); + furi_hal_bt_stop_advertising(); bt_profile_restore_default(bt_mouse->bt); diff --git a/non_catalog_apps/airmouse/views/bt_mouse.h b/non_catalog_apps/airmouse/views/bt_mouse.h index 09153d8fabc..e880a94c7f4 100644 --- a/non_catalog_apps/airmouse/views/bt_mouse.h +++ b/non_catalog_apps/airmouse/views/bt_mouse.h @@ -12,3 +12,5 @@ void bt_mouse_free(BtMouse* bt_mouse); View* bt_mouse_get_view(BtMouse* bt_mouse); void bt_mouse_set_connected_status(BtMouse* bt_mouse, bool connected); + +void bt_mouse_remove_pairing(void);