Skip to content

Commit

Permalink
upd airmouse
Browse files Browse the repository at this point in the history
  • Loading branch information
xMasterX committed Mar 20, 2024
1 parent 61bbee6 commit d453cfe
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
9 changes: 9 additions & 0 deletions non_catalog_apps/airmouse/air_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ enum AirMouseSubmenuIndex {
AirMouseSubmenuIndexBtMouse,
AirMouseSubmenuIndexUsbMouse,
AirMouseSubmenuIndexCalibration,
AirMouseSubmenuIndexRemovePairing,
};

void air_mouse_submenu_callback(void* context, uint32_t index) {
Expand All @@ -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();
}
}

Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions non_catalog_apps/airmouse/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
38 changes: 37 additions & 1 deletion non_catalog_apps/airmouse/views/bt_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <gui/elements.h>
#include <notification/notification.h>
#include <notification/notification_messages.h>
#include <storage/storage.h>

typedef struct ButtonEvent {
int8_t button;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions non_catalog_apps/airmouse/views/bt_mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit d453cfe

Please sign in to comment.