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

Merge pull request #26 from miccayo/main

Add 'Loop Transmit' setting, repeats transmission of commands indefinitely
David Lee 1 год назад
Родитель
Сommit
437dc950e6
7 измененных файлов с 80 добавлено и 21 удалено
  1. 9 0
      .gitignore
  2. 2 0
      helpers/xremote_storage.c
  3. 1 0
      helpers/xremote_storage.h
  4. 23 2
      scenes/xremote_scene_settings.c
  5. 37 18
      scenes/xremote_scene_transmit.c
  6. 2 1
      xremote.c
  7. 6 0
      xremote.h

+ 9 - 0
.gitignore

@@ -0,0 +1,9 @@
+dist/*
+.vscode
+.clang-format
+.clangd
+.editorconfig
+.env
+.ufbt
+.clang-format
+.vscode/settings.json

+ 2 - 0
helpers/xremote_storage.c

@@ -59,6 +59,7 @@ void xremote_save_settings(void* context) {
         fff_file, XREMOTE_SETTINGS_KEY_SAVE_SETTINGS, &app->save_settings, 1);
         fff_file, XREMOTE_SETTINGS_KEY_SAVE_SETTINGS, &app->save_settings, 1);
     flipper_format_write_uint32(fff_file, XREMOTE_SETTINGS_KEY_IR_TIMING, &app->ir_timing, 1);
     flipper_format_write_uint32(fff_file, XREMOTE_SETTINGS_KEY_IR_TIMING, &app->ir_timing, 1);
     flipper_format_write_uint32(fff_file, XREMOTE_SETTINGS_KEY_SG_TIMING, &app->sg_timing, 1);
     flipper_format_write_uint32(fff_file, XREMOTE_SETTINGS_KEY_SG_TIMING, &app->sg_timing, 1);
+    flipper_format_write_uint32(fff_file, XREMOTE_SETTINGS_KEY_LOOP_TRANSMIT, &app->loop_transmit, 1);
 
 
     if(!flipper_format_rewind(fff_file)) {
     if(!flipper_format_rewind(fff_file)) {
         xremote_close_config_file(fff_file);
         xremote_close_config_file(fff_file);
@@ -112,6 +113,7 @@ void xremote_read_settings(void* context) {
         fff_file, XREMOTE_SETTINGS_KEY_SAVE_SETTINGS, &app->save_settings, 1);
         fff_file, XREMOTE_SETTINGS_KEY_SAVE_SETTINGS, &app->save_settings, 1);
     flipper_format_read_uint32(fff_file, XREMOTE_SETTINGS_KEY_IR_TIMING, &app->ir_timing, 1);
     flipper_format_read_uint32(fff_file, XREMOTE_SETTINGS_KEY_IR_TIMING, &app->ir_timing, 1);
     flipper_format_read_uint32(fff_file, XREMOTE_SETTINGS_KEY_SG_TIMING, &app->sg_timing, 1);
     flipper_format_read_uint32(fff_file, XREMOTE_SETTINGS_KEY_SG_TIMING, &app->sg_timing, 1);
+    flipper_format_read_uint32(fff_file, XREMOTE_SETTINGS_KEY_LOOP_TRANSMIT, &app->loop_transmit, 1);
 
 
     flipper_format_rewind(fff_file);
     flipper_format_rewind(fff_file);
 
 

+ 1 - 0
helpers/xremote_storage.h

@@ -13,6 +13,7 @@
 #define XREMOTE_SETTINGS_KEY_SAVE_SETTINGS "SaveSettings"
 #define XREMOTE_SETTINGS_KEY_SAVE_SETTINGS "SaveSettings"
 #define XREMOTE_SETTINGS_KEY_IR_TIMING "IRTiming"
 #define XREMOTE_SETTINGS_KEY_IR_TIMING "IRTiming"
 #define XREMOTE_SETTINGS_KEY_SG_TIMING "SGTiming"
 #define XREMOTE_SETTINGS_KEY_SG_TIMING "SGTiming"
+#define XREMOTE_SETTINGS_KEY_LOOP_TRANSMIT "LoopTransmit"
 
 
 void xremote_save_settings(void* context);
 void xremote_save_settings(void* context);
 void xremote_read_settings(void* context);
 void xremote_read_settings(void* context);

+ 23 - 2
scenes/xremote_scene_settings.c

@@ -33,7 +33,14 @@ const uint32_t led_value[2] = {
     XRemoteLedOff,
     XRemoteLedOff,
     XRemoteLedOn,
     XRemoteLedOn,
 };
 };
-
+const char* const loop_text[2] = {
+    "OFF",
+    "ON",
+};
+const uint32_t loop_value[2] = {
+    XRemoteLoopOff,
+    XRemoteLoopOn,
+};
 const char* const settings_text[2] = {
 const char* const settings_text[2] = {
     "OFF",
     "OFF",
     "ON",
     "ON",
@@ -72,6 +79,13 @@ static void xremote_scene_settings_set_save_settings(VariableItem* item) {
     app->save_settings = settings_value[index];
     app->save_settings = settings_value[index];
 }
 }
 
 
+static void xremote_scene_settings_set_loop(VariableItem* item) {
+    XRemote* app = variable_item_get_context(item);
+    uint8_t index = variable_item_get_current_value_index(item);
+    variable_item_set_current_value_text(item, loop_text[index]);
+    app->loop_transmit = loop_value[index];
+}
+
 static void xremote_scene_settings_set_ir_timing(VariableItem* item) {
 static void xremote_scene_settings_set_ir_timing(VariableItem* item) {
     XRemote* app = variable_item_get_context(item);
     XRemote* app = variable_item_get_context(item);
     uint32_t index = variable_item_get_current_value_index(item);
     uint32_t index = variable_item_get_current_value_index(item);
@@ -116,11 +130,18 @@ void xremote_scene_settings_on_enter(void* context) {
 
 
     // LED Effects on/off
     // LED Effects on/off
     item = variable_item_list_add(
     item = variable_item_list_add(
-        app->variable_item_list, "LED FX:", 2, xremote_scene_settings_set_led, app);
+        app->variable_item_list, "LED FX", 2, xremote_scene_settings_set_led, app);
     value_index = value_index_uint32(app->led, led_value, 2);
     value_index = value_index_uint32(app->led, led_value, 2);
     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, led_text[value_index]);
     variable_item_set_current_value_text(item, led_text[value_index]);
 
 
+    /* NEW: Loop saved command functionality */
+    item = variable_item_list_add(
+        app->variable_item_list, "Loop Transmit", 2, xremote_scene_settings_set_loop, app);
+    value_index = value_index_uint32(app->loop_transmit, loop_value, 2);
+    variable_item_set_current_value_index(item, value_index);
+    variable_item_set_current_value_text(item, loop_text[value_index]);
+
     // Save Settings to File
     // Save Settings to File
     item = variable_item_list_add(
     item = variable_item_list_add(
         app->variable_item_list, "Save Settings", 2, xremote_scene_settings_set_save_settings, app);
         app->variable_item_list, "Save Settings", 2, xremote_scene_settings_set_save_settings, app);

+ 37 - 18
scenes/xremote_scene_transmit.c

@@ -120,29 +120,48 @@ void xremote_scene_transmit_run_remote(void* context) {
     CrossRemote* remote = app->cross_remote;
     CrossRemote* remote = app->cross_remote;
 
 
     size_t item_count = xremote_cross_remote_get_item_count(remote);
     size_t item_count = xremote_cross_remote_get_item_count(remote);
-    for(size_t i = 0; i < item_count;) {
-        if(xremote_cross_remote_get_transmitting(remote) == XRemoteTransmittingIdle) {
-            xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingStart);
-            CrossRemoteItem* item = xremote_cross_remote_get_item(remote, i);
-            xremote_scene_transmit_send_signal(app, item);
-            //furi_thread_flags_wait(0, FuriFlagWaitAny, 1000);
-        } else if(xremote_cross_remote_get_transmitting(remote) == XRemoteTransmittingStopSubghz) {
-            i++;
-            app->state_notifications = SubGhzNotificationStateIDLE;
-            app->transmitting = false;
-            subghz_txrx_stop(app->subghz->txrx);
-            xremote_scene_ir_notification_message(app, SubGhzNotificationMessageBlinkStop);
-            xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingIdle);
-            //furi_thread_flags_wait(0, FuriFlagWaitAny, 1000);
-        } else if(xremote_cross_remote_get_transmitting(remote) == XRemoteTransmittingStop) {
-            i++;
-            xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingIdle);
+    if (app->loop_transmit) {
+        while (true) {
+            for (size_t i = 0; i < item_count;) {
+                if (xremote_cross_remote_get_transmitting(remote) == XRemoteTransmittingIdle) {
+                    xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingStart);
+                    CrossRemoteItem* item = xremote_cross_remote_get_item(remote, i);
+                    xremote_scene_transmit_send_signal(app, item);
+                } else if (xremote_cross_remote_get_transmitting(remote) == XRemoteTransmittingStopSubghz) {
+                    i++;
+                    app->state_notifications = SubGhzNotificationStateIDLE;
+                    app->transmitting = false;
+                    subghz_txrx_stop(app->subghz->txrx);
+                    xremote_scene_ir_notification_message(app, SubGhzNotificationMessageBlinkStop);
+                    xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingIdle);
+                } else if (xremote_cross_remote_get_transmitting(remote) == XRemoteTransmittingStop) {
+                    i++;
+                    xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingIdle);
+                }
+            }
         }
         }
+    } else {
+        for (size_t i = 0; i < item_count;) {
+                if (xremote_cross_remote_get_transmitting(remote) == XRemoteTransmittingIdle) {
+                    xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingStart);
+                    CrossRemoteItem* item = xremote_cross_remote_get_item(remote, i);
+                    xremote_scene_transmit_send_signal(app, item);
+                } else if (xremote_cross_remote_get_transmitting(remote) == XRemoteTransmittingStopSubghz) {
+                    i++;
+                    app->state_notifications = SubGhzNotificationStateIDLE;
+                    app->transmitting = false;
+                    subghz_txrx_stop(app->subghz->txrx);
+                    xremote_scene_ir_notification_message(app, SubGhzNotificationMessageBlinkStop);
+                    xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingIdle);
+                } else if (xremote_cross_remote_get_transmitting(remote) == XRemoteTransmittingStop) {
+                    i++;
+                    xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingIdle);
+                }
+            }
     }
     }
     xremote_scene_ir_notification_message(app, InfraredNotificationMessageBlinkStop);
     xremote_scene_ir_notification_message(app, InfraredNotificationMessageBlinkStop);
 
 
     scene_manager_previous_scene(app->scene_manager);
     scene_manager_previous_scene(app->scene_manager);
-    //xremote_transmit_model_set_name(app->xremote_transmit, xremote_cross_remote_get_name(remote));
 }
 }
 
 
 void xremote_scene_transmit_on_enter(void* context) {
 void xremote_scene_transmit_on_enter(void* context) {

+ 2 - 1
xremote.c

@@ -29,7 +29,7 @@ XRemote* xremote_app_alloc() {
 
 
     //Scene additions
     //Scene additions
     app->view_dispatcher = view_dispatcher_alloc();
     app->view_dispatcher = view_dispatcher_alloc();
-    
+
     app->scene_manager = scene_manager_alloc(&xremote_scene_handlers, app);
     app->scene_manager = scene_manager_alloc(&xremote_scene_handlers, app);
     view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
     view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
     view_dispatcher_set_navigation_event_callback(
     view_dispatcher_set_navigation_event_callback(
@@ -51,6 +51,7 @@ XRemote* xremote_app_alloc() {
     app->sg_timing = 500;
     app->sg_timing = 500;
     app->sg_timing_char = "500";
     app->sg_timing_char = "500";
     app->stop_transmit = false;
     app->stop_transmit = false;
+    app->loop_transmit = 0;
 
 
     // Load configs
     // Load configs
     xremote_read_settings(app);
     xremote_read_settings(app);

+ 6 - 0
xremote.h

@@ -42,6 +42,7 @@ typedef struct {
     uint32_t speaker;
     uint32_t speaker;
     uint32_t led;
     uint32_t led;
     uint32_t save_settings;
     uint32_t save_settings;
+    uint32_t loop_transmit;
     uint32_t edit_item;
     uint32_t edit_item;
     uint32_t ir_timing;
     uint32_t ir_timing;
     char* ir_timing_char;
     char* ir_timing_char;
@@ -85,6 +86,11 @@ typedef enum {
     XRemoteLedOn,
     XRemoteLedOn,
 } XRemoteLedState;
 } XRemoteLedState;
 
 
+typedef enum {
+    XRemoteLoopOff,
+    XRemoteLoopOn,
+} XRemoteLoopState;
+
 typedef enum {
 typedef enum {
     XRemoteSettingsOff,
     XRemoteSettingsOff,
     XRemoteSettingsOn,
     XRemoteSettingsOn,