Simpler infrared last settings API

This commit is contained in:
Willy-JL
2024-02-02 00:49:46 +00:00
parent 9fbb17f4b2
commit c2a9ceaccb
4 changed files with 48 additions and 58 deletions

View File

@@ -206,22 +206,7 @@ static InfraredApp* infrared_alloc() {
infrared->last_settings = infrared_last_settings_alloc();
infrared_last_settings_load(infrared->last_settings);
furi_hal_infrared_set_auto_detect(infrared->last_settings->auto_detect);
if(!infrared->last_settings->auto_detect) {
furi_hal_infrared_set_debug_out(infrared->last_settings->ext_out);
if(infrared->last_settings->ext_5v) {
uint8_t attempts = 0;
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
furi_hal_power_enable_otg();
furi_delay_ms(10);
}
} else if(furi_hal_power_is_otg_enabled()) {
furi_hal_power_disable_otg();
}
} else if(furi_hal_power_is_otg_enabled()) {
furi_hal_power_disable_otg();
}
infrared_last_settings_apply(infrared->last_settings);
return infrared;
}
@@ -290,6 +275,7 @@ static void infrared_free(InfraredApp* infrared) {
furi_string_free(infrared->file_path);
furi_string_free(infrared->button_name);
infrared_last_settings_reset(infrared->last_settings);
infrared_last_settings_free(infrared->last_settings);
free(infrared);
@@ -491,7 +477,6 @@ void infrared_popup_closed_callback(void* context) {
}
int32_t infrared_app(char* p) {
bool otg_was_enabled = furi_hal_power_is_otg_enabled();
InfraredApp* infrared = infrared_alloc();
infrared_make_app_folder(infrared);
@@ -537,16 +522,5 @@ int32_t infrared_app(char* p) {
view_dispatcher_run(infrared->view_dispatcher);
infrared_free(infrared);
if(otg_was_enabled != furi_hal_power_is_otg_enabled()) {
if(otg_was_enabled) {
uint8_t attempts = 0;
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
furi_hal_power_enable_otg();
furi_delay_ms(10);
}
} else {
furi_hal_power_disable_otg();
}
}
return 0;
}

View File

@@ -1,5 +1,7 @@
#include "infrared_last_settings.h"
#include <furi_hal_infrared.h>
#define TAG "InfraredLastSettings"
#define INFRARED_LAST_SETTINGS_FILE_TYPE "Flipper Infrared Last Settings File"
@@ -93,4 +95,41 @@ bool infrared_last_settings_save(InfraredLastSettings* instance) {
furi_record_close(RECORD_STORAGE);
return saved;
}
void infrared_last_settings_apply(InfraredLastSettings* instance) {
furi_assert(instance);
instance->_otg_was_enabled = furi_hal_power_is_otg_enabled();
furi_hal_infrared_set_auto_detect(instance->auto_detect);
if(!instance->auto_detect) {
furi_hal_infrared_set_debug_out(instance->ext_out);
if(instance->ext_5v) {
uint8_t attempts = 0;
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
furi_hal_power_enable_otg();
furi_delay_ms(10);
}
} else if(furi_hal_power_is_otg_enabled()) {
furi_hal_power_disable_otg();
}
} else if(furi_hal_power_is_otg_enabled()) {
furi_hal_power_disable_otg();
}
}
void infrared_last_settings_reset(InfraredLastSettings* instance) {
furi_assert(instance);
if(instance->_otg_was_enabled != furi_hal_power_is_otg_enabled()) {
if(instance->_otg_was_enabled) {
uint8_t attempts = 0;
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
furi_hal_power_enable_otg();
furi_delay_ms(10);
}
} else {
furi_hal_power_disable_otg();
}
}
}

View File

@@ -8,9 +8,13 @@ typedef struct {
bool ext_5v;
bool ext_out;
bool auto_detect;
bool _otg_was_enabled;
} InfraredLastSettings;
InfraredLastSettings* infrared_last_settings_alloc(void);
void infrared_last_settings_free(InfraredLastSettings* instance);
void infrared_last_settings_load(InfraredLastSettings* instance);
bool infrared_last_settings_save(InfraredLastSettings* instance);
bool infrared_last_settings_save(InfraredLastSettings* instance);
void infrared_last_settings_apply(InfraredLastSettings* instance);
void infrared_last_settings_reset(InfraredLastSettings* instance);

View File

@@ -9,7 +9,6 @@
#include <ir_remote_icons.h>
#include <assets_icons.h>
#include "infrared_last_settings.h"
#include <furi_hal_infrared.h>
#include <notification/notification.h>
#include <notification/notification_messages.h>
@@ -402,25 +401,9 @@ int32_t infrared_remote_app(char* p) {
flipper_format_free(ff);
furi_record_close(RECORD_STORAGE);
bool otg_was_enabled = furi_hal_power_is_otg_enabled();
InfraredLastSettings* last_settings = infrared_last_settings_alloc();
infrared_last_settings_load(last_settings);
furi_hal_infrared_set_auto_detect(last_settings->auto_detect);
if(!last_settings->auto_detect) {
furi_hal_infrared_set_debug_out(last_settings->ext_out);
if(last_settings->ext_5v) {
uint8_t attempts = 0;
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
furi_hal_power_enable_otg();
furi_delay_ms(10);
}
} else if(furi_hal_power_is_otg_enabled()) {
furi_hal_power_disable_otg();
}
} else if(furi_hal_power_is_otg_enabled()) {
furi_hal_power_disable_otg();
}
infrared_last_settings_apply(last_settings);
bool running = true;
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
@@ -563,17 +546,7 @@ int32_t infrared_remote_app(char* p) {
}
}
if(otg_was_enabled != furi_hal_power_is_otg_enabled()) {
if(otg_was_enabled) {
uint8_t attempts = 0;
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
furi_hal_power_enable_otg();
furi_delay_ms(10);
}
} else {
furi_hal_power_disable_otg();
}
}
infrared_last_settings_reset(last_settings);
infrared_last_settings_free(last_settings);
// Free all things