mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
Improve infrared gpio setting consistency
This commit is contained in:
@@ -207,20 +207,20 @@ static InfraredApp* infrared_alloc() {
|
||||
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();
|
||||
furi_delay_ms(10);
|
||||
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();
|
||||
}
|
||||
|
||||
return infrared;
|
||||
@@ -290,10 +290,6 @@ static void infrared_free(InfraredApp* infrared) {
|
||||
furi_string_free(infrared->file_path);
|
||||
furi_string_free(infrared->button_name);
|
||||
|
||||
if(furi_hal_power_is_otg_enabled()) {
|
||||
furi_hal_power_disable_otg();
|
||||
}
|
||||
|
||||
infrared_last_settings_free(infrared->last_settings);
|
||||
|
||||
free(infrared);
|
||||
@@ -495,6 +491,7 @@ 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);
|
||||
@@ -540,5 +537,16 @@ 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;
|
||||
}
|
||||
|
||||
@@ -14,35 +14,29 @@ static void infrared_scene_debug_settings_auto_detect_changed(VariableItem* 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, "");
|
||||
// enable/disable other list items
|
||||
VariableItemList* var_item_list = infrared->variable_item_list;
|
||||
variable_item_set_locked(variable_item_list_get(var_item_list, 1), value, NULL);
|
||||
variable_item_set_locked(variable_item_list_get(var_item_list, 2), value, NULL);
|
||||
|
||||
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->auto_detect = value;
|
||||
infrared_last_settings_save(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();
|
||||
}
|
||||
}
|
||||
|
||||
static void infrared_scene_debug_settings_pin_changed(VariableItem* item) {
|
||||
@@ -96,7 +90,7 @@ void infrared_scene_debug_settings_on_enter(void* context) {
|
||||
infrared_scene_debug_settings_auto_detect_changed,
|
||||
infrared);
|
||||
|
||||
bool auto_detect = furi_hal_infrared_is_auto_detect_enabled();
|
||||
bool auto_detect = infrared->last_settings->auto_detect;
|
||||
|
||||
variable_item_set_current_value_index(item, auto_detect);
|
||||
variable_item_set_current_value_text(item, auto_detect ? "ON" : "OFF");
|
||||
@@ -108,16 +102,14 @@ void infrared_scene_debug_settings_on_enter(void* context) {
|
||||
infrared_scene_debug_settings_pin_changed,
|
||||
infrared);
|
||||
|
||||
value_index_ir = furi_hal_infrared_get_debug_out_status();
|
||||
value_index_ir = infrared->last_settings->ext_out;
|
||||
|
||||
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");
|
||||
}
|
||||
variable_item_set_locked(item, auto_detect, "Disable auto detect");
|
||||
|
||||
item = variable_item_list_add(
|
||||
variable_item_list,
|
||||
@@ -125,13 +117,10 @@ 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;
|
||||
bool enabled = infrared->last_settings->ext_5v;
|
||||
variable_item_set_current_value_index(item, enabled);
|
||||
variable_item_set_current_value_text(item, enabled ? "ON" : "OFF");
|
||||
if(auto_detect) {
|
||||
variable_item_set_locked(item, true, "Disable auto detect");
|
||||
}
|
||||
variable_item_set_locked(item, auto_detect, "Disable auto detect");
|
||||
|
||||
view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewVariableItemList);
|
||||
}
|
||||
|
||||
@@ -653,24 +653,25 @@ void furi_hal_infrared_async_tx_start(uint32_t freq, float duty_cycle) {
|
||||
|
||||
if(auto_detect) {
|
||||
infrared_external_output = furi_hal_infrared_is_external_connected();
|
||||
if(infrared_external_output) {
|
||||
if(!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);
|
||||
}
|
||||
}
|
||||
} else if(furi_hal_power_is_otg_enabled()) {
|
||||
furi_hal_power_disable_otg();
|
||||
}
|
||||
}
|
||||
|
||||
if(infrared_external_output) {
|
||||
if(!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_delay_ms(100);
|
||||
}
|
||||
|
||||
LL_GPIO_ResetOutputPin(
|
||||
gpio_ext_pa7.port, gpio_ext_pa7.pin); /* when disable it prevents false pulse */
|
||||
furi_hal_gpio_init_ex(
|
||||
&gpio_ext_pa7, GpioModeAltFunctionPushPull, GpioPullUp, GpioSpeedHigh, GpioAltFn1TIM1);
|
||||
} else {
|
||||
furi_hal_power_disable_otg();
|
||||
LL_GPIO_ResetOutputPin(
|
||||
gpio_infrared_tx.port,
|
||||
gpio_infrared_tx.pin); /* when disable it prevents false pulse */
|
||||
|
||||
Reference in New Issue
Block a user