mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
Revert infrared last settings + reworked the auto detect
This commit is contained in:
@@ -204,7 +204,18 @@ static InfraredApp* infrared_alloc() {
|
||||
infrared->loading = loading_alloc();
|
||||
infrared->progress = infrared_progress_view_alloc();
|
||||
|
||||
if(furi_hal_infrared_is_external_connected()) {
|
||||
infrared->last_settings = infrared_last_settings_alloc();
|
||||
infrared_last_settings_load(infrared->last_settings);
|
||||
|
||||
if(infrared->last_settings->auto_detect) {
|
||||
furi_hal_infrared_set_auto_detect(true);
|
||||
}
|
||||
|
||||
if(infrared->last_settings->ext_out && !furi_hal_infrared_get_debug_out_status()) {
|
||||
furi_hal_infrared_set_debug_out(true);
|
||||
}
|
||||
|
||||
if(infrared->last_settings->ext_5v) {
|
||||
uint8_t attempts = 0;
|
||||
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
|
||||
furi_hal_power_enable_otg();
|
||||
@@ -212,8 +223,6 @@ static InfraredApp* infrared_alloc() {
|
||||
}
|
||||
}
|
||||
|
||||
furi_hal_infrared_block_external_output(false);
|
||||
|
||||
return infrared;
|
||||
}
|
||||
|
||||
@@ -285,7 +294,7 @@ static void infrared_free(InfraredApp* infrared) {
|
||||
furi_hal_power_disable_otg();
|
||||
}
|
||||
|
||||
furi_hal_infrared_block_external_output(false);
|
||||
infrared_last_settings_free(infrared->last_settings);
|
||||
|
||||
free(infrared);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "infrared_remote.h"
|
||||
#include "infrared_brute_force.h"
|
||||
#include "infrared_custom_event.h"
|
||||
#include "infrared_last_settings.h"
|
||||
|
||||
#include "scenes/infrared_scene.h"
|
||||
#include "views/infrared_progress_view.h"
|
||||
@@ -128,6 +129,7 @@ struct InfraredApp {
|
||||
/** Arbitrary text storage for various inputs. */
|
||||
char text_store[INFRARED_TEXT_STORE_NUM][INFRARED_TEXT_STORE_SIZE + 1];
|
||||
InfraredAppState app_state; /**< Application state. */
|
||||
InfraredLastSettings* last_settings; /**< Last settings. */
|
||||
|
||||
void* rpc_ctx; /**< Pointer to the RPC context object. */
|
||||
};
|
||||
|
||||
96
applications/main/infrared/infrared_last_settings.c
Normal file
96
applications/main/infrared/infrared_last_settings.c
Normal file
@@ -0,0 +1,96 @@
|
||||
#include "infrared_last_settings.h"
|
||||
|
||||
#define TAG "InfraredLastSettings"
|
||||
|
||||
#define INFRARED_LAST_SETTINGS_FILE_TYPE "Flipper Infrared Last Settings File"
|
||||
#define INFRARED_LAST_SETTINGS_FILE_VERSION 1
|
||||
#define INFRARED_LAST_SETTINGS_PATH EXT_PATH("infrared/assets/last_infrared.settings")
|
||||
|
||||
#define INFRARED_LAST_SETTINGS_FIELD_EXTPOWER "External5V"
|
||||
#define INFRARED_LAST_SETTINGS_FIELD_EXTOUT "ExternalOut"
|
||||
#define INFRARED_LAST_SETTINGS_FIELD_AUTO_DETECT "AutoDetect"
|
||||
|
||||
InfraredLastSettings* infrared_last_settings_alloc(void) {
|
||||
InfraredLastSettings* instance = malloc(sizeof(InfraredLastSettings));
|
||||
return instance;
|
||||
}
|
||||
|
||||
void infrared_last_settings_free(InfraredLastSettings* instance) {
|
||||
furi_assert(instance);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void infrared_last_settings_load(InfraredLastSettings* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
|
||||
|
||||
bool temp_extpower = false;
|
||||
bool temp_extout = false;
|
||||
bool temp_auto_detect = false;
|
||||
|
||||
if(FSE_OK == storage_sd_status(storage) && INFRARED_LAST_SETTINGS_PATH &&
|
||||
flipper_format_file_open_existing(fff_data_file, INFRARED_LAST_SETTINGS_PATH)) {
|
||||
flipper_format_read_bool(
|
||||
fff_data_file, INFRARED_LAST_SETTINGS_FIELD_EXTPOWER, (bool*)&temp_extpower, 1);
|
||||
flipper_format_read_bool(
|
||||
fff_data_file, INFRARED_LAST_SETTINGS_FIELD_EXTOUT, (bool*)&temp_extout, 1);
|
||||
flipper_format_read_bool(
|
||||
fff_data_file, INFRARED_LAST_SETTINGS_FIELD_AUTO_DETECT, (bool*)&temp_auto_detect, 1);
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Error open file %s", INFRARED_LAST_SETTINGS_PATH);
|
||||
}
|
||||
|
||||
instance->ext_5v = temp_extpower;
|
||||
instance->ext_out = temp_extout;
|
||||
instance->auto_detect = temp_auto_detect;
|
||||
|
||||
flipper_format_file_close(fff_data_file);
|
||||
flipper_format_free(fff_data_file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
bool infrared_last_settings_save(InfraredLastSettings* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
bool saved = false;
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||
|
||||
do {
|
||||
if(FSE_OK != storage_sd_status(storage)) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Open file
|
||||
if(!flipper_format_file_open_always(file, INFRARED_LAST_SETTINGS_PATH)) break;
|
||||
|
||||
// Write header
|
||||
if(!flipper_format_write_header_cstr(
|
||||
file, INFRARED_LAST_SETTINGS_FILE_TYPE, INFRARED_LAST_SETTINGS_FILE_VERSION))
|
||||
break;
|
||||
|
||||
if(!flipper_format_insert_or_update_bool(
|
||||
file, INFRARED_LAST_SETTINGS_FIELD_EXTPOWER, &instance->ext_5v, 1))
|
||||
break;
|
||||
if(!flipper_format_insert_or_update_bool(
|
||||
file, INFRARED_LAST_SETTINGS_FIELD_EXTOUT, &instance->ext_out, 1))
|
||||
break;
|
||||
if(!flipper_format_insert_or_update_bool(
|
||||
file, INFRARED_LAST_SETTINGS_FIELD_AUTO_DETECT, &instance->auto_detect, 1))
|
||||
break;
|
||||
|
||||
saved = true;
|
||||
} while(0);
|
||||
|
||||
if(!saved) {
|
||||
FURI_LOG_E(TAG, "Error save file %s", INFRARED_LAST_SETTINGS_PATH);
|
||||
}
|
||||
|
||||
flipper_format_file_close(file);
|
||||
flipper_format_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
return saved;
|
||||
}
|
||||
16
applications/main/infrared/infrared_last_settings.h
Normal file
16
applications/main/infrared/infrared_last_settings.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <furi_hal.h>
|
||||
#include <storage/storage.h>
|
||||
#include <lib/flipper_format/flipper_format.h>
|
||||
|
||||
typedef struct {
|
||||
bool ext_5v;
|
||||
bool ext_out;
|
||||
bool auto_detect;
|
||||
} 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);
|
||||
@@ -8,30 +8,57 @@ const char* const infrared_debug_cfg_variables_text[] = {
|
||||
"2 (A7)",
|
||||
};
|
||||
|
||||
static void infrared_scene_debug_settings_changed(VariableItem* item) {
|
||||
static void infrared_scene_debug_settings_auto_detect_changed(VariableItem* item) {
|
||||
InfraredApp* infrared = variable_item_get_context(item);
|
||||
bool value = variable_item_get_current_value_index(item);
|
||||
|
||||
variable_item_set_current_value_text(item, value ? "ON" : "OFF");
|
||||
|
||||
if(value == 0) {
|
||||
furi_hal_infrared_set_auto_detect(false);
|
||||
// enable other list items
|
||||
VariableItemList* variable_item_list = infrared->variable_item_list;
|
||||
VariableItem* item = variable_item_list_get(variable_item_list, 1);
|
||||
variable_item_set_current_value_index(item, infrared->last_settings->ext_out);
|
||||
variable_item_set_current_value_text(
|
||||
item, infrared_debug_cfg_variables_text[infrared->last_settings->ext_out]);
|
||||
variable_item_set_locked(item, false, "");
|
||||
|
||||
item = variable_item_list_get(variable_item_list, 2);
|
||||
variable_item_set_current_value_index(item, infrared->last_settings->ext_5v);
|
||||
variable_item_set_current_value_text(item, infrared->last_settings->ext_5v ? "ON" : "OFF");
|
||||
variable_item_set_locked(item, false, "");
|
||||
} else {
|
||||
furi_hal_infrared_set_auto_detect(true);
|
||||
// disable other list items
|
||||
VariableItemList* variable_item_list = infrared->variable_item_list;
|
||||
VariableItem* item = variable_item_list_get(variable_item_list, 1);
|
||||
variable_item_set_current_value_index(item, 0);
|
||||
variable_item_set_locked(item, true, "Disable auto detect");
|
||||
|
||||
item = variable_item_list_get(variable_item_list, 2);
|
||||
variable_item_set_current_value_index(item, 0);
|
||||
variable_item_set_locked(item, true, "Disable auto detect");
|
||||
}
|
||||
|
||||
infrared->last_settings->auto_detect = value == 1;
|
||||
infrared_last_settings_save(infrared->last_settings);
|
||||
}
|
||||
|
||||
static void infrared_scene_debug_settings_pin_changed(VariableItem* item) {
|
||||
InfraredApp* infrared = variable_item_get_context(item);
|
||||
value_index_ir = variable_item_get_current_value_index(item);
|
||||
|
||||
variable_item_set_current_value_text(item, infrared_debug_cfg_variables_text[value_index_ir]);
|
||||
|
||||
if(value_index_ir == 0) {
|
||||
furi_hal_infrared_set_debug_out(false);
|
||||
furi_hal_infrared_block_external_output(true);
|
||||
if(furi_hal_power_is_otg_enabled()) {
|
||||
furi_hal_power_disable_otg();
|
||||
}
|
||||
} else {
|
||||
furi_hal_infrared_block_external_output(false);
|
||||
if(furi_hal_infrared_is_external_connected() && !furi_hal_power_is_otg_enabled()) {
|
||||
uint8_t attempts = 0;
|
||||
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
|
||||
furi_hal_power_enable_otg();
|
||||
furi_delay_ms(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
furi_hal_infrared_set_debug_out(value_index_ir);
|
||||
|
||||
infrared->last_settings->ext_out = value_index_ir == 1;
|
||||
infrared_last_settings_save(infrared->last_settings);
|
||||
}
|
||||
|
||||
static void infrared_scene_debug_settings_power_changed(VariableItem* item) {
|
||||
InfraredApp* infrared = variable_item_get_context(item);
|
||||
bool value = variable_item_get_current_value_index(item);
|
||||
if(value) {
|
||||
uint8_t attempts = 0;
|
||||
@@ -45,6 +72,9 @@ static void infrared_scene_debug_settings_power_changed(VariableItem* item) {
|
||||
}
|
||||
}
|
||||
variable_item_set_current_value_text(item, value ? "ON" : "OFF");
|
||||
|
||||
infrared->last_settings->ext_5v = value;
|
||||
infrared_last_settings_save(infrared->last_settings);
|
||||
}
|
||||
|
||||
static void infrared_debug_settings_start_var_list_enter_callback(void* context, uint32_t index) {
|
||||
@@ -56,23 +86,38 @@ void infrared_scene_debug_settings_on_enter(void* context) {
|
||||
InfraredApp* infrared = context;
|
||||
|
||||
VariableItemList* variable_item_list = infrared->variable_item_list;
|
||||
|
||||
value_index_ir =
|
||||
(furi_hal_infrared_is_external_connected() &&
|
||||
!furi_hal_infrared_is_external_output_blocked());
|
||||
variable_item_list_set_enter_callback(
|
||||
variable_item_list, infrared_debug_settings_start_var_list_enter_callback, infrared);
|
||||
|
||||
VariableItem* item = variable_item_list_add(
|
||||
variable_item_list,
|
||||
"Auto detect",
|
||||
2,
|
||||
infrared_scene_debug_settings_auto_detect_changed,
|
||||
infrared);
|
||||
|
||||
bool auto_detect = furi_hal_infrared_is_auto_detect_enabled();
|
||||
|
||||
variable_item_set_current_value_index(item, auto_detect);
|
||||
variable_item_set_current_value_text(item, auto_detect ? "ON" : "OFF");
|
||||
|
||||
item = variable_item_list_add(
|
||||
variable_item_list,
|
||||
"Send signal to",
|
||||
DEB_PINS_COUNT,
|
||||
infrared_scene_debug_settings_changed,
|
||||
infrared_scene_debug_settings_pin_changed,
|
||||
infrared);
|
||||
|
||||
value_index_ir = furi_hal_infrared_get_debug_out_status();
|
||||
|
||||
variable_item_list_set_enter_callback(
|
||||
variable_item_list, infrared_debug_settings_start_var_list_enter_callback, infrared);
|
||||
|
||||
variable_item_set_current_value_index(item, value_index_ir);
|
||||
variable_item_set_current_value_text(item, infrared_debug_cfg_variables_text[value_index_ir]);
|
||||
if(auto_detect) {
|
||||
variable_item_set_locked(item, true, "Disable auto detect");
|
||||
}
|
||||
|
||||
item = variable_item_list_add(
|
||||
variable_item_list,
|
||||
@@ -80,20 +125,12 @@ void infrared_scene_debug_settings_on_enter(void* context) {
|
||||
2,
|
||||
infrared_scene_debug_settings_power_changed,
|
||||
infrared);
|
||||
bool enabled = (furi_hal_power_is_otg_enabled() ||
|
||||
furi_hal_power_is_charging()) && // 5v is enabled via hardware if charging
|
||||
furi_hal_infrared_is_external_connected() &&
|
||||
!furi_hal_infrared_is_external_output_blocked();
|
||||
bool enabled = furi_hal_power_is_otg_enabled() ||
|
||||
furi_hal_power_is_charging(); // 5v is enabled via hardware if charging;
|
||||
variable_item_set_current_value_index(item, enabled);
|
||||
variable_item_set_current_value_text(item, enabled ? "ON" : "OFF");
|
||||
|
||||
if(furi_hal_infrared_is_external_connected() && !furi_hal_power_is_otg_enabled() &&
|
||||
!furi_hal_infrared_is_external_output_blocked()) {
|
||||
uint8_t attempts = 0;
|
||||
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
|
||||
furi_hal_power_enable_otg();
|
||||
furi_delay_ms(10);
|
||||
}
|
||||
if(auto_detect) {
|
||||
variable_item_set_locked(item, true, "Disable auto detect");
|
||||
}
|
||||
|
||||
view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewVariableItemList);
|
||||
|
||||
@@ -1319,11 +1319,11 @@ Function,+,furi_hal_infrared_async_tx_set_signal_sent_isr_callback,void,"FuriHal
|
||||
Function,+,furi_hal_infrared_async_tx_start,void,"uint32_t, float"
|
||||
Function,+,furi_hal_infrared_async_tx_stop,void,
|
||||
Function,+,furi_hal_infrared_async_tx_wait_termination,void,
|
||||
Function,+,furi_hal_infrared_block_external_output,void,_Bool
|
||||
Function,+,furi_hal_infrared_get_debug_out_status,_Bool,
|
||||
Function,+,furi_hal_infrared_is_auto_detect_enabled,_Bool,
|
||||
Function,+,furi_hal_infrared_is_busy,_Bool,
|
||||
Function,+,furi_hal_infrared_is_external_connected,_Bool,
|
||||
Function,+,furi_hal_infrared_is_external_output_blocked,_Bool,
|
||||
Function,+,furi_hal_infrared_set_auto_detect,void,_Bool
|
||||
Function,+,furi_hal_infrared_set_debug_out,void,_Bool
|
||||
Function,-,furi_hal_init,void,
|
||||
Function,-,furi_hal_init_early,void,
|
||||
|
||||
|
@@ -80,7 +80,7 @@ static volatile InfraredState furi_hal_infrared_state = InfraredStateIdle;
|
||||
static InfraredTimTx infrared_tim_tx;
|
||||
static InfraredTimRx infrared_tim_rx;
|
||||
static bool infrared_external_output;
|
||||
static bool block_external;
|
||||
static bool auto_detect;
|
||||
|
||||
static void furi_hal_infrared_tx_fill_buffer(uint8_t buf_num, uint8_t polarity_shift);
|
||||
static void furi_hal_infrared_async_tx_free_resources(void);
|
||||
@@ -651,9 +651,7 @@ void furi_hal_infrared_async_tx_start(uint32_t freq, float duty_cycle) {
|
||||
LL_TIM_GenerateEvent_UPDATE(INFRARED_DMA_TIMER); /* DMA -> TIMx_RCR */
|
||||
furi_delay_us(5);
|
||||
|
||||
if(block_external) {
|
||||
infrared_external_output = false;
|
||||
} else {
|
||||
if(auto_detect) {
|
||||
infrared_external_output = furi_hal_infrared_is_external_connected();
|
||||
}
|
||||
|
||||
@@ -736,10 +734,10 @@ bool furi_hal_infrared_is_external_connected() {
|
||||
return is_external_connected;
|
||||
}
|
||||
|
||||
void furi_hal_infrared_block_external_output(bool block) {
|
||||
block_external = block;
|
||||
void furi_hal_infrared_set_auto_detect(bool enable) {
|
||||
auto_detect = enable;
|
||||
}
|
||||
|
||||
bool furi_hal_infrared_is_external_output_blocked(void) {
|
||||
return block_external;
|
||||
bool furi_hal_infrared_is_auto_detect_enabled(void) {
|
||||
return auto_detect;
|
||||
}
|
||||
@@ -155,18 +155,17 @@ void furi_hal_infrared_async_tx_set_signal_sent_isr_callback(
|
||||
*/
|
||||
bool furi_hal_infrared_is_external_connected();
|
||||
|
||||
/** Block external output on PA7
|
||||
/** Set auto detect
|
||||
*
|
||||
* if blocked, its forced to internal IR. If unblocked, external IR is used if connected
|
||||
* @param block true to block, false to unblock
|
||||
*/
|
||||
void furi_hal_infrared_block_external_output(bool block);
|
||||
* if enabled, external IR is used automatic if connected, otherwise internal IR is used
|
||||
*/
|
||||
void furi_hal_infrared_set_auto_detect(bool enable);
|
||||
|
||||
/** Check if external output on PA7 is blocked
|
||||
/** Check if auto detect is enabled
|
||||
*
|
||||
* @return true if blocked, false otherwise
|
||||
* @return true if enabled, false otherwise
|
||||
*/
|
||||
bool furi_hal_infrared_is_external_output_blocked();
|
||||
bool furi_hal_infrared_is_auto_detect_enabled();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user