mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 13:28:36 -07:00
Unique ptr for xtreme settings, no more loading
This commit is contained in:
@@ -201,8 +201,7 @@ static void animation_manager_start_new_idle(AnimationManager* animation_manager
|
|||||||
const BubbleAnimation* bubble_animation =
|
const BubbleAnimation* bubble_animation =
|
||||||
animation_storage_get_bubble_animation(animation_manager->current_animation);
|
animation_storage_get_bubble_animation(animation_manager->current_animation);
|
||||||
animation_manager->state = AnimationManagerStateIdle;
|
animation_manager->state = AnimationManagerStateIdle;
|
||||||
XtremeSettings* xtreme = malloc(sizeof(XtremeSettings));
|
XtremeSettings* xtreme = XTREME_SETTINGS();
|
||||||
XTREME_SETTINGS_LOAD(xtreme);
|
|
||||||
int32_t duration = 0;
|
int32_t duration = 0;
|
||||||
if (xtreme->cycle_animation == 0) {
|
if (xtreme->cycle_animation == 0) {
|
||||||
duration = bubble_animation->duration;
|
duration = bubble_animation->duration;
|
||||||
@@ -210,7 +209,6 @@ static void animation_manager_start_new_idle(AnimationManager* animation_manager
|
|||||||
duration = xtreme->cycle_animation;
|
duration = xtreme->cycle_animation;
|
||||||
}
|
}
|
||||||
furi_timer_start(animation_manager->idle_animation_timer, duration * 1000);
|
furi_timer_start(animation_manager->idle_animation_timer, duration * 1000);
|
||||||
free(xtreme);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool animation_manager_check_blocking(AnimationManager* animation_manager) {
|
static bool animation_manager_check_blocking(AnimationManager* animation_manager) {
|
||||||
@@ -520,8 +518,7 @@ void animation_manager_load_and_continue_animation(AnimationManager* animation_m
|
|||||||
} else {
|
} else {
|
||||||
const BubbleAnimation* bubble_animation = animation_storage_get_bubble_animation(
|
const BubbleAnimation* bubble_animation = animation_storage_get_bubble_animation(
|
||||||
animation_manager->current_animation);
|
animation_manager->current_animation);
|
||||||
XtremeSettings* xtreme = malloc(sizeof(XtremeSettings));
|
XtremeSettings* xtreme = XTREME_SETTINGS();
|
||||||
XTREME_SETTINGS_LOAD(xtreme);
|
|
||||||
int32_t duration = 0;
|
int32_t duration = 0;
|
||||||
if (xtreme->cycle_animation == 0) {
|
if (xtreme->cycle_animation == 0) {
|
||||||
duration = bubble_animation->duration;
|
duration = bubble_animation->duration;
|
||||||
@@ -530,7 +527,6 @@ void animation_manager_load_and_continue_animation(AnimationManager* animation_m
|
|||||||
}
|
}
|
||||||
furi_timer_start(
|
furi_timer_start(
|
||||||
animation_manager->idle_animation_timer, duration * 1000);
|
animation_manager->idle_animation_timer, duration * 1000);
|
||||||
free(xtreme);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -22,14 +22,15 @@ const int32_t cycle_animation_values[CYCLE_ANIMATION_COUNT] =
|
|||||||
{-1, 0, 30, 60, 300, 600, 900, 1800, 3600, 7200, 21600, 43200, 86400};
|
{-1, 0, 30, 60, 300, 600, 900, 1800, 3600, 7200, 21600, 43200, 86400};
|
||||||
|
|
||||||
static void xtreme_settings_scene_start_cycle_animation_changed(VariableItem* item) {
|
static void xtreme_settings_scene_start_cycle_animation_changed(VariableItem* item) {
|
||||||
XtremeSettingsApp* app = variable_item_get_context(item);
|
|
||||||
uint8_t index = variable_item_get_current_value_index(item);
|
uint8_t index = variable_item_get_current_value_index(item);
|
||||||
variable_item_set_current_value_text(item, cycle_animation_names[index]);
|
variable_item_set_current_value_text(item, cycle_animation_names[index]);
|
||||||
app->settings.cycle_animation = cycle_animation_values[index];
|
XTREME_SETTINGS()->cycle_animation = cycle_animation_values[index];
|
||||||
|
XTREME_SETTINGS_SAVE();
|
||||||
}
|
}
|
||||||
|
|
||||||
void xtreme_settings_scene_start_on_enter(void* context) {
|
void xtreme_settings_scene_start_on_enter(void* context) {
|
||||||
XtremeSettingsApp* app = context;
|
XtremeSettingsApp* app = context;
|
||||||
|
XtremeSettings* xtreme = XTREME_SETTINGS();
|
||||||
VariableItemList* var_item_list = app->var_item_list;
|
VariableItemList* var_item_list = app->var_item_list;
|
||||||
VariableItem* item;
|
VariableItem* item;
|
||||||
uint8_t value_index;
|
uint8_t value_index;
|
||||||
@@ -40,9 +41,8 @@ void xtreme_settings_scene_start_on_enter(void* context) {
|
|||||||
CYCLE_ANIMATION_COUNT,
|
CYCLE_ANIMATION_COUNT,
|
||||||
xtreme_settings_scene_start_cycle_animation_changed,
|
xtreme_settings_scene_start_cycle_animation_changed,
|
||||||
app);
|
app);
|
||||||
|
|
||||||
value_index = value_index_int32(
|
value_index = value_index_int32(
|
||||||
app->settings.cycle_animation, cycle_animation_values, CYCLE_ANIMATION_COUNT);
|
xtreme->unlock_animations, cycle_animation_values, CYCLE_ANIMATION_COUNT);
|
||||||
variable_item_set_current_value_index(item, value_index);
|
variable_item_set_current_value_index(item, value_index);
|
||||||
variable_item_set_current_value_text(item, cycle_animation_names[value_index]);
|
variable_item_set_current_value_text(item, cycle_animation_names[value_index]);
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,35 @@
|
|||||||
#include "xtreme_settings.h"
|
#include "xtreme_settings.h"
|
||||||
|
|
||||||
bool XTREME_SETTINGS_LOAD(XtremeSettings* xtreme_settings) {
|
XtremeSettings* xtreme_settings = NULL;
|
||||||
|
|
||||||
|
XtremeSettings* XTREME_SETTINGS() {
|
||||||
|
if (xtreme_settings == NULL) {
|
||||||
|
xtreme_settings = malloc(sizeof(XtremeSettings));
|
||||||
|
_XTREME_SETTINGS_LOAD(xtreme_settings);
|
||||||
|
}
|
||||||
|
return xtreme_settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool XTREME_SETTINGS_SAVE() {
|
||||||
|
if (xtreme_settings == NULL) {
|
||||||
|
XTREME_SETTINGS();
|
||||||
|
}
|
||||||
|
return _XTREME_SETTINGS_SAVE(xtreme_settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _XTREME_SETTINGS_LOAD(XtremeSettings* xtreme_settings) {
|
||||||
furi_assert(xtreme_settings);
|
furi_assert(xtreme_settings);
|
||||||
|
|
||||||
bool loaded = saved_struct_load(
|
bool loaded = saved_struct_load(
|
||||||
XTREME_SETTINGS_PATH, xtreme_settings, sizeof(XtremeSettings), XTREME_SETTINGS_MAGIC, XTREME_SETTINGS_VERSION);
|
XTREME_SETTINGS_PATH, xtreme_settings, sizeof(XtremeSettings), XTREME_SETTINGS_MAGIC, XTREME_SETTINGS_VERSION);
|
||||||
if(!loaded) {
|
if(!loaded) {
|
||||||
memset(xtreme_settings, 0, sizeof(XtremeSettings));
|
memset(xtreme_settings, 0, sizeof(XtremeSettings));
|
||||||
loaded = XTREME_SETTINGS_SAVE(xtreme_settings);
|
loaded = _XTREME_SETTINGS_SAVE(xtreme_settings);
|
||||||
}
|
}
|
||||||
return loaded;
|
return loaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool XTREME_SETTINGS_SAVE(XtremeSettings* xtreme_settings) {
|
bool _XTREME_SETTINGS_SAVE(XtremeSettings* xtreme_settings) {
|
||||||
furi_assert(xtreme_settings);
|
furi_assert(xtreme_settings);
|
||||||
|
|
||||||
return saved_struct_save(
|
return saved_struct_save(
|
||||||
|
|||||||
@@ -14,9 +14,14 @@
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t cycle_animation;
|
int32_t cycle_animation;
|
||||||
|
bool unlock_animations;
|
||||||
// uint8_t sfw_mode;
|
// uint8_t sfw_mode;
|
||||||
} XtremeSettings;
|
} XtremeSettings;
|
||||||
|
|
||||||
bool XTREME_SETTINGS_LOAD(XtremeSettings* xtreme_settings);
|
XtremeSettings* XTREME_SETTINGS();
|
||||||
|
|
||||||
bool XTREME_SETTINGS_SAVE(XtremeSettings* xtreme_settings);
|
bool XTREME_SETTINGS_SAVE();
|
||||||
|
|
||||||
|
bool _XTREME_SETTINGS_LOAD(XtremeSettings* xtreme_settings);
|
||||||
|
|
||||||
|
bool _XTREME_SETTINGS_SAVE(XtremeSettings* xtreme_settings);
|
||||||
|
|||||||
@@ -14,9 +14,6 @@ static bool xtreme_settings_back_event_callback(void* context) {
|
|||||||
|
|
||||||
XtremeSettingsApp* xtreme_settings_app_alloc() {
|
XtremeSettingsApp* xtreme_settings_app_alloc() {
|
||||||
XtremeSettingsApp* app = malloc(sizeof(XtremeSettingsApp));
|
XtremeSettingsApp* app = malloc(sizeof(XtremeSettingsApp));
|
||||||
|
|
||||||
// Load settings
|
|
||||||
XTREME_SETTINGS_LOAD(&app->settings);
|
|
||||||
app->gui = furi_record_open(RECORD_GUI);
|
app->gui = furi_record_open(RECORD_GUI);
|
||||||
|
|
||||||
// View Dispatcher and Scene Manager
|
// View Dispatcher and Scene Manager
|
||||||
@@ -46,7 +43,7 @@ XtremeSettingsApp* xtreme_settings_app_alloc() {
|
|||||||
|
|
||||||
void xtreme_settings_app_free(XtremeSettingsApp* app) {
|
void xtreme_settings_app_free(XtremeSettingsApp* app) {
|
||||||
furi_assert(app);
|
furi_assert(app);
|
||||||
XTREME_SETTINGS_SAVE(&app->settings);
|
|
||||||
// Gui modules
|
// Gui modules
|
||||||
view_dispatcher_remove_view(app->view_dispatcher, XtremeSettingsAppViewVarItemList);
|
view_dispatcher_remove_view(app->view_dispatcher, XtremeSettingsAppViewVarItemList);
|
||||||
variable_item_list_free(app->var_item_list);
|
variable_item_list_free(app->var_item_list);
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
#include "scenes/xtreme_settings_scene.h"
|
#include "scenes/xtreme_settings_scene.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
XtremeSettings settings;
|
|
||||||
Gui* gui;
|
Gui* gui;
|
||||||
SceneManager* scene_manager;
|
SceneManager* scene_manager;
|
||||||
ViewDispatcher* view_dispatcher;
|
ViewDispatcher* view_dispatcher;
|
||||||
|
|||||||
Reference in New Issue
Block a user