Просмотр исходного кода

Merge pull request #1 from kala13x/settings

Allocate application settings and load from the file
Sandro Kalatozishvili 2 лет назад
Родитель
Сommit
958af1d9a9
10 измененных файлов с 144 добавлено и 14 удалено
  1. 2 1
      .vscode/settings.json
  2. 2 2
      README.md
  3. 18 1
      infrared/infrared_signal.c
  4. 4 1
      infrared/infrared_signal.h
  5. 2 2
      views/xremote_common_view.h
  6. 1 1
      xremote.h
  7. 99 3
      xremote_app.c
  8. 14 1
      xremote_app.h
  9. 1 1
      xremote_settings.c
  10. 1 1
      xremote_settings.h

+ 2 - 1
.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"
     }
 }

+ 2 - 2
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

+ 18 - 1
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);
+    }
+}

+ 4 - 1
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);

+ 2 - 2
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"

+ 1 - 1
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);

+ 99 - 3
xremote_app.c

@@ -8,14 +8,108 @@
 
 #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* ctx = malloc(sizeof(XRemoteAppContext));
+    ctx->app_argument = arg;
+
+    /* Open GUI and norification records */
     ctx->gui = furi_record_open(RECORD_GUI);
     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_attach_to_gui(ctx->view_dispatcher, ctx->gui, ViewDispatcherTypeFullscreen);
     return ctx;
@@ -25,6 +119,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 +198,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;

+ 14 - 1
xremote_app.h

@@ -18,6 +18,7 @@
 #include <notification/notification.h>
 #include <notification/notification_messages.h>
 
+#include <flipper_format/flipper_format.h>
 #include <storage/storage.h>
 #include <dialogs/dialogs.h>
 
@@ -28,15 +29,27 @@
 #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;
+    void* app_argument;
     Gui* gui;
-    void* arg;
 } XRemoteAppContext;
 
 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);
 

+ 1 - 1
xremote_settings.c

@@ -3,7 +3,7 @@
     @license This project is released under the GNU GPLv3 License
  *  @copyright (c) 2023 Sandro Kalatozishvili (s.kalatoz@gmail.com)
  *
- * @brief Remote controller application menu and view factory.
+ * @brief XRemote settins functionality and menu.
  */
 
 #include "xremote_settings.h"

+ 1 - 1
xremote_settings.h

@@ -3,7 +3,7 @@
     @license This project is released under the GNU GPLv3 License
  *  @copyright (c) 2023 Sandro Kalatozishvili (s.kalatoz@gmail.com)
  *
- * @brief Settings application menu and view factory.
+ * @brief XRemote settins functionality and menu.
  */
 
 #pragma once