Przeglądaj źródła

ir apps add support for new settings

by Willy-JL
MX 1 rok temu
rodzic
commit
b9a505f2ce

+ 1 - 1
infrared_remote.c

@@ -27,7 +27,7 @@ static void infrared_remote_clear_buttons(InfraredRemote* remote) {
     InfraredButtonArray_reset(remote->buttons);
     InfraredButtonArray_reset(remote->buttons);
 }
 }
 
 
-InfraredRemote* infrared_remote_alloc() {
+InfraredRemote* infrared_remote_alloc(void) {
     InfraredRemote* remote = malloc(sizeof(InfraredRemote));
     InfraredRemote* remote = malloc(sizeof(InfraredRemote));
     InfraredButtonArray_init(remote->buttons);
     InfraredButtonArray_init(remote->buttons);
     remote->name = furi_string_alloc();
     remote->name = furi_string_alloc();

+ 3 - 1
infrared_remote.h

@@ -4,9 +4,11 @@
 
 
 #include "infrared_remote_button.h"
 #include "infrared_remote_button.h"
 
 
+#define IR_REMOTE_PATH EXT_PATH("infrared/remote")
+
 typedef struct InfraredRemote InfraredRemote;
 typedef struct InfraredRemote InfraredRemote;
 
 
-InfraredRemote* infrared_remote_alloc();
+InfraredRemote* infrared_remote_alloc(void);
 void infrared_remote_free(InfraredRemote* remote);
 void infrared_remote_free(InfraredRemote* remote);
 void infrared_remote_reset(InfraredRemote* remote);
 void infrared_remote_reset(InfraredRemote* remote);
 
 

+ 55 - 11
infrared_remote_app.c

@@ -8,6 +8,9 @@
 #include <dialogs/dialogs.h>
 #include <dialogs/dialogs.h>
 #include <ir_remote_icons.h>
 #include <ir_remote_icons.h>
 
 
+#include <infrared/infrared_app.h>
+#include <toolbox/saved_struct.h>
+
 #include <notification/notification.h>
 #include <notification/notification.h>
 #include <notification/notification_messages.h>
 #include <notification/notification_messages.h>
 
 
@@ -109,8 +112,7 @@ static void app_input_callback(InputEvent* input_event, void* ctx) {
     furi_message_queue_put(event_queue, input_event, FuriWaitForever);
     furi_message_queue_put(event_queue, input_event, FuriWaitForever);
 }
 }
 
 
-int32_t infrared_remote_app(void* p) {
-    UNUSED(p);
+int32_t infrared_remote_app(char* p) {
     FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
     FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
 
 
     // App button string
     // App button string
@@ -139,18 +141,26 @@ int32_t infrared_remote_app(void* p) {
 
 
     InputEvent event;
     InputEvent event;
 
 
+    FuriString* map_file = furi_string_alloc();
     Storage* storage = furi_record_open(RECORD_STORAGE);
     Storage* storage = furi_record_open(RECORD_STORAGE);
     FlipperFormat* ff = flipper_format_file_alloc(storage);
     FlipperFormat* ff = flipper_format_file_alloc(storage);
+    if(!storage_file_exists(storage, IR_REMOTE_PATH)) {
+        storage_common_mkdir(storage, IR_REMOTE_PATH); //Make Folder If dir not exist
+    }
 
 
-    DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
-    DialogsFileBrowserOptions browser_options;
-    dialog_file_browser_set_basic_options(&browser_options, ".txt", &I_sub1_10px);
-    FuriString* map_file = furi_string_alloc();
-    furi_string_set(map_file, "/ext/ir_remote");
-
-    bool res = dialog_file_browser_show(dialogs, map_file, map_file, &browser_options);
-
-    furi_record_close(RECORD_DIALOGS);
+    bool res;
+    if(p && strlen(p)) {
+        furi_string_set(map_file, p);
+        res = true;
+    } else {
+        DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
+        DialogsFileBrowserOptions browser_options;
+        dialog_file_browser_set_basic_options(&browser_options, ".txt", &I_sub1_10px);
+        browser_options.base_path = IR_REMOTE_PATH;
+        furi_string_set(map_file, IR_REMOTE_PATH);
+        res = dialog_file_browser_show(dialogs, map_file, map_file, &browser_options);
+        furi_record_close(RECORD_DIALOGS);
+    }
 
 
     // if user didn't choose anything, free everything and exit
     // if user didn't choose anything, free everything and exit
     if(!res) {
     if(!res) {
@@ -392,6 +402,31 @@ int32_t infrared_remote_app(void* p) {
     flipper_format_free(ff);
     flipper_format_free(ff);
     furi_record_close(RECORD_STORAGE);
     furi_record_close(RECORD_STORAGE);
 
 
+    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();
+        }
+    }
+
     bool running = true;
     bool running = true;
     NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
     NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
 
 
@@ -533,6 +568,15 @@ int32_t infrared_remote_app(void* p) {
         }
         }
     }
     }
 
 
+    furi_hal_infrared_set_tx_output(FuriHalInfraredTxPinInternal);
+    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();
+        }
+    }
+
     // Free all things
     // Free all things
     furi_string_free(app->up_button);
     furi_string_free(app->up_button);
     furi_string_free(app->down_button);
     furi_string_free(app->down_button);

+ 1 - 1
infrared_remote_button.c

@@ -7,7 +7,7 @@ struct InfraredRemoteButton {
     InfraredSignal* signal;
     InfraredSignal* signal;
 };
 };
 
 
-InfraredRemoteButton* infrared_remote_button_alloc() {
+InfraredRemoteButton* infrared_remote_button_alloc(void) {
     InfraredRemoteButton* button = malloc(sizeof(InfraredRemoteButton));
     InfraredRemoteButton* button = malloc(sizeof(InfraredRemoteButton));
     button->name = furi_string_alloc();
     button->name = furi_string_alloc();
     button->signal = infrared_signal_alloc();
     button->signal = infrared_signal_alloc();

+ 1 - 1
infrared_remote_button.h

@@ -4,7 +4,7 @@
 
 
 typedef struct InfraredRemoteButton InfraredRemoteButton;
 typedef struct InfraredRemoteButton InfraredRemoteButton;
 
 
-InfraredRemoteButton* infrared_remote_button_alloc();
+InfraredRemoteButton* infrared_remote_button_alloc(void);
 void infrared_remote_button_free(InfraredRemoteButton* button);
 void infrared_remote_button_free(InfraredRemoteButton* button);
 
 
 void infrared_remote_button_set_name(InfraredRemoteButton* button, const char* name);
 void infrared_remote_button_set_name(InfraredRemoteButton* button, const char* name);

+ 1 - 1
infrared_signal.c

@@ -166,7 +166,7 @@ static bool infrared_signal_read_body(InfraredSignal* signal, FlipperFormat* ff)
     return success;
     return success;
 }
 }
 
 
-InfraredSignal* infrared_signal_alloc() {
+InfraredSignal* infrared_signal_alloc(void) {
     InfraredSignal* signal = malloc(sizeof(InfraredSignal));
     InfraredSignal* signal = malloc(sizeof(InfraredSignal));
 
 
     signal->is_raw = false;
     signal->is_raw = false;

+ 1 - 1
infrared_signal.h

@@ -16,7 +16,7 @@ typedef struct {
     float duty_cycle;
     float duty_cycle;
 } InfraredRawSignal;
 } InfraredRawSignal;
 
 
-InfraredSignal* infrared_signal_alloc();
+InfraredSignal* infrared_signal_alloc(void);
 void infrared_signal_free(InfraredSignal* signal);
 void infrared_signal_free(InfraredSignal* signal);
 
 
 bool infrared_signal_is_raw(InfraredSignal* signal);
 bool infrared_signal_is_raw(InfraredSignal* signal);