diff --git a/applications/services/power/power_service/power.c b/applications/services/power/power_service/power.c index 1814dbd4a5..207764e998 100644 --- a/applications/services/power/power_service/power.c +++ b/applications/services/power/power_service/power.c @@ -440,13 +440,15 @@ static void power_auto_poweroff_callback(const void* value, void* context) { static void power_auto_poweroff_timer_callback(void* context) { furi_assert(context); Power* power = context; - //check charging state and dont poweroff if battery not fully charged - power_check_charging_state(power); - if (power->state == PowerStateCharged) { + + //poweroff if not charging now or if connected to charger and charging done + if (((!furi_hal_power_is_charging())) || (furi_hal_power_is_charging_done())) { power_off(power); } else { + //else we dont poweroff device and restart timer FURI_LOG_D(TAG, "We dont auto_power_off until battery is charging"); + power_start_auto_poweroff_timer(power); } } @@ -493,12 +495,10 @@ static void power_loader_callback(const void* message, void* context) { static void power_settings_apply(Power* power) { //apply auto_poweroff settings if(power->settings.auto_poweroff_delay_ms && !power->app_running) { - return; power_auto_poweroff_arm(power); } else if (power_is_running_auto_poweroff_timer(power)) { power_auto_poweroff_disarm(power); } - return; } // do something depend from power queue message @@ -662,6 +662,10 @@ int32_t power_srv(void* p) { } Power* power = power_alloc(); + + // load inital settings for power service + power_init_settings(power); + power_update_info(power); furi_record_create(RECORD_POWER, power); @@ -671,9 +675,6 @@ int32_t power_srv(void* p) { power->app_running = loader_is_locked(loader); furi_record_close(RECORD_LOADER); - // load inital settings for power service - power_init_settings(power); - furi_event_loop_run(power->event_loop); return 0; diff --git a/applications/settings/power_settings_app/scenes/power_settings_scene_start.c b/applications/settings/power_settings_app/scenes/power_settings_scene_start.c index 6f9975114b..9a12d65aab 100644 --- a/applications/settings/power_settings_app/scenes/power_settings_scene_start.c +++ b/applications/settings/power_settings_app/scenes/power_settings_scene_start.c @@ -2,18 +2,18 @@ #include enum PowerSettingsSubmenuIndex { - PowerSettingsSubmenuIndexAutoPowerOff, PowerSettingsSubmenuIndexBatteryInfo, PowerSettingsSubmenuIndexReboot, PowerSettingsSubmenuIndexOff, + PowerSettingsSubmenuIndexAutoPowerOff, }; -#define AUTO_POWEROFF_DELAY_COUNT 9 +#define AUTO_POWEROFF_DELAY_COUNT 8 const char* const auto_poweroff_delay_text[AUTO_POWEROFF_DELAY_COUNT] = - {"OFF","5 sec","5min", "10min", "15min", "30min", "45min", "60min", "90min"}; + {"OFF","5min", "10min", "15min", "30min", "45min", "60min", "90min"}; const uint32_t auto_poweroff_delay_value[AUTO_POWEROFF_DELAY_COUNT] = - {0, 5000, 300000, 600000, 900000, 1800000, 2700000, 3600000, 5400000}; + {0, 300000, 600000, 900000, 1800000, 2700000, 3600000, 5400000}; // change variable_item_list visible text and app_poweroff_delay_time_settings when user change item in variable_item_list static void power_settings_scene_start_auto_poweroff_delay_changed(VariableItem* item) { @@ -34,6 +34,10 @@ void power_settings_scene_start_on_enter(void* context) { PowerSettingsApp* app = context; VariableItemList* variable_item_list = app->variable_item_list; + variable_item_list_add(variable_item_list, "Battery Info", 1, NULL, NULL); + variable_item_list_add(variable_item_list, "Reboot", 1, NULL, NULL); + variable_item_list_add(variable_item_list, "Power OFF", 1, NULL, NULL); + VariableItem* item; uint8_t value_index; item = variable_item_list_add( @@ -49,11 +53,7 @@ void power_settings_scene_start_on_enter(void* context) { AUTO_POWEROFF_DELAY_COUNT); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, auto_poweroff_delay_text[value_index]); - - variable_item_list_add(variable_item_list, "Battery Info", 1, NULL, NULL); - variable_item_list_add(variable_item_list, "Reboot", 1, NULL, NULL); - variable_item_list_add(variable_item_list, "Power OFF", 1, NULL, NULL); - + variable_item_list_set_selected_item( variable_item_list, scene_manager_get_scene_state(app->scene_manager, PowerSettingsAppSceneStart)); variable_item_list_set_enter_callback( //callback to show next mennu screen