Implement Auto Reboot Timer (#518) (#519)

* Implement Auto Reboot Timer (#518)

* Use > to check for values below -1

* Use TimeoutHelper and accept MS

* Add fatal_auto_reboot_interval into config (commented)

* Check for 0
This commit is contained in:
Sun 2019-04-22 00:18:01 -07:00 committed by SciresM
parent a09c08994f
commit be4ca7eee5
4 changed files with 16 additions and 1 deletions

View file

@ -6,6 +6,9 @@ upload_enabled = u8!0x0
usb30_force_enabled = u8!0x0
; Atmosphere custom settings
[atmosphere]
; Reboot from fatal automatically after 5 seconds (in milliseconds)
; If field is disabled fatal waits for an input indefinitely
; fatal_auto_reboot_interval = u64!5000
; Make the power menu's "reboot" button reboot to payload.
; Set to "normal" for normal reboot, "rcm" for rcm reboot.
power_menu_reboot_function = str!payload

View file

@ -18,7 +18,7 @@
#include "fatal_types.hpp"
#include "fatal_config.hpp"
static FatalConfig g_fatal_config;
static FatalConfig g_fatal_config = {};
static IEvent *g_fatal_settings_event = nullptr;
@ -84,5 +84,8 @@ void InitializeFatalConfig() {
setsysGetFlag(SetSysFlag_Quest, &config->quest_flag);
config->is_auto_reboot_enabled = R_SUCCEEDED(setsysGetSettingsItemValue("atmosphere", "fatal_auto_reboot_interval", &config->fatal_auto_reboot_interval, sizeof(config->fatal_auto_reboot_interval)));
config->is_auto_reboot_enabled &= (config->fatal_auto_reboot_interval != 0);
SetupConfigLanguages();
}

View file

@ -29,6 +29,8 @@ struct FatalConfig {
const char *error_msg;
const char *error_desc;
const char *quest_desc;
u64 fatal_auto_reboot_interval;
bool is_auto_reboot_enabled;
};
IEvent *GetFatalSettingsEvent();

View file

@ -96,6 +96,8 @@ void PowerButtonObserveTask::WaitForPowerButton() {
const FatalConfig *config = GetFatalConfig();
TimeoutHelper reboot_helper(config->quest_reboot_interval_second * 1000000000UL);
TimeoutHelper auto_reboot_helper(config->fatal_auto_reboot_interval * 1000000);
bool check_vol_up = true, check_vol_down = true;
GpioPadSession vol_up_btn, vol_down_btn;
if (R_FAILED(gpioOpenSession(&vol_up_btn, GpioPadName_ButtonVolUp))) {
@ -121,6 +123,11 @@ void PowerButtonObserveTask::WaitForPowerButton() {
GpioValue val;
while (true) {
Result rc = ResultSuccess;
if (config->is_auto_reboot_enabled && auto_reboot_helper.TimedOut() ) {
bpcRebootSystem();
return;
}
if (check_vol_up && R_SUCCEEDED((rc = gpioPadGetValue(&vol_up_btn, &val))) && val == GpioValue_Low) {
bpcRebootSystem();