Skip to content

Commit

Permalink
Hide error setting
Browse files Browse the repository at this point in the history
- Adds a setting to hide error messages while emulating
  • Loading branch information
acegoal07 committed Feb 9, 2024
1 parent 42ce380 commit 5999573
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This app was design, built and tested using the <a href="https://github.com/Flip
- Emulate time (How long the NFC card will be emulated for)
- Delay time (How long the gap between the cards will be)
- LED indicator (Whether or not the LED's will be on)
- Hide error messages (Hides any errors about NFC files and just skips to the next one)
- Reset settings (Puts all the settings back to the defaults)

## Playlist editor
Expand Down
2 changes: 1 addition & 1 deletion application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ App(
fap_category="NFC",
fap_author="@acegoal07",
fap_weburl="https://github.com/acegoal07/FlipperZero_NFC_Playlist/tree/main",
fap_version="1.3",
fap_version="1.4",
fap_icon="assets/icon.png",
fap_private_libs=[
Lib(
Expand Down
1 change: 1 addition & 0 deletions nfc_playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ static NfcPlaylist* nfc_playlist_alloc() {
nfc_playlist->settings.emulate_timeout = default_emulate_timeout;
nfc_playlist->settings.emulate_delay = default_emulate_delay;
nfc_playlist->settings.emulate_led_indicator = default_emulate_led_indicator;
nfc_playlist->settings.hide_error = default_hide_error;

nfc_playlist->notification = furi_record_open(RECORD_NOTIFICATION);
nfc_playlist->file_browser = file_browser_alloc(nfc_playlist->settings.file_path);
Expand Down
4 changes: 3 additions & 1 deletion nfc_playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef struct {
uint8_t emulate_timeout;
uint8_t emulate_delay;
bool emulate_led_indicator;
bool hide_error;
} NfcPlaylistSettings;

typedef struct {
Expand All @@ -62,4 +63,5 @@ static const int options_emulate_timeout[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
static const int default_emulate_timeout = 4;
static const int options_emulate_delay[] = { 0, 1, 2, 3, 4, 5, 6 };
static const int default_emulate_delay = 0;
static const bool default_emulate_led_indicator = true;
static const bool default_emulate_led_indicator = true;
static const bool default_hide_error = false;
12 changes: 11 additions & 1 deletion scences/emulation.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "nfc_playlist.h"
#include "scences/emulation.h"

bool hiding_error = false;
NfcPlaylistEmulationState EmulationState = NfcPlaylistEmulationState_Stopped;

void nfc_playlist_emulation_scene_on_enter(void* context) {
Expand Down Expand Up @@ -71,7 +72,7 @@ int32_t nfc_playlist_emulation_task(void* context) {

if (strlen(file_path) <= 1) {continue;}

if (nfc_playlist->settings.emulate_delay > 0 && file_position > 0) {
if (nfc_playlist->settings.emulate_delay > 0 && file_position > 0 && !hiding_error) {
popup_set_header(nfc_playlist->popup, "Delaying", 64, 10, AlignCenter, AlignTop);
start_blink(nfc_playlist, NfcPlaylistLedState_Error);
int time_counter_delay_ms = (options_emulate_delay[nfc_playlist->settings.emulate_delay]*1000);
Expand All @@ -86,6 +87,7 @@ int32_t nfc_playlist_emulation_task(void* context) {
file_position++;
}

if (hiding_error) {hiding_error = false;}
if (EmulationState != NfcPlaylistEmulationState_Emulating) {break;}

char const* full_file_name = strchr(file_path, '/') != NULL ? &strrchr(file_path, '/')[1] : file_path;
Expand All @@ -96,6 +98,10 @@ int32_t nfc_playlist_emulation_task(void* context) {
int time_counter_ms = (options_emulate_timeout[nfc_playlist->settings.emulate_timeout]*1000);

if (storage_file_exists(storage, file_path) == false) {
if (nfc_playlist->settings.hide_error) {
hiding_error = true;
continue;
}
int popup_header_text_size = strlen(file_name) + 18;
char popup_header_text[popup_header_text_size];
snprintf(popup_header_text, popup_header_text_size, "%s\n%s", "ERROR not found:", file_name);
Expand All @@ -109,6 +115,10 @@ int32_t nfc_playlist_emulation_task(void* context) {
time_counter_ms -= 50;
}
} else if (strcasestr(file_ext, "nfc") == NULL) {
if (nfc_playlist->settings.hide_error) {
hiding_error = true;
continue;
}
int popup_header_text_size = strlen(file_name) + 21;
char popup_header_text[popup_header_text_size];
snprintf(popup_header_text, popup_header_text_size, "%s\n%s", "ERROR invalid file:", file_name);
Expand Down
19 changes: 19 additions & 0 deletions scences/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ typedef enum {
NfcPlaylistSettings_Timeout,
NfcPlaylistSettings_Delay,
NfcPlaylistSettings_LedIndicator,
NfcPlaylistSettings_HideError,
NfcPlaylistSettings_Reset
} NfcPlaylistMenuSelection;

Expand All @@ -29,6 +30,11 @@ void nfc_playlist_settings_menu_callback(void* context, uint32_t index) {
VariableItem* emulation_led_indicator_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_LedIndicator);
variable_item_set_current_value_index(emulation_led_indicator_settings, nfc_playlist->settings.emulate_led_indicator);
variable_item_set_current_value_text(emulation_led_indicator_settings, nfc_playlist->settings.emulate_led_indicator ? "ON" : "OFF");

nfc_playlist->settings.hide_error = default_hide_error;
VariableItem* hide_error_indicator_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_HideError);
variable_item_set_current_value_index(hide_error_indicator_settings, nfc_playlist->settings.hide_error);
variable_item_set_current_value_text(hide_error_indicator_settings, nfc_playlist->settings.hide_error ? "ON" : "OFF");
}
}

Expand Down Expand Up @@ -57,6 +63,10 @@ void nfc_playlist_settings_options_change_callback(VariableItem* item) {
nfc_playlist->settings.emulate_led_indicator = option_value_index;
variable_item_set_current_value_text(item, nfc_playlist->settings.emulate_led_indicator ? "ON" : "OFF");
break;
case NfcPlaylistSettings_HideError:
nfc_playlist->settings.hide_error = option_value_index;
variable_item_set_current_value_text(item, nfc_playlist->settings.hide_error ? "ON" : "OFF");
break;
default:
break;
}
Expand Down Expand Up @@ -98,6 +108,15 @@ void nfc_playlist_settings_scene_on_enter(void* context) {
variable_item_set_current_value_index(emulation_led_indicator_settings, nfc_playlist->settings.emulate_led_indicator);
variable_item_set_current_value_text(emulation_led_indicator_settings, nfc_playlist->settings.emulate_led_indicator ? "ON" : "OFF");

VariableItem* hide_error_indicator_settings = variable_item_list_add(
nfc_playlist->variable_item_list,
"Hide error messages",
2,
nfc_playlist_settings_options_change_callback,
nfc_playlist);
variable_item_set_current_value_index(hide_error_indicator_settings, nfc_playlist->settings.hide_error);
variable_item_set_current_value_text(hide_error_indicator_settings, nfc_playlist->settings.hide_error ? "ON" : "OFF");

variable_item_list_add(nfc_playlist->variable_item_list, "Reset settings", 0, NULL, NULL);

variable_item_list_set_enter_callback(nfc_playlist->variable_item_list, nfc_playlist_settings_menu_callback, nfc_playlist);
Expand Down

0 comments on commit 5999573

Please sign in to comment.