mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-06-07 19:01:54 -07:00
Shutdown on Idle: auto-shutdown timer arm/inhibit hooked to loader events
This commit is contained in:
@@ -88,6 +88,18 @@ static void power_auto_shutdown_inhibit(Power* power) {
|
||||
}
|
||||
}
|
||||
|
||||
static void power_loader_callback(const void* message, void* context) {
|
||||
furi_assert(context);
|
||||
Power* power = context;
|
||||
const LoaderEvent* event = message;
|
||||
|
||||
if(event->type == LoaderEventTypeApplicationStarted) {
|
||||
power_auto_shutdown_inhibit(power);
|
||||
} else if(event->type == LoaderEventTypeApplicationStopped) {
|
||||
power_auto_shutdown_arm(power);
|
||||
}
|
||||
}
|
||||
|
||||
static void power_auto_shutdown_timer_callback(void* context) {
|
||||
furi_assert(context);
|
||||
Power* power = context;
|
||||
@@ -117,9 +129,13 @@ Power* power_alloc() {
|
||||
// Pubsub
|
||||
power->event_pubsub = furi_pubsub_alloc();
|
||||
power->settings_events = furi_pubsub_alloc();
|
||||
furi_pubsub_subscribe(power->settings_events, power_shutdown_time_changed_callback, power);
|
||||
power->loader = furi_record_open(RECORD_LOADER);
|
||||
power->input_events_pubsub = furi_record_open(RECORD_INPUT_EVENTS);
|
||||
power->input_events_subscription = NULL;
|
||||
power->app_start_stop_subscription =
|
||||
furi_pubsub_subscribe(loader_get_pubsub(power->loader), power_loader_callback, power);
|
||||
power->settings_events_subscription =
|
||||
furi_pubsub_subscribe(power->settings_events, power_shutdown_time_changed_callback, power);
|
||||
|
||||
// State initialization
|
||||
power->state = PowerStateNotCharging;
|
||||
@@ -166,21 +182,27 @@ void power_free(Power* power) {
|
||||
furi_mutex_free(power->api_mtx);
|
||||
|
||||
// FuriPubSub
|
||||
furi_pubsub_free(power->event_pubsub);
|
||||
furi_pubsub_free(power->settings_events);
|
||||
furi_pubsub_free(power->input_events_pubsub);
|
||||
furi_pubsub_unsubscribe(loader_get_pubsub(power->loader), power->app_start_stop_subscription);
|
||||
furi_pubsub_unsubscribe(power->settings_events, power->settings_events_subscription);
|
||||
|
||||
if(power->input_events_subscription) {
|
||||
furi_pubsub_unsubscribe(power->input_events_pubsub, power->input_events_subscription);
|
||||
power->input_events_subscription = NULL;
|
||||
}
|
||||
|
||||
furi_pubsub_free(power->event_pubsub);
|
||||
furi_pubsub_free(power->settings_events);
|
||||
power->loader = NULL;
|
||||
power->input_events_pubsub = NULL;
|
||||
|
||||
//Auto shutdown timer
|
||||
furi_timer_free(power->auto_shutdown_timer);
|
||||
|
||||
// Records
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
furi_record_close(RECORD_GUI);
|
||||
furi_record_close(RECORD_LOADER);
|
||||
furi_record_close(RECORD_INPUT_EVENTS);
|
||||
|
||||
free(power);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/gui.h>
|
||||
#include <assets_icons.h>
|
||||
#include <loader/loader.h>
|
||||
|
||||
#include <gui/modules/popup.h>
|
||||
#include "views/power_off.h"
|
||||
@@ -34,6 +35,8 @@ struct Power {
|
||||
FuriPubSub* settings_events;
|
||||
FuriPubSub* input_events_pubsub;
|
||||
FuriPubSubSubscription* input_events_subscription;
|
||||
FuriPubSubSubscription* app_start_stop_subscription;
|
||||
FuriPubSubSubscription* settings_events_subscription;
|
||||
PowerEvent event;
|
||||
|
||||
PowerState state;
|
||||
@@ -46,7 +49,7 @@ struct Power {
|
||||
|
||||
uint32_t shutdown_idle_delay_ms;
|
||||
FuriTimer* auto_shutdown_timer;
|
||||
|
||||
Loader* loader;
|
||||
FuriMutex* api_mtx;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user