update unirf remix app & keep custom icons

This commit is contained in:
Eng1n33r
2022-06-13 23:40:23 +03:00
parent c780aedf35
commit f08630849b

View File

@@ -148,14 +148,15 @@ static char* extract_filename(const char* name, int len) {
*/ */
void unirfremix_cfg_set_check(UniRFRemix* app) { void unirfremix_cfg_set_check(UniRFRemix* app) {
//set file name to universal_rf_map.txt first
string_t file_name; string_t file_name;
string_init(file_name); string_init(file_name);
string_set(file_name, "/any/subghz/assets/universal_rf_map"); string_set(file_name, "/any/subghz/assets/universal_rf_map.txt");
Storage* storage = furi_record_open("storage"); Storage* storage = furi_record_open("storage");
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
app->file_result = 0; app->file_result = 3;
app->file_blank = 0; app->file_blank = 0;
app->up_enabled = 1; app->up_enabled = 1;
@@ -165,20 +166,19 @@ void unirfremix_cfg_set_check(UniRFRemix* app) {
app->ok_enabled = 1; app->ok_enabled = 1;
int label_len = 12; int label_len = 12;
int legacy = 0;
//check that map file exists //check that map file exists
if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) { if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) {
FURI_LOG_I(TAG, "Could not open MAP file %s", string_get_cstr(file_name)); FURI_LOG_I(TAG, "Could not open MAP file %s", string_get_cstr(file_name));
app->file_result = 1; legacy = 1;
} } else {
else legacy = 0;
{ //Filename Assignment/Check Start
//Filename Assignment/Check Start
//assign variables to values within map file //assign variables to values within map file
//set missing filenames to N/A //set missing filenames to N/A
if(!flipper_format_read_string(fff_data_file, "UP", app->up_file)) if(!flipper_format_read_string(fff_data_file, "UP", app->up_file)) {
{
FURI_LOG_I(TAG, "Could not read UP string"); FURI_LOG_I(TAG, "Could not read UP string");
//increment file_blank for processing later //increment file_blank for processing later
@@ -191,19 +191,16 @@ void unirfremix_cfg_set_check(UniRFRemix* app) {
app->up_enabled = 0; app->up_enabled = 0;
FURI_LOG_I(TAG, "Up_Enabled: %d", app->up_enabled); FURI_LOG_I(TAG, "Up_Enabled: %d", app->up_enabled);
} } else {
else //check name length for proper screen fit
{ //then set filename as label. Might be replaced with defined label later on below.
//check name length for proper screen fit app->up_label = extract_filename(string_get_cstr(app->up_file), label_len);
//then set filename as label. Might be replaced with defined label later on below.
app->up_label = extract_filename(string_get_cstr(app->up_file), label_len);
FURI_LOG_I(TAG, "UP file: %s", string_get_cstr(app->up_file)); FURI_LOG_I(TAG, "UP file: %s", string_get_cstr(app->up_file));
} }
//Repeat process for Down //Repeat process for Down
if(!flipper_format_read_string(fff_data_file, "DOWN", app->down_file)) if(!flipper_format_read_string(fff_data_file, "DOWN", app->down_file)) {
{
FURI_LOG_I(TAG, "Could not read DOWN string"); FURI_LOG_I(TAG, "Could not read DOWN string");
app->file_blank++; app->file_blank++;
@@ -211,17 +208,14 @@ void unirfremix_cfg_set_check(UniRFRemix* app) {
app->down_enabled = 0; app->down_enabled = 0;
FURI_LOG_I(TAG, "Down_Enabled: %d", app->down_enabled); FURI_LOG_I(TAG, "Down_Enabled: %d", app->down_enabled);
} } else {
else
{
app->down_label = extract_filename(string_get_cstr(app->down_file), label_len); app->down_label = extract_filename(string_get_cstr(app->down_file), label_len);
FURI_LOG_I(TAG, "DOWN file: %s", string_get_cstr(app->down_file)); FURI_LOG_I(TAG, "DOWN file: %s", string_get_cstr(app->down_file));
} }
//Repeat process for Left //Repeat process for Left
if(!flipper_format_read_string(fff_data_file, "LEFT", app->left_file)) if(!flipper_format_read_string(fff_data_file, "LEFT", app->left_file)) {
{
FURI_LOG_I(TAG, "Could not read LEFT string"); FURI_LOG_I(TAG, "Could not read LEFT string");
app->file_blank++; app->file_blank++;
@@ -229,17 +223,14 @@ void unirfremix_cfg_set_check(UniRFRemix* app) {
app->left_enabled = 0; app->left_enabled = 0;
FURI_LOG_I(TAG, "Left_Enabled: %d", app->left_enabled); FURI_LOG_I(TAG, "Left_Enabled: %d", app->left_enabled);
} } else {
else
{
app->left_label = extract_filename(string_get_cstr(app->left_file), label_len); app->left_label = extract_filename(string_get_cstr(app->left_file), label_len);
FURI_LOG_I(TAG, "LEFT file: %s", string_get_cstr(app->left_file)); FURI_LOG_I(TAG, "LEFT file: %s", string_get_cstr(app->left_file));
} }
//Repeat process for Right //Repeat process for Right
if(!flipper_format_read_string(fff_data_file, "RIGHT", app->right_file)) if(!flipper_format_read_string(fff_data_file, "RIGHT", app->right_file)) {
{
FURI_LOG_I(TAG, "Could not read RIGHT string"); FURI_LOG_I(TAG, "Could not read RIGHT string");
app->file_blank++; app->file_blank++;
@@ -247,17 +238,14 @@ void unirfremix_cfg_set_check(UniRFRemix* app) {
app->right_enabled = 0; app->right_enabled = 0;
FURI_LOG_I(TAG, "Right_Enabled: %d", app->right_enabled); FURI_LOG_I(TAG, "Right_Enabled: %d", app->right_enabled);
} } else {
else
{
app->right_label = extract_filename(string_get_cstr(app->right_file), label_len); app->right_label = extract_filename(string_get_cstr(app->right_file), label_len);
FURI_LOG_I(TAG, "RIGHT file: %s", string_get_cstr(app->right_file)); FURI_LOG_I(TAG, "RIGHT file: %s", string_get_cstr(app->right_file));
} }
//Repeat process for Ok //Repeat process for Ok
if(!flipper_format_read_string(fff_data_file, "OK", app->ok_file)) if(!flipper_format_read_string(fff_data_file, "OK", app->ok_file)) {
{
FURI_LOG_I(TAG, "Could not read OK string"); FURI_LOG_I(TAG, "Could not read OK string");
app->file_blank++; app->file_blank++;
@@ -265,16 +253,11 @@ void unirfremix_cfg_set_check(UniRFRemix* app) {
app->ok_enabled = 0; app->ok_enabled = 0;
FURI_LOG_I(TAG, "Ok_Enabled: %d", app->ok_enabled); FURI_LOG_I(TAG, "Ok_Enabled: %d", app->ok_enabled);
} } else {
else
{
app->ok_label = extract_filename(string_get_cstr(app->ok_file), label_len); app->ok_label = extract_filename(string_get_cstr(app->ok_file), label_len);
FURI_LOG_I(TAG, "OK file: %s", string_get_cstr(app->ok_file)); FURI_LOG_I(TAG, "OK file: %s", string_get_cstr(app->ok_file));
} }
//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.
//File definitions are done. //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. //File checks will follow after label assignment in order to close the universal_rf_map file without the need to reopen it again.
@@ -364,137 +347,317 @@ void unirfremix_cfg_set_check(UniRFRemix* app) {
FURI_LOG_I(TAG, "OK label: %s", app->ok_label); FURI_LOG_I(TAG, "OK label: %s", app->ok_label);
} }
app->file_result = 4;
} }
//Close universal_rf_map
flipper_format_free(fff_data_file); flipper_format_free(fff_data_file);
furi_record_close("storage"); furi_record_close("storage");
//File Existence Check
//Check each file definition if not already set to "N/A"
//determine if files exist.
//determine whether or not to continue to launch app with missing variables
//if 5 files are missing, throw error
if(app->file_blank == 5) if(legacy == 1) {
{ //check if legacy map exists (universal_rf_map)
//trigger invalid file error screen string_set(file_name, "/any/subghz/assets/universal_rf_map");
app->file_result = 2;
} storage = furi_record_open("storage");
else fff_data_file = flipper_format_file_alloc(storage);
{
//check all files if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) {
//reset app->file_blank to redetermine if error needs to be thrown FURI_LOG_I(TAG, "Could not open legacy MAP file %s", string_get_cstr(file_name));
app->file_blank = 0; app->file_result = 1;
} else {
//if button is still enabled, check that file exists //Filename Assignment/Check Start
if(app->up_enabled == 1)
{ //assign variables to values within map file
string_set(file_name, app->up_file); //set missing filenames to N/A
Storage* storage = furi_record_open("storage"); if(!flipper_format_read_string(fff_data_file, "UP", app->up_file)) {
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); FURI_LOG_I(TAG, "Could not read UP string");
if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) //increment file_blank for processing later
{ app->file_blank++;
FURI_LOG_I(TAG, "Could not open UP file %s", string_get_cstr(file_name));
//set label to "N/A"
//disable button, and set label to "N/A" app->up_label = "N/A";
app->up_enabled = 0;
app->up_label = "N/A"; //disable the ability to process the signal on button press
app->file_blank++; app->up_enabled = 0;
}
FURI_LOG_I(TAG, "Up_Enabled: %d", app->up_enabled);
//close the file } else {
flipper_format_free(fff_data_file); //check name length for proper screen fit
furi_record_close("storage"); //then set filename as label. Might be replaced with defined label later on below.
} app->up_label = extract_filename(string_get_cstr(app->up_file), label_len);
if(app->down_enabled == 1) FURI_LOG_I(TAG, "UP file: %s", string_get_cstr(app->up_file));
{ }
string_set(file_name, app->down_file);
Storage* storage = furi_record_open("storage"); //Repeat process for Down
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); if(!flipper_format_read_string(fff_data_file, "DOWN", app->down_file)) {
FURI_LOG_I(TAG, "Could not read DOWN string");
if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name)))
{ app->file_blank++;
FURI_LOG_I(TAG, "Could not open DOWN file %s", string_get_cstr(file_name)); app->down_label = "N/A";
app->down_enabled = 0;
app->down_enabled = 0;
app->down_label = "N/A"; FURI_LOG_I(TAG, "Down_Enabled: %d", app->down_enabled);
app->file_blank++; } else {
} app->down_label = extract_filename(string_get_cstr(app->down_file), label_len);
flipper_format_free(fff_data_file); FURI_LOG_I(TAG, "DOWN file: %s", string_get_cstr(app->down_file));
furi_record_close("storage"); }
}
//Repeat process for Left
if(app->left_enabled == 1) if(!flipper_format_read_string(fff_data_file, "LEFT", app->left_file)) {
{ FURI_LOG_I(TAG, "Could not read LEFT string");
string_set(file_name, app->left_file);
Storage* storage = furi_record_open("storage"); app->file_blank++;
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); app->left_label = "N/A";
app->left_enabled = 0;
if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name)))
{ FURI_LOG_I(TAG, "Left_Enabled: %d", app->left_enabled);
FURI_LOG_I(TAG, "Could not open LEFT file %s", string_get_cstr(file_name)); } else {
app->left_label = extract_filename(string_get_cstr(app->left_file), label_len);
app->left_enabled = 0;
app->left_label = "N/A"; FURI_LOG_I(TAG, "LEFT file: %s", string_get_cstr(app->left_file));
app->file_blank++; }
}
//Repeat process for Right
flipper_format_free(fff_data_file); if(!flipper_format_read_string(fff_data_file, "RIGHT", app->right_file)) {
furi_record_close("storage"); FURI_LOG_I(TAG, "Could not read RIGHT string");
}
app->file_blank++;
if(app->right_enabled == 1) app->right_label = "N/A";
{ app->right_enabled = 0;
string_set(file_name, app->right_file);
Storage* storage = furi_record_open("storage"); FURI_LOG_I(TAG, "Right_Enabled: %d", app->right_enabled);
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); } else {
app->right_label = extract_filename(string_get_cstr(app->right_file), label_len);
if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name)))
{ FURI_LOG_I(TAG, "RIGHT file: %s", string_get_cstr(app->right_file));
FURI_LOG_I(TAG, "Could not open RIGHT file %s", string_get_cstr(file_name)); }
app->right_enabled = 0; //Repeat process for Ok
app->right_label = "N/A"; if(!flipper_format_read_string(fff_data_file, "OK", app->ok_file)) {
app->file_blank++; FURI_LOG_I(TAG, "Could not read OK string");
}
app->file_blank++;
flipper_format_free(fff_data_file); app->ok_label = "N/A";
furi_record_close("storage"); app->ok_enabled = 0;
}
FURI_LOG_I(TAG, "Ok_Enabled: %d", app->ok_enabled);
if(app->ok_enabled == 1) } else {
{ app->ok_label = extract_filename(string_get_cstr(app->ok_file), label_len);
string_set(file_name, app->ok_file);
Storage* storage = furi_record_open("storage"); FURI_LOG_I(TAG, "OK file: %s", string_get_cstr(app->ok_file));
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); }
if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) //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.
FURI_LOG_I(TAG, "Could not open OK file %s", string_get_cstr(file_name));
//Label Assignment/Check Start
app->ok_enabled = 0;
app->ok_label = "N/A"; //assign variables to values within map file
app->file_blank++; if(!flipper_format_read_string(fff_data_file, "ULABEL", app->up_l)) {
} FURI_LOG_I(TAG, "Could not read ULABEL string");
flipper_format_free(fff_data_file); //if Up button is disabled, set the label to "N/A";
furi_record_close("storage"); if(app->up_enabled == 0) {
} app->up_label = "N/A";
}
if(app->file_blank == 5) } else {
{ //check if button is disabled, and set label to "N/A" from missing map definition above
app->file_result = 2; if(app->up_enabled == 0) {
} app->up_label = "N/A";
else } else {
{ //set label from map to variable and shrink to fit screen
app->file_result = 0; app->up_label = char_to_str((char*)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_I(TAG, "Could not read DLABEL string");
if(app->down_enabled == 0) {
app->down_label = "N/A";
}
} else {
if(app->down_enabled == 0) {
app->down_label = "N/A";
} else {
app->down_label = char_to_str((char*)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_I(TAG, "Could not read LLABEL string");
if(app->left_enabled == 0) {
app->left_label = "N/A";
}
} else {
if(app->left_enabled == 0) {
app->left_label = "N/A";
} else {
app->left_label = char_to_str((char*)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_I(TAG, "Could not read RLABEL string");
if(app->right_enabled == 0) {
app->right_label = "N/A";
}
} else {
if(app->right_enabled == 0) {
app->right_label = "N/A";
} else {
app->right_label =
char_to_str((char*)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_I(TAG, "Could not read OKLABEL string");
if(app->ok_enabled == 0) {
app->ok_label = "N/A";
}
} else {
if(app->ok_enabled == 0) {
app->ok_label = "N/A";
} else {
app->ok_label = char_to_str((char*)string_get_cstr(app->ok_l), label_len);
}
FURI_LOG_I(TAG, "OK label: %s", app->ok_label);
}
app->file_result = 4;
}
flipper_format_free(fff_data_file);
furi_record_close("storage");
}
//File Existence Check
//Check each file definition if not already set to "N/A"
//determine if files exist.
//determine whether or not to continue to launch app with missing variables
//if 5 files are missing, throw error
FURI_LOG_I(TAG, "app->file_blank: %d", app->file_blank);
if(app->file_blank == 5) {
//trigger invalid file error screen
app->file_result = 2;
} else {
//check all files
//reset app->file_blank to redetermine if error needs to be thrown
app->file_blank = 0;
//if button is still enabled, check that file exists
if(app->up_enabled == 1) {
string_set(file_name, app->up_file);
storage = furi_record_open("storage");
fff_data_file = flipper_format_file_alloc(storage);
if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) {
FURI_LOG_I(TAG, "Could not open UP file %s", string_get_cstr(file_name));
//disable button, and set label to "N/A"
app->up_enabled = 0;
app->up_label = "N/A";
app->file_blank++;
}
//close the file
flipper_format_free(fff_data_file);
furi_record_close("storage");
}
if(app->down_enabled == 1) {
string_set(file_name, app->down_file);
storage = furi_record_open("storage");
fff_data_file = flipper_format_file_alloc(storage);
if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) {
FURI_LOG_I(TAG, "Could not open DOWN file %s", string_get_cstr(file_name));
app->down_enabled = 0;
app->down_label = "N/A";
app->file_blank++;
}
flipper_format_free(fff_data_file);
furi_record_close("storage");
}
if(app->left_enabled == 1) {
string_set(file_name, app->left_file);
storage = furi_record_open("storage");
fff_data_file = flipper_format_file_alloc(storage);
if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) {
FURI_LOG_I(TAG, "Could not open LEFT file %s", string_get_cstr(file_name));
app->left_enabled = 0;
app->left_label = "N/A";
app->file_blank++;
}
flipper_format_free(fff_data_file);
furi_record_close("storage");
}
if(app->right_enabled == 1) {
string_set(file_name, app->right_file);
storage = furi_record_open("storage");
fff_data_file = flipper_format_file_alloc(storage);
if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) {
FURI_LOG_I(TAG, "Could not open RIGHT file %s", string_get_cstr(file_name));
app->right_enabled = 0;
app->right_label = "N/A";
app->file_blank++;
}
flipper_format_free(fff_data_file);
furi_record_close("storage");
}
if(app->ok_enabled == 1) {
string_set(file_name, app->ok_file);
storage = furi_record_open("storage");
fff_data_file = flipper_format_file_alloc(storage);
if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) {
FURI_LOG_I(TAG, "Could not open OK file %s", string_get_cstr(file_name));
app->ok_enabled = 0;
app->ok_label = "N/A";
app->file_blank++;
}
flipper_format_free(fff_data_file);
furi_record_close("storage");
}
if(app->file_blank == 5) {
app->file_result = 2;
} else {
app->file_result = 4;
}
}
} }
static void unirfremix_end_send(UniRFRemix* app) { static void unirfremix_end_send(UniRFRemix* app) {
@@ -599,6 +762,8 @@ static void unirfremix_process_signal(UniRFRemix* app, string_t signal) {
FURI_LOG_I(TAG, "%lu", frequency_str); FURI_LOG_I(TAG, "%lu", frequency_str);
string_clear(file_name);
unirfremix_send_signal(app, frequency_str, signal, protocol); unirfremix_send_signal(app, frequency_str, signal, protocol);
} else if(strlen(string_get_cstr(signal)) < 10) { } else if(strlen(string_get_cstr(signal)) < 10) {
unirfremix_end_send(app); unirfremix_end_send(app);
@@ -628,6 +793,13 @@ static void render_callback(Canvas* canvas, void* ctx) {
canvas_draw_str_aligned(canvas, 62, 25, AlignCenter, AlignTop, "Please configure"); canvas_draw_str_aligned(canvas, 62, 25, AlignCenter, AlignTop, "Please configure");
canvas_draw_str_aligned(canvas, 62, 35, AlignCenter, AlignTop, "universal_rf_map"); canvas_draw_str_aligned(canvas, 62, 35, AlignCenter, AlignTop, "universal_rf_map");
canvas_draw_str_aligned(canvas, 62, 60, AlignCenter, AlignBottom, "Hold Back to Exit."); canvas_draw_str_aligned(canvas, 62, 60, AlignCenter, AlignBottom, "Hold Back to Exit.");
} else if(app->file_result == 3) {
//if map has no valid filenames defined
canvas_clear(canvas);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 62, 5, AlignCenter, AlignTop, "Config is loading.");
canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(canvas, 62, 35, AlignCenter, AlignTop, "Please wait.");
} else { } else {
//map found, draw all the things //map found, draw all the things
canvas_clear(canvas); canvas_clear(canvas);
@@ -713,6 +885,19 @@ UniRFRemix* unirfremix_alloc() {
} }
void unirfremix_free(UniRFRemix* app) { void unirfremix_free(UniRFRemix* app) {
string_clear(app->up_file);
string_clear(app->down_file);
string_clear(app->left_file);
string_clear(app->right_file);
string_clear(app->ok_file);
string_clear(app->empty);
string_clear(app->up_l);
string_clear(app->down_l);
string_clear(app->left_l);
string_clear(app->right_l);
string_clear(app->ok_l);
gui_remove_view_port(app->gui, app->view_port); gui_remove_view_port(app->gui, app->view_port);
furi_record_close("gui"); furi_record_close("gui");
view_port_free(app->view_port); view_port_free(app->view_port);
@@ -742,12 +927,14 @@ int32_t unirfremix_app(void* p) {
string_init(app->right_l); string_init(app->right_l);
string_init(app->ok_l); string_init(app->ok_l);
app->file_result = 3;
//check map and population variables //check map and population variables
unirfremix_cfg_set_check(app); unirfremix_cfg_set_check(app);
bool exit_loop = false; bool exit_loop = false;
if(app->file_result == 0) { if(app->file_result == 4) {
FURI_LOG_I( FURI_LOG_I(
TAG, TAG,
"U: %s - D: %s - L: %s - R: %s - O: %s ", "U: %s - D: %s - L: %s - R: %s - O: %s ",
@@ -867,7 +1054,7 @@ int32_t unirfremix_app(void* p) {
} else if(app->processing == 1) { } else if(app->processing == 1) {
FURI_LOG_I(TAG, "processing 1"); FURI_LOG_I(TAG, "processing 1");
app->send_status = "Sending"; app->send_status = "Send";
switch(app->button) { switch(app->button) {
case 1: case 1: