2021-04-19 19:26:25 +03:00
|
|
|
#include "power_cli.h"
|
2021-09-24 19:28:02 +03:00
|
|
|
|
2022-01-05 19:10:18 +03:00
|
|
|
#include <furi_hal.h>
|
2022-02-10 14:20:50 +03:00
|
|
|
#include <cli/cli.h>
|
|
|
|
#include <lib/toolbox/args.h>
|
|
|
|
#include <power/power_service/power.h>
|
2021-04-19 19:26:25 +03:00
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
void power_cli_off(Cli* cli, FuriString* args) {
|
2022-05-06 16:37:10 +03:00
|
|
|
UNUSED(cli);
|
|
|
|
UNUSED(args);
|
2022-07-26 15:21:51 +03:00
|
|
|
Power* power = furi_record_open(RECORD_POWER);
|
2021-09-24 19:28:02 +03:00
|
|
|
printf("It's now safe to disconnect USB from your flipper\r\n");
|
2022-07-20 13:56:33 +03:00
|
|
|
furi_delay_ms(666);
|
2021-10-06 18:41:22 +03:00
|
|
|
power_off(power);
|
2021-04-19 19:26:25 +03:00
|
|
|
}
|
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
void power_cli_reboot(Cli* cli, FuriString* args) {
|
2022-05-06 16:37:10 +03:00
|
|
|
UNUSED(cli);
|
|
|
|
UNUSED(args);
|
2024-08-07 06:49:41 +03:00
|
|
|
Power* power = furi_record_open(RECORD_POWER);
|
|
|
|
power_reboot(power, PowerBootModeNormal);
|
2021-04-19 19:26:25 +03:00
|
|
|
}
|
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
void power_cli_reboot2dfu(Cli* cli, FuriString* args) {
|
2022-05-06 16:37:10 +03:00
|
|
|
UNUSED(cli);
|
|
|
|
UNUSED(args);
|
2024-08-07 06:49:41 +03:00
|
|
|
Power* power = furi_record_open(RECORD_POWER);
|
|
|
|
power_reboot(power, PowerBootModeDfu);
|
2021-04-19 19:26:25 +03:00
|
|
|
}
|
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
void power_cli_5v(Cli* cli, FuriString* args) {
|
2022-05-06 16:37:10 +03:00
|
|
|
UNUSED(cli);
|
2022-10-05 18:15:23 +03:00
|
|
|
if(!furi_string_cmp(args, "0")) {
|
2021-08-08 21:03:25 +03:00
|
|
|
furi_hal_power_disable_otg();
|
2022-10-05 18:15:23 +03:00
|
|
|
} else if(!furi_string_cmp(args, "1")) {
|
2021-08-08 21:03:25 +03:00
|
|
|
furi_hal_power_enable_otg();
|
2021-05-24 17:50:28 +03:00
|
|
|
} else {
|
2022-10-05 18:15:23 +03:00
|
|
|
cli_print_usage("power_otg", "<1|0>", furi_string_get_cstr(args));
|
2021-05-24 17:50:28 +03:00
|
|
|
}
|
2021-04-19 19:26:25 +03:00
|
|
|
}
|
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
void power_cli_3v3(Cli* cli, FuriString* args) {
|
2022-05-06 16:37:10 +03:00
|
|
|
UNUSED(cli);
|
2022-10-05 18:15:23 +03:00
|
|
|
if(!furi_string_cmp(args, "0")) {
|
2021-08-08 21:03:25 +03:00
|
|
|
furi_hal_power_disable_external_3_3v();
|
2022-10-05 18:15:23 +03:00
|
|
|
} else if(!furi_string_cmp(args, "1")) {
|
2021-08-08 21:03:25 +03:00
|
|
|
furi_hal_power_enable_external_3_3v();
|
2021-08-02 14:15:24 +03:00
|
|
|
} else {
|
2022-10-05 18:15:23 +03:00
|
|
|
cli_print_usage("power_ext", "<1|0>", furi_string_get_cstr(args));
|
2021-08-02 14:15:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-19 17:43:52 +03:00
|
|
|
static void power_cli_command_print_usage(void) {
|
2022-02-10 14:20:50 +03:00
|
|
|
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");
|
|
|
|
printf("\t5v <0 or 1>\t - enable or disable 5v ext\r\n");
|
2022-03-16 10:25:07 +03: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 14:20:50 +03:00
|
|
|
}
|
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
void power_cli(Cli* cli, FuriString* args, void* context) {
|
2022-05-06 16:37:10 +03:00
|
|
|
UNUSED(context);
|
2022-10-05 18:15:23 +03:00
|
|
|
FuriString* cmd;
|
|
|
|
cmd = furi_string_alloc();
|
2022-02-10 14:20:50 +03:00
|
|
|
|
|
|
|
do {
|
|
|
|
if(!args_read_string_and_trim(args, cmd)) {
|
|
|
|
power_cli_command_print_usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
if(furi_string_cmp_str(cmd, "off") == 0) {
|
2022-02-10 14:20:50 +03:00
|
|
|
power_cli_off(cli, args);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
if(furi_string_cmp_str(cmd, "reboot") == 0) {
|
2022-02-10 14:20:50 +03:00
|
|
|
power_cli_reboot(cli, args);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
if(furi_string_cmp_str(cmd, "reboot2dfu") == 0) {
|
2022-02-10 14:20:50 +03:00
|
|
|
power_cli_reboot2dfu(cli, args);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
if(furi_string_cmp_str(cmd, "5v") == 0) {
|
2022-02-10 14:20:50 +03:00
|
|
|
power_cli_5v(cli, args);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-03-16 10:25:07 +03:00
|
|
|
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
2022-10-05 18:15:23 +03:00
|
|
|
if(furi_string_cmp_str(cmd, "3v3") == 0) {
|
2022-03-16 10:25:07 +03:00
|
|
|
power_cli_3v3(cli, args);
|
|
|
|
break;
|
|
|
|
}
|
2022-02-10 14:20:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
power_cli_command_print_usage();
|
|
|
|
} while(false);
|
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_free(cmd);
|
2022-02-10 14:20:50 +03:00
|
|
|
}
|
|
|
|
|
2024-03-19 17:43:52 +03:00
|
|
|
void power_on_system_start(void) {
|
2021-12-24 21:47:48 +03:00
|
|
|
#ifdef SRV_CLI
|
2022-07-26 15:21:51 +03:00
|
|
|
Cli* cli = furi_record_open(RECORD_CLI);
|
2021-09-24 19:28:02 +03:00
|
|
|
|
2022-02-10 14:20:50 +03:00
|
|
|
cli_add_command(cli, "power", CliCommandFlagParallelSafe, power_cli, NULL);
|
2021-09-24 19:28:02 +03:00
|
|
|
|
2022-07-26 15:21:51 +03:00
|
|
|
furi_record_close(RECORD_CLI);
|
2022-04-13 23:50:25 +03:00
|
|
|
#else
|
|
|
|
UNUSED(power_cli);
|
2021-12-24 21:47:48 +03:00
|
|
|
#endif
|
2021-04-19 19:26:25 +03:00
|
|
|
}
|