Willy-JL 1 год назад
Родитель
Сommit
6a65d71d11
3 измененных файлов с 20 добавлено и 15 удалено
  1. 1 0
      bt_trigger/application.fam
  2. 17 14
      bt_trigger/bt_trigger.c
  3. 2 1
      bt_trigger/bt_trigger.h

+ 1 - 0
bt_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",

+ 17 - 14
bt_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);

+ 2 - 1
bt_trigger/bt_trigger.h

@@ -4,7 +4,7 @@
 #include <furi.h>
 #include <furi_hal_bt.h>
 #include <furi_hal_usb_hid.h>
-#include <furi_hal_bt_hid.h>
+#include <extra_profiles/hid_profile.h>
 #include <gui/gui.h>
 #include <input/input.h>
 #include <notification/notification_messages.h>
@@ -35,6 +35,7 @@ typedef struct {
 
 typedef struct {
     Bt* bt;
+    FuriHalBleProfileBase* ble_hid_profile;
     Gui* gui;
     NotificationApp* notifications;
     ViewPort* view_port;