2021-11-24 16:21:12 +00:00
|
|
|
#include "assets_icons.h"
|
|
|
|
#include "cmsis_os2.h"
|
|
|
|
#include "desktop/desktop.h"
|
2021-09-28 09:40:39 +00:00
|
|
|
#include "desktop_i.h"
|
2022-01-02 21:39:56 +00:00
|
|
|
#include "gui/view_composed.h"
|
2021-11-24 16:21:12 +00:00
|
|
|
#include <dolphin/dolphin.h>
|
|
|
|
#include <furi/pubsub.h>
|
|
|
|
#include <furi/record.h>
|
|
|
|
#include "portmacro.h"
|
2022-01-05 16:10:18 +00:00
|
|
|
#include "storage/filesystem_api_defines.h"
|
2021-11-24 16:21:12 +00:00
|
|
|
#include "storage/storage.h"
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <power/power_service/power.h>
|
2022-01-02 21:39:56 +00:00
|
|
|
#include "animations/animation_manager.h"
|
2021-09-28 09:40:39 +00:00
|
|
|
|
|
|
|
static void desktop_lock_icon_callback(Canvas* canvas, void* context) {
|
|
|
|
furi_assert(canvas);
|
|
|
|
canvas_draw_icon(canvas, 0, 0, &I_Lock_8x8);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool desktop_custom_event_callback(void* context, uint32_t event) {
|
|
|
|
furi_assert(context);
|
|
|
|
Desktop* desktop = (Desktop*)context;
|
|
|
|
return scene_manager_handle_custom_event(desktop->scene_manager, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool desktop_back_event_callback(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
Desktop* desktop = (Desktop*)context;
|
|
|
|
return scene_manager_handle_back_event(desktop->scene_manager);
|
|
|
|
}
|
|
|
|
|
|
|
|
Desktop* desktop_alloc() {
|
|
|
|
Desktop* desktop = furi_alloc(sizeof(Desktop));
|
|
|
|
|
2022-01-02 21:39:56 +00:00
|
|
|
desktop->unload_animation_semaphore = osSemaphoreNew(1, 0, NULL);
|
|
|
|
desktop->animation_manager = animation_manager_alloc();
|
2021-09-28 09:40:39 +00:00
|
|
|
desktop->gui = furi_record_open("gui");
|
|
|
|
desktop->scene_thread = furi_thread_alloc();
|
|
|
|
desktop->view_dispatcher = view_dispatcher_alloc();
|
|
|
|
desktop->scene_manager = scene_manager_alloc(&desktop_scene_handlers, desktop);
|
|
|
|
|
|
|
|
view_dispatcher_enable_queue(desktop->view_dispatcher);
|
|
|
|
view_dispatcher_attach_to_gui(
|
2021-11-24 16:21:12 +00:00
|
|
|
desktop->view_dispatcher, desktop->gui, ViewDispatcherTypeDesktop);
|
2021-09-28 09:40:39 +00:00
|
|
|
|
|
|
|
view_dispatcher_set_event_callback_context(desktop->view_dispatcher, desktop);
|
|
|
|
view_dispatcher_set_custom_event_callback(
|
|
|
|
desktop->view_dispatcher, desktop_custom_event_callback);
|
|
|
|
view_dispatcher_set_navigation_event_callback(
|
|
|
|
desktop->view_dispatcher, desktop_back_event_callback);
|
|
|
|
|
2022-01-02 21:39:56 +00:00
|
|
|
desktop->dolphin_view = animation_manager_get_animation_view(desktop->animation_manager);
|
|
|
|
|
|
|
|
desktop->main_view_composed = view_composed_alloc();
|
2021-09-28 09:40:39 +00:00
|
|
|
desktop->main_view = desktop_main_alloc();
|
2022-01-02 21:39:56 +00:00
|
|
|
view_composed_tie_views(
|
|
|
|
desktop->main_view_composed,
|
|
|
|
desktop->dolphin_view,
|
|
|
|
desktop_main_get_view(desktop->main_view));
|
|
|
|
view_composed_top_enable(desktop->main_view_composed, true);
|
|
|
|
|
|
|
|
desktop->locked_view_composed = view_composed_alloc();
|
2021-09-28 09:40:39 +00:00
|
|
|
desktop->locked_view = desktop_locked_alloc();
|
2022-01-02 21:39:56 +00:00
|
|
|
view_composed_tie_views(
|
|
|
|
desktop->locked_view_composed,
|
|
|
|
desktop->dolphin_view,
|
|
|
|
desktop_locked_get_view(desktop->locked_view));
|
|
|
|
view_composed_top_enable(desktop->locked_view_composed, true);
|
|
|
|
|
|
|
|
desktop->lock_menu = desktop_lock_menu_alloc();
|
2021-09-28 09:40:39 +00:00
|
|
|
desktop->debug_view = desktop_debug_alloc();
|
|
|
|
desktop->first_start_view = desktop_first_start_alloc();
|
2021-10-04 09:33:31 +00:00
|
|
|
desktop->hw_mismatch_popup = popup_alloc();
|
2021-10-26 18:34:31 +00:00
|
|
|
desktop->code_input = code_input_alloc();
|
2021-09-28 09:40:39 +00:00
|
|
|
|
|
|
|
view_dispatcher_add_view(
|
2022-01-02 21:39:56 +00:00
|
|
|
desktop->view_dispatcher,
|
|
|
|
DesktopViewMain,
|
|
|
|
view_composed_get_view(desktop->main_view_composed));
|
2021-09-28 09:40:39 +00:00
|
|
|
view_dispatcher_add_view(
|
|
|
|
desktop->view_dispatcher,
|
|
|
|
DesktopViewLockMenu,
|
|
|
|
desktop_lock_menu_get_view(desktop->lock_menu));
|
|
|
|
view_dispatcher_add_view(
|
|
|
|
desktop->view_dispatcher, DesktopViewDebug, desktop_debug_get_view(desktop->debug_view));
|
|
|
|
view_dispatcher_add_view(
|
|
|
|
desktop->view_dispatcher,
|
|
|
|
DesktopViewLocked,
|
2022-01-02 21:39:56 +00:00
|
|
|
view_composed_get_view(desktop->locked_view_composed));
|
2021-09-28 09:40:39 +00:00
|
|
|
view_dispatcher_add_view(
|
|
|
|
desktop->view_dispatcher,
|
|
|
|
DesktopViewFirstStart,
|
|
|
|
desktop_first_start_get_view(desktop->first_start_view));
|
|
|
|
view_dispatcher_add_view(
|
|
|
|
desktop->view_dispatcher,
|
|
|
|
DesktopViewHwMismatch,
|
2021-10-04 09:33:31 +00:00
|
|
|
popup_get_view(desktop->hw_mismatch_popup));
|
2021-10-26 18:34:31 +00:00
|
|
|
view_dispatcher_add_view(
|
|
|
|
desktop->view_dispatcher, DesktopViewPinSetup, code_input_get_view(desktop->code_input));
|
2021-09-28 09:40:39 +00:00
|
|
|
// Lock icon
|
|
|
|
desktop->lock_viewport = view_port_alloc();
|
|
|
|
view_port_set_width(desktop->lock_viewport, icon_get_width(&I_Lock_8x8));
|
|
|
|
view_port_draw_callback_set(desktop->lock_viewport, desktop_lock_icon_callback, desktop);
|
|
|
|
view_port_enabled_set(desktop->lock_viewport, false);
|
|
|
|
gui_add_view_port(desktop->gui, desktop->lock_viewport, GuiLayerStatusBarLeft);
|
|
|
|
|
|
|
|
return desktop;
|
|
|
|
}
|
|
|
|
|
|
|
|
void desktop_free(Desktop* desktop) {
|
|
|
|
furi_assert(desktop);
|
|
|
|
|
|
|
|
view_dispatcher_remove_view(desktop->view_dispatcher, DesktopViewMain);
|
|
|
|
view_dispatcher_remove_view(desktop->view_dispatcher, DesktopViewLockMenu);
|
|
|
|
view_dispatcher_remove_view(desktop->view_dispatcher, DesktopViewLocked);
|
|
|
|
view_dispatcher_remove_view(desktop->view_dispatcher, DesktopViewDebug);
|
|
|
|
view_dispatcher_remove_view(desktop->view_dispatcher, DesktopViewFirstStart);
|
|
|
|
view_dispatcher_remove_view(desktop->view_dispatcher, DesktopViewHwMismatch);
|
2021-10-26 18:34:31 +00:00
|
|
|
view_dispatcher_remove_view(desktop->view_dispatcher, DesktopViewPinSetup);
|
2021-09-28 09:40:39 +00:00
|
|
|
|
|
|
|
view_dispatcher_free(desktop->view_dispatcher);
|
|
|
|
scene_manager_free(desktop->scene_manager);
|
|
|
|
|
2022-01-02 21:39:56 +00:00
|
|
|
animation_manager_free(desktop->animation_manager);
|
|
|
|
view_composed_free(desktop->main_view_composed);
|
|
|
|
view_composed_free(desktop->locked_view_composed);
|
2021-09-28 09:40:39 +00:00
|
|
|
desktop_main_free(desktop->main_view);
|
|
|
|
desktop_lock_menu_free(desktop->lock_menu);
|
|
|
|
desktop_locked_free(desktop->locked_view);
|
|
|
|
desktop_debug_free(desktop->debug_view);
|
|
|
|
desktop_first_start_free(desktop->first_start_view);
|
2021-10-04 09:33:31 +00:00
|
|
|
popup_free(desktop->hw_mismatch_popup);
|
2021-10-26 18:34:31 +00:00
|
|
|
code_input_free(desktop->code_input);
|
2021-09-28 09:40:39 +00:00
|
|
|
|
2022-01-02 21:39:56 +00:00
|
|
|
osSemaphoreDelete(desktop->unload_animation_semaphore);
|
|
|
|
|
2021-09-28 09:40:39 +00:00
|
|
|
furi_record_close("gui");
|
|
|
|
desktop->gui = NULL;
|
|
|
|
|
|
|
|
furi_thread_free(desktop->scene_thread);
|
|
|
|
|
|
|
|
furi_record_close("menu");
|
|
|
|
|
|
|
|
free(desktop);
|
|
|
|
}
|
|
|
|
|
2021-09-28 14:42:52 +00:00
|
|
|
static bool desktop_is_first_start() {
|
|
|
|
Storage* storage = furi_record_open("storage");
|
|
|
|
bool exists = storage_common_stat(storage, "/int/first_start", NULL) == FSE_OK;
|
|
|
|
furi_record_close("storage");
|
|
|
|
|
|
|
|
return exists;
|
|
|
|
}
|
|
|
|
|
2021-09-28 09:40:39 +00:00
|
|
|
int32_t desktop_srv(void* p) {
|
|
|
|
Desktop* desktop = desktop_alloc();
|
2021-11-24 16:21:12 +00:00
|
|
|
|
2021-11-03 17:22:49 +00:00
|
|
|
bool loaded = LOAD_DESKTOP_SETTINGS(&desktop->settings);
|
|
|
|
if(!loaded) {
|
2021-12-24 14:33:58 +00:00
|
|
|
furi_hal_rtc_reset_flag(FuriHalRtcFlagLock);
|
2021-11-03 17:22:49 +00:00
|
|
|
memset(&desktop->settings, 0, sizeof(desktop->settings));
|
2021-11-04 17:26:41 +00:00
|
|
|
SAVE_DESKTOP_SETTINGS(&desktop->settings);
|
2021-11-03 17:22:49 +00:00
|
|
|
}
|
2021-09-28 09:40:39 +00:00
|
|
|
|
2021-09-28 14:42:52 +00:00
|
|
|
scene_manager_next_scene(desktop->scene_manager, DesktopSceneMain);
|
|
|
|
|
2021-12-24 14:33:58 +00:00
|
|
|
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagLock)) {
|
2021-11-03 17:22:49 +00:00
|
|
|
furi_hal_usb_disable();
|
|
|
|
scene_manager_set_scene_state(
|
|
|
|
desktop->scene_manager, DesktopSceneLocked, DesktopLockedWithPin);
|
|
|
|
scene_manager_next_scene(desktop->scene_manager, DesktopSceneLocked);
|
|
|
|
}
|
|
|
|
|
2021-09-28 14:42:52 +00:00
|
|
|
if(desktop_is_first_start()) {
|
2021-09-28 09:40:39 +00:00
|
|
|
scene_manager_next_scene(desktop->scene_manager, DesktopSceneFirstStart);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!furi_hal_version_do_i_belong_here()) {
|
|
|
|
scene_manager_next_scene(desktop->scene_manager, DesktopSceneHwMismatch);
|
|
|
|
}
|
|
|
|
|
2021-12-31 17:32:49 +00:00
|
|
|
if(furi_hal_rtc_get_fault_data()) {
|
|
|
|
scene_manager_next_scene(desktop->scene_manager, DesktopSceneFault);
|
|
|
|
}
|
|
|
|
|
2021-09-28 09:40:39 +00:00
|
|
|
view_dispatcher_run(desktop->view_dispatcher);
|
|
|
|
desktop_free(desktop);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|