2021-04-19 16:26:25 +00:00
|
|
|
#include "power_cli.h"
|
2021-09-24 16:28:02 +00:00
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
#include <furi_hal.h>
|
2022-02-10 11:20:50 +00:00
|
|
|
#include <cli/cli.h>
|
|
|
|
#include <lib/toolbox/args.h>
|
|
|
|
#include <power/power_service/power.h>
|
2021-04-19 16:26:25 +00:00
|
|
|
|
2022-02-10 11:20:50 +00:00
|
|
|
void power_cli_off(Cli* cli, string_t args) {
|
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");
|
2022-02-13 19:24:03 +00:00
|
|
|
osDelay(666);
|
2021-10-06 15:41:22 +00:00
|
|
|
power_off(power);
|
2021-04-19 16:26:25 +00:00
|
|
|
}
|
|
|
|
|
2022-02-10 11:20:50 +00:00
|
|
|
void power_cli_reboot(Cli* cli, string_t args) {
|
2021-09-24 16:28:02 +00:00
|
|
|
power_reboot(PowerBootModeNormal);
|
2021-04-19 16:26:25 +00:00
|
|
|
}
|
|
|
|
|
2022-02-10 11:20:50 +00:00
|
|
|
void power_cli_reboot2dfu(Cli* cli, string_t args) {
|
2021-09-24 16:28:02 +00:00
|
|
|
power_reboot(PowerBootModeDfu);
|
2021-04-19 16:26:25 +00:00
|
|
|
}
|
|
|
|
|
2022-04-07 15:00:45 +00:00
|
|
|
static void power_cli_info_callback(const char* key, const char* value, bool last, void* context) {
|
|
|
|
printf("%-24s: %s\r\n", key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void power_cli_info(Cli* cli, string_t args) {
|
|
|
|
furi_hal_power_info_get(power_cli_info_callback, NULL);
|
|
|
|
}
|
|
|
|
|
2022-02-10 11:20:50 +00:00
|
|
|
void power_cli_debug(Cli* cli, string_t args) {
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_power_dump_state();
|
2021-04-19 16:26:25 +00:00
|
|
|
}
|
|
|
|
|
2022-02-10 11:20:50 +00:00
|
|
|
void power_cli_5v(Cli* cli, string_t args) {
|
2021-05-24 14:50:28 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-02-10 11:20:50 +00:00
|
|
|
void power_cli_3v3(Cli* cli, string_t args) {
|
2021-08-02 11:15:24 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-10 11:20:50 +00:00
|
|
|
static void power_cli_command_print_usage() {
|
|
|
|
printf("Usage:\r\n");
|
|
|
|
printf("power <cmd> <args>\r\n");
|
|
|
|
printf("Cmd list:\r\n");
|
|
|
|
|
|
|
|
printf("\toff\t - shutdown power\r\n");
|
|
|
|
printf("\treboot\t - reboot\r\n");
|
|
|
|
printf("\treboot2dfu\t - reboot to dfu bootloader\r\n");
|
2022-04-07 15:00:45 +00:00
|
|
|
printf("\tinfo\t - show power info\r\n");
|
2022-02-10 11:20:50 +00:00
|
|
|
printf("\tdebug\t - show debug information\r\n");
|
|
|
|
printf("\t5v <0 or 1>\t - enable or disable 5v ext\r\n");
|
2022-03-16 07:25:07 +00:00
|
|
|
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
|
|
|
printf("\t3v3 <0 or 1>\t - enable or disable 3v3 ext\r\n");
|
|
|
|
}
|
2022-02-10 11:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void power_cli(Cli* cli, string_t args, void* context) {
|
|
|
|
string_t cmd;
|
|
|
|
string_init(cmd);
|
|
|
|
|
|
|
|
do {
|
|
|
|
if(!args_read_string_and_trim(args, cmd)) {
|
|
|
|
power_cli_command_print_usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(string_cmp_str(cmd, "off") == 0) {
|
|
|
|
power_cli_off(cli, args);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(string_cmp_str(cmd, "reboot") == 0) {
|
|
|
|
power_cli_reboot(cli, args);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(string_cmp_str(cmd, "reboot2dfu") == 0) {
|
|
|
|
power_cli_reboot2dfu(cli, args);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-04-07 15:00:45 +00:00
|
|
|
if(string_cmp_str(cmd, "info") == 0) {
|
|
|
|
power_cli_info(cli, args);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-02-10 11:20:50 +00:00
|
|
|
if(string_cmp_str(cmd, "debug") == 0) {
|
|
|
|
power_cli_debug(cli, args);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(string_cmp_str(cmd, "5v") == 0) {
|
|
|
|
power_cli_5v(cli, args);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-03-16 07:25:07 +00:00
|
|
|
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
|
|
|
if(string_cmp_str(cmd, "3v3") == 0) {
|
|
|
|
power_cli_3v3(cli, args);
|
|
|
|
break;
|
|
|
|
}
|
2022-02-10 11:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
power_cli_command_print_usage();
|
|
|
|
} while(false);
|
|
|
|
|
|
|
|
string_clear(cmd);
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
|
2022-02-10 11:20:50 +00:00
|
|
|
cli_add_command(cli, "power", CliCommandFlagParallelSafe, power_cli, NULL);
|
2021-09-24 16:28:02 +00:00
|
|
|
|
|
|
|
furi_record_close("cli");
|
2021-12-24 18:47:48 +00:00
|
|
|
#endif
|
2021-04-19 16:26:25 +00:00
|
|
|
}
|