diff --git a/applications/bt/bt_settings_app/bt_settings_app.h b/applications/bt/bt_settings_app/bt_settings_app.h index db379436..5b4a8d13 100755 --- a/applications/bt/bt_settings_app/bt_settings_app.h +++ b/applications/bt/bt_settings_app/bt_settings_app.h @@ -14,6 +14,14 @@ #include "../bt_settings.h" #include "scenes/bt_settings_scene.h" +enum BtSettingsCustomEvent { + // Keep first 10 events reserved for button types and indexes + BtSettingsCustomEventReserved = 10, + + BtSettingsCustomEventForgetDevices, + BtSettingsCustomEventExitView, +}; + typedef struct { BtSettings settings; Bt* bt; diff --git a/applications/bt/bt_settings_app/scenes/bt_settings_scene_forget_dev_success.c b/applications/bt/bt_settings_app/scenes/bt_settings_scene_forget_dev_success.c index e43082af..c0b0c80a 100755 --- a/applications/bt/bt_settings_app/scenes/bt_settings_scene_forget_dev_success.c +++ b/applications/bt/bt_settings_app/scenes/bt_settings_scene_forget_dev_success.c @@ -1,11 +1,9 @@ #include "../bt_settings_app.h" #include "furi_hal_bt.h" -#define SCENE_FORGET_DEV_SUCCESS_CUSTOM_EVENT (0UL) - void bt_settings_app_scene_forget_dev_success_popup_callback(void* context) { BtSettingsApp* app = context; - view_dispatcher_send_custom_event(app->view_dispatcher, SCENE_FORGET_DEV_SUCCESS_CUSTOM_EVENT); + view_dispatcher_send_custom_event(app->view_dispatcher, BtSettingsCustomEventExitView); } void bt_settings_scene_forget_dev_success_on_enter(void* context) { @@ -26,7 +24,7 @@ bool bt_settings_scene_forget_dev_success_on_event(void* context, SceneManagerEv bool consumed = false; if(event.type == SceneManagerEventTypeCustom) { - if(event.event == SCENE_FORGET_DEV_SUCCESS_CUSTOM_EVENT) { + if(event.event == BtSettingsCustomEventExitView) { if(scene_manager_has_previous_scene(app->scene_manager, BtSettingsAppSceneStart)) { consumed = scene_manager_search_and_switch_to_previous_scene( app->scene_manager, BtSettingsAppSceneStart); diff --git a/applications/bt/bt_settings_app/scenes/bt_settings_scene_start.c b/applications/bt/bt_settings_app/scenes/bt_settings_scene_start.c index 33c0bb5a..9dd0b1e7 100755 --- a/applications/bt/bt_settings_app/scenes/bt_settings_scene_start.c +++ b/applications/bt/bt_settings_app/scenes/bt_settings_scene_start.c @@ -1,14 +1,17 @@ #include "../bt_settings_app.h" #include "furi_hal_bt.h" -#define SCENE_START_FORGET_DEV_SELECTED_EVENT (10UL) - enum BtSetting { BtSettingOff, BtSettingOn, BtSettingNum, }; +enum BtSettingIndex { + BtSettingIndexSwitchBt, + BtSettingIndexForgetDev, +}; + const char* const bt_settings_text[BtSettingNum] = { "OFF", "ON", @@ -25,7 +28,10 @@ static void bt_settings_scene_start_var_list_change_callback(VariableItem* item) static void bt_settings_scene_start_var_list_enter_callback(void* context, uint32_t index) { furi_assert(context); BtSettingsApp* app = context; - view_dispatcher_send_custom_event(app->view_dispatcher, SCENE_START_FORGET_DEV_SELECTED_EVENT); + if(index == BtSettingIndexForgetDev) { + view_dispatcher_send_custom_event( + app->view_dispatcher, BtSettingsCustomEventForgetDevices); + } } void bt_settings_scene_start_on_enter(void* context) { @@ -72,7 +78,7 @@ bool bt_settings_scene_start_on_event(void* context, SceneManagerEvent event) { app->settings.enabled = false; furi_hal_bt_stop_advertising(); consumed = true; - } else if(event.event == SCENE_START_FORGET_DEV_SELECTED_EVENT) { + } else if(event.event == BtSettingsCustomEventForgetDevices) { scene_manager_next_scene(app->scene_manager, BtSettingsAppSceneForgetDevConfirm); consumed = true; } diff --git a/applications/desktop/animations/animation_manager.h b/applications/desktop/animations/animation_manager.h index d86a162c..74f31b8a 100644 --- a/applications/desktop/animations/animation_manager.h +++ b/applications/desktop/animations/animation_manager.h @@ -26,7 +26,7 @@ typedef struct { const FrameBubble* const* frame_bubble_sequences; uint8_t frame_bubble_sequences_count; const Icon icon_animation; - uint8_t frame_order[20]; + const uint8_t* frame_order; uint8_t passive_frames; uint8_t active_frames; uint8_t active_cycles; diff --git a/applications/desktop/animations/animation_storage.c b/applications/desktop/animations/animation_storage.c index 94b23be6..f9a76959 100644 --- a/applications/desktop/animations/animation_storage.c +++ b/applications/desktop/animations/animation_storage.c @@ -209,6 +209,9 @@ static void animation_storage_free_animation(BubbleAnimation** animation) { if(*animation) { animation_storage_free_bubbles(*animation); animation_storage_free_frames(*animation); + if((*animation)->frame_order) { + free((void*)(*animation)->frame_order); + } free(*animation); *animation = NULL; } @@ -268,7 +271,24 @@ static bool animation_storage_load_frames( uint32_t* frame_order, uint8_t width, uint8_t height) { - uint16_t frame_order_size = animation->passive_frames + animation->active_frames; + uint16_t frame_order_count = animation->passive_frames + animation->active_frames; + + /* The frames should go in order (0...N), without omissions */ + size_t max_frame_count = 0; + for(int i = 0; i < frame_order_count; ++i) { + max_frame_count = MAX(max_frame_count, frame_order[i]); + } + + if((max_frame_count >= frame_order_count) || (max_frame_count >= 256 /* max uint8_t */)) { + return false; + } + + Icon* icon = (Icon*)&animation->icon_animation; + FURI_CONST_ASSIGN(icon->frame_count, max_frame_count + 1); + FURI_CONST_ASSIGN(icon->frame_rate, 0); + FURI_CONST_ASSIGN(icon->height, height); + FURI_CONST_ASSIGN(icon->width, width); + icon->frames = furi_alloc(sizeof(const uint8_t*) * icon->frame_count); bool frames_ok = false; File* file = storage_file_alloc(storage); @@ -276,17 +296,10 @@ static bool animation_storage_load_frames( string_t filename; string_init(filename); size_t max_filesize = ROUND_UP_TO(width, 8) * height + 1; - Icon* icon = (Icon*)&animation->icon_animation; - FURI_CONST_ASSIGN(icon->frame_count, frame_order_size); - FURI_CONST_ASSIGN(icon->frame_rate, 0); - FURI_CONST_ASSIGN(icon->height, height); - FURI_CONST_ASSIGN(icon->width, width); - icon->frames = furi_alloc(sizeof(const uint8_t*) * frame_order_size); - - for(int i = 0; i < frame_order_size; ++i) { + for(int i = 0; i < icon->frame_count; ++i) { frames_ok = false; - string_printf(filename, ANIMATION_DIR "/%s/frame_%d.bm", name, frame_order[i]); + string_printf(filename, ANIMATION_DIR "/%s/frame_%d.bm", name, i); if(storage_common_stat(storage, string_get_cstr(filename), &file_info) != FSE_OK) break; if(file_info.size > max_filesize) { @@ -453,14 +466,15 @@ static BubbleAnimation* animation_storage_load_animation(const char* name) { uint8_t frames = animation->passive_frames + animation->active_frames; uint32_t count = 0; if(!flipper_file_get_value_count(ff, "Frames order", &count)) break; - if((count != frames) || (frames > COUNT_OF(animation->frame_order))) { + if(count != frames) { FURI_LOG_E(TAG, "Error loading animation: frames order"); break; } u32array = furi_alloc(sizeof(uint32_t) * frames); if(!flipper_file_read_uint32(ff, "Frames order", u32array, frames)) break; + animation->frame_order = furi_alloc(sizeof(uint8_t) * frames); for(int i = 0; i < frames; ++i) { - animation->frame_order[i] = u32array[i]; + FURI_CONST_ASSIGN(animation->frame_order[i], u32array[i]); } /* passive and active frames must be loaded up to this point */ @@ -488,6 +502,9 @@ static BubbleAnimation* animation_storage_load_animation(const char* name) { } if(!success) { + if(animation->frame_order) { + free((void*)animation->frame_order); + } free(animation); animation = NULL; } diff --git a/applications/desktop/views/desktop_main.c b/applications/desktop/views/desktop_main.c index b03381b9..83d561df 100644 --- a/applications/desktop/views/desktop_main.c +++ b/applications/desktop/views/desktop_main.c @@ -35,25 +35,26 @@ bool desktop_main_input(InputEvent* event, void* context) { furi_assert(context); DesktopMainView* main_view = context; - bool consumed = false; - if(event->key == InputKeyOk && event->type == InputTypeShort) { - main_view->callback(DesktopMainEventOpenMenu, main_view->context); - } else if(event->key == InputKeyDown && event->type == InputTypeLong) { - main_view->callback(DesktopMainEventOpenDebug, main_view->context); - } else if(event->key == InputKeyUp && event->type == InputTypeShort) { - main_view->callback(DesktopMainEventOpenLockMenu, main_view->context); - } else if(event->key == InputKeyDown && event->type == InputTypeShort) { - main_view->callback(DesktopMainEventOpenArchive, main_view->context); - } else if(event->key == InputKeyLeft && event->type == InputTypeShort) { - main_view->callback(DesktopMainEventOpenFavorite, main_view->context); - } else if(event->key == InputKeyRight && event->type == InputTypeShort) { - main_view->callback(DesktopMainEventRightShort, main_view->context); - } else if(event->key == InputKeyBack && event->type == InputTypeShort) { - consumed = true; + if(event->type == InputTypeShort) { + if(event->key == InputKeyOk) { + main_view->callback(DesktopMainEventOpenMenu, main_view->context); + } else if(event->key == InputKeyUp) { + main_view->callback(DesktopMainEventOpenLockMenu, main_view->context); + } else if(event->key == InputKeyDown) { + main_view->callback(DesktopMainEventOpenArchive, main_view->context); + } else if(event->key == InputKeyLeft) { + main_view->callback(DesktopMainEventOpenFavorite, main_view->context); + } else if(event->key == InputKeyRight) { + main_view->callback(DesktopMainEventRightShort, main_view->context); + } + } else if(event->type == InputTypeLong) { + if(event->key == InputKeyDown) { + main_view->callback(DesktopMainEventOpenDebug, main_view->context); + } } - return consumed; + return true; } DesktopMainView* desktop_main_alloc() { diff --git a/applications/gui/view_stack.c b/applications/gui/view_stack.c index 39ffc8c7..d790b801 100644 --- a/applications/gui/view_stack.c +++ b/applications/gui/view_stack.c @@ -105,13 +105,14 @@ static bool view_stack_input(InputEvent* event, void* context) { furi_assert(event); furi_assert(context); - bool consumed = false; ViewStack* view_stack = context; + bool consumed = false; ViewStackModel* model = view_get_model(view_stack->view); - for(int i = MAX_VIEWS - 1; !consumed && (i >= 0); --i) { - if(model->views[i]) { - consumed = view_input(model->views[i], event); + for(int i = MAX_VIEWS - 1; i >= 0; i--) { + if(model->views[i] && view_input(model->views[i], event)) { + consumed = true; + break; } } view_commit_model(view_stack->view, false); diff --git a/assets/compiled/assets_dolphin_blocking.c b/assets/compiled/assets_dolphin_blocking.c index a14b8c5f..9ea09e2f 100644 --- a/assets/compiled/assets_dolphin_blocking.c +++ b/assets/compiled/assets_dolphin_blocking.c @@ -36,6 +36,8 @@ const uint8_t *_A_L0_NoDb_128x51[] = { +const uint8_t L0_NoDb_128x51_frame_order[] = { 0, 1, 2, 3 }; + const BubbleAnimation BA_L0_NoDb_128x51 = { .icon_animation = { .width = 128, @@ -44,7 +46,7 @@ const BubbleAnimation BA_L0_NoDb_128x51 = { .frame_rate = 2, .frames = _A_L0_NoDb_128x51 }, - .frame_order = { 0, 1, 2, 3 }, + .frame_order = L0_NoDb_128x51_frame_order, .passive_frames = 4, .active_frames = 0, .active_cooldown = 0, @@ -76,6 +78,8 @@ const uint8_t *_A_L0_SdBad_128x51[] = { +const uint8_t L0_SdBad_128x51_frame_order[] = { 0, 1 }; + const BubbleAnimation BA_L0_SdBad_128x51 = { .icon_animation = { .width = 128, @@ -84,7 +88,7 @@ const BubbleAnimation BA_L0_SdBad_128x51 = { .frame_rate = 2, .frames = _A_L0_SdBad_128x51 }, - .frame_order = { 0, 1 }, + .frame_order = L0_SdBad_128x51_frame_order, .passive_frames = 2, .active_frames = 0, .active_cooldown = 0, @@ -128,6 +132,8 @@ const uint8_t *_A_L0_SdOk_128x51[] = { +const uint8_t L0_SdOk_128x51_frame_order[] = { 0, 1, 2, 3 }; + const BubbleAnimation BA_L0_SdOk_128x51 = { .icon_animation = { .width = 128, @@ -136,7 +142,7 @@ const BubbleAnimation BA_L0_SdOk_128x51 = { .frame_rate = 2, .frames = _A_L0_SdOk_128x51 }, - .frame_order = { 0, 1, 2, 3 }, + .frame_order = L0_SdOk_128x51_frame_order, .passive_frames = 4, .active_frames = 0, .active_cooldown = 0, @@ -180,6 +186,8 @@ const uint8_t *_A_L0_Url_128x51[] = { +const uint8_t L0_Url_128x51_frame_order[] = { 0, 1, 2, 3 }; + const BubbleAnimation BA_L0_Url_128x51 = { .icon_animation = { .width = 128, @@ -188,7 +196,7 @@ const BubbleAnimation BA_L0_Url_128x51 = { .frame_rate = 2, .frames = _A_L0_Url_128x51 }, - .frame_order = { 0, 1, 2, 3 }, + .frame_order = L0_Url_128x51_frame_order, .passive_frames = 4, .active_frames = 0, .active_cooldown = 0, @@ -232,6 +240,8 @@ const uint8_t *_A_L0_NewMail_128x51[] = { +const uint8_t L0_NewMail_128x51_frame_order[] = { 0, 1, 2, 3, 2, 1 }; + const BubbleAnimation BA_L0_NewMail_128x51 = { .icon_animation = { .width = 128, @@ -240,7 +250,7 @@ const BubbleAnimation BA_L0_NewMail_128x51 = { .frame_rate = 2, .frames = _A_L0_NewMail_128x51 }, - .frame_order = { 0, 1, 2, 3, 2, 1 }, + .frame_order = L0_NewMail_128x51_frame_order, .passive_frames = 6, .active_frames = 0, .active_cooldown = 0, diff --git a/assets/compiled/assets_dolphin_internal.c b/assets/compiled/assets_dolphin_internal.c index 99cab819..373a2873 100644 --- a/assets/compiled/assets_dolphin_internal.c +++ b/assets/compiled/assets_dolphin_internal.c @@ -104,6 +104,8 @@ const FrameBubble L1_Tv_128x47_bubble_1_0 = { +const uint8_t L1_Tv_128x47_frame_order[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; + const BubbleAnimation BA_L1_Tv_128x47 = { .icon_animation = { .width = 128, @@ -112,7 +114,7 @@ const BubbleAnimation BA_L1_Tv_128x47 = { .frame_rate = 2, .frames = _A_L1_Tv_128x47 }, - .frame_order = { 0, 1, 2, 3, 4, 5, 6, 7 }, + .frame_order = L1_Tv_128x47_frame_order, .passive_frames = 6, .active_frames = 2, .active_cooldown = 5, @@ -170,6 +172,8 @@ const FrameBubble L1_BadBattery_128x47_bubble_0_0 = { +const uint8_t L1_BadBattery_128x47_frame_order[] = { 0, 1 }; + const BubbleAnimation BA_L1_BadBattery_128x47 = { .icon_animation = { .width = 128, @@ -178,7 +182,7 @@ const BubbleAnimation BA_L1_BadBattery_128x47 = { .frame_rate = 2, .frames = _A_L1_BadBattery_128x47 }, - .frame_order = { 0, 1 }, + .frame_order = L1_BadBattery_128x47_frame_order, .passive_frames = 2, .active_frames = 0, .active_cooldown = 0, @@ -260,6 +264,8 @@ const FrameBubble L1_NoSd_128x49_bubble_0_0 = { +const uint8_t L1_NoSd_128x49_frame_order[] = { 0, 1, 0, 1, 0, 2, 3, 4, 3, 5 }; + const BubbleAnimation BA_L1_NoSd_128x49 = { .icon_animation = { .width = 128, @@ -268,7 +274,7 @@ const BubbleAnimation BA_L1_NoSd_128x49 = { .frame_rate = 2, .frames = _A_L1_NoSd_128x49 }, - .frame_order = { 0, 1, 0, 1, 0, 2, 3, 4, 3, 5 }, + .frame_order = L1_NoSd_128x49_frame_order, .passive_frames = 10, .active_frames = 0, .active_cooldown = 0, diff --git a/scripts/flipper/assets/templates/dolphin.c.tmpl b/scripts/flipper/assets/templates/dolphin.c.tmpl index d085678d..633a374e 100644 --- a/scripts/flipper/assets/templates/dolphin.c.tmpl +++ b/scripts/flipper/assets/templates/dolphin.c.tmpl @@ -49,6 +49,8 @@ const FrameBubble {{animation.name}}_bubble_{{bubble["Slot"]}}_{{bubble["_Bubble {% :endfor %} {% :endif %} +const uint8_t {{animation.name}}_frame_order[] = { {{ "%s" % ", ".join(str(i) for i in animation.meta['Frames order']) }} }; + const BubbleAnimation BA_{{animation.name}} = { .icon_animation = { .width = {{ animation.meta['Width'] }}, @@ -57,7 +59,7 @@ const BubbleAnimation BA_{{animation.name}} = { .frame_rate = {{ animation.meta['Frame rate'] }}, .frames = _A_{{ animation.name }} }, - .frame_order = { {{ "%s" % ", ".join(str(i) for i in animation.meta['Frames order']) }} }, + .frame_order = {{animation.name}}_frame_order, .passive_frames = {{ animation.meta['Passive frames'] }}, .active_frames = {{ animation.meta['Active frames'] }}, .active_cooldown = {{ animation.meta['Active cooldown'] }},