From 2cdc44254523ff501d5c4ec02cac3f241d884664 Mon Sep 17 00:00:00 2001 From: Sandro Kalatozishvili Date: Fri, 29 Sep 2023 16:26:34 +0400 Subject: [PATCH] Implemented settings load and store functionality --- .vscode/settings.json | 3 +- README.md | 4 +- infrared/infrared_signal.c | 19 +++++++- infrared/infrared_signal.h | 5 ++- views/xremote_common_view.h | 4 +- xremote.h | 2 +- xremote_app.c | 86 ++++++++++++++++++++++++++++++++++++- xremote_app.h | 13 ++++++ 8 files changed, 127 insertions(+), 9 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5bae53e..7d32e9f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,6 +7,7 @@ "xremote_app.h": "c", "xremote_saved_view.h": "c", "infrared_remote.h": "c", - "xremote_navigation_view.h": "c" + "xremote_navigation_view.h": "c", + "xremote_settings_view.h": "c" } } \ No newline at end of file diff --git a/README.md b/README.md index 99660e4..1b4031e 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ Button name | Description `Vol_dn` | Volume down `Ch_next` | Next channel `Ch_prev` | Previous channel -`Jump_fo` | Jump forward -`Jump_ba` | Jump backward +`Next` | Jump forward +`Prev` | Jump backward `Fast_fo` | Fast forward `Fast_ba` | Fast backward `Play_pa` | Play/Pause diff --git a/infrared/infrared_signal.c b/infrared/infrared_signal.c index 1bb97b0..a17f34d 100644 --- a/infrared/infrared_signal.c +++ b/infrared/infrared_signal.c @@ -3,7 +3,9 @@ https://github.com/DarkFlippers/unleashed-firmware The original project is licensed under the GNU GPLv3 - No modifications were made to this file. + + Modifications made: + - Added function infrared_signal_transmit_times() */ #include "infrared_signal.h" @@ -321,3 +323,18 @@ void infrared_signal_transmit(InfraredSignal* signal) { infrared_send(message, 1); } } + +void infrared_signal_transmit_times(InfraredSignal* signal, int times) { + if(signal->is_raw) { + InfraredRawSignal* raw_signal = &signal->payload.raw; + infrared_send_raw_ext( + raw_signal->timings, + raw_signal->timings_size, + true, + raw_signal->frequency, + raw_signal->duty_cycle); + } else { + InfraredMessage* message = &signal->payload.message; + infrared_send(message, times); + } +} diff --git a/infrared/infrared_signal.h b/infrared/infrared_signal.h index dd9199d..6a2bfd3 100644 --- a/infrared/infrared_signal.h +++ b/infrared/infrared_signal.h @@ -3,7 +3,9 @@ https://github.com/DarkFlippers/unleashed-firmware The original project is licensed under the GNU GPLv3 - No modifications were made to this file. + + Modifications made: + - Added function infrared_signal_transmit_times() */ #pragma once @@ -51,3 +53,4 @@ bool infrared_signal_search_and_read( const FuriString* name); void infrared_signal_transmit(InfraredSignal* signal); +void infrared_signal_transmit_times(InfraredSignal* signal, int times); \ No newline at end of file diff --git a/views/xremote_common_view.h b/views/xremote_common_view.h index 3ad41ea..33a08fc 100644 --- a/views/xremote_common_view.h +++ b/views/xremote_common_view.h @@ -30,8 +30,8 @@ #define XREMOTE_COMMAND_DOWN "Down" #define XREMOTE_COMMAND_LEFT "Left" #define XREMOTE_COMMAND_RIGHT "Right" -#define XREMOTE_COMMAND_JUMP_FORWARD "Jump_fo" -#define XREMOTE_COMMAND_JUMP_BACKWARD "Jump_ba" +#define XREMOTE_COMMAND_JUMP_FORWARD "Next" +#define XREMOTE_COMMAND_JUMP_BACKWARD "Prev" #define XREMOTE_COMMAND_FAST_FORWARD "Fast_fo" #define XREMOTE_COMMAND_FAST_BACKWARD "Fast_ba" #define XREMOTE_COMMAND_PLAY_PAUSE "Play_pa" diff --git a/xremote.h b/xremote.h index 24eba27..a8dacf6 100644 --- a/xremote.h +++ b/xremote.h @@ -10,6 +10,6 @@ #define XREMOTE_VERSION_MAJOR 0 #define XREMOTE_VERSION_MINOR 9 -#define XREMOTE_BUILD_NUMBER 16 +#define XREMOTE_BUILD_NUMBER 18 void xremote_get_version(char *version, size_t length); \ No newline at end of file diff --git a/xremote_app.c b/xremote_app.c index 11a5060..98d826e 100644 --- a/xremote_app.c +++ b/xremote_app.c @@ -8,12 +8,94 @@ #include "xremote_app.h" +#define XREMOTE_APP_SETTINGS "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 file: \'%s\'", XREMOTE_APP_SETTINGS); + bool success = false; + + do { + if (!flipper_format_file_open_always(ff, XREMOTE_APP_SETTINGS)) break; + if (!flipper_format_write_header_cstr(ff, "XRemote settings file", 1)) break; + + if (settings->orientation == ViewOrientationHorizontal && + !flipper_format_write_string_cstr(ff, "orientation", "horizontal")) break; + else if (settings->orientation == ViewOrientationVertical && + !flipper_format_write_string_cstr(ff, "orientation", "vertical")) break; + + if (!flipper_format_write_uint32(ff, "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 file: \'%s\'", XREMOTE_APP_SETTINGS); + uint32_t version = 0; + uint32_t repeat = 0; + bool success = false; + + do { + 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; + + if (!flipper_format_read_string(ff, "orientation", orient)) break; + if (!flipper_format_read_uint32(ff, "repeat", &repeat, 1)) break; + + 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* ctx = malloc(sizeof(XRemoteAppContext)); ctx->gui = furi_record_open(RECORD_GUI); ctx->notifications = furi_record_open(RECORD_NOTIFICATION); ctx->view_dispatcher = view_dispatcher_alloc(); + ctx->app_settings = xremote_app_settings_alloc(); ctx->arg = arg; view_dispatcher_enable_queue(ctx->view_dispatcher); @@ -25,6 +107,7 @@ void xremote_app_context_free(XRemoteAppContext* ctx) { xremote_app_assert_void(ctx); notification_internal_message(ctx->notifications, &sequence_reset_blue); + xremote_app_settings_free(ctx->app_settings); view_dispatcher_free(ctx->view_dispatcher); furi_record_close(RECORD_NOTIFICATION); furi_record_close(RECORD_GUI); @@ -103,7 +186,8 @@ void xremote_app_submenu_alloc(XRemoteApp* app, uint32_t index, ViewNavigationCa app->submenu = submenu_alloc(); 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); ViewDispatcher* view_disp = app->app_ctx->view_dispatcher; diff --git a/xremote_app.h b/xremote_app.h index 1cb446e..98442aa 100644 --- a/xremote_app.h +++ b/xremote_app.h @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -28,6 +29,15 @@ #define xremote_app_assert(cond, var) if (!cond) return var typedef struct { + ViewOrientation orientation; + uint32_t repeat_count; +} XRemoteAppSettings; + +XRemoteAppSettings* xremote_app_settings_alloc(); +void xremote_app_settings_free(XRemoteAppSettings* settings); + +typedef struct { + XRemoteAppSettings* app_settings; NotificationApp* notifications; ViewDispatcher* view_dispatcher; Gui* gui; @@ -37,6 +47,9 @@ typedef struct { XRemoteAppContext* xremote_app_context_alloc(void* arg); void xremote_app_context_free(XRemoteAppContext* ctx); +bool xremote_app_settings_store(XRemoteAppSettings* settings); +bool xremote_app_settings_load(XRemoteAppSettings* settings); + typedef XRemoteView* (*XRemoteViewAllocator)(NotificationApp* notifications); typedef void (*XRemoteAppClearCallback)(void *context);