2021-04-19 16:26:25 +00:00
|
|
|
#include "power_cli.h"
|
|
|
|
#include <api-hal.h>
|
|
|
|
|
2021-05-18 13:57:39 +00:00
|
|
|
void power_cli_poweroff(Cli* cli, string_t args, void* context) {
|
2021-04-30 04:51:48 +00:00
|
|
|
Power* power = context;
|
|
|
|
power_off(power);
|
2021-04-19 16:26:25 +00:00
|
|
|
}
|
|
|
|
|
2021-07-01 22:53:20 +00:00
|
|
|
void power_cli_reboot(Cli* cli, string_t args, void* context) {
|
2021-04-30 04:51:48 +00:00
|
|
|
Power* power = context;
|
2021-07-01 22:53:20 +00:00
|
|
|
power_reboot(power, PowerBootModeNormal);
|
2021-04-19 16:26:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 13:57:39 +00:00
|
|
|
void power_cli_dfu(Cli* cli, string_t args, void* context) {
|
2021-04-30 04:51:48 +00:00
|
|
|
Power* power = context;
|
2021-07-01 22:53:20 +00:00
|
|
|
power_reboot(power, PowerBootModeDfu);
|
2021-04-19 16:26:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 13:57:39 +00:00
|
|
|
void power_cli_factory_reset(Cli* cli, string_t args, void* context) {
|
|
|
|
Power* power = context;
|
|
|
|
printf("All data will be lost. Are you sure (y/n)?\r\n");
|
|
|
|
char c = cli_getc(cli);
|
|
|
|
if(c == 'y' || c == 'Y') {
|
|
|
|
printf("Data will be wiped after reboot.\r\n");
|
|
|
|
api_hal_boot_set_flags(ApiHalBootFlagFactoryReset);
|
2021-07-01 22:53:20 +00:00
|
|
|
power_reboot(power, PowerBootModeNormal);
|
2021-05-18 13:57:39 +00:00
|
|
|
} else {
|
|
|
|
printf("Safe choice.\r\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-24 14:50:28 +00:00
|
|
|
void power_cli_info(Cli* cli, string_t args, void* context) {
|
2021-04-19 16:26:25 +00:00
|
|
|
api_hal_power_dump_state();
|
|
|
|
}
|
|
|
|
|
2021-05-24 14:50:28 +00:00
|
|
|
void power_cli_otg(Cli* cli, string_t args, void* context) {
|
|
|
|
if(!string_cmp(args, "0")) {
|
|
|
|
api_hal_power_disable_otg();
|
|
|
|
} else if(!string_cmp(args, "1")) {
|
|
|
|
api_hal_power_enable_otg();
|
|
|
|
} else {
|
|
|
|
cli_print_usage("power_otg", "<1|0>", string_get_cstr(args));
|
|
|
|
}
|
2021-04-19 16:26:25 +00:00
|
|
|
}
|
|
|
|
|
2021-08-02 11:15:24 +00:00
|
|
|
void power_cli_ext(Cli* cli, string_t args, void* context) {
|
|
|
|
if(!string_cmp(args, "0")) {
|
|
|
|
api_hal_power_disable_external_3_3v();
|
|
|
|
} else if(!string_cmp(args, "1")) {
|
|
|
|
api_hal_power_enable_external_3_3v();
|
|
|
|
} else {
|
|
|
|
cli_print_usage("power_ext", "<1|0>", string_get_cstr(args));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-30 04:51:48 +00:00
|
|
|
void power_cli_init(Cli* cli, Power* power) {
|
2021-07-18 18:09:00 +00:00
|
|
|
cli_add_command(cli, "poweroff", CliCommandFlagParallelSafe, power_cli_poweroff, power);
|
|
|
|
cli_add_command(cli, "reboot", CliCommandFlagParallelSafe, power_cli_reboot, power);
|
|
|
|
cli_add_command(
|
|
|
|
cli, "factory_reset", CliCommandFlagParallelSafe, power_cli_factory_reset, power);
|
|
|
|
cli_add_command(cli, "dfu", CliCommandFlagParallelSafe, power_cli_dfu, power);
|
|
|
|
cli_add_command(cli, "power_info", CliCommandFlagParallelSafe, power_cli_info, power);
|
|
|
|
cli_add_command(cli, "power_otg", CliCommandFlagParallelSafe, power_cli_otg, power);
|
2021-08-02 11:15:24 +00:00
|
|
|
cli_add_command(cli, "power_ext", CliCommandFlagParallelSafe, power_cli_ext, power);
|
2021-04-19 16:26:25 +00:00
|
|
|
}
|