Skip to content

Commit

Permalink
Led indicator
Browse files Browse the repository at this point in the history
- Adds led indicator to emulation window which shows a different colour if when delaying to when its emulating
- Adds setting letting you disable it
  • Loading branch information
acegoal07 committed Dec 21, 2023
1 parent 7dca89a commit ea43c22
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 6 deletions.
3 changes: 3 additions & 0 deletions application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ App(
Lib(
name="worker",
),
Lib(
name="led",
),
],
)
41 changes: 41 additions & 0 deletions lib/led/nfc_playlist_led.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "nfc_playlist_led.h"

NotificationMessage blink_message_normal = {
.type = NotificationMessageTypeLedBlinkStart,
.data.led_blink.color = LightBlue | LightGreen,
.data.led_blink.on_time = 10,
.data.led_blink.period = 100,
};
const NotificationSequence blink_sequence_normal = {
&blink_message_normal,
&message_do_not_reset,
NULL,
};
void start_normal_blink(NfcPlaylist* nfc_playlist) {
if (nfc_playlist->emulate_led_indicator) {
notification_message_block(nfc_playlist->notification, &blink_sequence_normal);
}
}

NotificationMessage blink_message_error = {
.type = NotificationMessageTypeLedBlinkStart,
.data.led_blink.color = LightRed,
.data.led_blink.on_time = 10,
.data.led_blink.period = 100,
};
const NotificationSequence blink_sequence_error = {
&blink_message_error,
&message_do_not_reset,
NULL,
};
void start_error_blink(NfcPlaylist* nfc_playlist) {
if (nfc_playlist->emulate_led_indicator) {
notification_message_block(nfc_playlist->notification, &blink_sequence_error);
}
}

void stop_blink(NfcPlaylist* nfc_playlist) {
if (nfc_playlist->emulate_led_indicator) {
notification_message_block(nfc_playlist->notification, &sequence_blink_stop);
}
}
7 changes: 7 additions & 0 deletions lib/led/nfc_playlist_led.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once
#include <../../nfc_playlist.h>
#include <notification/notification_messages.h>

void start_normal_blink(NfcPlaylist* nfc_playlist);
void start_error_blink(NfcPlaylist* nfc_playlist);
void stop_blink(NfcPlaylist* nfc_playlist);
5 changes: 4 additions & 1 deletion nfc_playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ static NfcPlaylist* nfc_playlist_alloc() {
nfc_playlist->popup = popup_alloc();
nfc_playlist->emulate_timeout = default_emulate_timeout;
nfc_playlist->emulate_delay = default_emulate_delay;
nfc_playlist->emulate_led_indicator = default_emulate_led_indicator;
nfc_playlist->notification = furi_record_open(RECORD_NOTIFICATION);

view_dispatcher_set_event_callback_context(nfc_playlist->view_dispatcher, nfc_playlist);
view_dispatcher_set_custom_event_callback(nfc_playlist->view_dispatcher, nfc_playlist_custom_callback);
Expand All @@ -67,6 +69,7 @@ static void nfc_playlist_free(NfcPlaylist* nfc_playlist) {
view_dispatcher_free(nfc_playlist->view_dispatcher);
variable_item_list_free(nfc_playlist->variable_item_list);
popup_free(nfc_playlist->popup);
furi_record_close(RECORD_NOTIFICATION);
free(nfc_playlist);
}

Expand All @@ -84,4 +87,4 @@ int32_t nfc_playlist_main(void* p) {
nfc_playlist_free(nfc_playlist);

return 0;
}
}
6 changes: 5 additions & 1 deletion nfc_playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <gui/scene_manager.h>
#include <gui/modules/popup.h>
#include <gui/modules/variable_item_list.h>
#include <notification/notification_messages.h>

typedef enum {
NfcPlaylistView_Menu,
Expand All @@ -23,11 +24,14 @@ typedef struct {
ViewDispatcher* view_dispatcher;
VariableItemList* variable_item_list;
Popup* popup;
NotificationApp* notification;
uint8_t emulate_timeout;
uint8_t emulate_delay;
bool emulate_led_indicator;
} NfcPlaylist;

static const int options_emulate_timeout[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
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 int default_emulate_delay = 0;
static const bool default_emulate_led_indicator = true;
9 changes: 5 additions & 4 deletions scences/emulation.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void nfc_playlist_emulation_scene_on_enter(void* context) {
while(stream_read_line(stream, line)) {
if (options_emulate_delay[nfc_playlist->emulate_delay] > 0) {
if (file_position > 0) {
start_error_blink(nfc_playlist);
int time_counter_delay_ms = (options_emulate_delay[nfc_playlist->emulate_delay] * 1000);
do {
char display_text[30];
Expand All @@ -39,6 +40,7 @@ void nfc_playlist_emulation_scene_on_enter(void* context) {
int time_counter_ms = (options_emulate_timeout[nfc_playlist->emulate_timeout] * 1000);

if (storage_file_exists(storage, file_path) == false) {
start_error_blink(nfc_playlist);
char const* popup_text_unformatted = strcat(file_name, "\nnot found");
int popup_text_size = (strlen(popup_text_unformatted) + 4);
char popup_text[popup_text_size];
Expand All @@ -50,6 +52,7 @@ void nfc_playlist_emulation_scene_on_enter(void* context) {
time_counter_ms -= 500;
} while(time_counter_ms > 0);
} else {
start_normal_blink(nfc_playlist);
nfc_playlist_worker_set_nfc_data(nfc_worker, file_path);
nfc_playlist_worker_start(nfc_worker);

Expand All @@ -62,14 +65,12 @@ void nfc_playlist_emulation_scene_on_enter(void* context) {
furi_delay_ms(500);
time_counter_ms -= 500;
} while(nfc_playlist_worker_is_emulating(nfc_worker) && time_counter_ms > 0);

if (nfc_playlist_worker_is_emulating(nfc_worker)) {
nfc_playlist_worker_stop(nfc_worker);
}
nfc_playlist_worker_stop(nfc_worker);
}
}
popup_reset(nfc_playlist->popup);
scene_manager_previous_scene(nfc_playlist->scene_manager);
stop_blink(nfc_playlist);
} else {
popup_reset(nfc_playlist->popup);
popup_set_context(nfc_playlist->popup, nfc_playlist);
Expand Down
1 change: 1 addition & 0 deletions scences/emulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <toolbox/stream/stream.h>
#include <toolbox/stream/file_stream.h>
#include <lib/worker/nfc_playlist_worker.h>
#include <lib/led/nfc_playlist_led.h>
#include <gui/gui.h>
#include <gui/view_dispatcher.h>
#include <gui/scene_manager.h>
Expand Down
15 changes: 15 additions & 0 deletions scences/main_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ typedef enum {
typedef enum {
NfcPlaylistSettings_Timeout,
NfcPlaylistSettings_Delay,
NfcPlaylistSettings_LedIndicator,
NfcPlaylistMenuSelection_Start
} NfcPlaylistMenuSelection;

Expand Down Expand Up @@ -43,6 +44,10 @@ static void nfc_playlist_settings_change_callback(VariableItem* item) {
variable_item_set_current_value_text(item, (char*)emulate_delay_text);
break;
}
case NfcPlaylistSettings_LedIndicator:
nfc_playlist->emulate_led_indicator = option_value_index;
variable_item_set_current_value_text(item, nfc_playlist->emulate_led_indicator ? "ON" : "OFF");
break;
default:
break;
}
Expand Down Expand Up @@ -74,6 +79,16 @@ void nfc_playlist_main_menu_scene_on_enter(void* context) {
snprintf(emulation_delay_settings_text, 10, "%ds", options_emulate_delay[nfc_playlist->emulate_delay]);
variable_item_set_current_value_text(emulation_delay_settings, (char*)emulation_delay_settings_text);

// add bool setting
VariableItem* emulation_led_indicator_settings = variable_item_list_add(
nfc_playlist->variable_item_list,
"LED Indicator",
2,
nfc_playlist_settings_change_callback,
nfc_playlist);
variable_item_set_current_value_index(emulation_led_indicator_settings, nfc_playlist->emulate_led_indicator);
variable_item_set_current_value_text(emulation_led_indicator_settings, nfc_playlist->emulate_led_indicator ? "ON" : "OFF");

variable_item_list_add(nfc_playlist->variable_item_list, "Start", 0, NULL, NULL);
variable_item_list_set_enter_callback(nfc_playlist->variable_item_list, nfc_playlist_menu_callback, nfc_playlist);
view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Menu);
Expand Down

0 comments on commit ea43c22

Please sign in to comment.