Sfoglia il codice sorgente

Merge pull request #9 from daniilty/ir_external

Add external IR module support
rdefeo 1 anno fa
parent
commit
9cda143ef2
6 ha cambiato i file con 62 aggiunte e 24 eliminazioni
  1. 1 0
      README.md
  2. 16 1
      actions/action_ir.c
  3. 3 1
      actions/action_ir_utils.h
  4. 1 0
      quac.h
  5. 15 3
      quac_settings.c
  6. 26 19
      scenes/scene_settings.c

+ 1 - 0
README.md

@@ -118,6 +118,7 @@ The settings menu will appear as the last item when you are viewing the "root" d
 * RFID Duration: Changes the length of time a RFID signal is transmitted. Within playlists, this can be overridden per `.rfid` file.
 * NFC Duration: Changes the length of time a NFC signal is transmitted. Within playlists, this can be overridden per `.nfc` file.
 * SubGhz Ext Ant: Whether to try using the external antenna for sub-ghz signals. If this is "Enabled" but no external antenna is attached, or the external antenna can't be accessed, Quac! will fall back to using the internal antenna.
+* IR Ext Ant: Whether to use the external device for IR signals. If enabled, but no external IR device is attached to TX, then the internal IR device will be used.
 * Show Hidden: Will display files and folders that start with a period (`.`)
 * About: Application info
 

+ 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);
-}
+}

+ 26 - 19
scenes/scene_settings.c

@@ -14,17 +14,11 @@
 
 #include <lib/toolbox/path.h>
 
-typedef enum {
-    SceneSettingsLayout,
-    SceneSettingsIcons,
-    SceneSettingsHeaders,
-    SceneSettingsRFIDDuration,
-    SceneSettingsNFCDuration,
-    SceneSettingsSubGHzRepeat,
-    SceneSettingsSubGHzExtAnt,
-    SceneSettingsHidden,
-    SceneSettingsAbout
-} SceneSettingsIndex;
+// Unfortunately, the VariableItemList does not provide a method to query the length
+// of the list. Since we intend to place "About" last, it would be convenient to
+// dynamically know it's list index for our on_event method. However, we'll need to
+// hardcode the value..
+#define SCENE_SETTINGS_ABOUT 9 // 10 items in our Settings list, so last index is 9
 
 static const char* const layout_text[2] = {"Vert", "Horiz"};
 static const uint32_t layout_value[2] = {QUAC_APP_PORTRAIT, QUAC_APP_LANDSCAPE};
@@ -67,8 +61,8 @@ static const char* const repeat_text[V_REPEAT_COUNT] = {
     "50"};
 static const uint32_t repeat_value[V_REPEAT_COUNT] = {1, 2, 3, 5, 8, 10, 15, 20, 50};
 
-static const char* const subghz_ext_text[2] = {"Disabled", "Enabled"};
-static const uint32_t subghz_ext_value[2] = {false, true};
+static const char* const disabled_enabled_text[2] = {"Disabled", "Enabled"};
+static const uint32_t disabled_enabled_value[2] = {false, true};
 
 static void scene_settings_layout_changed(VariableItem* item) {
     App* app = variable_item_get_context(item);
@@ -115,8 +109,15 @@ static void scene_settings_subghz_repeat_changed(VariableItem* item) {
 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];
+    variable_item_set_current_value_text(item, disabled_enabled_text[index]);
+    app->settings.subghz_use_ext_antenna = disabled_enabled_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, disabled_enabled_text[index]);
+    app->settings.ir_use_ext_module = disabled_enabled_value[index];
 }
 
 static void scene_settings_show_hidden_changed(VariableItem* item) {
@@ -178,9 +179,15 @@ void scene_settings_on_enter(void* context) {
 
     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);
+    value_index =
+        value_index_uint32(app->settings.subghz_use_ext_antenna, disabled_enabled_value, 2);
+    variable_item_set_current_value_index(item, value_index);
+    variable_item_set_current_value_text(item, disabled_enabled_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, disabled_enabled_value, 2);
     variable_item_set_current_value_index(item, value_index);
-    variable_item_set_current_value_text(item, subghz_ext_text[value_index]);
+    variable_item_set_current_value_text(item, disabled_enabled_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);
@@ -200,7 +207,7 @@ bool scene_settings_on_event(void* context, SceneManagerEvent event) {
 
     if(event.type == SceneManagerEventTypeCustom) {
         switch(event.event) {
-        case SceneSettingsAbout:
+        case SCENE_SETTINGS_ABOUT:
             consumed = true;
             scene_manager_next_scene(app->scene_manager, QScene_About);
             break;
@@ -218,4 +225,4 @@ void scene_settings_on_exit(void* context) {
     variable_item_list_reset(vil);
 
     quac_save_settings(app);
-}
+}