unleashed-firmware/applications/services/power/power_service/power_api.c
あく acc39a4bc0
Api Symbols: replace asserts with checks (#3507)
* Api Symbols: replace asserts with checks
* Api Symbols: replace asserts with checks part 2
* Update no args function signatures with void, to help compiler to track incorrect usage
* More unavoidable void
* Update PVS config and code to make it happy
* Format sources
* nfc: fix checks
* dead code cleanup & include fixes

Co-authored-by: gornekich <n.gorbadey@gmail.com>
Co-authored-by: hedger <hedger@users.noreply.github.com>
Co-authored-by: hedger <hedger@nanode.su>
2024-03-19 23:43:52 +09:00

60 lines
1.7 KiB
C

#include "power_i.h"
#include <furi.h>
#include <furi_hal.h>
#include <update_util/update_operation.h>
void power_off(Power* power) {
furi_check(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, PowerViewUnplugUsb);
furi_delay_ms(100);
furi_halt("Disconnect USB for safe shutdown");
}
void power_reboot(PowerBootMode mode) {
if(mode == PowerBootModeNormal) {
update_operation_disarm();
} else if(mode == PowerBootModeDfu) {
furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeDfu);
} else if(mode == PowerBootModeUpdateStart) {
furi_hal_rtc_set_boot_mode(FuriHalRtcBootModePreUpdate);
} else {
furi_crash();
}
furi_hal_power_reset();
}
void power_get_info(Power* power, PowerInfo* info) {
furi_check(power);
furi_check(info);
furi_mutex_acquire(power->api_mtx, FuriWaitForever);
memcpy(info, &power->info, sizeof(power->info));
furi_mutex_release(power->api_mtx);
}
FuriPubSub* power_get_pubsub(Power* power) {
furi_check(power);
return power->event_pubsub;
}
bool power_is_battery_healthy(Power* power) {
furi_check(power);
bool is_healthy = false;
furi_mutex_acquire(power->api_mtx, FuriWaitForever);
is_healthy = power->info.health > POWER_BATTERY_HEALTHY_LEVEL;
furi_mutex_release(power->api_mtx);
return is_healthy;
}
void power_enable_low_battery_level_notification(Power* power, bool enable) {
furi_check(power);
furi_mutex_acquire(power->api_mtx, FuriWaitForever);
power->show_low_bat_level_message = enable;
furi_mutex_release(power->api_mtx);
}