|
@@ -8,14 +8,108 @@
|
|
|
|
|
|
|
|
#include "xremote_app.h"
|
|
#include "xremote_app.h"
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+#define XREMOTE_APP_SETTINGS ANY_PATH("infrared/assets/xremote.cfg")
|
|
|
|
|
+#define TAG "XRemoteApp"
|
|
|
|
|
+
|
|
|
|
|
+XRemoteAppSettings* xremote_app_settings_alloc()
|
|
|
|
|
+{
|
|
|
|
|
+ XRemoteAppSettings* settings = malloc(sizeof(XRemoteAppSettings));
|
|
|
|
|
+ settings->orientation = ViewOrientationVertical;
|
|
|
|
|
+ settings->repeat_count = 1;
|
|
|
|
|
+ return settings;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void xremote_app_settings_free(XRemoteAppSettings* settings)
|
|
|
|
|
+{
|
|
|
|
|
+ xremote_app_assert_void(settings);
|
|
|
|
|
+ free(settings);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+bool xremote_app_settings_store(XRemoteAppSettings* settings)
|
|
|
|
|
+{
|
|
|
|
|
+ Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
|
|
|
+ FlipperFormat* ff = flipper_format_file_alloc(storage);
|
|
|
|
|
+
|
|
|
|
|
+ FURI_LOG_I(TAG, "store config file: \'%s\'", XREMOTE_APP_SETTINGS);
|
|
|
|
|
+ bool vertical = settings->orientation == ViewOrientationVertical;
|
|
|
|
|
+ bool success = false;
|
|
|
|
|
+
|
|
|
|
|
+ do {
|
|
|
|
|
+ /* Write header in config file */
|
|
|
|
|
+ if (!flipper_format_file_open_always(ff, XREMOTE_APP_SETTINGS)) break;
|
|
|
|
|
+ if (!flipper_format_write_header_cstr(ff, "XRemote settings file", 1)) break;
|
|
|
|
|
+ if (!flipper_format_write_comment_cstr(ff, "")) break;
|
|
|
|
|
+
|
|
|
|
|
+ /* Write actual configuration to the settings file */
|
|
|
|
|
+ const char *orientation = vertical ? "vertical" : "horizontal";
|
|
|
|
|
+ if (!flipper_format_write_string_cstr(ff, "orientation", orientation)) break;
|
|
|
|
|
+ if (!flipper_format_write_uint32(ff, "cmd_repeat", &settings->repeat_count, 1)) break;
|
|
|
|
|
+
|
|
|
|
|
+ success = true;
|
|
|
|
|
+ } while(false);
|
|
|
|
|
+
|
|
|
|
|
+ furi_record_close(RECORD_STORAGE);
|
|
|
|
|
+ flipper_format_free(ff);
|
|
|
|
|
+
|
|
|
|
|
+ return success;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+bool xremote_app_settings_load(XRemoteAppSettings* settings)
|
|
|
|
|
+{
|
|
|
|
|
+ Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
|
|
|
+ FlipperFormat* ff = flipper_format_buffered_file_alloc(storage);
|
|
|
|
|
+ FuriString* header = furi_string_alloc();
|
|
|
|
|
+ FuriString* orient = furi_string_alloc();
|
|
|
|
|
+
|
|
|
|
|
+ FURI_LOG_I(TAG, "load config file: \'%s\'", XREMOTE_APP_SETTINGS);
|
|
|
|
|
+ uint32_t version = 0;
|
|
|
|
|
+ uint32_t repeat = 0;
|
|
|
|
|
+ bool success = false;
|
|
|
|
|
+
|
|
|
|
|
+ do {
|
|
|
|
|
+ /* Open file and read the header */
|
|
|
|
|
+ if (!flipper_format_buffered_file_open_existing(ff, XREMOTE_APP_SETTINGS)) break;
|
|
|
|
|
+ if (!flipper_format_read_header(ff, header, &version)) break;
|
|
|
|
|
+ if (!furi_string_equal(header, "XRemote settings file") || (version != 1)) break;
|
|
|
|
|
+
|
|
|
|
|
+ /* Read config data from the file */
|
|
|
|
|
+ if (!flipper_format_read_string(ff, "orientation", orient)) break;
|
|
|
|
|
+ if (!flipper_format_read_uint32(ff, "cmd_repeat", &repeat, 1)) break;
|
|
|
|
|
+
|
|
|
|
|
+ /* Parse config data from the buffer */
|
|
|
|
|
+ if (furi_string_equal(orient, "vertical"))
|
|
|
|
|
+ settings->orientation = ViewOrientationVertical;
|
|
|
|
|
+ else if (furi_string_equal(orient, "horizontal"))
|
|
|
|
|
+ settings->orientation = ViewOrientationHorizontal;
|
|
|
|
|
+
|
|
|
|
|
+ settings->repeat_count = repeat;
|
|
|
|
|
+ success = true;
|
|
|
|
|
+ } while(false);
|
|
|
|
|
+
|
|
|
|
|
+ furi_record_close(RECORD_STORAGE);
|
|
|
|
|
+ furi_string_free(orient);
|
|
|
|
|
+ furi_string_free(header);
|
|
|
|
|
+ flipper_format_free(ff);
|
|
|
|
|
+
|
|
|
|
|
+ return success;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
XRemoteAppContext* xremote_app_context_alloc(void *arg)
|
|
XRemoteAppContext* xremote_app_context_alloc(void *arg)
|
|
|
{
|
|
{
|
|
|
XRemoteAppContext* ctx = malloc(sizeof(XRemoteAppContext));
|
|
XRemoteAppContext* ctx = malloc(sizeof(XRemoteAppContext));
|
|
|
|
|
+ ctx->app_argument = arg;
|
|
|
|
|
+
|
|
|
|
|
+ /* Open GUI and norification records */
|
|
|
ctx->gui = furi_record_open(RECORD_GUI);
|
|
ctx->gui = furi_record_open(RECORD_GUI);
|
|
|
ctx->notifications = furi_record_open(RECORD_NOTIFICATION);
|
|
ctx->notifications = furi_record_open(RECORD_NOTIFICATION);
|
|
|
- ctx->view_dispatcher = view_dispatcher_alloc();
|
|
|
|
|
- ctx->arg = arg;
|
|
|
|
|
|
|
|
|
|
|
|
+ /* Allocate and load global app settings */
|
|
|
|
|
+ ctx->app_settings = xremote_app_settings_alloc();
|
|
|
|
|
+ xremote_app_settings_load(ctx->app_settings);
|
|
|
|
|
+
|
|
|
|
|
+ /* Allocate and setup view dispatcher */
|
|
|
|
|
+ ctx->view_dispatcher = view_dispatcher_alloc();
|
|
|
view_dispatcher_enable_queue(ctx->view_dispatcher);
|
|
view_dispatcher_enable_queue(ctx->view_dispatcher);
|
|
|
view_dispatcher_attach_to_gui(ctx->view_dispatcher, ctx->gui, ViewDispatcherTypeFullscreen);
|
|
view_dispatcher_attach_to_gui(ctx->view_dispatcher, ctx->gui, ViewDispatcherTypeFullscreen);
|
|
|
return ctx;
|
|
return ctx;
|
|
@@ -25,6 +119,7 @@ void xremote_app_context_free(XRemoteAppContext* ctx)
|
|
|
{
|
|
{
|
|
|
xremote_app_assert_void(ctx);
|
|
xremote_app_assert_void(ctx);
|
|
|
notification_internal_message(ctx->notifications, &sequence_reset_blue);
|
|
notification_internal_message(ctx->notifications, &sequence_reset_blue);
|
|
|
|
|
+ xremote_app_settings_free(ctx->app_settings);
|
|
|
view_dispatcher_free(ctx->view_dispatcher);
|
|
view_dispatcher_free(ctx->view_dispatcher);
|
|
|
furi_record_close(RECORD_NOTIFICATION);
|
|
furi_record_close(RECORD_NOTIFICATION);
|
|
|
furi_record_close(RECORD_GUI);
|
|
furi_record_close(RECORD_GUI);
|
|
@@ -103,7 +198,8 @@ void xremote_app_submenu_alloc(XRemoteApp* app, uint32_t index, ViewNavigationCa
|
|
|
app->submenu = submenu_alloc();
|
|
app->submenu = submenu_alloc();
|
|
|
app->submenu_id = index;
|
|
app->submenu_id = index;
|
|
|
|
|
|
|
|
- submenu_set_orientation(app->submenu, ViewOrientationVertical);
|
|
|
|
|
|
|
+ XRemoteAppSettings *settings = app->app_ctx->app_settings;
|
|
|
|
|
+ submenu_set_orientation(app->submenu, settings->orientation);
|
|
|
view_set_previous_callback(submenu_get_view(app->submenu), prev_cb);
|
|
view_set_previous_callback(submenu_get_view(app->submenu), prev_cb);
|
|
|
|
|
|
|
|
ViewDispatcher* view_disp = app->app_ctx->view_dispatcher;
|
|
ViewDispatcher* view_disp = app->app_ctx->view_dispatcher;
|