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

IR: Support new settings from OFW

Willy-JL 1 год назад
Родитель
Сommit
b552847933

+ 0 - 1
ir_intervalometer/infrared_last_settings.c

@@ -1 +0,0 @@
-#include <infrared/infrared_last_settings.c>

+ 33 - 6
ir_intervalometer/intervalometer.c

@@ -13,7 +13,8 @@
 #include <gui/icon.h>
 #include <infrared_transmit.h>
 
-#include <infrared/infrared_last_settings.h>
+#include <infrared/infrared_app.h>
+#include <toolbox/saved_struct.h>
 
 #include <input/input.h>
 
@@ -630,9 +631,30 @@ int32_t flipvalo_app() {
 
     flipvalo_priv_init(fv_priv);
 
-    InfraredLastSettings* last_settings = infrared_last_settings_alloc();
-    infrared_last_settings_load(last_settings);
-    infrared_last_settings_apply(last_settings);
+    bool otg_was_enabled = furi_hal_power_is_otg_enabled();
+    InfraredSettings settings = {0};
+    saved_struct_load(
+        INFRARED_SETTINGS_PATH,
+        &settings,
+        sizeof(InfraredSettings),
+        INFRARED_SETTINGS_MAGIC,
+        INFRARED_SETTINGS_VERSION);
+    if(settings.tx_pin < FuriHalInfraredTxPinMax) {
+        furi_hal_infrared_set_tx_output(settings.tx_pin);
+        if(settings.otg_enabled != otg_was_enabled) {
+            if(settings.otg_enabled) {
+                furi_hal_power_enable_otg();
+            } else {
+                furi_hal_power_disable_otg();
+            }
+        }
+    } else {
+        FuriHalInfraredTxPin tx_pin_detected = furi_hal_infrared_detect_tx_output();
+        furi_hal_infrared_set_tx_output(tx_pin_detected);
+        if(tx_pin_detected != FuriHalInfraredTxPinInternal) {
+            furi_hal_power_enable_otg();
+        }
+    }
 
     if(!fv_priv->mutex) {
         FURI_LOG_E("Flipvalo", "Cannot create mutex\r\n");
@@ -730,8 +752,13 @@ cleanup:
         }
         view_port_free(view_port);
     }
-    infrared_last_settings_reset(last_settings);
-    infrared_last_settings_free(last_settings);
+    if(furi_hal_power_is_otg_enabled() != otg_was_enabled) {
+        if(otg_was_enabled) {
+            furi_hal_power_enable_otg();
+        } else {
+            furi_hal_power_disable_otg();
+        }
+    }
     if(event_queue) {
         furi_message_queue_free(event_queue);
     }

+ 0 - 1
xremote/infrared_last_settings.c

@@ -1 +0,0 @@
-#include <infrared/infrared_last_settings.c>

+ 33 - 6
xremote/xremote.c

@@ -16,7 +16,8 @@
 #include "views/xremote_learn_view.h"
 #include "views/xremote_signal_view.h"
 
-#include <infrared/infrared_last_settings.h>
+#include <infrared/infrared_app.h>
+#include <toolbox/saved_struct.h>
 
 #define TAG "XRemote"
 
@@ -92,16 +93,42 @@ int32_t xremote_main(void* p) {
     xremote_app_submenu_add(app, "Settings", XRemoteViewSettings, xremote_submenu_callback);
     xremote_app_submenu_add(app, "About", XRemoteViewAbout, xremote_submenu_callback);
 
-    InfraredLastSettings* last_settings = infrared_last_settings_alloc();
-    infrared_last_settings_load(last_settings);
-    infrared_last_settings_apply(last_settings);
+    bool otg_was_enabled = furi_hal_power_is_otg_enabled();
+    InfraredSettings settings = {0};
+    saved_struct_load(
+        INFRARED_SETTINGS_PATH,
+        &settings,
+        sizeof(InfraredSettings),
+        INFRARED_SETTINGS_MAGIC,
+        INFRARED_SETTINGS_VERSION);
+    if(settings.tx_pin < FuriHalInfraredTxPinMax) {
+        furi_hal_infrared_set_tx_output(settings.tx_pin);
+        if(settings.otg_enabled != otg_was_enabled) {
+            if(settings.otg_enabled) {
+                furi_hal_power_enable_otg();
+            } else {
+                furi_hal_power_disable_otg();
+            }
+        }
+    } else {
+        FuriHalInfraredTxPin tx_pin_detected = furi_hal_infrared_detect_tx_output();
+        furi_hal_infrared_set_tx_output(tx_pin_detected);
+        if(tx_pin_detected != FuriHalInfraredTxPinInternal) {
+            furi_hal_power_enable_otg();
+        }
+    }
 
     /* Switch to main menu by default and run disparcher*/
     xremote_app_switch_to_view(app, XRemoteViewSubmenu);
     view_dispatcher_run(app->app_ctx->view_dispatcher);
 
-    infrared_last_settings_reset(last_settings);
-    infrared_last_settings_free(last_settings);
+    if(furi_hal_power_is_otg_enabled() != otg_was_enabled) {
+        if(otg_was_enabled) {
+            furi_hal_power_enable_otg();
+        } else {
+            furi_hal_power_disable_otg();
+        }
+    }
 
     /* Cleanup and exit */
     xremote_app_free(app);