From 79de9177e4a7fcdc5e9e6223707d0dc8f769f41b Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Mon, 19 Feb 2024 04:13:45 +0300 Subject: [PATCH] triggerble updates by Willy-JL --- .../bluetooth-trigger/application.fam | 1 + .../bluetooth-trigger/bt_trigger.c | 31 ++++++++++--------- .../bluetooth-trigger/bt_trigger.h | 4 ++- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/apps_source_code/bluetooth-trigger/application.fam b/apps_source_code/bluetooth-trigger/application.fam index 5b8dd7f744d..e54d5801934 100644 --- a/apps_source_code/bluetooth-trigger/application.fam +++ b/apps_source_code/bluetooth-trigger/application.fam @@ -9,6 +9,7 @@ App( fap_icon="bt_trigger_logo.png", fap_category="Bluetooth", fap_icon_assets="assets", + fap_libs=["ble_profile"], fap_author="@Nem0oo", fap_weburl="https://github.com/Nem0oo/flipper-zero-bluetooth-trigger", fap_version="1.2", diff --git a/apps_source_code/bluetooth-trigger/bt_trigger.c b/apps_source_code/bluetooth-trigger/bt_trigger.c index 67d60d11953..07873a9e2f3 100644 --- a/apps_source_code/bluetooth-trigger/bt_trigger.c +++ b/apps_source_code/bluetooth-trigger/bt_trigger.c @@ -5,16 +5,15 @@ __int32_t bt_trigger_app(void* p) { UNUSED(p); AppStruct* app = appStructAlloc(); - //bt_disconnect(app->bt); + bt_disconnect(app->bt); // Wait 2nd core to update nvm storage - //furi_delay_ms(200); + furi_delay_ms(200); bt_keys_storage_set_storage_path(app->bt, HID_BT_KEYS_STORAGE_PATH); - if(!bt_set_profile(app->bt, BtProfileHidKeyboard)) { - FURI_LOG_E(TAG, "Failed to switch to HID profile"); - } + 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); @@ -58,8 +57,10 @@ __int32_t bt_trigger_app(void* p) { if(app->delay > 0) { app->shooting = !app->shooting; if(app->shooting) { - furi_hal_bt_hid_consumer_key_press(HID_CONSUMER_VOLUME_INCREMENT); - furi_hal_bt_hid_consumer_key_release(HID_CONSUMER_VOLUME_INCREMENT); + ble_profile_hid_consumer_key_press( + app->ble_hid_profile, HID_CONSUMER_VOLUME_INCREMENT); + ble_profile_hid_consumer_key_release( + app->ble_hid_profile, HID_CONSUMER_VOLUME_INCREMENT); notification_message(app->notifications, &sequence_blink_blue_100); app->shots++; //Timer triggered every delay ms @@ -87,8 +88,10 @@ __int32_t bt_trigger_app(void* p) { break; case(InputKeyRight): //Take a shot if(!app->shooting) { - furi_hal_bt_hid_consumer_key_press(HID_CONSUMER_VOLUME_INCREMENT); - furi_hal_bt_hid_consumer_key_release(HID_CONSUMER_VOLUME_INCREMENT); + ble_profile_hid_consumer_key_press( + app->ble_hid_profile, HID_CONSUMER_VOLUME_INCREMENT); + ble_profile_hid_consumer_key_release( + app->ble_hid_profile, HID_CONSUMER_VOLUME_INCREMENT); notification_message(app->notifications, &sequence_blink_blue_100); app->shots++; } @@ -102,8 +105,10 @@ __int32_t bt_trigger_app(void* p) { case(EventTypeTick): if(app->shooting) { //sending command to trigger via BT - furi_hal_bt_hid_consumer_key_press(HID_CONSUMER_VOLUME_INCREMENT); - furi_hal_bt_hid_consumer_key_release(HID_CONSUMER_VOLUME_INCREMENT); + ble_profile_hid_consumer_key_press( + app->ble_hid_profile, HID_CONSUMER_VOLUME_INCREMENT); + ble_profile_hid_consumer_key_release( + app->ble_hid_profile, HID_CONSUMER_VOLUME_INCREMENT); notification_message(app->notifications, &sequence_blink_blue_100); app->shots++; } @@ -120,9 +125,7 @@ __int32_t bt_trigger_app(void* p) { // Wait 2nd core to update nvm storage furi_delay_ms(200); bt_keys_storage_set_default_path(app->bt); - if(!bt_set_profile(app->bt, BtProfileSerial)) { - FURI_LOG_E(TAG, "Failed to switch to Serial profile"); - } + furi_check(bt_profile_restore_default(app->bt)); //Freeing memory furi_message_queue_free(event_queue); diff --git a/apps_source_code/bluetooth-trigger/bt_trigger.h b/apps_source_code/bluetooth-trigger/bt_trigger.h index fef2ac95a42..a89cc316281 100644 --- a/apps_source_code/bluetooth-trigger/bt_trigger.h +++ b/apps_source_code/bluetooth-trigger/bt_trigger.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include #include @@ -15,6 +15,7 @@ #include #include "bt_trigger_icons.h" + #define HID_BT_KEYS_STORAGE_PATH EXT_PATH("apps_data/hid_ble/.bt_hid.keys") #define TAG "bt_trigger" @@ -33,6 +34,7 @@ typedef struct { typedef struct { Bt* bt; + FuriHalBleProfileBase* ble_hid_profile; Gui* gui; NotificationApp* notifications; ViewPort* view_port;