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

Merge quac from https://github.com/rdefeo/quac

Willy-JL 1 год назад
Родитель
Сommit
99bf0a5581
3 измененных файлов с 62 добавлено и 32 удалено
  1. 1 0
      quac/.gitignore
  2. 1 0
      quac/quac.h
  3. 60 32
      quac/scenes/scene_action_ir_list.c

+ 1 - 0
quac/.gitignore

@@ -1,6 +1,7 @@
 dist/*
 dist/*
 .vscode
 .vscode
 .clang-format
 .clang-format
+.clangd
 .editorconfig
 .editorconfig
 .env
 .env
 .ufbt
 .ufbt

+ 1 - 0
quac/quac.h

@@ -52,6 +52,7 @@ typedef struct App {
 
 
     FuriString* temp_str; // used for renames/etc
     FuriString* temp_str; // used for renames/etc
     char temp_cstr[MAX_NAME_LEN]; // used for renames/etc
     char temp_cstr[MAX_NAME_LEN]; // used for renames/etc
+    uint32_t temp_u32;
 
 
     struct {
     struct {
         QuacAppLayout layout; // Defaults to Portrait
         QuacAppLayout layout; // Defaults to Portrait

+ 60 - 32
quac/scenes/scene_action_ir_list.c

@@ -27,10 +27,14 @@ void scene_action_ir_list_on_enter(void* context) {
     // Our selected IR File is app->temp_str
     // Our selected IR File is app->temp_str
     submenu_set_header(menu, "Select IR Command");
     submenu_set_header(menu, "Select IR Command");
 
 
+    uint32_t index = 0;
+
+    // Add an entry for IMPORT ALL
+    submenu_add_item(menu, "* IMPORT ALL *", index++, scene_action_ir_list_callback, app);
+
     // read the IR file and load the names of all of the commands
     // read the IR file and load the names of all of the commands
     FuriString* name = furi_string_alloc();
     FuriString* name = furi_string_alloc();
 
 
-    uint32_t index = 0;
     FlipperFormat* fff_data_file = flipper_format_file_alloc(app->storage);
     FlipperFormat* fff_data_file = flipper_format_file_alloc(app->storage);
     if(flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(app->temp_str))) {
     if(flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(app->temp_str))) {
         while(flipper_format_read_string(fff_data_file, "name", name)) {
         while(flipper_format_read_string(fff_data_file, "name", name)) {
@@ -40,8 +44,11 @@ void scene_action_ir_list_on_enter(void* context) {
         }
         }
     }
     }
 
 
-    if(index == 0) {
-        FURI_LOG_E(TAG, "Failed to get commands from %s", furi_string_get_cstr(app->temp_str));
+    // Number of IR Commands in file
+    app->temp_u32 = index - 1;
+    if(app->temp_u32 == 0) {
+        FURI_LOG_E(TAG, "Failed to get ANY commands from %s", furi_string_get_cstr(app->temp_str));
+        submenu_change_item_label(menu, 0, "No IR cmds!");
     }
     }
 
 
     flipper_format_file_close(fff_data_file);
     flipper_format_file_close(fff_data_file);
@@ -66,42 +73,63 @@ bool scene_action_ir_list_on_event(void* context, SceneManagerEvent event) {
         FuriString* file_name = furi_string_alloc(); // new IR file name
         FuriString* file_name = furi_string_alloc(); // new IR file name
 
 
         do {
         do {
-            if(!flipper_format_file_open_existing(
-                   fff_data_file, furi_string_get_cstr(app->temp_str))) {
-                FURI_LOG_E(TAG, "Failed to open %s", furi_string_get_cstr(app->temp_str));
-                break;
+            uint32_t num_imported = 0;
+            uint32_t start = index - 1;
+            uint32_t end = index;
+            if(index == 0) {
+                start = 0;
+                end = app->temp_u32; // Number of IR Commands in file
             }
             }
-            if(!infrared_utils_read_signal_at_index(fff_data_file, index, signal, name)) {
-                FURI_LOG_E(TAG, "Failed to read signal at %lu", index);
-                break;
+            for(uint32_t ir_index = start; ir_index < end; ir_index++) {
+                if(!flipper_format_file_open_existing(
+                       fff_data_file, furi_string_get_cstr(app->temp_str))) {
+                    FURI_LOG_E(TAG, "Failed to open %s", furi_string_get_cstr(app->temp_str));
+                    break;
+                }
+
+                if(!infrared_utils_read_signal_at_index(fff_data_file, ir_index, signal, name)) {
+                    FURI_LOG_E(TAG, "Failed to read signal at %lu", index);
+                    break;
+                }
+                FURI_LOG_I(TAG, "Read IR signal: %s", furi_string_get_cstr(name));
+                flipper_format_file_close(fff_data_file);
+
+                // generate the new path, based on current item's dir and new command name
+                if(app->selected_item != EMPTY_ACTION_INDEX) {
+                    Item* item = ItemArray_get(app->items_view->items, app->selected_item);
+                    path_extract_dirname(furi_string_get_cstr(item->path), file_name);
+                } else {
+                    furi_string_set(file_name, app->items_view->path);
+                }
+                furi_string_cat_printf(file_name, "/%s.ir", furi_string_get_cstr(name));
+
+                FURI_LOG_I(TAG, "Writing new IR file: %s", furi_string_get_cstr(file_name));
+                if(!flipper_format_file_open_new(fff_data_file, furi_string_get_cstr(file_name))) {
+                    FURI_LOG_E(
+                        TAG, "Error creating new file: %s", furi_string_get_cstr(file_name));
+                    break;
+                }
+                if(!infrared_utils_write_signal(fff_data_file, signal, name)) {
+                    FURI_LOG_E(TAG, "Failed to write signal!");
+                    break;
+                }
+                flipper_format_file_close(fff_data_file);
+                FURI_LOG_I(TAG, "Imported %s", furi_string_get_cstr(name));
+                num_imported++;
             }
             }
-            FURI_LOG_I(TAG, "Read IR signal: %s", furi_string_get_cstr(name));
-            flipper_format_file_close(fff_data_file);
 
 
-            // generate the new path, based on current item's dir and new command name
-            if(app->selected_item != EMPTY_ACTION_INDEX) {
-                Item* item = ItemArray_get(app->items_view->items, app->selected_item);
-                path_extract_dirname(furi_string_get_cstr(item->path), file_name);
+            if(num_imported == (end - start)) {
+                // Import successful!
+                notification_message(app->notifications, &sequence_success);
             } else {
             } else {
-                furi_string_set(file_name, app->items_view->path);
+                FURI_LOG_E(
+                    TAG,
+                    "Error importing IR command(s) from %s",
+                    furi_string_get_cstr(app->temp_str));
+                notification_message(app->notifications, &sequence_error);
             }
             }
-            furi_string_cat_printf(file_name, "/%s.ir", furi_string_get_cstr(name));
-
-            FURI_LOG_I(TAG, "Writing new IR file: %s", furi_string_get_cstr(file_name));
-            if(!flipper_format_file_open_new(fff_data_file, furi_string_get_cstr(file_name))) {
-                FURI_LOG_E(TAG, "Error creating new file: %s", furi_string_get_cstr(file_name));
-                break;
-            }
-            if(!infrared_utils_write_signal(fff_data_file, signal, name)) {
-                FURI_LOG_E(TAG, "Failed to write signal!");
-                break;
-            }
-
-            // Import successful!
             // Leave the user on this scene, in case they want to import
             // Leave the user on this scene, in case they want to import
             // more commands from this IR file
             // more commands from this IR file
-            notification_message(app->notifications, &sequence_success);
-
         } while(false);
         } while(false);
 
 
         // cleanup
         // cleanup