mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
Add basic Xtreme app, move animcycle option to app
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include "animation_manager.h"
|
||||
|
||||
#include "../../../settings/desktop_settings/desktop_settings_app.h"
|
||||
#include "../../../settings/xtreme_settings/xtreme_settings.h"
|
||||
|
||||
#define TAG "AnimationManager"
|
||||
|
||||
@@ -200,11 +201,16 @@ static void animation_manager_start_new_idle(AnimationManager* animation_manager
|
||||
const BubbleAnimation* bubble_animation =
|
||||
animation_storage_get_bubble_animation(animation_manager->current_animation);
|
||||
animation_manager->state = AnimationManagerStateIdle;
|
||||
DesktopSettings* settings = malloc(sizeof(DesktopSettings));
|
||||
DESKTOP_SETTINGS_LOAD(settings);
|
||||
int32_t duration_s = settings->cycle_animation_s == -1 ? bubble_animation->duration : (settings->cycle_animation_s - 1);
|
||||
furi_timer_start(animation_manager->idle_animation_timer, duration_s * 1000);
|
||||
free(settings);
|
||||
XtremeSettings* xtreme = malloc(sizeof(XtremeSettings));
|
||||
XTREME_SETTINGS_LOAD(xtreme);
|
||||
int32_t duration = 0;
|
||||
if (xtreme->cycle_animation == 0) {
|
||||
duration = bubble_animation->duration;
|
||||
} else if (xtreme->cycle_animation != -1) {
|
||||
duration = xtreme->cycle_animation;
|
||||
}
|
||||
furi_timer_start(animation_manager->idle_animation_timer, duration * 1000);
|
||||
free(xtreme);
|
||||
}
|
||||
|
||||
static bool animation_manager_check_blocking(AnimationManager* animation_manager) {
|
||||
@@ -512,14 +518,19 @@ void animation_manager_load_and_continue_animation(AnimationManager* animation_m
|
||||
animation_manager->idle_animation_timer,
|
||||
animation_manager->freezed_animation_time_left);
|
||||
} else {
|
||||
const BubbleAnimation* animation = animation_storage_get_bubble_animation(
|
||||
const BubbleAnimation* bubble_animation = animation_storage_get_bubble_animation(
|
||||
animation_manager->current_animation);
|
||||
DesktopSettings* settings = malloc(sizeof(DesktopSettings));
|
||||
DESKTOP_SETTINGS_LOAD(settings);
|
||||
int32_t duration_s = settings->cycle_animation_s == -1 ? animation->duration : (settings->cycle_animation_s - 1);
|
||||
XtremeSettings* xtreme = malloc(sizeof(XtremeSettings));
|
||||
XTREME_SETTINGS_LOAD(xtreme);
|
||||
int32_t duration = 0;
|
||||
if (xtreme->cycle_animation == 0) {
|
||||
duration = bubble_animation->duration;
|
||||
} else if (xtreme->cycle_animation != -1) {
|
||||
duration = xtreme->cycle_animation;
|
||||
}
|
||||
furi_timer_start(
|
||||
animation_manager->idle_animation_timer, duration_s * 1000);
|
||||
free(settings);
|
||||
animation_manager->idle_animation_timer, duration * 1000);
|
||||
free(xtreme);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -322,11 +322,6 @@ int32_t desktop_srv(void* p) {
|
||||
DESKTOP_SETTINGS_SAVE(&desktop->settings);
|
||||
}
|
||||
|
||||
if(!desktop->settings.cycle_animation_s) {
|
||||
desktop->settings.cycle_animation_s = -1;
|
||||
DESKTOP_SETTINGS_SAVE(&desktop->settings);
|
||||
}
|
||||
|
||||
desktop_main_set_sfw_mode_state(desktop->main_view, desktop->settings.sfw_mode);
|
||||
|
||||
scene_manager_next_scene(desktop->scene_manager, DesktopSceneMain);
|
||||
|
||||
@@ -64,5 +64,4 @@ typedef struct {
|
||||
uint8_t displayBatteryPercentage;
|
||||
bool is_sfwmode;
|
||||
uint8_t sfw_mode;
|
||||
int32_t cycle_animation_s;
|
||||
} DesktopSettings;
|
||||
|
||||
@@ -5,6 +5,7 @@ App(
|
||||
provides=[
|
||||
"passport",
|
||||
"system_settings",
|
||||
"xtreme_settings",
|
||||
"about",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -39,26 +39,6 @@ const uint32_t displayBatteryPercentage_value[BATTERY_VIEW_COUNT] = {
|
||||
|
||||
uint8_t origBattDisp_value = 0;
|
||||
|
||||
#define CYCLE_ANIMATION_COUNT 13
|
||||
const char* const cycle_animation_text[CYCLE_ANIMATION_COUNT] = {
|
||||
"OFF",
|
||||
"Manifest",
|
||||
"30 S",
|
||||
"1 M",
|
||||
"5 M",
|
||||
"10 M",
|
||||
"15 M",
|
||||
"30 M",
|
||||
"1 H",
|
||||
"2 H",
|
||||
"6 H",
|
||||
"12 H",
|
||||
"24 H",
|
||||
};
|
||||
// Values are offset by 1 so that 0 is not a valid value and desktop.c can detect this to set a default value (3601 / 1 H)
|
||||
const int32_t cycle_animation_value[CYCLE_ANIMATION_COUNT] =
|
||||
{1, -1, 31, 61, 301, 601, 901, 1801, 3601, 7201, 21601, 43201, 86401};
|
||||
|
||||
static void desktop_settings_scene_start_var_list_enter_callback(void* context, uint32_t index) {
|
||||
DesktopSettingsApp* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, index);
|
||||
@@ -80,14 +60,6 @@ static void desktop_settings_scene_start_battery_view_changed(VariableItem* item
|
||||
app->settings.displayBatteryPercentage = index;
|
||||
}
|
||||
|
||||
static void desktop_settings_scene_start_cycle_animation_changed(VariableItem* item) {
|
||||
DesktopSettingsApp* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
variable_item_set_current_value_text(item, cycle_animation_text[index]);
|
||||
app->settings.cycle_animation_s = cycle_animation_value[index];
|
||||
}
|
||||
|
||||
void desktop_settings_scene_start_on_enter(void* context) {
|
||||
DesktopSettingsApp* app = context;
|
||||
VariableItemList* variable_item_list = app->variable_item_list;
|
||||
@@ -130,18 +102,6 @@ void desktop_settings_scene_start_on_enter(void* context) {
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, battery_view_count_text[value_index]);
|
||||
|
||||
item = variable_item_list_add(
|
||||
variable_item_list,
|
||||
"Cycle Animation",
|
||||
CYCLE_ANIMATION_COUNT,
|
||||
desktop_settings_scene_start_cycle_animation_changed,
|
||||
app);
|
||||
|
||||
value_index = value_index_int32(
|
||||
app->settings.cycle_animation_s, cycle_animation_value, CYCLE_ANIMATION_COUNT);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, cycle_animation_text[value_index]);
|
||||
|
||||
variable_item_list_set_enter_callback(
|
||||
variable_item_list, desktop_settings_scene_start_var_list_enter_callback, app);
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, DesktopSettingsAppViewVarItemList);
|
||||
|
||||
11
applications/settings/xtreme_settings/application.fam
Normal file
11
applications/settings/xtreme_settings/application.fam
Normal file
@@ -0,0 +1,11 @@
|
||||
App(
|
||||
appid="xtreme_settings",
|
||||
name="Xtreme FW",
|
||||
apptype=FlipperAppType.SETTINGS,
|
||||
entry_point="xtreme_settings_app",
|
||||
stack_size=2 * 1024,
|
||||
requires=[
|
||||
"gui",
|
||||
],
|
||||
order=90,
|
||||
)
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "xtreme_settings_scene.h"
|
||||
|
||||
// Generate scene on_enter handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||
void (*const xtreme_settings_on_enter_handlers[])(void*) = {
|
||||
#include "xtreme_settings_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
|
||||
bool (*const xtreme_settings_on_event_handlers[])(void* context, SceneManagerEvent event) = {
|
||||
#include "xtreme_settings_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
|
||||
void (*const xtreme_settings_on_exit_handlers[])(void* context) = {
|
||||
#include "xtreme_settings_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Initialize scene handlers configuration structure
|
||||
const SceneManagerHandlers xtreme_settings_scene_handlers = {
|
||||
.on_enter_handlers = xtreme_settings_on_enter_handlers,
|
||||
.on_event_handlers = xtreme_settings_on_event_handlers,
|
||||
.on_exit_handlers = xtreme_settings_on_exit_handlers,
|
||||
.scene_num = XtremeSettingsAppSceneNum,
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/scene_manager.h>
|
||||
|
||||
// Generate scene id and total number
|
||||
#define ADD_SCENE(prefix, name, id) XtremeSettingsAppScene##id,
|
||||
typedef enum {
|
||||
#include "xtreme_settings_scene_config.h"
|
||||
XtremeSettingsAppSceneNum,
|
||||
} XtremeSettingsAppScene;
|
||||
#undef ADD_SCENE
|
||||
|
||||
extern const SceneManagerHandlers xtreme_settings_scene_handlers;
|
||||
|
||||
// Generate scene on_enter handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
|
||||
#include "xtreme_settings_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) \
|
||||
bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
|
||||
#include "xtreme_settings_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
|
||||
#include "xtreme_settings_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
@@ -0,0 +1 @@
|
||||
ADD_SCENE(xtreme_settings, start, Start)
|
||||
@@ -0,0 +1,62 @@
|
||||
#include "../xtreme_settings_app.h"
|
||||
#include <lib/toolbox/value_index.h>
|
||||
|
||||
#define CYCLE_ANIMATION_COUNT 13
|
||||
const char* const cycle_animation_names[CYCLE_ANIMATION_COUNT] = {
|
||||
"OFF",
|
||||
"Manifest",
|
||||
"30 S",
|
||||
"1 M",
|
||||
"5 M",
|
||||
"10 M",
|
||||
"15 M",
|
||||
"30 M",
|
||||
"1 H",
|
||||
"2 H",
|
||||
"6 H",
|
||||
"12 H",
|
||||
"24 H",
|
||||
};
|
||||
|
||||
const int32_t cycle_animation_values[CYCLE_ANIMATION_COUNT] =
|
||||
{-1, 0, 30, 60, 300, 600, 900, 1800, 3600, 7200, 21600, 43200, 86400};
|
||||
|
||||
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);
|
||||
variable_item_set_current_value_text(item, cycle_animation_names[index]);
|
||||
app->settings.cycle_animation = cycle_animation_values[index];
|
||||
}
|
||||
|
||||
void xtreme_settings_scene_start_on_enter(void* context) {
|
||||
XtremeSettingsApp* app = context;
|
||||
VariableItemList* var_item_list = app->var_item_list;
|
||||
VariableItem* item;
|
||||
uint8_t value_index;
|
||||
|
||||
item = variable_item_list_add(
|
||||
var_item_list,
|
||||
"Cycle Animation",
|
||||
CYCLE_ANIMATION_COUNT,
|
||||
xtreme_settings_scene_start_cycle_animation_changed,
|
||||
app);
|
||||
|
||||
value_index = value_index_int32(
|
||||
app->settings.cycle_animation, cycle_animation_values, CYCLE_ANIMATION_COUNT);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, cycle_animation_names[value_index]);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, XtremeSettingsAppViewVarItemList);
|
||||
}
|
||||
|
||||
bool xtreme_settings_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||
UNUSED(context);
|
||||
UNUSED(event);
|
||||
bool consumed = false;
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void xtreme_settings_scene_start_on_exit(void* context) {
|
||||
XtremeSettingsApp* app = context;
|
||||
variable_item_list_reset(app->var_item_list);
|
||||
}
|
||||
20
applications/settings/xtreme_settings/xtreme_settings.c
Normal file
20
applications/settings/xtreme_settings/xtreme_settings.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "xtreme_settings.h"
|
||||
|
||||
bool XTREME_SETTINGS_LOAD(XtremeSettings* xtreme_settings) {
|
||||
furi_assert(xtreme_settings);
|
||||
|
||||
bool loaded = saved_struct_load(
|
||||
XTREME_SETTINGS_PATH, xtreme_settings, sizeof(XtremeSettings), XTREME_SETTINGS_MAGIC, XTREME_SETTINGS_VERSION);
|
||||
if(!loaded) {
|
||||
memset(xtreme_settings, 0, sizeof(XtremeSettings));
|
||||
loaded = XTREME_SETTINGS_SAVE(xtreme_settings);
|
||||
}
|
||||
return loaded;
|
||||
}
|
||||
|
||||
bool XTREME_SETTINGS_SAVE(XtremeSettings* xtreme_settings) {
|
||||
furi_assert(xtreme_settings);
|
||||
|
||||
return saved_struct_save(
|
||||
XTREME_SETTINGS_PATH, xtreme_settings, sizeof(XtremeSettings), XTREME_SETTINGS_MAGIC, XTREME_SETTINGS_VERSION);
|
||||
}
|
||||
22
applications/settings/xtreme_settings/xtreme_settings.h
Normal file
22
applications/settings/xtreme_settings/xtreme_settings.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "xtreme_settings_filename.h"
|
||||
|
||||
#include <furi_hal.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <toolbox/saved_struct.h>
|
||||
#include <storage/storage.h>
|
||||
|
||||
#define XTREME_SETTINGS_VERSION (1)
|
||||
#define XTREME_SETTINGS_PATH INT_PATH(XTREME_SETTINGS_FILE_NAME)
|
||||
#define XTREME_SETTINGS_MAGIC (0x69)
|
||||
|
||||
typedef struct {
|
||||
int32_t cycle_animation;
|
||||
// uint8_t sfw_mode;
|
||||
} XtremeSettings;
|
||||
|
||||
bool XTREME_SETTINGS_LOAD(XtremeSettings* xtreme_settings);
|
||||
|
||||
bool XTREME_SETTINGS_SAVE(XtremeSettings* xtreme_settings);
|
||||
69
applications/settings/xtreme_settings/xtreme_settings_app.c
Normal file
69
applications/settings/xtreme_settings/xtreme_settings_app.c
Normal file
@@ -0,0 +1,69 @@
|
||||
#include "xtreme_settings_app.h"
|
||||
|
||||
static bool xtreme_settings_custom_event_callback(void* context, uint32_t event) {
|
||||
furi_assert(context);
|
||||
XtremeSettingsApp* app = context;
|
||||
return scene_manager_handle_custom_event(app->scene_manager, event);
|
||||
}
|
||||
|
||||
static bool xtreme_settings_back_event_callback(void* context) {
|
||||
furi_assert(context);
|
||||
XtremeSettingsApp* app = context;
|
||||
return scene_manager_handle_back_event(app->scene_manager);
|
||||
}
|
||||
|
||||
XtremeSettingsApp* xtreme_settings_app_alloc() {
|
||||
XtremeSettingsApp* app = malloc(sizeof(XtremeSettingsApp));
|
||||
|
||||
// Load settings
|
||||
XTREME_SETTINGS_LOAD(&app->settings);
|
||||
app->gui = furi_record_open(RECORD_GUI);
|
||||
|
||||
// View Dispatcher and Scene Manager
|
||||
app->view_dispatcher = view_dispatcher_alloc();
|
||||
app->scene_manager = scene_manager_alloc(&xtreme_settings_scene_handlers, app);
|
||||
view_dispatcher_enable_queue(app->view_dispatcher);
|
||||
view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
|
||||
|
||||
view_dispatcher_set_custom_event_callback(
|
||||
app->view_dispatcher, xtreme_settings_custom_event_callback);
|
||||
view_dispatcher_set_navigation_event_callback(
|
||||
app->view_dispatcher, xtreme_settings_back_event_callback);
|
||||
|
||||
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
|
||||
|
||||
// Gui Modules
|
||||
app->var_item_list = variable_item_list_alloc();
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher,
|
||||
XtremeSettingsAppViewVarItemList,
|
||||
variable_item_list_get_view(app->var_item_list));
|
||||
|
||||
// Set first scene
|
||||
scene_manager_next_scene(app->scene_manager, XtremeSettingsAppSceneStart);
|
||||
return app;
|
||||
}
|
||||
|
||||
void xtreme_settings_app_free(XtremeSettingsApp* app) {
|
||||
furi_assert(app);
|
||||
XTREME_SETTINGS_SAVE(&app->settings);
|
||||
// Gui modules
|
||||
view_dispatcher_remove_view(app->view_dispatcher, XtremeSettingsAppViewVarItemList);
|
||||
variable_item_list_free(app->var_item_list);
|
||||
|
||||
// View Dispatcher and Scene Manager
|
||||
view_dispatcher_free(app->view_dispatcher);
|
||||
scene_manager_free(app->scene_manager);
|
||||
|
||||
// Records
|
||||
furi_record_close(RECORD_GUI);
|
||||
free(app);
|
||||
}
|
||||
|
||||
extern int32_t xtreme_settings_app(void* p) {
|
||||
UNUSED(p);
|
||||
XtremeSettingsApp* app = xtreme_settings_app_alloc();
|
||||
view_dispatcher_run(app->view_dispatcher);
|
||||
xtreme_settings_app_free(app);
|
||||
return 0;
|
||||
}
|
||||
23
applications/settings/xtreme_settings/xtreme_settings_app.h
Normal file
23
applications/settings/xtreme_settings/xtreme_settings_app.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <furi.h>
|
||||
#include <gui/gui.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/scene_manager.h>
|
||||
#include <assets_icons.h>
|
||||
#include <gui/modules/variable_item_list.h>
|
||||
#include "xtreme_settings.h"
|
||||
#include "scenes/xtreme_settings_scene.h"
|
||||
|
||||
typedef struct {
|
||||
XtremeSettings settings;
|
||||
Gui* gui;
|
||||
SceneManager* scene_manager;
|
||||
ViewDispatcher* view_dispatcher;
|
||||
VariableItemList* var_item_list;
|
||||
} XtremeSettingsApp;
|
||||
|
||||
typedef enum {
|
||||
XtremeSettingsAppViewVarItemList,
|
||||
} XtremeSettingsAppView;
|
||||
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define XTREME_SETTINGS_FILE_NAME ".xtreme.settings"
|
||||
Reference in New Issue
Block a user