Forráskód Böngészése

add support for external subghz antenna

rdefeo 1 éve
szülő
commit
30e0fbe906
5 módosított fájl, 86 hozzáadás és 10 törlés
  1. 56 9
      actions/action_subghz.c
  2. 1 0
      quac.h
  3. 12 0
      quac_settings.c
  4. 1 1
      scenes/scene_action_rename.c
  5. 16 0
      scenes/scene_settings.c

+ 56 - 9
actions/action_subghz.c

@@ -12,6 +12,9 @@
 #include "action_i.h"
 #include "quac.h"
 
+#define SUBGHZ_DEVICE_CC1101_EXT_NAME "cc1101_ext"
+#define SUBGHZ_DEVICE_CC1101_INT_NAME "cc1101_int"
+
 static FuriHalSubGhzPreset action_subghz_get_preset_name(const char* preset_name) {
     FuriHalSubGhzPreset preset = FuriHalSubGhzPresetIDLE;
     if(!strcmp(preset_name, "FuriHalSubGhzPresetOok270Async")) {
@@ -30,12 +33,49 @@ static FuriHalSubGhzPreset action_subghz_get_preset_name(const char* preset_name
     return preset;
 }
 
+static const SubGhzDevice* action_subghz_get_device(uint32_t* device_ind) {
+    const SubGhzDevice* device = NULL;
+    switch(*device_ind) {
+    case 1:
+        // Power on the external antenna
+        uint8_t attempts = 5;
+        while(--attempts > 0) {
+            if(furi_hal_power_enable_otg()) break;
+        }
+        if(attempts == 0) {
+            if(furi_hal_power_get_usb_voltage() < 4.5f) {
+                FURI_LOG_E(
+                    TAG,
+                    "Error power otg enable. BQ2589 check otg fault = %d",
+                    furi_hal_power_check_otg_fault() ? 1 : 0);
+            }
+        }
+        device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_EXT_NAME);
+        break;
+    default:
+        device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME);
+        break;
+    }
+    if(!subghz_devices_is_connect(device)) {
+        // Power off
+        if(furi_hal_power_is_otg_enabled()) {
+            furi_hal_power_disable_otg();
+        }
+        if(*device_ind == 1) {
+            FURI_LOG_W(TAG, "Can't connect to External antenna, using Internal");
+        }
+        device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME);
+        *device_ind = 0;
+    }
+    return device;
+}
+
 // Lifted from flipperzero-firmware/applications/main/subghz/subghz_cli.c
 void action_subghz_tx(void* context, const FuriString* action_path, FuriString* error) {
     App* app = context;
     const char* file_name = furi_string_get_cstr(action_path);
     uint32_t repeat = 1; //
-    // uint32_t device_ind = 0; // 0 - CC1101_INT, 1 - CC1101_EXT
+    uint32_t device_ind = app->settings.subghz_use_ext_antenna ? 1 : 0;
 
     FlipperFormat* fff_data_file = flipper_format_file_alloc(app->storage);
     FlipperFormat* fff_data_raw = flipper_format_string_alloc();
@@ -67,15 +107,22 @@ void action_subghz_tx(void* context, const FuriString* action_path, FuriString*
     subghz_environment_set_protocol_registry(environment, (void*)&subghz_protocol_registry);
 
     do {
-        // SUBGHZ_DEVICE_CC1101_INT_NAME = "cc1101_int"
-        device = subghz_devices_get_by_name("cc1101_int");
-        if(!subghz_devices_is_connect(device)) {
-            // power off
-            if(furi_hal_power_is_otg_enabled()) furi_hal_power_disable_otg();
-            device = subghz_devices_get_by_name("cc1101_int");
-            // device_ind = 0;
+        device = action_subghz_get_device(&device_ind);
+        if(device == NULL) {
+            FURI_LOG_E(TAG, "Error device not found");
+            ACTION_SET_ERROR("SUBGHZ: Device not found");
+            break;
         }
 
+        // // SUBGHZ_DEVICE_CC1101_INT_NAME = "cc1101_int"
+        // device = subghz_devices_get_by_name("cc1101_int");
+        // if(!subghz_devices_is_connect(device)) {
+        //     // power off
+        //     if(furi_hal_power_is_otg_enabled()) furi_hal_power_disable_otg();
+        //     device = subghz_devices_get_by_name("cc1101_int");
+        //     // device_ind = 0;
+        // }
+
         if(!flipper_format_file_open_existing(fff_data_file, file_name)) {
             FURI_LOG_E(TAG, "Error opening %s", file_name);
             ACTION_SET_ERROR("SUBGHZ: Error opening %s", file_name);
@@ -218,7 +265,7 @@ void action_subghz_tx(void* context, const FuriString* action_path, FuriString*
         furi_hal_power_suppress_charge_enter();
         FURI_LOG_I(
             TAG,
-            "Listening at %s. Frequency=%lu, Protocol=%s",
+            "Transmitting at %s. Frequency=%lu, Protocol=%s",
             file_name,
             frequency,
             furi_string_get_cstr(temp_str));

+ 1 - 0
quac.h

@@ -54,6 +54,7 @@ typedef struct App {
         bool show_icons; // Defaults to True
         bool show_headers; // Defaults to True
         uint32_t rfid_duration; // Defaults to 2500 ms
+        bool subghz_use_ext_antenna; // Defaults to False
     } settings;
 
 } App;

+ 12 - 0
quac_settings.c

@@ -13,6 +13,7 @@ void quac_set_default_settings(App* app) {
     app->settings.layout = QUAC_APP_LANDSCAPE;
     app->settings.show_icons = true;
     app->settings.show_headers = true;
+    app->settings.subghz_use_ext_antenna = false;
 }
 
 void quac_load_settings(App* app) {
@@ -73,6 +74,12 @@ void quac_load_settings(App* app) {
         }
         app->settings.rfid_duration = temp_data32;
 
+        if(!flipper_format_read_uint32(fff_settings, "SubGHz Ext Antenna", &temp_data32, 1)) {
+            FURI_LOG_E(TAG, "SETTINGS: Missing 'SubGHz Ext Antenna'");
+            break;
+        }
+        app->settings.subghz_use_ext_antenna = (temp_data32 == 1) ? true : false;
+
         successful = true;
     } while(false);
 
@@ -125,6 +132,11 @@ void quac_save_settings(App* app) {
             FURI_LOG_E(TAG, "SETTINGS: Failed to write 'RFID Duration'");
             break;
         }
+        temp_data32 = app->settings.subghz_use_ext_antenna ? 1 : 0;
+        if(!flipper_format_write_uint32(fff_settings, "SubGHz Ext Antenna", &temp_data32, 1)) {
+            FURI_LOG_E(TAG, "SETTINGS: Failed to write 'SubGHz Ext Antenna'");
+            break;
+        }
         successful = true;
     } while(false);
 

+ 1 - 1
scenes/scene_action_rename.c

@@ -55,7 +55,7 @@ bool scene_action_rename_on_event(void* context, SceneManagerEvent event) {
             path_extract_filename(item->path, file_name, true);
             // FURI_LOG_I(TAG, "Original name is %s", furi_string_get_cstr(file_name));
             if(!furi_string_cmp_str(file_name, app->temp_cstr)) {
-                // FURI_LOG_W(TAG, "Rename: File names are the same!");
+                FURI_LOG_W(TAG, "Rename: File names are the same!");
                 furi_string_free(file_name);
                 return false;
             }

+ 16 - 0
scenes/scene_settings.c

@@ -45,6 +45,9 @@ static const uint32_t rfid_duration_value[V_RFID_DURATION_COUNT] = {
     10000,
 };
 
+static const char* const subghz_ext_text[2] = {"Disabled", "Enabled"};
+static const uint32_t subghz_ext_value[2] = {false, true};
+
 static void scene_settings_layout_changed(VariableItem* item) {
     App* app = variable_item_get_context(item);
     uint8_t index = variable_item_get_current_value_index(item);
@@ -73,6 +76,13 @@ static void scene_settings_rfid_duration_changed(VariableItem* item) {
     app->settings.rfid_duration = rfid_duration_value[index];
 }
 
+static void scene_settings_subghz_ext_changed(VariableItem* item) {
+    App* app = variable_item_get_context(item);
+    uint8_t index = variable_item_get_current_value_index(item);
+    variable_item_set_current_value_text(item, subghz_ext_text[index]);
+    app->settings.subghz_use_ext_antenna = subghz_ext_value[index];
+}
+
 // For each scene, implement handler callbacks
 void scene_settings_on_enter(void* context) {
     App* app = context;
@@ -106,6 +116,12 @@ void scene_settings_on_enter(void* context) {
     variable_item_set_current_value_index(item, value_index);
     variable_item_set_current_value_text(item, rfid_duration_text[value_index]);
 
+    item =
+        variable_item_list_add(vil, "SubGHz Ext Ant", 2, scene_settings_subghz_ext_changed, app);
+    value_index = value_index_uint32(app->settings.subghz_use_ext_antenna, subghz_ext_value, 2);
+    variable_item_set_current_value_index(item, value_index);
+    variable_item_set_current_value_text(item, subghz_ext_text[value_index]);
+
     // TODO: Set Enter callback here - why?? All settings have custom callbacks
     // variable_item_list_set_enter_callback(vil, my_cb, app);