2021-09-24 16:28:02 +00:00
|
|
|
#include "power_i.h"
|
2021-11-01 20:35:54 +00:00
|
|
|
|
2021-09-24 16:28:02 +00:00
|
|
|
#include <furi.h>
|
2022-04-13 20:50:25 +00:00
|
|
|
#include <furi_hal.h>
|
2022-05-06 16:26:25 +00:00
|
|
|
#include <update_util/update_operation.h>
|
2021-09-24 16:28:02 +00:00
|
|
|
|
2021-10-06 15:41:22 +00:00
|
|
|
void power_off(Power* power) {
|
2021-09-24 16:28:02 +00:00
|
|
|
furi_hal_power_off();
|
2021-10-06 15:41:22 +00:00
|
|
|
// Notify user if USB is plugged
|
|
|
|
view_dispatcher_send_to_front(power->view_dispatcher);
|
|
|
|
view_dispatcher_switch_to_view(power->view_dispatcher, PowerViewPopup);
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_delay_ms(10);
|
2022-02-10 11:20:50 +00:00
|
|
|
furi_halt("Disconnect USB for safe shutdown");
|
2021-09-24 16:28:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void power_reboot(PowerBootMode mode) {
|
|
|
|
if(mode == PowerBootModeNormal) {
|
2022-05-06 16:26:25 +00:00
|
|
|
update_operation_disarm();
|
2021-09-24 16:28:02 +00:00
|
|
|
} else if(mode == PowerBootModeDfu) {
|
2022-04-13 20:50:25 +00:00
|
|
|
furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeDfu);
|
2022-04-15 16:47:57 +00:00
|
|
|
} else if(mode == PowerBootModeUpdateStart) {
|
|
|
|
furi_hal_rtc_set_boot_mode(FuriHalRtcBootModePreUpdate);
|
2021-09-24 16:28:02 +00:00
|
|
|
}
|
|
|
|
furi_hal_power_reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void power_get_info(Power* power, PowerInfo* info) {
|
|
|
|
furi_assert(power);
|
|
|
|
furi_assert(info);
|
|
|
|
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_mutex_acquire(power->api_mtx, FuriWaitForever);
|
2021-09-24 16:28:02 +00:00
|
|
|
memcpy(info, &power->info, sizeof(power->info));
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_mutex_release(power->api_mtx);
|
2021-09-24 16:28:02 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 20:35:54 +00:00
|
|
|
FuriPubSub* power_get_pubsub(Power* power) {
|
2021-09-24 16:28:02 +00:00
|
|
|
furi_assert(power);
|
2021-11-01 20:35:54 +00:00
|
|
|
return power->event_pubsub;
|
2021-09-24 16:28:02 +00:00
|
|
|
}
|
2022-01-02 22:52:45 +00:00
|
|
|
|
|
|
|
bool power_is_battery_healthy(Power* power) {
|
|
|
|
furi_assert(power);
|
|
|
|
bool is_healthy = false;
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_mutex_acquire(power->api_mtx, FuriWaitForever);
|
2022-01-02 22:52:45 +00:00
|
|
|
is_healthy = power->info.health > POWER_BATTERY_HEALTHY_LEVEL;
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_mutex_release(power->api_mtx);
|
2022-01-02 22:52:45 +00:00
|
|
|
return is_healthy;
|
|
|
|
}
|
|
|
|
|
|
|
|
void power_enable_low_battery_level_notification(Power* power, bool enable) {
|
|
|
|
furi_assert(power);
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_mutex_acquire(power->api_mtx, FuriWaitForever);
|
2022-01-02 22:52:45 +00:00
|
|
|
power->show_low_bat_level_message = enable;
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_mutex_release(power->api_mtx);
|
2022-01-02 22:52:45 +00:00
|
|
|
}
|