Skip to content

Commit 2fe1ce7

Browse files
authored
Merge pull request #11 from rdefeo/ir_all
Add Import All for IR files
2 parents 91dfcbd + 6f79e18 commit 2fe1ce7

File tree

3 files changed

+69
-36
lines changed

3 files changed

+69
-36
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
dist/*
22
.vscode
33
.clang-format
4+
.clangd
45
.editorconfig
56
.env
67
.ufbt

quac.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "views/action_menu.h"
1717
#include "item.h"
1818

19-
#define QUAC_NAME "Quac!"
19+
#define QUAC_NAME "Quac!"
2020
#define QUAC_VERSION "v0.6.3"
2121
#define QUAC_ABOUT \
2222
"Quick Action remote control\n" QUAC_VERSION "\n" \
@@ -25,9 +25,12 @@
2525

2626
// Location of our actions and folders
2727
#define QUAC_SETTINGS_FILENAME ".quac.conf"
28-
#define QUAC_SETTINGS_PATH APP_DATA_PATH(QUAC_SETTINGS_FILENAME)
28+
#define QUAC_SETTINGS_PATH APP_DATA_PATH(QUAC_SETTINGS_FILENAME)
2929

30-
typedef enum { QUAC_APP_PORTRAIT, QUAC_APP_LANDSCAPE } QuacAppLayout;
30+
typedef enum {
31+
QUAC_APP_PORTRAIT,
32+
QUAC_APP_LANDSCAPE
33+
} QuacAppLayout;
3134

3235
typedef struct App {
3336
SceneManager* scene_manager;
@@ -49,6 +52,7 @@ typedef struct App {
4952

5053
FuriString* temp_str; // used for renames/etc
5154
char temp_cstr[MAX_NAME_LEN]; // used for renames/etc
55+
uint32_t temp_u32;
5256

5357
struct {
5458
QuacAppLayout layout; // Defaults to Portrait
@@ -65,4 +69,4 @@ typedef struct App {
6569
} App;
6670

6771
App* app_alloc();
68-
void app_free(App* app);
72+
void app_free(App* app);

scenes/scene_action_ir_list.c

+60-32
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ void scene_action_ir_list_on_enter(void* context) {
2727
// Our selected IR File is app->temp_str
2828
submenu_set_header(menu, "Select IR Command");
2929

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+
3035
// read the IR file and load the names of all of the commands
3136
FuriString* name = furi_string_alloc();
3237

33-
uint32_t index = 0;
3438
FlipperFormat* fff_data_file = flipper_format_file_alloc(app->storage);
3539
if(flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(app->temp_str))) {
3640
while(flipper_format_read_string(fff_data_file, "name", name)) {
@@ -40,8 +44,11 @@ void scene_action_ir_list_on_enter(void* context) {
4044
}
4145
}
4246

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!");
4552
}
4653

4754
flipper_format_file_close(fff_data_file);
@@ -66,42 +73,63 @@ bool scene_action_ir_list_on_event(void* context, SceneManagerEvent event) {
6673
FuriString* file_name = furi_string_alloc(); // new IR file name
6774

6875
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
7382
}
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++;
77119
}
78-
FURI_LOG_I(TAG, "Read IR signal: %s", furi_string_get_cstr(name));
79-
flipper_format_file_close(fff_data_file);
80120

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);
85124
} 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);
87130
}
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!
101131
// Leave the user on this scene, in case they want to import
102132
// more commands from this IR file
103-
notification_message(app->notifications, &sequence_success);
104-
105133
} while(false);
106134

107135
// cleanup

0 commit comments

Comments
 (0)