2021-09-24 19:28:02 +03:00
|
|
|
#include "power_i.h"
|
2021-11-01 23:35:54 +03:00
|
|
|
|
2021-09-24 19:28:02 +03:00
|
|
|
#include <furi.h>
|
2022-01-05 19:10:18 +03:00
|
|
|
#include "furi_hal_power.h"
|
|
|
|
#include "furi_hal_bootloader.h"
|
2021-09-24 19:28:02 +03:00
|
|
|
|
2021-10-06 18:41:22 +03:00
|
|
|
void power_off(Power* power) {
|
2021-09-24 19:28:02 +03:00
|
|
|
furi_hal_power_off();
|
2021-10-06 18:41:22 +03:00
|
|
|
// 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");
|
2021-09-24 19:28:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void power_reboot(PowerBootMode mode) {
|
|
|
|
if(mode == PowerBootModeNormal) {
|
2021-10-26 15:24:14 +03:00
|
|
|
furi_hal_bootloader_set_mode(FuriHalBootloaderModeNormal);
|
2021-09-24 19:28:02 +03:00
|
|
|
} else if(mode == PowerBootModeDfu) {
|
2021-10-26 15:24:14 +03:00
|
|
|
furi_hal_bootloader_set_mode(FuriHalBootloaderModeDFU);
|
2021-09-24 19:28:02 +03:00
|
|
|
}
|
|
|
|
furi_hal_power_reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void power_get_info(Power* power, PowerInfo* info) {
|
|
|
|
furi_assert(power);
|
|
|
|
furi_assert(info);
|
|
|
|
|
2022-01-03 01:52:45 +03:00
|
|
|
osMutexAcquire(power->api_mtx, osWaitForever);
|
2021-09-24 19:28:02 +03:00
|
|
|
memcpy(info, &power->info, sizeof(power->info));
|
2022-01-03 01:52:45 +03:00
|
|
|
osMutexRelease(power->api_mtx);
|
2021-09-24 19:28:02 +03:00
|
|
|
}
|
|
|
|
|
2021-11-01 23:35:54 +03:00
|
|
|
FuriPubSub* power_get_pubsub(Power* power) {
|
2021-09-24 19:28:02 +03:00
|
|
|
furi_assert(power);
|
2021-11-01 23:35:54 +03:00
|
|
|
return power->event_pubsub;
|
2021-09-24 19:28:02 +03:00
|
|
|
}
|
2022-01-03 01:52:45 +03:00
|
|
|
|
|
|
|
bool power_is_battery_healthy(Power* power) {
|
|
|
|
furi_assert(power);
|
|
|
|
bool is_healthy = false;
|
|
|
|
osMutexAcquire(power->api_mtx, osWaitForever);
|
|
|
|
is_healthy = power->info.health > POWER_BATTERY_HEALTHY_LEVEL;
|
|
|
|
osMutexRelease(power->api_mtx);
|
|
|
|
return is_healthy;
|
|
|
|
}
|
|
|
|
|
|
|
|
void power_enable_low_battery_level_notification(Power* power, bool enable) {
|
|
|
|
furi_assert(power);
|
|
|
|
osMutexAcquire(power->api_mtx, osWaitForever);
|
|
|
|
power->show_low_bat_level_message = enable;
|
|
|
|
osMutexRelease(power->api_mtx);
|
|
|
|
}
|