diff --git a/applications/applications.c b/applications/applications.c index c5850aa26..f61dc5b76 100644 --- a/applications/applications.c +++ b/applications/applications.c @@ -39,6 +39,7 @@ int32_t lfrfid_debug_app(void* p); int32_t storage_app(void* p); int32_t storage_app_test(void* p); int32_t dialogs_app(void* p); +int32_t power_observer(void* p); // On system start hooks declaration void irda_cli_init(); @@ -91,6 +92,10 @@ const FlipperApplication FLIPPER_SERVICES[] = { {.app = power_task, .name = "power_task", .stack_size = 1024, .icon = &A_Plugins_14}, #endif +#ifdef SRV_POWER_OBSERVER + {.app = power_observer, .name = "power_observer", .stack_size = 1024, .icon = &A_Plugins_14}, +#endif + #ifdef SRV_BT {.app = bt_task, .name = "bt_task", .stack_size = 1024, .icon = &A_Plugins_14}, #endif diff --git a/applications/applications.mk b/applications/applications.mk index cfc91d605..c19015f98 100644 --- a/applications/applications.mk +++ b/applications/applications.mk @@ -20,6 +20,7 @@ SRV_DOLPHIN = 1 SRV_NOTIFICATION = 1 SRV_STORAGE = 1 SRV_DIALOGS = 1 +SRV_POWER_OBSERVER = 1 # Main Apps APP_IRDA = 1 @@ -59,6 +60,12 @@ SRV_CLI = 1 CFLAGS += -DSRV_POWER endif +SRV_POWER_OBSERVER ?= 0 +ifeq ($(SRV_POWER_OBSERVER), 1) +SRV_POWER = 1 +CFLAGS += -DSRV_POWER_OBSERVER +endif + SRV_BT ?= 0 ifeq ($(SRV_BT), 1) SRV_CLI = 1 diff --git a/applications/power-observer/power-observer.c b/applications/power-observer/power-observer.c new file mode 100644 index 000000000..5a411eca6 --- /dev/null +++ b/applications/power-observer/power-observer.c @@ -0,0 +1,33 @@ +#include +#include +#include + +const NotificationMessage message_green_110 = { + .type = NotificationMessageTypeLedGreen, + .data.led.value = 110, +}; + +static const NotificationSequence sequence_overconsumption = { + &message_green_110, + &message_red_255, + &message_delay_100, + NULL, +}; + +int32_t power_observer(void* p) { + NotificationApp* notifications = furi_record_open("notification"); + + const float overconsumption_limit = 0.03f; + + while(true) { + float current = -api_hal_power_get_battery_current(ApiHalPowerICFuelGauge); + + if(current >= overconsumption_limit) { + notification_message_block(notifications, &sequence_overconsumption); + } + + delay(1000); + } + + return 0; +} \ No newline at end of file diff --git a/applications/power/power_cli.c b/applications/power/power_cli.c index 64c828d40..e66e82b19 100644 --- a/applications/power/power_cli.c +++ b/applications/power/power_cli.c @@ -43,6 +43,16 @@ void power_cli_otg(Cli* cli, string_t args, void* context) { } } +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)); + } +} + void power_cli_init(Cli* cli, Power* power) { cli_add_command(cli, "poweroff", CliCommandFlagParallelSafe, power_cli_poweroff, power); cli_add_command(cli, "reboot", CliCommandFlagParallelSafe, power_cli_reboot, power); @@ -51,4 +61,5 @@ void power_cli_init(Cli* cli, Power* 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); + cli_add_command(cli, "power_ext", CliCommandFlagParallelSafe, power_cli_ext, power); }