Skip to content

Commit

Permalink
[FL-2556] Update complete screen (flipperdevices#1332)
Browse files Browse the repository at this point in the history
* Desktop: slideshow implementation
* Updater: handling splashscreen installation; added format version field to slideshow binary
* Desktop: added bidirectional slideshow navigation + instant cancel by "back" button; Updater: rebalanced update stages weights
* Updater: fixed missing field init; fixed potential loop when baking slideshows
* Assets: fixed "update complete" image to match original
* Desktop: added check for slideshow file version
* Scripts: slideshow.py cleanup
* Desktop: removed first start intro sequence
* Desktop: removed first start remnants
  • Loading branch information
hedger authored Jun 21, 2022
1 parent 4b02a40 commit eb31fed
Show file tree
Hide file tree
Showing 23 changed files with 437 additions and 266 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ PROJECT_ROOT := $(abspath $(dir $(abspath $(firstword $(MAKEFILE_LIST)))))

include $(PROJECT_ROOT)/make/git.mk
include $(PROJECT_ROOT)/assets/copro.mk
include $(PROJECT_ROOT)/assets/splash.mk

PROJECT_SOURCE_DIRECTORIES := \
$(PROJECT_ROOT)/applications \
Expand Down Expand Up @@ -103,7 +104,8 @@ updater_package: firmware_all updater assets_manifest
--radio $(COPRO_STACK_BIN_PATH) \
--radiotype $(COPRO_STACK_TYPE) \
$(COPRO_DISCLAIMER) \
--obdata $(PROJECT_ROOT)/scripts/$(COPRO_OB_DATA)
--obdata $(PROJECT_ROOT)/scripts/$(COPRO_OB_DATA) \
--splash $(UPDATER_SPLASH_DIR)

.PHONY: assets_manifest
assets_manifest:
Expand Down
20 changes: 9 additions & 11 deletions applications/desktop/desktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ Desktop* desktop_alloc() {

desktop->lock_menu = desktop_lock_menu_alloc();
desktop->debug_view = desktop_debug_alloc();
desktop->first_start_view = desktop_first_start_alloc();
desktop->hw_mismatch_popup = popup_alloc();
desktop->locked_view = desktop_view_locked_alloc();
desktop->pin_input_view = desktop_view_pin_input_alloc();
desktop->pin_timeout_view = desktop_view_pin_timeout_alloc();
desktop->slideshow_view = desktop_view_slideshow_alloc();

desktop->main_view_stack = view_stack_alloc();
desktop->main_view = desktop_main_alloc();
Expand Down Expand Up @@ -193,10 +193,6 @@ Desktop* desktop_alloc() {
desktop_lock_menu_get_view(desktop->lock_menu));
view_dispatcher_add_view(
desktop->view_dispatcher, DesktopViewIdDebug, desktop_debug_get_view(desktop->debug_view));
view_dispatcher_add_view(
desktop->view_dispatcher,
DesktopViewIdFirstStart,
desktop_first_start_get_view(desktop->first_start_view));
view_dispatcher_add_view(
desktop->view_dispatcher,
DesktopViewIdHwMismatch,
Expand All @@ -209,6 +205,10 @@ Desktop* desktop_alloc() {
desktop->view_dispatcher,
DesktopViewIdPinInput,
desktop_view_pin_input_get_view(desktop->pin_input_view));
view_dispatcher_add_view(
desktop->view_dispatcher,
DesktopViewIdSlideshow,
desktop_view_slideshow_get_view(desktop->slideshow_view));

// Lock icon
desktop->lock_viewport = view_port_alloc();
Expand Down Expand Up @@ -258,7 +258,6 @@ void desktop_free(Desktop* desktop) {
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, DesktopViewIdFirstStart);
view_dispatcher_remove_view(desktop->view_dispatcher, DesktopViewIdHwMismatch);
view_dispatcher_remove_view(desktop->view_dispatcher, DesktopViewIdPinInput);
view_dispatcher_remove_view(desktop->view_dispatcher, DesktopViewIdPinTimeout);
Expand All @@ -274,7 +273,6 @@ void desktop_free(Desktop* desktop) {
desktop_lock_menu_free(desktop->lock_menu);
desktop_view_locked_free(desktop->locked_view);
desktop_debug_free(desktop->debug_view);
desktop_first_start_free(desktop->first_start_view);
popup_free(desktop->hw_mismatch_popup);
desktop_view_pin_timeout_free(desktop->pin_timeout_view);

Expand All @@ -290,9 +288,9 @@ void desktop_free(Desktop* desktop) {
free(desktop);
}

static bool desktop_is_first_start() {
static bool desktop_check_file_flag(const char* flag_path) {
Storage* storage = furi_record_open("storage");
bool exists = storage_common_stat(storage, "/int/first_start", NULL) == FSE_OK;
bool exists = storage_common_stat(storage, flag_path, NULL) == FSE_OK;
furi_record_close("storage");

return exists;
Expand Down Expand Up @@ -320,8 +318,8 @@ int32_t desktop_srv(void* p) {
desktop_lock(desktop);
}

if(desktop_is_first_start()) {
scene_manager_next_scene(desktop->scene_manager, DesktopSceneFirstStart);
if(desktop_check_file_flag("/int/slideshow")) {
scene_manager_next_scene(desktop->scene_manager, DesktopSceneSlideshow);
}

if(!furi_hal_version_do_i_belong_here()) {
Expand Down
6 changes: 3 additions & 3 deletions applications/desktop/desktop_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include "views/desktop_view_pin_input.h"
#include "views/desktop_view_locked.h"
#include "views/desktop_view_main.h"
#include "views/desktop_view_first_start.h"
#include "views/desktop_view_lock_menu.h"
#include "views/desktop_view_debug.h"
#include "views/desktop_view_slideshow.h"
#include "desktop/desktop_settings/desktop_settings.h"

#include <furi.h>
Expand All @@ -28,10 +28,10 @@ typedef enum {
DesktopViewIdLockMenu,
DesktopViewIdLocked,
DesktopViewIdDebug,
DesktopViewIdFirstStart,
DesktopViewIdHwMismatch,
DesktopViewIdPinInput,
DesktopViewIdPinTimeout,
DesktopViewIdSlideshow,
DesktopViewIdTotal,
} DesktopViewId;

Expand All @@ -43,13 +43,13 @@ struct Desktop {
ViewDispatcher* view_dispatcher;
SceneManager* scene_manager;

DesktopFirstStartView* first_start_view;
Popup* hw_mismatch_popup;
DesktopLockMenuView* lock_menu;
DesktopDebugView* debug_view;
DesktopViewLocked* locked_view;
DesktopMainView* main_view;
DesktopViewPinTimeout* pin_timeout_view;
DesktopSlideshowView* slideshow_view;

ViewStack* main_view_stack;
ViewStack* locked_view_stack;
Expand Down
115 changes: 115 additions & 0 deletions applications/desktop/helpers/slideshow.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#include "slideshow.h"

#include <stddef.h>
#include <storage/storage.h>
#include <gui/icon.h>
#include <gui/icon_i.h>
#include <furi/dangerous_defines.h>

#define SLIDESHOW_MAGIC 0x72676468
#define SLIDESHOW_MAX_SUPPORTED_VERSION 1

struct Slideshow {
Icon icon;
uint32_t current_frame;
};

#pragma pack(push, 1)

typedef struct {
uint32_t magic;
uint8_t version;
uint8_t width;
uint8_t height;
uint8_t frame_count;
} SlideshowFileHeader;
_Static_assert(sizeof(SlideshowFileHeader) == 8, "Incorrect SlideshowFileHeader size");

typedef struct {
uint16_t size;
} SlideshowFrameHeader;
_Static_assert(sizeof(SlideshowFrameHeader) == 2, "Incorrect SlideshowFrameHeader size");

#pragma pack(pop)

Slideshow* slideshow_alloc() {
Slideshow* ret = malloc(sizeof(Slideshow));
return ret;
}

void slideshow_free(Slideshow* slideshow) {
Icon* icon = &slideshow->icon;
if(icon) {
for(int frame_idx = 0; frame_idx < icon->frame_count; ++frame_idx) {
uint8_t* frame_data = (uint8_t*)icon->frames[frame_idx];
free(frame_data);
}
free((uint8_t**)icon->frames);
}
free(slideshow);
}

bool slideshow_load(Slideshow* slideshow, const char* fspath) {
Storage* storage = furi_record_open("storage");
File* slideshow_file = storage_file_alloc(storage);
bool load_success = false;
do {
if(!storage_file_open(slideshow_file, fspath, FSAM_READ, FSOM_OPEN_EXISTING)) {
break;
}
SlideshowFileHeader header;
if((storage_file_read(slideshow_file, &header, sizeof(header)) != sizeof(header)) ||
(header.magic != SLIDESHOW_MAGIC) ||
(header.version > SLIDESHOW_MAX_SUPPORTED_VERSION)) {
break;
}
Icon* icon = &slideshow->icon;
FURI_CONST_ASSIGN(icon->frame_count, header.frame_count);
FURI_CONST_ASSIGN(icon->width, header.width);
FURI_CONST_ASSIGN(icon->height, header.height);
icon->frames = malloc(header.frame_count * sizeof(uint8_t*));
for(int frame_idx = 0; frame_idx < header.frame_count; ++frame_idx) {
SlideshowFrameHeader frame_header;
if(storage_file_read(slideshow_file, &frame_header, sizeof(frame_header)) !=
sizeof(frame_header)) {
break;
}
FURI_CONST_ASSIGN_PTR(icon->frames[frame_idx], malloc(frame_header.size));
uint8_t* frame_data = (uint8_t*)icon->frames[frame_idx];
if(storage_file_read(slideshow_file, frame_data, frame_header.size) !=
frame_header.size) {
break;
}
load_success = (frame_idx + 1) == header.frame_count;
}
} while(false);
storage_file_free(slideshow_file);
furi_record_close("storage");
return load_success;
}

bool slideshow_advance(Slideshow* slideshow) {
uint8_t next_frame = slideshow->current_frame + 1;
if(next_frame < slideshow->icon.frame_count) {
slideshow->current_frame = next_frame;
return true;
}
return false;
}

void slideshow_goback(Slideshow* slideshow) {
if(slideshow->current_frame > 0) {
slideshow->current_frame--;
}
}

void slideshow_draw(Slideshow* slideshow, Canvas* canvas, uint8_t x, uint8_t y) {
furi_assert(slideshow->current_frame < slideshow->icon.frame_count);
canvas_draw_bitmap(
canvas,
x,
y,
slideshow->icon.width,
slideshow->icon.height,
slideshow->icon.frames[slideshow->current_frame]);
}
13 changes: 13 additions & 0 deletions applications/desktop/helpers/slideshow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <gui/canvas.h>

typedef struct Slideshow Slideshow;

Slideshow* slideshow_alloc();

void slideshow_free(Slideshow* slideshow);
bool slideshow_load(Slideshow* slideshow, const char* fspath);
void slideshow_goback(Slideshow* slideshow);
bool slideshow_advance(Slideshow* slideshow);
void slideshow_draw(Slideshow* slideshow, Canvas* canvas, uint8_t x, uint8_t y);
2 changes: 1 addition & 1 deletion applications/desktop/scenes/desktop_scene_config.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
ADD_SCENE(desktop, main, Main)
ADD_SCENE(desktop, lock_menu, LockMenu)
ADD_SCENE(desktop, debug, Debug)
ADD_SCENE(desktop, first_start, FirstStart)
ADD_SCENE(desktop, hw_mismatch, HwMismatch)
ADD_SCENE(desktop, fault, Fault)
ADD_SCENE(desktop, locked, Locked)
ADD_SCENE(desktop, pin_input, PinInput)
ADD_SCENE(desktop, pin_timeout, PinTimeout)
ADD_SCENE(desktop, slideshow, Slideshow)
54 changes: 0 additions & 54 deletions applications/desktop/scenes/desktop_scene_first_start.c

This file was deleted.

45 changes: 45 additions & 0 deletions applications/desktop/scenes/desktop_scene_slideshow.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <storage/storage.h>

#include "../desktop_i.h"
#include "../views/desktop_view_slideshow.h"
#include "../views/desktop_events.h"

void desktop_scene_slideshow_callback(DesktopEvent event, void* context) {
Desktop* desktop = (Desktop*)context;
view_dispatcher_send_custom_event(desktop->view_dispatcher, event);
}

void desktop_scene_slideshow_on_enter(void* context) {
Desktop* desktop = (Desktop*)context;
DesktopSlideshowView* slideshow_view = desktop->slideshow_view;

desktop_view_slideshow_set_callback(slideshow_view, desktop_scene_slideshow_callback, desktop);

view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdSlideshow);
}

bool desktop_scene_slideshow_on_event(void* context, SceneManagerEvent event) {
Desktop* desktop = (Desktop*)context;
bool consumed = false;
Storage* storage = NULL;

if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case DesktopSlideshowCompleted:
storage = furi_record_open("storage");
storage_common_remove(storage, "/int/slideshow");
furi_record_close("storage");
scene_manager_previous_scene(desktop->scene_manager);
consumed = true;
break;

default:
break;
}
}
return consumed;
}

void desktop_scene_slideshow_on_exit(void* context) {
UNUSED(context);
}
5 changes: 2 additions & 3 deletions applications/desktop/views/desktop_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ typedef enum {
DesktopDebugEventSaveState,
DesktopDebugEventExit,

DesktopFirstStartCompleted,
DesktopFirstStartPoweroff,

DesktopLockMenuEventLock,
DesktopLockMenuEventPinLock,
DesktopLockMenuEventExit,
Expand All @@ -37,6 +34,8 @@ typedef enum {
DesktopAnimationEventNewIdleAnimation,
DesktopAnimationEventInteractAnimation,

DesktopSlideshowCompleted,

// Global events
DesktopGlobalBeforeAppStarted,
DesktopGlobalAfterAppFinished,
Expand Down
Loading

0 comments on commit eb31fed

Please sign in to comment.