mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-12 20:08:36 -07:00
Merge branch 'dev' of https://github.com/DarkFlippers/unleashed-firmware into xfw-dev
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <furi_hal.h>
|
||||
#include <cli/cli.h>
|
||||
#include <cli/cli_vcp.h>
|
||||
#include <locale/locale.h>
|
||||
|
||||
#include "animations/animation_manager.h"
|
||||
#include "desktop/scenes/desktop_scene.h"
|
||||
@@ -41,6 +42,77 @@ static void desktop_lock_icon_draw_callback(Canvas* canvas, void* context) {
|
||||
canvas_draw_icon(canvas, 0, 0, &I_Lock_7x8);
|
||||
}
|
||||
|
||||
static void desktop_toggle_clock_view(Desktop* desktop, bool is_enabled) {
|
||||
furi_assert(desktop);
|
||||
|
||||
// clock type upd after 1 minute
|
||||
desktop->clock_type = (locale_get_time_format() == LocaleTimeFormat24h);
|
||||
|
||||
if(is_enabled) { // && !furi_timer_is_running(desktop->update_clock_timer)) {
|
||||
furi_timer_start(desktop->update_clock_timer, furi_ms_to_ticks(1000));
|
||||
} else if(!is_enabled) { //&& furi_timer_is_running(desktop->update_clock_timer)) {
|
||||
furi_timer_stop(desktop->update_clock_timer);
|
||||
}
|
||||
|
||||
view_port_enabled_set(desktop->clock_viewport, is_enabled);
|
||||
}
|
||||
|
||||
static uint8_t desktop_clock_get_num_w(uint8_t num) {
|
||||
if(num == 1) {
|
||||
return 3;
|
||||
} else if(num == 4) {
|
||||
return 6;
|
||||
} else {
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
static const char* digit[10] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
|
||||
|
||||
static void desktop_clock_draw_callback(Canvas* canvas, void* context) {
|
||||
furi_assert(context);
|
||||
furi_assert(canvas);
|
||||
|
||||
Desktop* desktop = context;
|
||||
|
||||
uint8_t d[4] = {
|
||||
desktop->minute % 10,
|
||||
desktop->minute / 10,
|
||||
desktop->hour % 10,
|
||||
desktop->hour / 10,
|
||||
};
|
||||
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
|
||||
uint8_t new_w = desktop_clock_get_num_w(d[0]) + //c1
|
||||
desktop_clock_get_num_w(d[1]) + //c2
|
||||
desktop_clock_get_num_w(d[2]) + //c3
|
||||
desktop_clock_get_num_w(d[3]) + //c4
|
||||
2 + 4; // ":" + 4 separators
|
||||
|
||||
// further away from the battery charge indicator, if the smallest minute is 1
|
||||
view_port_set_width(desktop->clock_viewport, new_w - !(d[0] == 1));
|
||||
|
||||
uint8_t x = new_w;
|
||||
|
||||
uint8_t y = 8;
|
||||
uint8_t offset_r;
|
||||
|
||||
canvas_draw_str_aligned(canvas, x, y, AlignRight, AlignBottom, digit[d[0]]);
|
||||
offset_r = desktop_clock_get_num_w(d[0]);
|
||||
|
||||
canvas_draw_str_aligned(canvas, x -= (offset_r + 1), y, AlignRight, AlignBottom, digit[d[1]]);
|
||||
offset_r = desktop_clock_get_num_w(d[1]);
|
||||
|
||||
canvas_draw_str_aligned(canvas, x -= (offset_r + 1), y - 1, AlignRight, AlignBottom, ":");
|
||||
offset_r = 2;
|
||||
|
||||
canvas_draw_str_aligned(canvas, x -= (offset_r + 1), y, AlignRight, AlignBottom, digit[d[2]]);
|
||||
offset_r = desktop_clock_get_num_w(d[2]);
|
||||
|
||||
canvas_draw_str_aligned(canvas, x -= (offset_r + 1), y, AlignRight, AlignBottom, digit[d[3]]);
|
||||
}
|
||||
|
||||
static void desktop_stealth_mode_icon_draw_callback(Canvas* canvas, void* context) {
|
||||
UNUSED(context);
|
||||
furi_assert(canvas);
|
||||
@@ -61,6 +133,9 @@ static bool desktop_custom_event_callback(void* context, uint32_t event) {
|
||||
// TODO: Implement a message mechanism for loading settings and (optionally)
|
||||
// locking and unlocking
|
||||
DESKTOP_SETTINGS_LOAD(&desktop->settings);
|
||||
|
||||
desktop_toggle_clock_view(desktop, desktop->settings.display_clock);
|
||||
|
||||
desktop_auto_lock_arm(desktop);
|
||||
return true;
|
||||
case DesktopGlobalAutoLock:
|
||||
@@ -126,6 +201,31 @@ static void desktop_auto_lock_inhibit(Desktop* desktop) {
|
||||
}
|
||||
}
|
||||
|
||||
static void desktop_update_clock_timer_callback(void* context) {
|
||||
furi_assert(context);
|
||||
Desktop* desktop = context;
|
||||
|
||||
if(gui_get_count_of_enabled_view_port_in_layer(desktop->gui, GuiLayerStatusBarLeft) < 6) {
|
||||
FuriHalRtcDateTime curr_dt;
|
||||
furi_hal_rtc_get_datetime(&curr_dt);
|
||||
|
||||
if(desktop->minute != curr_dt.minute) {
|
||||
if(desktop->clock_type) {
|
||||
desktop->hour = curr_dt.hour;
|
||||
} else {
|
||||
desktop->hour = (curr_dt.hour > 12) ? curr_dt.hour - 12 :
|
||||
((curr_dt.hour == 0) ? 12 : curr_dt.hour);
|
||||
}
|
||||
desktop->minute = curr_dt.minute;
|
||||
view_port_update(desktop->clock_viewport);
|
||||
}
|
||||
|
||||
view_port_enabled_set(desktop->clock_viewport, true);
|
||||
} else {
|
||||
view_port_enabled_set(desktop->clock_viewport, false);
|
||||
}
|
||||
}
|
||||
|
||||
void desktop_lock(Desktop* desktop, bool pin_lock) {
|
||||
pin_lock = pin_lock && desktop->settings.pin_code.length > 0;
|
||||
if(!furi_hal_rtc_is_flag_set(FuriHalRtcFlagLock)) {
|
||||
@@ -142,6 +242,9 @@ void desktop_lock(Desktop* desktop, bool pin_lock) {
|
||||
scene_manager_set_scene_state(
|
||||
desktop->scene_manager, DesktopSceneLocked, SCENE_LOCKED_FIRST_ENTER);
|
||||
scene_manager_next_scene(desktop->scene_manager, DesktopSceneLocked);
|
||||
|
||||
DesktopStatus status = {.locked = true};
|
||||
furi_pubsub_publish(desktop->status_pubsub, &status);
|
||||
}
|
||||
|
||||
void desktop_unlock(Desktop* desktop) {
|
||||
@@ -160,6 +263,9 @@ void desktop_unlock(Desktop* desktop) {
|
||||
cli_session_open(cli, &cli_vcp);
|
||||
furi_record_close(RECORD_CLI);
|
||||
}
|
||||
|
||||
DesktopStatus status = {.locked = false};
|
||||
furi_pubsub_publish(desktop->status_pubsub, &status);
|
||||
}
|
||||
|
||||
void desktop_set_stealth_mode_state(Desktop* desktop, bool enabled) {
|
||||
@@ -257,6 +363,13 @@ Desktop* desktop_alloc() {
|
||||
view_port_enabled_set(desktop->lock_icon_viewport, false);
|
||||
gui_add_view_port(desktop->gui, desktop->lock_icon_viewport, GuiLayerStatusBarLeft);
|
||||
|
||||
// Clock
|
||||
desktop->clock_viewport = view_port_alloc();
|
||||
view_port_set_width(desktop->clock_viewport, 25);
|
||||
view_port_draw_callback_set(desktop->clock_viewport, desktop_clock_draw_callback, desktop);
|
||||
view_port_enabled_set(desktop->clock_viewport, false);
|
||||
gui_add_view_port(desktop->gui, desktop->clock_viewport, GuiLayerStatusBarRight);
|
||||
|
||||
// Stealth mode icon
|
||||
desktop->stealth_mode_icon_viewport = view_port_alloc();
|
||||
view_port_set_width(desktop->stealth_mode_icon_viewport, icon_get_width(&I_Muted_8x8));
|
||||
@@ -286,63 +399,27 @@ Desktop* desktop_alloc() {
|
||||
desktop->auto_lock_timer =
|
||||
furi_timer_alloc(desktop_auto_lock_timer_callback, FuriTimerTypeOnce, desktop);
|
||||
|
||||
desktop->status_pubsub = furi_pubsub_alloc();
|
||||
|
||||
desktop->update_clock_timer =
|
||||
furi_timer_alloc(desktop_update_clock_timer_callback, FuriTimerTypePeriodic, desktop);
|
||||
|
||||
FuriHalRtcDateTime curr_dt;
|
||||
furi_hal_rtc_get_datetime(&curr_dt);
|
||||
|
||||
if(desktop->clock_type) {
|
||||
desktop->hour = curr_dt.hour;
|
||||
} else {
|
||||
desktop->hour = (curr_dt.hour > 12) ? curr_dt.hour - 12 :
|
||||
((curr_dt.hour == 0) ? 12 : curr_dt.hour);
|
||||
}
|
||||
desktop->minute = curr_dt.minute;
|
||||
|
||||
furi_record_create(RECORD_DESKTOP, desktop);
|
||||
|
||||
return desktop;
|
||||
}
|
||||
|
||||
void desktop_free(Desktop* desktop) {
|
||||
furi_assert(desktop);
|
||||
furi_check(furi_record_destroy(RECORD_DESKTOP));
|
||||
|
||||
furi_pubsub_unsubscribe(
|
||||
loader_get_pubsub(desktop->loader), desktop->app_start_stop_subscription);
|
||||
|
||||
if(desktop->input_events_subscription) {
|
||||
furi_pubsub_unsubscribe(desktop->input_events_pubsub, desktop->input_events_subscription);
|
||||
desktop->input_events_subscription = NULL;
|
||||
}
|
||||
|
||||
desktop->loader = NULL;
|
||||
desktop->input_events_pubsub = NULL;
|
||||
furi_record_close(RECORD_LOADER);
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
furi_record_close(RECORD_INPUT_EVENTS);
|
||||
|
||||
view_dispatcher_remove_view(desktop->view_dispatcher, DesktopViewIdMain);
|
||||
view_dispatcher_remove_view(desktop->view_dispatcher, DesktopViewIdLockMenu);
|
||||
view_dispatcher_remove_view(desktop->view_dispatcher, DesktopViewIdLocked);
|
||||
view_dispatcher_remove_view(desktop->view_dispatcher, DesktopViewIdDebug);
|
||||
view_dispatcher_remove_view(desktop->view_dispatcher, DesktopViewIdHwMismatch);
|
||||
view_dispatcher_remove_view(desktop->view_dispatcher, DesktopViewIdPinInput);
|
||||
view_dispatcher_remove_view(desktop->view_dispatcher, DesktopViewIdPinTimeout);
|
||||
|
||||
view_dispatcher_free(desktop->view_dispatcher);
|
||||
scene_manager_free(desktop->scene_manager);
|
||||
|
||||
animation_manager_free(desktop->animation_manager);
|
||||
view_stack_free(desktop->main_view_stack);
|
||||
desktop_main_free(desktop->main_view);
|
||||
view_stack_free(desktop->locked_view_stack);
|
||||
desktop_view_locked_free(desktop->locked_view);
|
||||
desktop_lock_menu_free(desktop->lock_menu);
|
||||
desktop_view_locked_free(desktop->locked_view);
|
||||
desktop_debug_free(desktop->debug_view);
|
||||
popup_free(desktop->hw_mismatch_popup);
|
||||
desktop_view_pin_timeout_free(desktop->pin_timeout_view);
|
||||
|
||||
furi_record_close(RECORD_GUI);
|
||||
desktop->gui = NULL;
|
||||
|
||||
furi_thread_free(desktop->scene_thread);
|
||||
|
||||
furi_record_close("menu");
|
||||
|
||||
furi_timer_free(desktop->auto_lock_timer);
|
||||
|
||||
free(desktop);
|
||||
}
|
||||
|
||||
static bool desktop_check_file_flag(const char* flag_path) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
bool exists = storage_common_stat(storage, flag_path, NULL) == FSE_OK;
|
||||
@@ -361,6 +438,11 @@ void desktop_api_unlock(Desktop* instance) {
|
||||
view_dispatcher_send_custom_event(instance->view_dispatcher, DesktopLockedEventUnlocked);
|
||||
}
|
||||
|
||||
FuriPubSub* desktop_api_get_status_pubsub(Desktop* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->status_pubsub;
|
||||
}
|
||||
|
||||
int32_t desktop_srv(void* p) {
|
||||
UNUSED(p);
|
||||
|
||||
@@ -377,6 +459,8 @@ int32_t desktop_srv(void* p) {
|
||||
DESKTOP_SETTINGS_SAVE(&desktop->settings);
|
||||
}
|
||||
|
||||
desktop_toggle_clock_view(desktop, desktop->settings.display_clock);
|
||||
|
||||
scene_manager_next_scene(desktop->scene_manager, DesktopSceneMain);
|
||||
|
||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagLock)) {
|
||||
@@ -400,7 +484,8 @@ int32_t desktop_srv(void* p) {
|
||||
}
|
||||
|
||||
view_dispatcher_run(desktop->view_dispatcher);
|
||||
desktop_free(desktop);
|
||||
|
||||
furi_crash("That was unexpected");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
typedef struct Desktop Desktop;
|
||||
|
||||
#define RECORD_DESKTOP "desktop"
|
||||
@@ -7,3 +9,9 @@ typedef struct Desktop Desktop;
|
||||
bool desktop_api_is_locked(Desktop* instance);
|
||||
|
||||
void desktop_api_unlock(Desktop* instance);
|
||||
|
||||
typedef struct {
|
||||
bool locked;
|
||||
} DesktopStatus;
|
||||
|
||||
FuriPubSub* desktop_api_get_status_pubsub(Desktop* instance);
|
||||
|
||||
@@ -58,6 +58,7 @@ struct Desktop {
|
||||
DesktopViewPinInput* pin_input_view;
|
||||
|
||||
ViewPort* lock_icon_viewport;
|
||||
ViewPort* clock_viewport;
|
||||
ViewPort* stealth_mode_icon_viewport;
|
||||
|
||||
AnimationManager* animation_manager;
|
||||
@@ -69,8 +70,14 @@ struct Desktop {
|
||||
FuriPubSub* input_events_pubsub;
|
||||
FuriPubSubSubscription* input_events_subscription;
|
||||
FuriTimer* auto_lock_timer;
|
||||
FuriTimer* update_clock_timer;
|
||||
|
||||
bool in_transition;
|
||||
FuriPubSub* status_pubsub;
|
||||
uint8_t hour;
|
||||
uint8_t minute;
|
||||
bool clock_type : 1; // true - 24h false - 12h
|
||||
|
||||
bool in_transition : 1;
|
||||
};
|
||||
|
||||
Desktop* desktop_alloc();
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <storage/storage.h>
|
||||
#include <loader/loader.h>
|
||||
|
||||
#define DESKTOP_SETTINGS_VER (8)
|
||||
#define DESKTOP_SETTINGS_VER (9)
|
||||
|
||||
#define DESKTOP_SETTINGS_OLD_PATH CFG_PATH("desktop.settings")
|
||||
#define DESKTOP_SETTINGS_PATH INT_PATH(".desktop.settings")
|
||||
@@ -36,6 +36,7 @@ typedef struct {
|
||||
PinCode pin_code;
|
||||
uint32_t auto_lock_delay_ms;
|
||||
bool auto_lock_with_pin;
|
||||
uint8_t display_clock;
|
||||
} DesktopSettings;
|
||||
|
||||
bool DESKTOP_SETTINGS_SAVE(DesktopSettings* x);
|
||||
|
||||
@@ -60,6 +60,21 @@ static void desktop_switch_to_app(Desktop* desktop, const FlipperApplication* fl
|
||||
}
|
||||
#endif
|
||||
|
||||
static void desktop_scene_main_start_favorite(Desktop* desktop, FavoriteApp* application) {
|
||||
LoaderStatus status = LoaderStatusErrorInternal;
|
||||
if(application->is_external) {
|
||||
status = loader_start(desktop->loader, FAP_LOADER_APP_NAME, application->name_or_path);
|
||||
} else if(strlen(application->name_or_path) > 0) {
|
||||
status = loader_start(desktop->loader, application->name_or_path, NULL);
|
||||
} else {
|
||||
status = loader_start(desktop->loader, FAP_LOADER_APP_NAME, NULL);
|
||||
}
|
||||
|
||||
if(status != LoaderStatusOk) {
|
||||
FURI_LOG_E(TAG, "loader_start failed: %d", status);
|
||||
}
|
||||
}
|
||||
|
||||
void desktop_scene_main_callback(DesktopEvent event, void* context) {
|
||||
Desktop* desktop = (Desktop*)context;
|
||||
if(desktop->in_transition) return;
|
||||
@@ -128,40 +143,12 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) {
|
||||
}
|
||||
case DesktopMainEventOpenFavoritePrimary:
|
||||
DESKTOP_SETTINGS_LOAD(&desktop->settings);
|
||||
if(desktop->settings.favorite_primary.is_external) {
|
||||
LoaderStatus status = loader_start(
|
||||
desktop->loader,
|
||||
FAP_LOADER_APP_NAME,
|
||||
desktop->settings.favorite_primary.name_or_path);
|
||||
if(status != LoaderStatusOk) {
|
||||
FURI_LOG_E(TAG, "loader_start failed: %d", status);
|
||||
}
|
||||
} else {
|
||||
LoaderStatus status = loader_start(
|
||||
desktop->loader, desktop->settings.favorite_primary.name_or_path, NULL);
|
||||
if(status != LoaderStatusOk) {
|
||||
FURI_LOG_E(TAG, "loader_start failed: %d", status);
|
||||
}
|
||||
}
|
||||
desktop_scene_main_start_favorite(desktop, &desktop->settings.favorite_primary);
|
||||
consumed = true;
|
||||
break;
|
||||
case DesktopMainEventOpenFavoriteSecondary:
|
||||
DESKTOP_SETTINGS_LOAD(&desktop->settings);
|
||||
if(desktop->settings.favorite_secondary.is_external) {
|
||||
LoaderStatus status = loader_start(
|
||||
desktop->loader,
|
||||
FAP_LOADER_APP_NAME,
|
||||
desktop->settings.favorite_secondary.name_or_path);
|
||||
if(status != LoaderStatusOk) {
|
||||
FURI_LOG_E(TAG, "loader_start failed: %d", status);
|
||||
}
|
||||
} else {
|
||||
LoaderStatus status = loader_start(
|
||||
desktop->loader, desktop->settings.favorite_secondary.name_or_path, NULL);
|
||||
if(status != LoaderStatusOk) {
|
||||
FURI_LOG_E(TAG, "loader_start failed: %d", status);
|
||||
}
|
||||
}
|
||||
desktop_scene_main_start_favorite(desktop, &desktop->settings.favorite_secondary);
|
||||
consumed = true;
|
||||
break;
|
||||
case DesktopAnimationEventCheckAnimation:
|
||||
|
||||
@@ -95,15 +95,6 @@ Dolphin* dolphin_alloc() {
|
||||
return dolphin;
|
||||
}
|
||||
|
||||
void dolphin_free(Dolphin* dolphin) {
|
||||
furi_assert(dolphin);
|
||||
|
||||
dolphin_state_free(dolphin->state);
|
||||
furi_message_queue_free(dolphin->event_queue);
|
||||
|
||||
free(dolphin);
|
||||
}
|
||||
|
||||
void dolphin_event_send_async(Dolphin* dolphin, DolphinEvent* event) {
|
||||
furi_assert(dolphin);
|
||||
furi_assert(event);
|
||||
@@ -210,7 +201,7 @@ int32_t dolphin_srv(void* p) {
|
||||
}
|
||||
}
|
||||
|
||||
dolphin_free(dolphin);
|
||||
furi_crash("That was unexpected");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -37,8 +37,6 @@ struct Dolphin {
|
||||
|
||||
Dolphin* dolphin_alloc();
|
||||
|
||||
void dolphin_free(Dolphin* dolphin);
|
||||
|
||||
void dolphin_event_send_async(Dolphin* dolphin, DolphinEvent* event);
|
||||
|
||||
void dolphin_event_send_wait(Dolphin* dolphin, DolphinEvent* event);
|
||||
|
||||
@@ -20,6 +20,23 @@ ViewPort* gui_view_port_find_enabled(ViewPortArray_t array) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint8_t gui_get_count_of_enabled_view_port_in_layer(Gui* gui, GuiLayer layer) {
|
||||
furi_assert(gui);
|
||||
furi_check(layer < GuiLayerMAX);
|
||||
uint8_t ret = 0;
|
||||
|
||||
ViewPortArray_it_t it;
|
||||
ViewPortArray_it_last(it, gui->layers[layer]);
|
||||
while(!ViewPortArray_end_p(it)) {
|
||||
ViewPort* view_port = *ViewPortArray_ref(it);
|
||||
if(view_port_is_enabled(view_port)) {
|
||||
ret++;
|
||||
}
|
||||
ViewPortArray_previous(it);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void gui_update(Gui* gui) {
|
||||
furi_assert(gui);
|
||||
if(!gui->direct_draw) furi_thread_flags_set(gui->thread_id, GUI_THREAD_FLAG_DRAW);
|
||||
|
||||
@@ -141,6 +141,8 @@ Canvas* gui_direct_draw_acquire(Gui* gui);
|
||||
*/
|
||||
void gui_direct_draw_release(Gui* gui);
|
||||
|
||||
uint8_t gui_get_count_of_enabled_view_port_in_layer(Gui* gui, GuiLayer layer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -365,46 +365,6 @@ Power* power_alloc() {
|
||||
return power;
|
||||
}
|
||||
|
||||
void power_free(Power* power) {
|
||||
furi_assert(power);
|
||||
|
||||
// Gui
|
||||
view_dispatcher_remove_view(power->view_dispatcher, PowerViewOff);
|
||||
power_off_free(power->power_off);
|
||||
view_dispatcher_remove_view(power->view_dispatcher, PowerViewUnplugUsb);
|
||||
power_unplug_usb_free(power->power_unplug_usb);
|
||||
|
||||
view_port_free(power->battery_view_port);
|
||||
|
||||
// State
|
||||
furi_mutex_free(power->api_mtx);
|
||||
|
||||
// FuriPubSub
|
||||
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);
|
||||
}
|
||||
|
||||
static void power_check_charging_state(Power* power) {
|
||||
if(furi_hal_power_is_charging()) {
|
||||
if((power->info.charge == 100) || (furi_hal_power_is_charging_done())) {
|
||||
@@ -558,8 +518,8 @@ int32_t power_srv(void* p) {
|
||||
|
||||
furi_delay_ms(1000);
|
||||
}
|
||||
power_auto_shutdown_inhibit(power);
|
||||
power_free(power);
|
||||
|
||||
furi_crash("That was unexpected");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
typedef struct {
|
||||
RpcSession* session;
|
||||
Desktop* desktop;
|
||||
FuriPubSub* status_pubsub;
|
||||
FuriPubSubSubscription* status_subscription;
|
||||
} RpcDesktop;
|
||||
|
||||
static void rpc_desktop_on_is_locked_request(const PB_Main* request, void* context) {
|
||||
@@ -39,11 +41,63 @@ static void rpc_desktop_on_unlock_request(const PB_Main* request, void* context)
|
||||
rpc_send_and_release_empty(session, request->command_id, PB_CommandStatus_OK);
|
||||
}
|
||||
|
||||
static void rpc_desktop_on_desktop_pubsub(const void* message, void* context) {
|
||||
RpcDesktop* rpc_desktop = context;
|
||||
RpcSession* session = rpc_desktop->session;
|
||||
const DesktopStatus* status = message;
|
||||
|
||||
PB_Main rpc_message = {
|
||||
.command_id = 0,
|
||||
.command_status = PB_CommandStatus_OK,
|
||||
.has_next = false,
|
||||
.which_content = PB_Main_desktop_status_tag,
|
||||
.content.desktop_status.locked = status->locked,
|
||||
};
|
||||
rpc_send_and_release(session, &rpc_message);
|
||||
}
|
||||
|
||||
static void rpc_desktop_on_status_subscribe_request(const PB_Main* request, void* context) {
|
||||
furi_assert(request);
|
||||
furi_assert(context);
|
||||
furi_assert(request->which_content == PB_Main_desktop_status_subscribe_request_tag);
|
||||
|
||||
FURI_LOG_D(TAG, "StatusSubscribeRequest");
|
||||
RpcDesktop* rpc_desktop = context;
|
||||
RpcSession* session = rpc_desktop->session;
|
||||
|
||||
if(rpc_desktop->status_subscription) {
|
||||
rpc_send_and_release_empty(session, request->command_id, PB_CommandStatus_ERROR);
|
||||
} else {
|
||||
rpc_desktop->status_subscription = furi_pubsub_subscribe(
|
||||
rpc_desktop->status_pubsub, rpc_desktop_on_desktop_pubsub, rpc_desktop);
|
||||
rpc_send_and_release_empty(session, request->command_id, PB_CommandStatus_OK);
|
||||
}
|
||||
}
|
||||
|
||||
static void rpc_desktop_on_status_unsubscribe_request(const PB_Main* request, void* context) {
|
||||
furi_assert(request);
|
||||
furi_assert(context);
|
||||
furi_assert(request->which_content == PB_Main_desktop_status_unsubscribe_request_tag);
|
||||
|
||||
FURI_LOG_D(TAG, "StatusUnsubscribeRequest");
|
||||
RpcDesktop* rpc_desktop = context;
|
||||
RpcSession* session = rpc_desktop->session;
|
||||
|
||||
if(rpc_desktop->status_subscription) {
|
||||
furi_pubsub_unsubscribe(rpc_desktop->status_pubsub, rpc_desktop->status_subscription);
|
||||
rpc_desktop->status_subscription = NULL;
|
||||
rpc_send_and_release_empty(session, request->command_id, PB_CommandStatus_OK);
|
||||
} else {
|
||||
rpc_send_and_release_empty(session, request->command_id, PB_CommandStatus_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
void* rpc_desktop_alloc(RpcSession* session) {
|
||||
furi_assert(session);
|
||||
|
||||
RpcDesktop* rpc_desktop = malloc(sizeof(RpcDesktop));
|
||||
rpc_desktop->desktop = furi_record_open(RECORD_DESKTOP);
|
||||
rpc_desktop->status_pubsub = desktop_api_get_status_pubsub(rpc_desktop->desktop);
|
||||
rpc_desktop->session = session;
|
||||
|
||||
RpcHandler rpc_handler = {
|
||||
@@ -58,6 +112,12 @@ void* rpc_desktop_alloc(RpcSession* session) {
|
||||
rpc_handler.message_handler = rpc_desktop_on_unlock_request;
|
||||
rpc_add_handler(session, PB_Main_desktop_unlock_request_tag, &rpc_handler);
|
||||
|
||||
rpc_handler.message_handler = rpc_desktop_on_status_subscribe_request;
|
||||
rpc_add_handler(session, PB_Main_desktop_status_subscribe_request_tag, &rpc_handler);
|
||||
|
||||
rpc_handler.message_handler = rpc_desktop_on_status_unsubscribe_request;
|
||||
rpc_add_handler(session, PB_Main_desktop_status_unsubscribe_request_tag, &rpc_handler);
|
||||
|
||||
return rpc_desktop;
|
||||
}
|
||||
|
||||
@@ -65,6 +125,10 @@ void rpc_desktop_free(void* context) {
|
||||
furi_assert(context);
|
||||
RpcDesktop* rpc_desktop = context;
|
||||
|
||||
if(rpc_desktop->status_subscription) {
|
||||
furi_pubsub_unsubscribe(rpc_desktop->status_pubsub, rpc_desktop->status_subscription);
|
||||
}
|
||||
|
||||
furi_assert(rpc_desktop->desktop);
|
||||
furi_record_close(RECORD_DESKTOP);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user