flipperzero-firmware/applications/power/power_service/power_api.c
gornekich 5232d5daba
[FL-1905] Fix power off notification (#748)
* view dispatcher: add set view front API
* power: add power off notification
* Gui: rename ViewPort `send_to` API.
* Makefile: add blackmagick support

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-10-06 18:41:22 +03:00

37 lines
1006 B
C

#include "power_i.h"
#include <furi.h>
#include "furi-hal-power.h"
#include "furi-hal-boot.h"
void power_off(Power* power) {
furi_hal_power_off();
// Notify user if USB is plugged
view_dispatcher_send_to_front(power->view_dispatcher);
view_dispatcher_switch_to_view(power->view_dispatcher, PowerViewPopup);
osDelay(10);
furi_crash("Disconnect USB for safe shutdown");
}
void power_reboot(PowerBootMode mode) {
if(mode == PowerBootModeNormal) {
furi_hal_boot_set_mode(FuriHalBootModeNormal);
} else if(mode == PowerBootModeDfu) {
furi_hal_boot_set_mode(FuriHalBootModeDFU);
}
furi_hal_power_reset();
}
void power_get_info(Power* power, PowerInfo* info) {
furi_assert(power);
furi_assert(info);
osMutexAcquire(power->info_mtx, osWaitForever);
memcpy(info, &power->info, sizeof(power->info));
osMutexRelease(power->info_mtx);
}
PubSub* power_get_pubsub(Power* power) {
furi_assert(power);
return &power->event_pubsub;
}