Skip to content

Commit 8fc3140

Browse files
authored
Merge pull request #124 from ESurge/unleashed
UniRFRemix - Cleaned up error checking + Bug fix
2 parents 235af1a + f291c95 commit 8fc3140

File tree

1 file changed

+87
-130
lines changed

1 file changed

+87
-130
lines changed

applications/main/unirfremix/unirfremix_app.c

+87-130
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ typedef struct {
8989

9090
int file_result;
9191
bool tx_not_allowed;
92-
int file_blank;
9392

9493
FuriString* signal;
9594
} UniRFRemix;
@@ -168,14 +167,13 @@ void unirfremix_cfg_set_check(UniRFRemix* app, FuriString* file_name) {
168167
Storage* storage = furi_record_open(RECORD_STORAGE);
169168
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
170169

171-
app->file_result = 3;
172-
app->file_blank = 0;
170+
app->file_result = 1;
173171

174-
app->up_enabled = 1;
175-
app->down_enabled = 1;
176-
app->left_enabled = 1;
177-
app->right_enabled = 1;
178-
app->ok_enabled = 1;
172+
app->up_enabled = 0;
173+
app->down_enabled = 0;
174+
app->left_enabled = 0;
175+
app->right_enabled = 0;
176+
app->ok_enabled = 0;
179177

180178
int label_len = 16;
181179

@@ -189,61 +187,55 @@ void unirfremix_cfg_set_check(UniRFRemix* app, FuriString* file_name) {
189187
//set missing filenames to N/A
190188
if(!flipper_format_read_string(fff_data_file, "UP", app->up_file)) {
191189
FURI_LOG_W(TAG, "Could not read UP string");
192-
//increment file_blank for processing later
193-
app->file_blank++;
194190
//set label to "N/A"
195191
app->up_label = "N/A";
196-
//disable the ability to process the signal on button press
197-
app->up_enabled = 0;
198192
} else {
199193
//check name length for proper screen fit
200194
//then set filename as label. Might be replaced with defined label later on below.
201195
app->up_label = extract_filename(furi_string_get_cstr(app->up_file), label_len);
202196
FURI_LOG_I(TAG, "UP file: %s", furi_string_get_cstr(app->up_file));
197+
//enable processing of the signal on button press
198+
app->up_enabled = 1;
203199
}
204200

205201
//Repeat process for Down
206202
if(!flipper_format_read_string(fff_data_file, "DOWN", app->down_file)) {
207203
FURI_LOG_W(TAG, "Could not read DOWN string");
208-
app->file_blank++;
209204
app->down_label = "N/A";
210-
app->down_enabled = 0;
211205
} else {
212206
app->down_label = extract_filename(furi_string_get_cstr(app->down_file), label_len);
213207
FURI_LOG_I(TAG, "DOWN file: %s", furi_string_get_cstr(app->down_file));
208+
app->down_enabled = 1;
214209
}
215210

216211
//Repeat process for Left
217212
if(!flipper_format_read_string(fff_data_file, "LEFT", app->left_file)) {
218213
FURI_LOG_W(TAG, "Could not read LEFT string");
219-
app->file_blank++;
220214
app->left_label = "N/A";
221-
app->left_enabled = 0;
222215
} else {
223216
app->left_label = extract_filename(furi_string_get_cstr(app->left_file), label_len);
224217
FURI_LOG_I(TAG, "LEFT file: %s", furi_string_get_cstr(app->left_file));
218+
app->left_enabled = 1;
225219
}
226220

227221
//Repeat process for Right
228222
if(!flipper_format_read_string(fff_data_file, "RIGHT", app->right_file)) {
229223
FURI_LOG_W(TAG, "Could not read RIGHT string");
230-
app->file_blank++;
231224
app->right_label = "N/A";
232-
app->right_enabled = 0;
233225
} else {
234226
app->right_label = extract_filename(furi_string_get_cstr(app->right_file), label_len);
235227
FURI_LOG_I(TAG, "RIGHT file: %s", furi_string_get_cstr(app->right_file));
228+
app->right_enabled = 1;
236229
}
237230

238231
//Repeat process for Ok
239232
if(!flipper_format_read_string(fff_data_file, "OK", app->ok_file)) {
240233
FURI_LOG_W(TAG, "Could not read OK string");
241-
app->file_blank++;
242234
app->ok_label = "N/A";
243-
app->ok_enabled = 0;
244235
} else {
245236
app->ok_label = extract_filename(furi_string_get_cstr(app->ok_file), label_len);
246237
FURI_LOG_I(TAG, "OK file: %s", furi_string_get_cstr(app->ok_file));
238+
app->ok_enabled = 1;
247239
}
248240

249241
//File definitions are done.
@@ -254,15 +246,9 @@ void unirfremix_cfg_set_check(UniRFRemix* app, FuriString* file_name) {
254246
//assign variables to values within map file
255247
if(!flipper_format_read_string(fff_data_file, "ULABEL", app->up_l)) {
256248
FURI_LOG_W(TAG, "Could not read ULABEL string");
257-
//if Up button is disabled, set the label to "N/A";
258-
if(app->up_enabled == 0) {
259-
app->up_label = "N/A";
260-
}
261249
} else {
262-
//check if button is disabled, and set label to "N/A" from missing map definition above
263-
if(app->up_enabled == 0) {
264-
app->up_label = "N/A";
265-
} else {
250+
//check if button is enabled, and set label
251+
if(app->up_enabled == 1) {
266252
//set label from map to variable and shrink to fit screen
267253
app->up_label = char_to_str((char*)furi_string_get_cstr(app->up_l), label_len);
268254
}
@@ -271,41 +257,26 @@ void unirfremix_cfg_set_check(UniRFRemix* app, FuriString* file_name) {
271257

272258
if(!flipper_format_read_string(fff_data_file, "DLABEL", app->down_l)) {
273259
FURI_LOG_W(TAG, "Could not read DLABEL string");
274-
if(app->down_enabled == 0) {
275-
app->down_label = "N/A";
276-
}
277260
} else {
278-
if(app->down_enabled == 0) {
279-
app->down_label = "N/A";
280-
} else {
261+
if(app->down_enabled == 1) {
281262
app->down_label = char_to_str((char*)furi_string_get_cstr(app->down_l), label_len);
282263
}
283264
FURI_LOG_I(TAG, "DOWN label: %s", app->down_label);
284265
}
285266

286267
if(!flipper_format_read_string(fff_data_file, "LLABEL", app->left_l)) {
287268
FURI_LOG_W(TAG, "Could not read LLABEL string");
288-
if(app->left_enabled == 0) {
289-
app->left_label = "N/A";
290-
}
291269
} else {
292-
if(app->left_enabled == 0) {
293-
app->left_label = "N/A";
294-
} else {
270+
if(app->left_enabled == 1) {
295271
app->left_label = char_to_str((char*)furi_string_get_cstr(app->left_l), label_len);
296272
}
297273
FURI_LOG_I(TAG, "LEFT label: %s", app->left_label);
298274
}
299275

300276
if(!flipper_format_read_string(fff_data_file, "RLABEL", app->right_l)) {
301277
FURI_LOG_W(TAG, "Could not read RLABEL string");
302-
if(app->right_enabled == 0) {
303-
app->right_label = "N/A";
304-
}
305278
} else {
306-
if(app->right_enabled == 0) {
307-
app->right_label = "N/A";
308-
} else {
279+
if(app->right_enabled == 1) {
309280
app->right_label =
310281
char_to_str((char*)furi_string_get_cstr(app->right_l), label_len);
311282
}
@@ -314,19 +285,12 @@ void unirfremix_cfg_set_check(UniRFRemix* app, FuriString* file_name) {
314285

315286
if(!flipper_format_read_string(fff_data_file, "OKLABEL", app->ok_l)) {
316287
FURI_LOG_W(TAG, "Could not read OKLABEL string");
317-
if(app->ok_enabled == 0) {
318-
app->ok_label = "N/A";
319-
}
320288
} else {
321-
if(app->ok_enabled == 0) {
322-
app->ok_label = "N/A";
323-
} else {
289+
if(app->ok_enabled == 1) {
324290
app->ok_label = char_to_str((char*)furi_string_get_cstr(app->ok_l), label_len);
325291
}
326292
FURI_LOG_I(TAG, "OK label: %s", app->ok_label);
327293
}
328-
329-
app->file_result = 2;
330294
}
331295

332296
flipper_format_file_close(fff_data_file);
@@ -339,106 +303,91 @@ void unirfremix_cfg_set_check(UniRFRemix* app, FuriString* file_name) {
339303
//determine whether or not to continue to launch app with missing variables
340304
//if 5 files are missing, throw error
341305

342-
FURI_LOG_D(TAG, "app->file_blank: %d", app->file_blank);
306+
//if button is still enabled, check that file exists
307+
if(app->up_enabled == 1) {
308+
furi_string_set(file_name, app->up_file);
309+
fff_data_file = flipper_format_file_alloc(storage);
343310

344-
if(app->file_blank == 5) {
345-
//trigger invalid file error screen
346-
app->file_result = 1;
347-
} else {
348-
//check all files
349-
//reset app->file_blank to redetermine if error needs to be thrown
350-
app->file_blank = 0;
351-
352-
//if button is still enabled, check that file exists
353-
if(app->up_enabled == 1) {
354-
furi_string_set(file_name, app->up_file);
355-
fff_data_file = flipper_format_file_alloc(storage);
356-
357-
if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) {
358-
FURI_LOG_W(TAG, "Could not open UP file %s", furi_string_get_cstr(file_name));
359-
360-
//disable button, and set label to "N/A"
361-
app->up_enabled = 0;
362-
app->up_label = "N/A";
363-
app->file_blank++;
364-
}
311+
if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) {
312+
FURI_LOG_W(TAG, "Could not open UP file %s", furi_string_get_cstr(file_name));
365313

366-
//close the file
367-
flipper_format_file_close(fff_data_file);
368-
flipper_format_free(fff_data_file);
314+
//disable button, and set label to "N/A"
315+
app->up_enabled = 0;
316+
app->up_label = "N/A";
369317
}
370318

371-
if(app->down_enabled == 1) {
372-
furi_string_set(file_name, app->down_file);
373-
fff_data_file = flipper_format_file_alloc(storage);
319+
//close the file
320+
flipper_format_file_close(fff_data_file);
321+
flipper_format_free(fff_data_file);
322+
}
374323

375-
if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) {
376-
FURI_LOG_W(TAG, "Could not open DOWN file %s", furi_string_get_cstr(file_name));
324+
if(app->down_enabled == 1) {
325+
furi_string_set(file_name, app->down_file);
326+
fff_data_file = flipper_format_file_alloc(storage);
377327

378-
app->down_enabled = 0;
379-
app->down_label = "N/A";
380-
app->file_blank++;
381-
}
328+
if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) {
329+
FURI_LOG_W(TAG, "Could not open DOWN file %s", furi_string_get_cstr(file_name));
382330

383-
flipper_format_file_close(fff_data_file);
384-
flipper_format_free(fff_data_file);
331+
app->down_enabled = 0;
332+
app->down_label = "N/A";
385333
}
386334

387-
if(app->left_enabled == 1) {
388-
furi_string_set(file_name, app->left_file);
389-
fff_data_file = flipper_format_file_alloc(storage);
335+
flipper_format_file_close(fff_data_file);
336+
flipper_format_free(fff_data_file);
337+
}
390338

391-
if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) {
392-
FURI_LOG_W(TAG, "Could not open LEFT file %s", furi_string_get_cstr(file_name));
339+
if(app->left_enabled == 1) {
340+
furi_string_set(file_name, app->left_file);
341+
fff_data_file = flipper_format_file_alloc(storage);
393342

394-
app->left_enabled = 0;
395-
app->left_label = "N/A";
396-
app->file_blank++;
397-
}
343+
if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) {
344+
FURI_LOG_W(TAG, "Could not open LEFT file %s", furi_string_get_cstr(file_name));
398345

399-
flipper_format_file_close(fff_data_file);
400-
flipper_format_free(fff_data_file);
346+
app->left_enabled = 0;
347+
app->left_label = "N/A";
401348
}
402349

403-
if(app->right_enabled == 1) {
404-
furi_string_set(file_name, app->right_file);
405-
fff_data_file = flipper_format_file_alloc(storage);
350+
flipper_format_file_close(fff_data_file);
351+
flipper_format_free(fff_data_file);
352+
}
406353

407-
if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) {
408-
FURI_LOG_W(TAG, "Could not open RIGHT file %s", furi_string_get_cstr(file_name));
354+
if(app->right_enabled == 1) {
355+
furi_string_set(file_name, app->right_file);
356+
fff_data_file = flipper_format_file_alloc(storage);
409357

410-
app->right_enabled = 0;
411-
app->right_label = "N/A";
412-
app->file_blank++;
413-
}
358+
if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) {
359+
FURI_LOG_W(TAG, "Could not open RIGHT file %s", furi_string_get_cstr(file_name));
414360

415-
flipper_format_file_close(fff_data_file);
416-
flipper_format_free(fff_data_file);
361+
app->right_enabled = 0;
362+
app->right_label = "N/A";
417363
}
418364

419-
if(app->ok_enabled == 1) {
420-
furi_string_set(file_name, app->ok_file);
421-
fff_data_file = flipper_format_file_alloc(storage);
365+
flipper_format_file_close(fff_data_file);
366+
flipper_format_free(fff_data_file);
367+
}
422368

423-
if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) {
424-
FURI_LOG_W(TAG, "Could not open OK file %s", furi_string_get_cstr(file_name));
369+
if(app->ok_enabled == 1) {
370+
furi_string_set(file_name, app->ok_file);
371+
fff_data_file = flipper_format_file_alloc(storage);
425372

426-
app->ok_enabled = 0;
427-
app->ok_label = "N/A";
428-
app->file_blank++;
429-
}
373+
if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) {
374+
FURI_LOG_W(TAG, "Could not open OK file %s", furi_string_get_cstr(file_name));
430375

431-
flipper_format_file_close(fff_data_file);
432-
flipper_format_free(fff_data_file);
376+
app->ok_enabled = 0;
377+
app->ok_label = "N/A";
433378
}
434379

435-
furi_record_close(RECORD_STORAGE);
380+
flipper_format_file_close(fff_data_file);
381+
flipper_format_free(fff_data_file);
382+
}
436383

437-
if(app->file_blank == 5) {
438-
app->file_result = 1;
439-
} else {
440-
app->file_result = 2;
441-
}
384+
furi_record_close(RECORD_STORAGE);
385+
386+
if(app->up_enabled == 0 && app->down_enabled == 0 && app->left_enabled == 0 &&
387+
app->right_enabled == 0 && app->ok_enabled == 0) {
388+
app->file_result = 1;
389+
} else {
390+
app->file_result = 2;
442391
}
443392
}
444393

@@ -742,6 +691,14 @@ static void render_callback(Canvas* canvas, void* ctx) {
742691
canvas_set_font(canvas, FontSecondary);
743692
canvas_draw_str_aligned(canvas, 62, 30, AlignCenter, AlignTop, "Please configure map.");
744693
canvas_draw_str_aligned(canvas, 62, 60, AlignCenter, AlignBottom, "Press Back to Exit.");
694+
} else if(app->file_result == 3) {
695+
//if map has no valid filenames defined
696+
canvas_clear(canvas);
697+
canvas_set_font(canvas, FontPrimary);
698+
canvas_draw_str_aligned(canvas, 62, 5, AlignCenter, AlignTop, "Checking config.");
699+
canvas_set_font(canvas, FontSecondary);
700+
canvas_draw_str_aligned(canvas, 62, 30, AlignCenter, AlignTop, "If app is stuck...");
701+
canvas_draw_str_aligned(canvas, 62, 60, AlignCenter, AlignBottom, "Press Back to Exit.");
745702
} else if(app->tx_not_allowed) {
746703
canvas_clear(canvas);
747704
canvas_set_font(canvas, FontPrimary);
@@ -1129,7 +1086,7 @@ int32_t unirfremix_app(void* p) {
11291086
furi_mutex_release(app->model_mutex);
11301087
view_port_update(app->view_port);
11311088
}
1132-
} else if(app->file_result == 1) {
1089+
} else if(app->file_result == 1 || app->file_result == 3) {
11331090
//refresh screen to update variables before processing main screen or error screens
11341091
view_port_update(app->view_port);
11351092

0 commit comments

Comments
 (0)