Просмотр исходного кода

[WIP] Add external module support

Daniil Turaev 1 год назад
Родитель
Сommit
776f5b1c52
5 измененных файлов с 51 добавлено и 6 удалено
  1. 16 1
      actions/action_ir.c
  2. 3 1
      actions/action_ir_utils.h
  3. 1 0
      quac.h
  4. 15 3
      quac_settings.c
  5. 16 1
      scenes/scene_settings.c

+ 16 - 1
actions/action_ir.c

@@ -29,6 +29,8 @@ void action_ir_tx(void* context, const FuriString* action_path, FuriString* erro
             break;
         }
 
+        if(app->settings.ir_use_ext_module) action_ir_power_otg(true);
+
         if(signal->is_raw) {
             // raw
             FURI_LOG_I(
@@ -62,9 +64,22 @@ void action_ir_tx(void* context, const FuriString* action_path, FuriString* erro
             FURI_LOG_I(TAG, "IR: Send complete");
         }
 
+        if(app->settings.ir_use_ext_module) action_ir_power_otg(false);
     } while(false);
 
     furi_string_free(temp_str);
     flipper_format_free(fff_data_file);
     infrared_utils_signal_free(signal);
-}
+}
+
+void action_ir_power_otg(bool enable) {
+    FuriHalInfraredTxPin tx_pin_detected = furi_hal_infrared_detect_tx_output();
+    furi_hal_infrared_set_tx_output(tx_pin_detected);
+
+    if(tx_pin_detected == FuriHalInfraredTxPinInternal) return;
+
+    if(enable)
+        furi_hal_power_enable_otg();
+    else
+        furi_hal_power_disable_otg();
+}

+ 3 - 1
actions/action_ir_utils.h

@@ -7,7 +7,7 @@
 
 #include <flipper_format/flipper_format.h>
 
-#define INFRARED_FILE_TYPE "IR signals file"
+#define INFRARED_FILE_TYPE    "IR signals file"
 #define INFRARED_FILE_VERSION 1
 
 typedef struct {
@@ -36,3 +36,5 @@ bool infrared_utils_read_signal_at_index(
     FuriString* name);
 
 bool infrared_utils_write_signal(FlipperFormat* fffile, InfraredSignal* signal, FuriString* name);
+
+void action_ir_power_otg(bool enable);

+ 1 - 0
quac.h

@@ -58,6 +58,7 @@ typedef struct App {
         uint32_t nfc_duration; // Defaults to 1000 ms
         uint32_t subghz_repeat; // Defaults to 10, just like the CLI
         bool subghz_use_ext_antenna; // Defaults to False
+        bool ir_use_ext_module; // Defaults to False
         bool show_hidden; // Defaults to False
     } settings;
 

+ 15 - 3
quac_settings.c

@@ -3,7 +3,7 @@
 #include <flipper_format/flipper_format.h>
 
 // Quac Settings File Info
-#define QUAC_SETTINGS_FILE_TYPE "Quac Settings File"
+#define QUAC_SETTINGS_FILE_TYPE    "Quac Settings File"
 #define QUAC_SETTINGS_FILE_VERSION 1
 
 void quac_set_default_settings(App* app) {
@@ -14,6 +14,7 @@ void quac_set_default_settings(App* app) {
     app->settings.nfc_duration = 1000;
     app->settings.subghz_repeat = 10;
     app->settings.subghz_use_ext_antenna = false;
+    app->settings.ir_use_ext_module = false;
     app->settings.show_hidden = false;
 }
 
@@ -91,7 +92,13 @@ void quac_load_settings(App* app) {
         if(!flipper_format_read_uint32(fff_settings, "SubGHz Ext Antenna", &temp_data32, 1)) {
             FURI_LOG_W(TAG, "SETTINGS: Missing 'SubGHz Ext Antenna'");
         } else {
-            app->settings.subghz_use_ext_antenna = (temp_data32 == 1) ? true : false;
+            app->settings.subghz_use_ext_antenna = temp_data32 == 1;
+        }
+
+        if(!flipper_format_read_uint32(fff_settings, "IR Ext Module", &temp_data32, 1)) {
+            FURI_LOG_W(TAG, "SETTINGS: Missing 'IR Ext Module'");
+        } else {
+            app->settings.ir_use_ext_module = temp_data32 == 1;
         }
 
         if(!flipper_format_read_uint32(fff_settings, "Show Hidden", &temp_data32, 1)) {
@@ -161,6 +168,11 @@ void quac_save_settings(App* app) {
             FURI_LOG_E(TAG, "SETTINGS: Failed to write 'SubGHz Ext Antenna'");
             break;
         }
+        temp_data32 = app->settings.ir_use_ext_module ? 1 : 0;
+        if(!flipper_format_write_uint32(fff_settings, "IR Ext Module", &temp_data32, 1)) {
+            FURI_LOG_E(TAG, "SETTINGS: Failed to write 'IR Ext Module'");
+            break;
+        }
         temp_data32 = app->settings.show_hidden ? 1 : 0;
         if(!flipper_format_write_uint32(fff_settings, "Show Hidden", &temp_data32, 1)) {
             FURI_LOG_E(TAG, "SETTINGS: Failed to write 'Show Hidden'");
@@ -176,4 +188,4 @@ void quac_save_settings(App* app) {
 
     flipper_format_file_close(fff_settings);
     flipper_format_free(fff_settings);
-}
+}

+ 16 - 1
scenes/scene_settings.c

@@ -70,6 +70,9 @@ static const uint32_t repeat_value[V_REPEAT_COUNT] = {1, 2, 3, 5, 8, 10, 15, 20,
 static const char* const subghz_ext_text[2] = {"Disabled", "Enabled"};
 static const uint32_t subghz_ext_value[2] = {false, true};
 
+static const char* const ir_ext_text[2] = {"Disabled", "Enabled"};
+static const uint32_t ir_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);
@@ -119,6 +122,13 @@ static void scene_settings_subghz_ext_changed(VariableItem* item) {
     app->settings.subghz_use_ext_antenna = subghz_ext_value[index];
 }
 
+static void scene_settings_ir_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, ir_ext_text[index]);
+    app->settings.ir_use_ext_module = ir_ext_value[index];
+}
+
 static void scene_settings_show_hidden_changed(VariableItem* item) {
     App* app = variable_item_get_context(item);
     uint8_t index = variable_item_get_current_value_index(item);
@@ -182,6 +192,11 @@ void scene_settings_on_enter(void* context) {
     variable_item_set_current_value_index(item, value_index);
     variable_item_set_current_value_text(item, subghz_ext_text[value_index]);
 
+    item = variable_item_list_add(vil, "IR Ext Module", 2, scene_settings_ir_ext_changed, app);
+    value_index = value_index_uint32(app->settings.ir_use_ext_module, ir_ext_value, 2);
+    variable_item_set_current_value_index(item, value_index);
+    variable_item_set_current_value_text(item, ir_ext_text[value_index]);
+
     item = variable_item_list_add(vil, "Show Hidden", 2, scene_settings_show_hidden_changed, app);
     value_index = value_index_uint32(app->settings.show_hidden, show_offon_value, 2);
     variable_item_set_current_value_index(item, value_index);
@@ -218,4 +233,4 @@ void scene_settings_on_exit(void* context) {
     variable_item_list_reset(vil);
 
     quac_save_settings(app);
-}
+}