Procházet zdrojové kódy

Led indicator

- Adds led indicator to emulation window which shows a different colour if when delaying to when its emulating
- Adds setting letting you disable it
acegoal07 před 2 roky
rodič
revize
ea43c22ce5

+ 3 - 0
application.fam

@@ -13,5 +13,8 @@ App(
         Lib(
             name="worker",
         ),
+        Lib(
+            name="led",
+        ),
     ],
 )

+ 41 - 0
lib/led/nfc_playlist_led.c

@@ -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 - 0
lib/led/nfc_playlist_led.h

@@ -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);

+ 4 - 1
nfc_playlist.c

@@ -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);
@@ -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);
 }
 
@@ -84,4 +87,4 @@ int32_t nfc_playlist_main(void* p) {
    nfc_playlist_free(nfc_playlist);
 
    return 0;
-}
+}

+ 5 - 1
nfc_playlist.h

@@ -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,
@@ -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;

+ 5 - 4
scences/emulation.c

@@ -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];
@@ -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];
@@ -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);
 
@@ -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);

+ 1 - 0
scences/emulation.h

@@ -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>

+ 15 - 0
scences/main_menu.c

@@ -8,6 +8,7 @@ typedef enum {
 typedef enum {
     NfcPlaylistSettings_Timeout,
     NfcPlaylistSettings_Delay,
+    NfcPlaylistSettings_LedIndicator,
     NfcPlaylistMenuSelection_Start
 } NfcPlaylistMenuSelection;
 
@@ -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;
    }
@@ -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);