Skip to content

Commit

Permalink
Apps: IR: Support new settings from OFW
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy-JL committed Mar 29, 2024
1 parent 923eb59 commit dba42cc
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 16 deletions.
8 changes: 0 additions & 8 deletions applications/main/infrared/infrared_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
#define INFRARED_TX_MIN_INTERVAL_MS (50U)
#define INFRARED_TASK_STACK_SIZE (2048UL)

#define INFRARED_SETTINGS_VERSION (1)
#define INFRARED_SETTINGS_MAGIC (0x1F)

typedef struct {
FuriHalInfraredTxPin tx_pin;
bool otg_enabled;
} InfraredSettings;

static const NotificationSequence*
infrared_notification_sequences[InfraredNotificationMessageCount] = {
&sequence_success,
Expand Down
9 changes: 9 additions & 0 deletions applications/main/infrared/infrared_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,13 @@
typedef struct InfraredApp InfraredApp;

#include <storage/storage.h>
#include <furi_hal_infrared.h>

#define INFRARED_SETTINGS_PATH EXT_PATH("infrared/.infrared.settings")
#define INFRARED_SETTINGS_VERSION (1)
#define INFRARED_SETTINGS_MAGIC (0x1F)

typedef struct {
FuriHalInfraredTxPin tx_pin;
bool otg_enabled;
} InfraredSettings;
1 change: 0 additions & 1 deletion applications/system/ir_remote/infrared_last_settings.c

This file was deleted.

40 changes: 34 additions & 6 deletions applications/system/ir_remote/infrared_remote_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#include <dialogs/dialogs.h>
#include <ir_remote_icons.h>
#include <assets_icons.h>
#include <infrared/infrared_last_settings.h>

#include <infrared/infrared_app.h>
#include <toolbox/saved_struct.h>

#include <notification/notification.h>
#include <notification/notification_messages.h>
Expand Down Expand Up @@ -401,9 +403,30 @@ int32_t infrared_remote_app(char* p) {
flipper_format_free(ff);
furi_record_close(RECORD_STORAGE);

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

bool running = true;
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
Expand Down Expand Up @@ -546,8 +569,13 @@ int32_t infrared_remote_app(char* p) {
}
}

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

// Free all things
furi_string_free(app->up_button);
Expand Down

0 comments on commit dba42cc

Please sign in to comment.