Skip to content

Commit ce8288b

Browse files
authored
Merge branch 'dev' into astra/3766-unlock-crash-fix
2 parents 12fd270 + e0654fe commit ce8288b

24 files changed

+602
-269
lines changed

applications/main/infrared/infrared_app.c

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ static void infrared_free(InfraredApp* infrared) {
297297
free(infrared);
298298
}
299299

300-
bool infrared_add_remote_with_button(
300+
InfraredErrorCode infrared_add_remote_with_button(
301301
const InfraredApp* infrared,
302302
const char* button_name,
303303
const InfraredSignal* signal) {
@@ -310,21 +310,23 @@ bool infrared_add_remote_with_button(
310310
furi_string_cat_printf(
311311
new_path, "/%s%s", furi_string_get_cstr(new_name), INFRARED_APP_EXTENSION);
312312

313-
bool success = false;
313+
InfraredErrorCode error = InfraredErrorCodeNone;
314314

315315
do {
316-
if(!infrared_remote_create(remote, furi_string_get_cstr(new_path))) break;
317-
if(!infrared_remote_append_signal(remote, signal, button_name)) break;
318-
success = true;
316+
error = infrared_remote_create(remote, furi_string_get_cstr(new_path));
317+
if(INFRARED_ERROR_PRESENT(error)) break;
318+
319+
error = infrared_remote_append_signal(remote, signal, button_name);
319320
} while(false);
320321

321322
furi_string_free(new_name);
322323
furi_string_free(new_path);
323324

324-
return success;
325+
return error;
325326
}
326327

327-
bool infrared_rename_current_remote(const InfraredApp* infrared, const char* new_name) {
328+
InfraredErrorCode
329+
infrared_rename_current_remote(const InfraredApp* infrared, const char* new_name) {
328330
InfraredRemote* remote = infrared->remote;
329331
const char* old_path = infrared_remote_get_path(remote);
330332

@@ -344,12 +346,13 @@ bool infrared_rename_current_remote(const InfraredApp* infrared, const char* new
344346
path_append(new_path_fstr, furi_string_get_cstr(new_name_fstr));
345347
furi_string_cat(new_path_fstr, INFRARED_APP_EXTENSION);
346348

347-
const bool success = infrared_remote_rename(remote, furi_string_get_cstr(new_path_fstr));
349+
const InfraredErrorCode error =
350+
infrared_remote_rename(remote, furi_string_get_cstr(new_path_fstr));
348351

349352
furi_string_free(new_name_fstr);
350353
furi_string_free(new_path_fstr);
351354

352-
return success;
355+
return error;
353356
}
354357

355358
void infrared_tx_start(InfraredApp* infrared) {
@@ -382,15 +385,16 @@ void infrared_tx_start(InfraredApp* infrared) {
382385
infrared->app_state.is_transmitting = true;
383386
}
384387

385-
bool infrared_tx_start_button_index(InfraredApp* infrared, size_t button_index) {
388+
InfraredErrorCode infrared_tx_start_button_index(InfraredApp* infrared, size_t button_index) {
386389
furi_assert(button_index < infrared_remote_get_signal_count(infrared->remote));
387390

388-
bool result =
391+
InfraredErrorCode error =
389392
infrared_remote_load_signal(infrared->remote, infrared->current_signal, button_index);
390-
if(result) {
393+
394+
if(!INFRARED_ERROR_PRESENT(error)) {
391395
infrared_tx_start(infrared);
392396
}
393-
return result;
397+
return error;
394398
}
395399

396400
void infrared_tx_stop(InfraredApp* infrared) {
@@ -413,7 +417,7 @@ void infrared_blocking_task_start(InfraredApp* infrared, FuriThreadCallback call
413417
furi_thread_start(infrared->task_thread);
414418
}
415419

416-
bool infrared_blocking_task_finalize(InfraredApp* infrared) {
420+
InfraredErrorCode infrared_blocking_task_finalize(InfraredApp* infrared) {
417421
furi_thread_join(infrared->task_thread);
418422
return furi_thread_get_return_code(infrared->task_thread);
419423
}
@@ -563,10 +567,18 @@ int32_t infrared_app(void* p) {
563567
is_rpc_mode = true;
564568
} else {
565569
const char* file_path = (const char*)p;
566-
is_remote_loaded = infrared_remote_load(infrared->remote, file_path);
567-
568-
if(!is_remote_loaded) {
569-
infrared_show_error_message(infrared, "Failed to load\n\"%s\"", file_path);
570+
InfraredErrorCode error = infrared_remote_load(infrared->remote, file_path);
571+
572+
if(!INFRARED_ERROR_PRESENT(error)) {
573+
is_remote_loaded = true;
574+
} else {
575+
is_remote_loaded = false;
576+
bool wrong_file_type = INFRARED_ERROR_CHECK(error, InfraredErrorCodeWrongFileType);
577+
const char* format = wrong_file_type ?
578+
"Library file\n\"%s\" can't be openned as a remote" :
579+
"Failed to load\n\"%s\"";
580+
581+
infrared_show_error_message(infrared, format, file_path);
570582
return -1;
571583
}
572584

applications/main/infrared/infrared_app_i.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ typedef enum {
174174
* @param[in] infrared pointer to the application instance.
175175
* @param[in] name pointer to a zero-terminated string containing the signal name.
176176
* @param[in] signal pointer to the signal to be added.
177-
* @return true if the remote was successfully created, false otherwise.
177+
* @return InfraredErrorCodeNone if the remote was successfully created, otherwise error code.
178178
*/
179-
bool infrared_add_remote_with_button(
179+
InfraredErrorCode infrared_add_remote_with_button(
180180
const InfraredApp* infrared,
181181
const char* name,
182182
const InfraredSignal* signal);
@@ -186,9 +186,10 @@ bool infrared_add_remote_with_button(
186186
*
187187
* @param[in] infrared pointer to the application instance.
188188
* @param[in] new_name pointer to a zero-terminated string containing the new remote name.
189-
* @return true if the remote was successfully renamed, false otherwise.
189+
* @return InfraredErrorCodeNone if the remote was successfully renamed, otherwise error code.
190190
*/
191-
bool infrared_rename_current_remote(const InfraredApp* infrared, const char* new_name);
191+
InfraredErrorCode
192+
infrared_rename_current_remote(const InfraredApp* infrared, const char* new_name);
192193

193194
/**
194195
* @brief Begin transmission of the currently loaded signal.
@@ -206,9 +207,9 @@ void infrared_tx_start(InfraredApp* infrared);
206207
*
207208
* @param[in,out] infrared pointer to the application instance.
208209
* @param[in] button_index index of the signal to be loaded.
209-
* @returns true if the signal could be loaded, false otherwise.
210+
* @returns InfraredErrorCodeNone if the signal could be loaded, otherwise error code.
210211
*/
211-
bool infrared_tx_start_button_index(InfraredApp* infrared, size_t button_index);
212+
InfraredErrorCode infrared_tx_start_button_index(InfraredApp* infrared, size_t button_index);
212213

213214
/**
214215
* @brief Stop transmission of the currently loaded signal.
@@ -236,9 +237,9 @@ void infrared_blocking_task_start(InfraredApp* infrared, FuriThreadCallback call
236237
* (e.g. to display the results), the caller code MUST set it explicitly.
237238
*
238239
* @param[in,out] infrared pointer to the application instance.
239-
* @return true if the blocking task finished successfully, false otherwise.
240+
* @return InfraredErrorCodeNone if the blocking task finished successfully, otherwise error code.
240241
*/
241-
bool infrared_blocking_task_finalize(InfraredApp* infrared);
242+
InfraredErrorCode infrared_blocking_task_finalize(InfraredApp* infrared);
242243

243244
/**
244245
* @brief Set the internal text store with formatted text.

applications/main/infrared/infrared_brute_force.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,26 @@ void infrared_brute_force_set_db_filename(InfraredBruteForce* brute_force, const
5050
brute_force->db_filename = db_filename;
5151
}
5252

53-
bool infrared_brute_force_calculate_messages(InfraredBruteForce* brute_force) {
53+
InfraredErrorCode infrared_brute_force_calculate_messages(InfraredBruteForce* brute_force) {
5454
furi_assert(!brute_force->is_started);
5555
furi_assert(brute_force->db_filename);
56-
bool success = false;
56+
InfraredErrorCode error = InfraredErrorCodeNone;
5757

5858
Storage* storage = furi_record_open(RECORD_STORAGE);
5959
FlipperFormat* ff = flipper_format_buffered_file_alloc(storage);
6060
FuriString* signal_name = furi_string_alloc();
6161
InfraredSignal* signal = infrared_signal_alloc();
6262

6363
do {
64-
if(!flipper_format_buffered_file_open_existing(ff, brute_force->db_filename)) break;
64+
if(!flipper_format_buffered_file_open_existing(ff, brute_force->db_filename)) {
65+
error = InfraredErrorCodeFileOperationFailed;
66+
break;
67+
}
6568

6669
bool signals_valid = false;
67-
while(infrared_signal_read_name(ff, signal_name)) {
68-
signals_valid = infrared_signal_read_body(signal, ff) &&
69-
infrared_signal_is_valid(signal);
70+
while(infrared_signal_read_name(ff, signal_name) == InfraredErrorCodeNone) {
71+
error = infrared_signal_read_body(signal, ff);
72+
signals_valid = (!INFRARED_ERROR_PRESENT(error)) && infrared_signal_is_valid(signal);
7073
if(!signals_valid) break;
7174

7275
InfraredBruteForceRecord* record =
@@ -75,17 +78,15 @@ bool infrared_brute_force_calculate_messages(InfraredBruteForce* brute_force) {
7578
++(record->count);
7679
}
7780
}
78-
7981
if(!signals_valid) break;
80-
success = true;
8182
} while(false);
8283

8384
infrared_signal_free(signal);
8485
furi_string_free(signal_name);
8586

8687
flipper_format_free(ff);
8788
furi_record_close(RECORD_STORAGE);
88-
return success;
89+
return error;
8990
}
9091

9192
bool infrared_brute_force_start(
@@ -139,10 +140,12 @@ void infrared_brute_force_stop(InfraredBruteForce* brute_force) {
139140

140141
bool infrared_brute_force_send_next(InfraredBruteForce* brute_force) {
141142
furi_assert(brute_force->is_started);
143+
142144
const bool success = infrared_signal_search_by_name_and_read(
143-
brute_force->current_signal,
144-
brute_force->ff,
145-
furi_string_get_cstr(brute_force->current_record_name));
145+
brute_force->current_signal,
146+
brute_force->ff,
147+
furi_string_get_cstr(brute_force->current_record_name)) ==
148+
InfraredErrorCodeNone;
146149
if(success) {
147150
infrared_signal_transmit(brute_force->current_signal);
148151
}

applications/main/infrared/infrared_brute_force.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <stdint.h>
1212
#include <stdbool.h>
13+
#include "infrared_error_code.h"
1314

1415
/**
1516
* @brief InfraredBruteForce opaque type declaration.
@@ -45,9 +46,9 @@ void infrared_brute_force_set_db_filename(InfraredBruteForce* brute_force, const
4546
* a infrared_brute_force_set_db_filename() call.
4647
*
4748
* @param[in,out] brute_force pointer to the instance to be updated.
48-
* @returns true on success, false otherwise.
49+
* @returns InfraredErrorCodeNone on success, otherwise error code.
4950
*/
50-
bool infrared_brute_force_calculate_messages(InfraredBruteForce* brute_force);
51+
InfraredErrorCode infrared_brute_force_calculate_messages(InfraredBruteForce* brute_force);
5152

5253
/**
5354
* @brief Start transmitting signals from a category stored in an InfraredBruteForce's instance dictionary.

applications/main/infrared/infrared_cli.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,15 @@ static void infrared_cli_start_ir_tx(Cli* cli, FuriString* args) {
232232

233233
static bool
234234
infrared_cli_save_signal(InfraredSignal* signal, FlipperFormat* file, const char* name) {
235-
bool ret = infrared_signal_save(signal, file, name);
236-
if(!ret) {
237-
printf("Failed to save signal: \"%s\"\r\n", name);
235+
bool ret = true;
236+
InfraredErrorCode error = infrared_signal_save(signal, file, name);
237+
if(INFRARED_ERROR_PRESENT(error)) {
238+
printf(
239+
"Failed to save signal: \"%s\" code: 0x%X index: 0x%02X\r\n",
240+
name,
241+
INFRARED_ERROR_GET_CODE(error),
242+
INFRARED_ERROR_GET_INDEX(error));
243+
ret = false;
238244
}
239245
return ret;
240246
}
@@ -296,7 +302,7 @@ static bool infrared_cli_decode_file(FlipperFormat* input_file, FlipperFormat* o
296302
FuriString* tmp;
297303
tmp = furi_string_alloc();
298304

299-
while(infrared_signal_read(signal, input_file, tmp)) {
305+
while(infrared_signal_read(signal, input_file, tmp) == InfraredErrorCodeNone) {
300306
ret = false;
301307
if(!infrared_signal_is_valid(signal)) {
302308
printf("Invalid signal\r\n");
@@ -464,7 +470,7 @@ static void
464470
printf("Missing signal name.\r\n");
465471
break;
466472
}
467-
if(!infrared_brute_force_calculate_messages(brute_force)) {
473+
if(infrared_brute_force_calculate_messages(brute_force) != InfraredErrorCodeNone) {
468474
printf("Invalid remote name.\r\n");
469475
break;
470476
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#pragma once
2+
3+
typedef enum {
4+
InfraredErrorCodeNone = 0,
5+
InfraredErrorCodeFileOperationFailed = 0x800000,
6+
InfraredErrorCodeWrongFileType = 0x80000100,
7+
InfraredErrorCodeWrongFileVersion = 0x80000200,
8+
9+
//Common signal errors
10+
InfraredErrorCodeSignalTypeUnknown = 0x80000300,
11+
InfraredErrorCodeSignalNameNotFound = 0x80000400,
12+
InfraredErrorCodeSignalUnableToReadType = 0x80000500,
13+
InfraredErrorCodeSignalUnableToWriteType = 0x80000600,
14+
15+
//Raw signal errors
16+
InfraredErrorCodeSignalRawUnableToReadFrequency = 0x80000700,
17+
InfraredErrorCodeSignalRawUnableToReadDutyCycle = 0x80000800,
18+
InfraredErrorCodeSignalRawUnableToReadTimingsSize = 0x80000900,
19+
InfraredErrorCodeSignalRawUnableToReadTooLongData = 0x80000A00,
20+
InfraredErrorCodeSignalRawUnableToReadData = 0x80000B00,
21+
22+
InfraredErrorCodeSignalRawUnableToWriteFrequency = 0x80000C00,
23+
InfraredErrorCodeSignalRawUnableToWriteDutyCycle = 0x80000D00,
24+
InfraredErrorCodeSignalRawUnableToWriteData = 0x80000E00,
25+
26+
//Message signal errors
27+
InfraredErrorCodeSignalMessageUnableToReadProtocol = 0x80000F00,
28+
InfraredErrorCodeSignalMessageUnableToReadAddress = 0x80001000,
29+
InfraredErrorCodeSignalMessageUnableToReadCommand = 0x80001100,
30+
InfraredErrorCodeSignalMessageIsInvalid = 0x80001200,
31+
32+
InfraredErrorCodeSignalMessageUnableToWriteProtocol = 0x80001300,
33+
InfraredErrorCodeSignalMessageUnableToWriteAddress = 0x80001400,
34+
InfraredErrorCodeSignalMessageUnableToWriteCommand = 0x80001500,
35+
} InfraredErrorCode;
36+
37+
#define INFRARED_ERROR_CODE_MASK (0xFFFFFF00)
38+
#define INFRARED_ERROR_INDEX_MASK (0x000000FF)
39+
40+
#define INFRARED_ERROR_GET_CODE(error) (error & INFRARED_ERROR_CODE_MASK)
41+
#define INFRARED_ERROR_GET_INDEX(error) (error & INFRARED_ERROR_INDEX_MASK)
42+
#define INFRARED_ERROR_SET_INDEX(code, index) (code |= (index & INFRARED_ERROR_INDEX_MASK))
43+
44+
#define INFRARED_ERROR_PRESENT(error) (INFRARED_ERROR_GET_CODE(error) != InfraredErrorCodeNone)
45+
#define INFRARED_ERROR_CHECK(error, test_code) (INFRARED_ERROR_GET_CODE(error) == test_code)

0 commit comments

Comments
 (0)