mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-18 19:01:47 +03:00
Cleanup code in unirf, fix issue #153
This commit is contained in:
parent
b93f2dc293
commit
22902aabcc
@ -58,12 +58,6 @@ typedef struct {
|
||||
FuriString* right_file;
|
||||
FuriString* ok_file;
|
||||
|
||||
FuriString* up_l;
|
||||
FuriString* left_l;
|
||||
FuriString* right_l;
|
||||
FuriString* down_l;
|
||||
FuriString* ok_l;
|
||||
|
||||
FuriString* file_path;
|
||||
|
||||
char* up_label;
|
||||
@ -115,34 +109,7 @@ static char* char_to_str(char* str, int i) {
|
||||
|
||||
return converted;
|
||||
}
|
||||
/*
|
||||
static const char* int_to_char(int number) {
|
||||
switch(number) {
|
||||
case 0:
|
||||
return "0";
|
||||
case 1:
|
||||
return "1";
|
||||
case 2:
|
||||
return "2";
|
||||
case 3:
|
||||
return "3";
|
||||
case 4:
|
||||
return "4";
|
||||
case 5:
|
||||
return "5";
|
||||
case 6:
|
||||
return "6";
|
||||
case 7:
|
||||
return "7";
|
||||
case 8:
|
||||
return "8";
|
||||
case 9:
|
||||
return "9";
|
||||
default:
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//get filename without path
|
||||
static char* extract_filename(const char* name, int len) {
|
||||
FuriString* tmp;
|
||||
@ -154,6 +121,43 @@ static char* extract_filename(const char* name, int len) {
|
||||
return char_to_str((char*)furi_string_get_cstr(tmp), len);
|
||||
}
|
||||
|
||||
static void cfg_read_file_path(
|
||||
FlipperFormat* fff_file,
|
||||
FuriString* text_file_path,
|
||||
char** text_file_label,
|
||||
const char* read_key,
|
||||
int* is_enabled) {
|
||||
if(!flipper_format_read_string(fff_file, read_key, text_file_path)) {
|
||||
FURI_LOG_W(TAG, "Could not read %s string", read_key);
|
||||
*text_file_label = "N/A";
|
||||
*is_enabled = 0;
|
||||
} else {
|
||||
*text_file_label = extract_filename(furi_string_get_cstr(text_file_path), 16);
|
||||
FURI_LOG_D(TAG, "%s file: %s", read_key, furi_string_get_cstr(text_file_path));
|
||||
*is_enabled = 1;
|
||||
}
|
||||
flipper_format_rewind(fff_file);
|
||||
}
|
||||
|
||||
static void cfg_read_file_label(
|
||||
FlipperFormat* fff_file,
|
||||
char** text_file_label,
|
||||
const char* read_key,
|
||||
bool is_enabled) {
|
||||
FuriString* temp_label = furi_string_alloc();
|
||||
|
||||
if(!flipper_format_read_string(fff_file, read_key, temp_label)) {
|
||||
FURI_LOG_W(TAG, "Could not read %s string", read_key);
|
||||
} else {
|
||||
if(is_enabled == 1) {
|
||||
*text_file_label = char_to_str((char*)furi_string_get_cstr(temp_label), 16);
|
||||
}
|
||||
FURI_LOG_D(TAG, "%s label: %s", read_key, *text_file_label);
|
||||
}
|
||||
flipper_format_rewind(fff_file);
|
||||
furi_string_free(temp_label);
|
||||
}
|
||||
|
||||
/*
|
||||
* check that map file exists
|
||||
* assign variables to values within map file
|
||||
@ -175,8 +179,6 @@ void unirfremix_cfg_set_check(UniRFRemix* app, FuriString* file_name) {
|
||||
app->right_enabled = 0;
|
||||
app->ok_enabled = 0;
|
||||
|
||||
int label_len = 16;
|
||||
|
||||
//check that map file exists
|
||||
if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) {
|
||||
FURI_LOG_E(TAG, "Could not open MAP file %s", furi_string_get_cstr(file_name));
|
||||
@ -185,112 +187,29 @@ void unirfremix_cfg_set_check(UniRFRemix* app, FuriString* file_name) {
|
||||
|
||||
//assign variables to values within map file
|
||||
//set missing filenames to N/A
|
||||
if(!flipper_format_read_string(fff_data_file, "UP", app->up_file)) {
|
||||
FURI_LOG_W(TAG, "Could not read UP string");
|
||||
//set label to "N/A"
|
||||
app->up_label = "N/A";
|
||||
} else {
|
||||
//check name length for proper screen fit
|
||||
//then set filename as label. Might be replaced with defined label later on below.
|
||||
app->up_label = extract_filename(furi_string_get_cstr(app->up_file), label_len);
|
||||
FURI_LOG_I(TAG, "UP file: %s", furi_string_get_cstr(app->up_file));
|
||||
//enable processing of the signal on button press
|
||||
app->up_enabled = 1;
|
||||
}
|
||||
cfg_read_file_path(fff_data_file, app->up_file, &app->up_label, "UP", &app->up_enabled);
|
||||
|
||||
//Repeat process for Down
|
||||
if(!flipper_format_read_string(fff_data_file, "DOWN", app->down_file)) {
|
||||
FURI_LOG_W(TAG, "Could not read DOWN string");
|
||||
app->down_label = "N/A";
|
||||
} else {
|
||||
app->down_label = extract_filename(furi_string_get_cstr(app->down_file), label_len);
|
||||
FURI_LOG_I(TAG, "DOWN file: %s", furi_string_get_cstr(app->down_file));
|
||||
app->down_enabled = 1;
|
||||
}
|
||||
cfg_read_file_path(
|
||||
fff_data_file, app->down_file, &app->down_label, "DOWN", &app->down_enabled);
|
||||
|
||||
//Repeat process for Left
|
||||
if(!flipper_format_read_string(fff_data_file, "LEFT", app->left_file)) {
|
||||
FURI_LOG_W(TAG, "Could not read LEFT string");
|
||||
app->left_label = "N/A";
|
||||
} else {
|
||||
app->left_label = extract_filename(furi_string_get_cstr(app->left_file), label_len);
|
||||
FURI_LOG_I(TAG, "LEFT file: %s", furi_string_get_cstr(app->left_file));
|
||||
app->left_enabled = 1;
|
||||
}
|
||||
cfg_read_file_path(
|
||||
fff_data_file, app->left_file, &app->left_label, "LEFT", &app->left_enabled);
|
||||
|
||||
//Repeat process for Right
|
||||
if(!flipper_format_read_string(fff_data_file, "RIGHT", app->right_file)) {
|
||||
FURI_LOG_W(TAG, "Could not read RIGHT string");
|
||||
app->right_label = "N/A";
|
||||
} else {
|
||||
app->right_label = extract_filename(furi_string_get_cstr(app->right_file), label_len);
|
||||
FURI_LOG_I(TAG, "RIGHT file: %s", furi_string_get_cstr(app->right_file));
|
||||
app->right_enabled = 1;
|
||||
}
|
||||
cfg_read_file_path(
|
||||
fff_data_file, app->right_file, &app->right_label, "RIGHT", &app->right_enabled);
|
||||
|
||||
//Repeat process for Ok
|
||||
if(!flipper_format_read_string(fff_data_file, "OK", app->ok_file)) {
|
||||
FURI_LOG_W(TAG, "Could not read OK string");
|
||||
app->ok_label = "N/A";
|
||||
} else {
|
||||
app->ok_label = extract_filename(furi_string_get_cstr(app->ok_file), label_len);
|
||||
FURI_LOG_I(TAG, "OK file: %s", furi_string_get_cstr(app->ok_file));
|
||||
app->ok_enabled = 1;
|
||||
}
|
||||
cfg_read_file_path(fff_data_file, app->ok_file, &app->ok_label, "OK", &app->ok_enabled);
|
||||
|
||||
//File definitions are done.
|
||||
//File checks will follow after label assignment in order to close the universal_rf_map file without the need to reopen it again.
|
||||
|
||||
//Label Assignment/Check Start
|
||||
|
||||
//assign variables to values within map file
|
||||
if(!flipper_format_read_string(fff_data_file, "ULABEL", app->up_l)) {
|
||||
FURI_LOG_W(TAG, "Could not read ULABEL string");
|
||||
} else {
|
||||
//check if button is enabled, and set label
|
||||
if(app->up_enabled == 1) {
|
||||
//set label from map to variable and shrink to fit screen
|
||||
app->up_label = char_to_str((char*)furi_string_get_cstr(app->up_l), label_len);
|
||||
}
|
||||
FURI_LOG_I(TAG, "UP label: %s", app->up_label);
|
||||
}
|
||||
|
||||
if(!flipper_format_read_string(fff_data_file, "DLABEL", app->down_l)) {
|
||||
FURI_LOG_W(TAG, "Could not read DLABEL string");
|
||||
} else {
|
||||
if(app->down_enabled == 1) {
|
||||
app->down_label = char_to_str((char*)furi_string_get_cstr(app->down_l), label_len);
|
||||
}
|
||||
FURI_LOG_I(TAG, "DOWN label: %s", app->down_label);
|
||||
}
|
||||
|
||||
if(!flipper_format_read_string(fff_data_file, "LLABEL", app->left_l)) {
|
||||
FURI_LOG_W(TAG, "Could not read LLABEL string");
|
||||
} else {
|
||||
if(app->left_enabled == 1) {
|
||||
app->left_label = char_to_str((char*)furi_string_get_cstr(app->left_l), label_len);
|
||||
}
|
||||
FURI_LOG_I(TAG, "LEFT label: %s", app->left_label);
|
||||
}
|
||||
|
||||
if(!flipper_format_read_string(fff_data_file, "RLABEL", app->right_l)) {
|
||||
FURI_LOG_W(TAG, "Could not read RLABEL string");
|
||||
} else {
|
||||
if(app->right_enabled == 1) {
|
||||
app->right_label =
|
||||
char_to_str((char*)furi_string_get_cstr(app->right_l), label_len);
|
||||
}
|
||||
FURI_LOG_I(TAG, "RIGHT label: %s", app->right_label);
|
||||
}
|
||||
|
||||
if(!flipper_format_read_string(fff_data_file, "OKLABEL", app->ok_l)) {
|
||||
FURI_LOG_W(TAG, "Could not read OKLABEL string");
|
||||
} else {
|
||||
if(app->ok_enabled == 1) {
|
||||
app->ok_label = char_to_str((char*)furi_string_get_cstr(app->ok_l), label_len);
|
||||
}
|
||||
FURI_LOG_I(TAG, "OK label: %s", app->ok_label);
|
||||
}
|
||||
cfg_read_file_label(fff_data_file, &app->up_label, "ULABEL", app->up_enabled);
|
||||
cfg_read_file_label(fff_data_file, &app->down_label, "DLABEL", app->down_enabled);
|
||||
cfg_read_file_label(fff_data_file, &app->left_label, "LLABEL", app->left_enabled);
|
||||
cfg_read_file_label(fff_data_file, &app->right_label, "RLABEL", app->right_enabled);
|
||||
cfg_read_file_label(fff_data_file, &app->ok_label, "OKLABEL", app->ok_enabled);
|
||||
}
|
||||
|
||||
flipper_format_file_close(fff_data_file);
|
||||
@ -547,7 +466,7 @@ void unirfremix_tx_stop(UniRFRemix* app) {
|
||||
|
||||
//Stop TX
|
||||
furi_hal_subghz_stop_async_tx();
|
||||
FURI_LOG_I(TAG, "TX Done!");
|
||||
//FURI_LOG_I(TAG, "TX Done!");
|
||||
subghz_transmitter_stop(app->tx_transmitter);
|
||||
|
||||
FURI_LOG_D(TAG, "Checking if protocol is dynamic");
|
||||
@ -616,7 +535,7 @@ static bool unirfremix_send_sub(UniRFRemix* app, FlipperFormat* fff_data) {
|
||||
break;
|
||||
}
|
||||
|
||||
FURI_LOG_I(TAG, "Sending...");
|
||||
//FURI_LOG_I(TAG, "Sending...");
|
||||
notification_message(app->notification, &sequence_blink_start_magenta);
|
||||
|
||||
furi_hal_subghz_start_async_tx(subghz_transmitter_yield, app->tx_transmitter);
|
||||
@ -628,7 +547,7 @@ static bool unirfremix_send_sub(UniRFRemix* app, FlipperFormat* fff_data) {
|
||||
}
|
||||
|
||||
static void unirfremix_send_signal(UniRFRemix* app, Storage* storage, const char* path) {
|
||||
FURI_LOG_I(TAG, "Sending: %s", path);
|
||||
FURI_LOG_D(TAG, "Sending: %s", path);
|
||||
|
||||
app->tx_file_path = path;
|
||||
|
||||
@ -668,7 +587,7 @@ static void unirfremix_send_signal(UniRFRemix* app, Storage* storage, const char
|
||||
static void unirfremix_process_signal(UniRFRemix* app, FuriString* signal) {
|
||||
view_port_update(app->view_port);
|
||||
|
||||
FURI_LOG_I(TAG, "signal = %s", furi_string_get_cstr(signal));
|
||||
FURI_LOG_D(TAG, "signal = %s", furi_string_get_cstr(signal));
|
||||
|
||||
if(strlen(furi_string_get_cstr(signal)) > 12) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
@ -834,12 +753,6 @@ void unirfremix_free(UniRFRemix* app, bool with_subghz) {
|
||||
furi_string_free(app->right_file);
|
||||
furi_string_free(app->ok_file);
|
||||
|
||||
furi_string_free(app->up_l);
|
||||
furi_string_free(app->down_l);
|
||||
furi_string_free(app->left_l);
|
||||
furi_string_free(app->right_l);
|
||||
furi_string_free(app->ok_l);
|
||||
|
||||
furi_string_free(app->file_path);
|
||||
furi_string_free(app->signal);
|
||||
|
||||
@ -879,12 +792,6 @@ int32_t unirfremix_app(void* p) {
|
||||
app->right_file = furi_string_alloc();
|
||||
app->ok_file = furi_string_alloc();
|
||||
|
||||
app->up_l = furi_string_alloc();
|
||||
app->down_l = furi_string_alloc();
|
||||
app->left_l = furi_string_alloc();
|
||||
app->right_l = furi_string_alloc();
|
||||
app->ok_l = furi_string_alloc();
|
||||
|
||||
app->file_result = 3;
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
Loading…
Reference in New Issue
Block a user