unleashed-firmware/applications/power/power_cli.c
gornekich d3b58f732f
[FL-1783] Power service refactoring (#718)
* settings power: introduce power settings app
* power: move power API to separate file
* settings power: implement reboot scene
* settings power: add power off scene
* assets: add crying dolphin, fix Subghz assets names
* settings power: fix power off scene GUI
* settings power: add battery info scene
* power: add cli to application on start hook
* power: remove power from main menu
* power: move to power service folder
* power service: rework power off logic
* power: add pubsub events
* bt: subscribe to battery level change, update characteristic
* application: change order of Settings applications
* gui: add bubble element
* power: gui improvements
* application: rename Notification -> LCD and notifications
* Applications: menu order according to documentation and add missing power cli init
* settings power: add disconnect USB scene
* power cli: notify user to disconnect USB after poweroff
* Power: update poweroff message in cli

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-09-24 19:28:02 +03:00

72 lines
2.3 KiB
C

#include "power_cli.h"
#include <power/power_service/power.h>
#include <cli/cli.h>
#include <furi-hal.h>
void power_cli_poweroff(Cli* cli, string_t args, void* context) {
power_off();
printf("It's now safe to disconnect USB from your flipper\r\n");
while(cli_getc(cli)) {
}
}
void power_cli_reboot(Cli* cli, string_t args, void* context) {
power_reboot(PowerBootModeNormal);
}
void power_cli_dfu(Cli* cli, string_t args, void* context) {
power_reboot(PowerBootModeDfu);
}
void power_cli_factory_reset(Cli* cli, string_t args, void* 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");
furi_hal_boot_set_flags(FuriHalBootFlagFactoryReset);
power_reboot(PowerBootModeNormal);
} else {
printf("Safe choice.\r\n");
}
}
void power_cli_info(Cli* cli, string_t args, void* context) {
furi_hal_power_dump_state();
}
void power_cli_otg(Cli* cli, string_t args, void* context) {
if(!string_cmp(args, "0")) {
furi_hal_power_disable_otg();
} else if(!string_cmp(args, "1")) {
furi_hal_power_enable_otg();
} else {
cli_print_usage("power_otg", "<1|0>", string_get_cstr(args));
}
}
void power_cli_ext(Cli* cli, string_t args, void* context) {
if(!string_cmp(args, "0")) {
furi_hal_power_disable_external_3_3v();
} else if(!string_cmp(args, "1")) {
furi_hal_power_enable_external_3_3v();
} else {
cli_print_usage("power_ext", "<1|0>", string_get_cstr(args));
}
}
void power_cli_init() {
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, "factory_reset", CliCommandFlagParallelSafe, power_cli_factory_reset, 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");
}