[FL-2864] NFC update detect reader (#1820)
* nfc: update detect reader view * nfc: make detect reader more interractive * nfc: update icons * nfc: fix detect reader gui * nfc: fix gui, fix worker events * nfc: fix notifications * nfc: add nfc_worker NULL assert Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
#include "../nfc_i.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
#define NFC_SCENE_DETECT_READER_PAIR_NONCES_MAX (10U)
|
||||
|
||||
static const NotificationSequence sequence_detect_reader = {
|
||||
&message_green_255,
|
||||
&message_blue_255,
|
||||
&message_do_not_reset,
|
||||
NULL,
|
||||
};
|
||||
|
||||
bool nfc_detect_reader_worker_callback(NfcWorkerEvent event, void* context) {
|
||||
UNUSED(event);
|
||||
furi_assert(context);
|
||||
@@ -20,21 +29,26 @@ void nfc_scene_detect_reader_on_enter(void* context) {
|
||||
DOLPHIN_DEED(DolphinDeedNfcEmulate);
|
||||
|
||||
detect_reader_set_callback(nfc->detect_reader, nfc_scene_detect_reader_callback, nfc);
|
||||
detect_reader_set_nonces_max(nfc->detect_reader, NFC_SCENE_DETECT_READER_PAIR_NONCES_MAX);
|
||||
|
||||
// Store number of collected nonces in scene state
|
||||
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneDetectReader, 0);
|
||||
notification_message(nfc->notifications, &sequence_detect_reader);
|
||||
|
||||
nfc_worker_start(
|
||||
nfc->worker,
|
||||
NfcWorkerStateAnalyzeReader,
|
||||
&nfc->dev->dev_data,
|
||||
nfc_detect_reader_worker_callback,
|
||||
nfc);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewDetectReader);
|
||||
|
||||
nfc_blink_read_start(nfc);
|
||||
}
|
||||
|
||||
bool nfc_scene_detect_reader_on_event(void* context, SceneManagerEvent event) {
|
||||
Nfc* nfc = context;
|
||||
bool consumed = false;
|
||||
uint32_t nonces_collected =
|
||||
scene_manager_get_scene_state(nfc->scene_manager, NfcSceneDetectReader);
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == NfcCustomEventViewExit) {
|
||||
@@ -42,8 +56,29 @@ bool nfc_scene_detect_reader_on_event(void* context, SceneManagerEvent event) {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfkeyNoncesInfo);
|
||||
consumed = true;
|
||||
} else if(event.event == NfcWorkerEventDetectReaderMfkeyCollected) {
|
||||
detect_reader_inc_nonce_cnt(nfc->detect_reader);
|
||||
nonces_collected += 2;
|
||||
scene_manager_set_scene_state(
|
||||
nfc->scene_manager, NfcSceneDetectReader, nonces_collected);
|
||||
detect_reader_set_nonces_collected(nfc->detect_reader, nonces_collected);
|
||||
if(nonces_collected >= NFC_SCENE_DETECT_READER_PAIR_NONCES_MAX) {
|
||||
detect_reader_set_state(nfc->detect_reader, DetectReaderStateDone);
|
||||
nfc_blink_stop(nfc);
|
||||
notification_message(nfc->notifications, &sequence_single_vibro);
|
||||
notification_message(nfc->notifications, &sequence_set_green_255);
|
||||
nfc_worker_stop(nfc->worker);
|
||||
}
|
||||
consumed = true;
|
||||
} else if(event.event == NfcWorkerEventDetectReaderDetected) {
|
||||
if(nonces_collected < NFC_SCENE_DETECT_READER_PAIR_NONCES_MAX) {
|
||||
notification_message(nfc->notifications, &sequence_blink_start_cyan);
|
||||
detect_reader_set_state(nfc->detect_reader, DetectReaderStateReaderDetected);
|
||||
}
|
||||
} else if(event.event == NfcWorkerEventDetectReaderLost) {
|
||||
if(nonces_collected < NFC_SCENE_DETECT_READER_PAIR_NONCES_MAX) {
|
||||
nfc_blink_stop(nfc);
|
||||
notification_message(nfc->notifications, &sequence_detect_reader);
|
||||
detect_reader_set_state(nfc->detect_reader, DetectReaderStateReaderLost);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,5 +94,7 @@ void nfc_scene_detect_reader_on_exit(void* context) {
|
||||
// Clear view
|
||||
detect_reader_reset(nfc->detect_reader);
|
||||
|
||||
// Stop notifications
|
||||
nfc_blink_stop(nfc);
|
||||
notification_message(nfc->notifications, &sequence_reset_green);
|
||||
}
|
||||
|
@@ -16,14 +16,14 @@ void nfc_scene_mfkey_nonces_info_on_enter(void* context) {
|
||||
|
||||
uint16_t nonces_saved = mfkey32_get_auth_sectors(temp_str);
|
||||
widget_add_text_scroll_element(nfc->widget, 0, 22, 128, 42, furi_string_get_cstr(temp_str));
|
||||
furi_string_printf(temp_str, "Nonces saved %d", nonces_saved);
|
||||
furi_string_printf(temp_str, "Nonce pairs saved: %d", nonces_saved);
|
||||
widget_add_string_element(
|
||||
nfc->widget, 0, 0, AlignLeft, AlignTop, FontPrimary, furi_string_get_cstr(temp_str));
|
||||
widget_add_string_element(
|
||||
nfc->widget, 0, 12, AlignLeft, AlignTop, FontSecondary, "Authenticated sectors:");
|
||||
|
||||
widget_add_button_element(
|
||||
nfc->widget, GuiButtonTypeRight, "Next", nfc_scene_mfkey_nonces_info_callback, nfc);
|
||||
nfc->widget, GuiButtonTypeCenter, "OK", nfc_scene_mfkey_nonces_info_callback, nfc);
|
||||
|
||||
furi_string_free(temp_str);
|
||||
|
||||
@@ -35,7 +35,7 @@ bool nfc_scene_mfkey_nonces_info_on_event(void* context, SceneManagerEvent event
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == GuiButtonTypeRight) {
|
||||
if(event.event == GuiButtonTypeCenter) {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfkeyComplete);
|
||||
consumed = true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user