@@ -27,10 +27,14 @@ void scene_action_ir_list_on_enter(void* context) {
27
27
// Our selected IR File is app->temp_str
28
28
submenu_set_header (menu , "Select IR Command" );
29
29
30
+ uint32_t index = 0 ;
31
+
32
+ // Add an entry for IMPORT ALL
33
+ submenu_add_item (menu , "* IMPORT ALL *" , index ++ , scene_action_ir_list_callback , app );
34
+
30
35
// read the IR file and load the names of all of the commands
31
36
FuriString * name = furi_string_alloc ();
32
37
33
- uint32_t index = 0 ;
34
38
FlipperFormat * fff_data_file = flipper_format_file_alloc (app -> storage );
35
39
if (flipper_format_file_open_existing (fff_data_file , furi_string_get_cstr (app -> temp_str ))) {
36
40
while (flipper_format_read_string (fff_data_file , "name" , name )) {
@@ -40,8 +44,11 @@ void scene_action_ir_list_on_enter(void* context) {
40
44
}
41
45
}
42
46
43
- if (index == 0 ) {
44
- FURI_LOG_E (TAG , "Failed to get commands from %s" , furi_string_get_cstr (app -> temp_str ));
47
+ // Number of IR Commands in file
48
+ app -> temp_u32 = index - 1 ;
49
+ if (app -> temp_u32 == 0 ) {
50
+ FURI_LOG_E (TAG , "Failed to get ANY commands from %s" , furi_string_get_cstr (app -> temp_str ));
51
+ submenu_change_item_label (menu , 0 , "No IR cmds!" );
45
52
}
46
53
47
54
flipper_format_file_close (fff_data_file );
@@ -66,42 +73,63 @@ bool scene_action_ir_list_on_event(void* context, SceneManagerEvent event) {
66
73
FuriString * file_name = furi_string_alloc (); // new IR file name
67
74
68
75
do {
69
- if (!flipper_format_file_open_existing (
70
- fff_data_file , furi_string_get_cstr (app -> temp_str ))) {
71
- FURI_LOG_E (TAG , "Failed to open %s" , furi_string_get_cstr (app -> temp_str ));
72
- break ;
76
+ uint32_t num_imported = 0 ;
77
+ uint32_t start = index - 1 ;
78
+ uint32_t end = index ;
79
+ if (index == 0 ) {
80
+ start = 0 ;
81
+ end = app -> temp_u32 ; // Number of IR Commands in file
73
82
}
74
- if (!infrared_utils_read_signal_at_index (fff_data_file , index , signal , name )) {
75
- FURI_LOG_E (TAG , "Failed to read signal at %lu" , index );
76
- break ;
83
+ for (uint32_t ir_index = start ; ir_index < end ; ir_index ++ ) {
84
+ if (!flipper_format_file_open_existing (
85
+ fff_data_file , furi_string_get_cstr (app -> temp_str ))) {
86
+ FURI_LOG_E (TAG , "Failed to open %s" , furi_string_get_cstr (app -> temp_str ));
87
+ break ;
88
+ }
89
+
90
+ if (!infrared_utils_read_signal_at_index (fff_data_file , ir_index , signal , name )) {
91
+ FURI_LOG_E (TAG , "Failed to read signal at %lu" , index );
92
+ break ;
93
+ }
94
+ FURI_LOG_I (TAG , "Read IR signal: %s" , furi_string_get_cstr (name ));
95
+ flipper_format_file_close (fff_data_file );
96
+
97
+ // generate the new path, based on current item's dir and new command name
98
+ if (app -> selected_item != EMPTY_ACTION_INDEX ) {
99
+ Item * item = ItemArray_get (app -> items_view -> items , app -> selected_item );
100
+ path_extract_dirname (furi_string_get_cstr (item -> path ), file_name );
101
+ } else {
102
+ furi_string_set (file_name , app -> items_view -> path );
103
+ }
104
+ furi_string_cat_printf (file_name , "/%s.ir" , furi_string_get_cstr (name ));
105
+
106
+ FURI_LOG_I (TAG , "Writing new IR file: %s" , furi_string_get_cstr (file_name ));
107
+ if (!flipper_format_file_open_new (fff_data_file , furi_string_get_cstr (file_name ))) {
108
+ FURI_LOG_E (
109
+ TAG , "Error creating new file: %s" , furi_string_get_cstr (file_name ));
110
+ break ;
111
+ }
112
+ if (!infrared_utils_write_signal (fff_data_file , signal , name )) {
113
+ FURI_LOG_E (TAG , "Failed to write signal!" );
114
+ break ;
115
+ }
116
+ flipper_format_file_close (fff_data_file );
117
+ FURI_LOG_I (TAG , "Imported %s" , furi_string_get_cstr (name ));
118
+ num_imported ++ ;
77
119
}
78
- FURI_LOG_I (TAG , "Read IR signal: %s" , furi_string_get_cstr (name ));
79
- flipper_format_file_close (fff_data_file );
80
120
81
- // generate the new path, based on current item's dir and new command name
82
- if (app -> selected_item != EMPTY_ACTION_INDEX ) {
83
- Item * item = ItemArray_get (app -> items_view -> items , app -> selected_item );
84
- path_extract_dirname (furi_string_get_cstr (item -> path ), file_name );
121
+ if (num_imported == (end - start )) {
122
+ // Import successful!
123
+ notification_message (app -> notifications , & sequence_success );
85
124
} else {
86
- furi_string_set (file_name , app -> items_view -> path );
125
+ FURI_LOG_E (
126
+ TAG ,
127
+ "Error importing IR command(s) from %s" ,
128
+ furi_string_get_cstr (app -> temp_str ));
129
+ notification_message (app -> notifications , & sequence_error );
87
130
}
88
- furi_string_cat_printf (file_name , "/%s.ir" , furi_string_get_cstr (name ));
89
-
90
- FURI_LOG_I (TAG , "Writing new IR file: %s" , furi_string_get_cstr (file_name ));
91
- if (!flipper_format_file_open_new (fff_data_file , furi_string_get_cstr (file_name ))) {
92
- FURI_LOG_E (TAG , "Error creating new file: %s" , furi_string_get_cstr (file_name ));
93
- break ;
94
- }
95
- if (!infrared_utils_write_signal (fff_data_file , signal , name )) {
96
- FURI_LOG_E (TAG , "Failed to write signal!" );
97
- break ;
98
- }
99
-
100
- // Import successful!
101
131
// Leave the user on this scene, in case they want to import
102
132
// more commands from this IR file
103
- notification_message (app -> notifications , & sequence_success );
104
-
105
133
} while (false);
106
134
107
135
// cleanup
0 commit comments