2021-04-19 16:26:25 +00:00
|
|
|
#include "power_cli.h"
|
2021-09-24 16:28:02 +00:00
|
|
|
|
|
|
|
#include <power/power_service/power.h>
|
|
|
|
#include <cli/cli.h>
|
2022-01-05 16:10:18 +00:00
|
|
|
#include <furi_hal.h>
|
2021-04-19 16:26:25 +00:00
|
|
|
|
2021-05-18 13:57:39 +00:00
|
|
|
void power_cli_poweroff(Cli* cli, string_t args, void* context) {
|
2021-10-06 15:41:22 +00:00
|
|
|
Power* power = furi_record_open("power");
|
2021-09-24 16:28:02 +00:00
|
|
|
printf("It's now safe to disconnect USB from your flipper\r\n");
|
2021-10-06 15:41:22 +00:00
|
|
|
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-09-24 16:28:02 +00:00
|
|
|
power_reboot(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-09-24 16:28:02 +00:00
|
|
|
power_reboot(PowerBootModeDfu);
|
2021-04-19 16:26:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-24 14:50:28 +00:00
|
|
|
void power_cli_info(Cli* cli, string_t args, void* context) {
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_power_dump_state();
|
2021-04-19 16:26:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-24 14:50:28 +00:00
|
|
|
void power_cli_otg(Cli* cli, string_t args, void* context) {
|
|
|
|
if(!string_cmp(args, "0")) {
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_power_disable_otg();
|
2021-05-24 14:50:28 +00:00
|
|
|
} else if(!string_cmp(args, "1")) {
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_power_enable_otg();
|
2021-05-24 14:50:28 +00:00
|
|
|
} 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")) {
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_power_disable_external_3_3v();
|
2021-08-02 11:15:24 +00:00
|
|
|
} else if(!string_cmp(args, "1")) {
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_power_enable_external_3_3v();
|
2021-08-02 11:15:24 +00:00
|
|
|
} else {
|
|
|
|
cli_print_usage("power_ext", "<1|0>", string_get_cstr(args));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-24 18:47:48 +00:00
|
|
|
void power_on_system_start() {
|
|
|
|
#ifdef SRV_CLI
|
2021-09-24 16:28:02 +00:00
|
|
|
Cli* cli = furi_record_open("cli");
|
|
|
|
|
|
|
|
cli_add_command(cli, "poweroff", CliCommandFlagParallelSafe, power_cli_poweroff, NULL);
|
|
|
|
cli_add_command(cli, "reboot", CliCommandFlagParallelSafe, power_cli_reboot, NULL);
|
|
|
|
cli_add_command(cli, "dfu", CliCommandFlagParallelSafe, power_cli_dfu, NULL);
|
|
|
|
cli_add_command(cli, "power_info", CliCommandFlagParallelSafe, power_cli_info, NULL);
|
|
|
|
cli_add_command(cli, "power_otg", CliCommandFlagParallelSafe, power_cli_otg, NULL);
|
|
|
|
cli_add_command(cli, "power_ext", CliCommandFlagParallelSafe, power_cli_ext, NULL);
|
|
|
|
|
|
|
|
furi_record_close("cli");
|
2021-12-24 18:47:48 +00:00
|
|
|
#endif
|
2021-04-19 16:26:25 +00:00
|
|
|
}
|