Files
Momentum-Firmware/applications/services/power/power_service/power_api.c
T
Georgii Surkov f4122a924a [FL-3841] FuriEventLoop Pt.2 (#3703)
* Abstract primitive type from main logic in FuriEventLoop
* Remove message_queue_i.h
* Add stream buffer support for event loop
* Add semaphore support for event loop
* Add temporary unit test workaround
* Make the linter happy
* Add mutex support for event loop
* Implement event subscription and unsubscription while the event loop is running
* Implement edge events
* Fix leftover logical errors
* Add event loop timer example application
* Implement flag-based edge trigger and one-shot mode
* Add event loop mutex example application
* Only notify the event loop if stream buffer is at or above its trigger level
* Reformat comments
* Add event loop stream buffer example application
* Add event loop multiple elements example application
* Improve event loop flag names
* Remove redundant signal handler as it is already handled by the event loop
* Refactor Power service, improve ViewHolder
* Use ViewHolder instead of ViewDispatcher in About app
* Enable ViewDispatcher queue on construction, deprecate view_dispatcher_enable_queue()
* Remove all invocations of view_dispatcher_enable_queue()
* Remove app-scened-template
* Remove missing library from target.json
* Port Accessor app to ViewHolder
* Make the linter happy
* Add example_view_holder application, update ViewHolder docs
* Add example_view_dispatcher application, update ViewDispatcher docs
* Replace FuriSemaphore with FuriApiLock, remove workaround delay
* Fix logical error
* Fix another logical error
* Use the sources directive to speed up compilation
* Use constant define macro
* Improve FuriEventLoop documentation
* Improve FuriEventLoop documentation once more
* Bump API Version
* Gui: remove redundant checks from ViewDispatcher
* Gui: remove dead ifs from ViewDispatcher

Co-authored-by: Silent <CookiePLMonster@users.noreply.github.com>
Co-authored-by: hedger <hedger@users.noreply.github.com>
Co-authored-by: あく <alleteam@gmail.com>
2024-08-07 12:49:41 +09:00

66 lines
1.8 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;
}
FuriPubSub* power_get_settings_events_pubsub(Power* power) {
furi_assert(power);
return power->settings_events;
}
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);
}