Files
Momentum-Firmware/applications/main/infrared/infrared_settings.h
jay candel 0a8b9a701a IR: Easy Learn (#350)
* initial working commit

* update names + format

* add skip functionality

* misc tweaks

* change back gpio label

* remove gpio setting changes

* misc fixes

* bug fixes and polish

* add subtitle button and reorganize order

* update ir settings to version 2

* ir settings v1 migration support

* fixes

* format

* misc fixes

* Simplify and standardize settings handling

* Auto-calculate easy_mode_button_count

* Case insensitive match existing remote buttons

* Display button name more prominently

* Sort submenu indexes and handling

* Fine to keep text highlighted

* Some formatting for less conflicts

* Not sure how these got lost kek

* Update changelog

---------

Co-authored-by: Willy-JL <49810075+Willy-JL@users.noreply.github.com>
2025-01-22 03:46:40 +00:00

63 lines
1.6 KiB
C

#pragma once
#include <storage/storage.h>
#include <furi_hal_infrared.h>
#include <toolbox/saved_struct.h>
#define INFRARED_SETTINGS_PATH INT_PATH(".infrared.settings")
#define INFRARED_SETTINGS_VERSION (2)
#define INFRARED_SETTINGS_MAGIC (0x1F)
typedef struct {
FuriHalInfraredTxPin tx_pin;
bool otg_enabled;
bool easy_mode;
} InfraredSettings;
typedef struct {
FuriHalInfraredTxPin tx_pin;
bool otg_enabled;
} _InfraredSettingsV1;
bool infrared_settings_load(InfraredSettings* settings) {
// Default load
if(saved_struct_load(
INFRARED_SETTINGS_PATH,
settings,
sizeof(*settings),
INFRARED_SETTINGS_MAGIC,
INFRARED_SETTINGS_VERSION)) {
return true;
}
// Set defaults
settings->tx_pin = FuriHalInfraredTxPinInternal;
settings->otg_enabled = false;
settings->easy_mode = false;
// Try to migrate
uint8_t magic, version;
if(saved_struct_get_metadata(INFRARED_SETTINGS_PATH, &magic, &version, NULL) &&
magic == INFRARED_SETTINGS_MAGIC) {
_InfraredSettingsV1 v1;
if(version == 1 &&
saved_struct_load(INFRARED_SETTINGS_PATH, &v1, sizeof(v1), magic, version)) {
settings->tx_pin = v1.tx_pin;
settings->otg_enabled = v1.otg_enabled;
return true;
}
}
return false;
}
bool infrared_settings_save(InfraredSettings* settings) {
return saved_struct_save(
INFRARED_SETTINGS_PATH,
settings,
sizeof(*settings),
INFRARED_SETTINGS_MAGIC,
INFRARED_SETTINGS_VERSION);
}