Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FL-3388] NFC/RFID detector #2795

Merged
merged 12 commits into from
Jun 28, 2023
Merged
13 changes: 13 additions & 0 deletions applications/external/nfc_rfid_detector/application.fam
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
App(
appid="nfc_rfid_detector",
name="NFC/RFID detector",
apptype=FlipperAppType.EXTERNAL,
targets=["f7"],
entry_point="nfc_rfid_detector_app",
requires=["gui"],
stack_size=4 * 1024,
order=50,
fap_icon="nfc_rfid_detector_10px.png",
fap_category="Tools",
fap_icon_assets="images",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

typedef enum {
//NfcRfidDetectorCustomEvent
NfcRfidDetectorCustomEventStartId = 100,

} NfcRfidDetectorCustomEvent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <furi.h>
#include <furi_hal.h>

#define NFC_RFID_DETECTOR_VERSION_APP "0.1"
#define NFC_RFID_DETECTOR_DEVELOPED "SkorP"
#define NFC_RFID_DETECTOR_GITHUB "https://github.com/flipperdevices/flipperzero-firmware"

typedef enum {
NfcRfidDetectorViewVariableItemList,
NfcRfidDetectorViewSubmenu,
NfcRfidDetectorViewFieldPresence,
NfcRfidDetectorViewWidget,
} NfcRfidDetectorView;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
108 changes: 108 additions & 0 deletions applications/external/nfc_rfid_detector/nfc_rfid_detector_app.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#include "nfc_rfid_detector_app_i.h"

#include <furi.h>
#include <furi_hal.h>

static bool nfc_rfid_detector_app_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
NfcRfidDetectorApp* app = context;
return scene_manager_handle_custom_event(app->scene_manager, event);
}

static bool nfc_rfid_detector_app_back_event_callback(void* context) {
furi_assert(context);
NfcRfidDetectorApp* app = context;
return scene_manager_handle_back_event(app->scene_manager);
}

static void nfc_rfid_detector_app_tick_event_callback(void* context) {
furi_assert(context);
NfcRfidDetectorApp* app = context;
scene_manager_handle_tick_event(app->scene_manager);
}

NfcRfidDetectorApp* nfc_rfid_detector_app_alloc() {
NfcRfidDetectorApp* app = malloc(sizeof(NfcRfidDetectorApp));

// GUI
app->gui = furi_record_open(RECORD_GUI);

// View Dispatcher
app->view_dispatcher = view_dispatcher_alloc();
app->scene_manager = scene_manager_alloc(&nfc_rfid_detector_scene_handlers, app);
view_dispatcher_enable_queue(app->view_dispatcher);

view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
view_dispatcher_set_custom_event_callback(
app->view_dispatcher, nfc_rfid_detector_app_custom_event_callback);
view_dispatcher_set_navigation_event_callback(
app->view_dispatcher, nfc_rfid_detector_app_back_event_callback);
view_dispatcher_set_tick_event_callback(
app->view_dispatcher, nfc_rfid_detector_app_tick_event_callback, 100);

view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);

// Open Notification record
app->notifications = furi_record_open(RECORD_NOTIFICATION);

// SubMenu
app->submenu = submenu_alloc();
view_dispatcher_add_view(
app->view_dispatcher, NfcRfidDetectorViewSubmenu, submenu_get_view(app->submenu));

// Widget
app->widget = widget_alloc();
view_dispatcher_add_view(
app->view_dispatcher, NfcRfidDetectorViewWidget, widget_get_view(app->widget));

// Field Presence
app->nfc_rfid_detector_field_presence = nfc_rfid_detector_view_field_presence_alloc();
view_dispatcher_add_view(
app->view_dispatcher,
NfcRfidDetectorViewFieldPresence,
nfc_rfid_detector_view_field_presence_get_view(app->nfc_rfid_detector_field_presence));

scene_manager_next_scene(app->scene_manager, NfcRfidDetectorSceneStart);

return app;
}

void nfc_rfid_detector_app_free(NfcRfidDetectorApp* app) {
furi_assert(app);

// Submenu
view_dispatcher_remove_view(app->view_dispatcher, NfcRfidDetectorViewSubmenu);
submenu_free(app->submenu);

// Widget
view_dispatcher_remove_view(app->view_dispatcher, NfcRfidDetectorViewWidget);
widget_free(app->widget);

// Field Presence
view_dispatcher_remove_view(app->view_dispatcher, NfcRfidDetectorViewFieldPresence);
nfc_rfid_detector_view_field_presence_free(app->nfc_rfid_detector_field_presence);

// View dispatcher
view_dispatcher_free(app->view_dispatcher);
scene_manager_free(app->scene_manager);

// Notifications
furi_record_close(RECORD_NOTIFICATION);
app->notifications = NULL;

// Close records
furi_record_close(RECORD_GUI);

free(app);
}

int32_t nfc_rfid_detector_app(void* p) {
UNUSED(p);
NfcRfidDetectorApp* nfc_rfid_detector_app = nfc_rfid_detector_app_alloc();

view_dispatcher_run(nfc_rfid_detector_app->view_dispatcher);

nfc_rfid_detector_app_free(nfc_rfid_detector_app);

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "nfc_rfid_detector_app_i.h"

#include <furi.h>

#define TAG "NfcRfidDetector"

void nfc_rfid_detector_app_field_presence_start(NfcRfidDetectorApp* app) {
furi_assert(app);

// start the field presence rfid detection
furi_hal_rfid_field_detect_start();

// start the field presence nfc detection
furi_hal_nfc_exit_sleep();
furi_hal_nfc_field_detect_start();
}

void nfc_rfid_detector_app_field_presence_stop(NfcRfidDetectorApp* app) {
furi_assert(app);

// stop the field presence rfid detection
furi_hal_rfid_field_detect_stop();

// stop the field presence nfc detection
furi_hal_nfc_start_sleep();
}

bool nfc_rfid_detector_app_field_presence_is_nfc(NfcRfidDetectorApp* app) {
furi_assert(app);

// check if the field presence is nfc
return furi_hal_nfc_field_is_present();
}

bool nfc_rfid_detector_app_field_presence_is_rfid(NfcRfidDetectorApp* app, uint32_t* frequency) {
furi_assert(app);

// check if the field presence is rfid
return furi_hal_rfid_field_is_present(frequency);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "helpers/nfc_rfid_detector_types.h"
#include "helpers/nfc_rfid_detector_event.h"

#include "scenes/nfc_rfid_detector_scene.h"
#include <gui/gui.h>
#include <gui/view_dispatcher.h>
#include <gui/scene_manager.h>
#include <gui/modules/submenu.h>
#include <gui/modules/widget.h>
#include <notification/notification_messages.h>
#include "views/nfc_rfid_detector_view_field_presence.h"

typedef struct NfcRfidDetectorApp NfcRfidDetectorApp;

struct NfcRfidDetectorApp {
Gui* gui;
ViewDispatcher* view_dispatcher;
SceneManager* scene_manager;
NotificationApp* notifications;
Submenu* submenu;
Widget* widget;
NfcRfidDetectorFieldPresence* nfc_rfid_detector_field_presence;
};

void nfc_rfid_detector_app_field_presence_start(NfcRfidDetectorApp* app);
void nfc_rfid_detector_app_field_presence_stop(NfcRfidDetectorApp* app);
bool nfc_rfid_detector_app_field_presence_is_nfc(NfcRfidDetectorApp* app);
bool nfc_rfid_detector_app_field_presence_is_rfid(NfcRfidDetectorApp* app, uint32_t* frequency);
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "../nfc_rfid_detector_app_i.h"

// Generate scene on_enter handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
void (*const nfc_rfid_detector_scene_on_enter_handlers[])(void*) = {
#include "nfc_rfid_detector_scene_config.h"
};
#undef ADD_SCENE

// Generate scene on_event handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
bool (*const nfc_rfid_detector_scene_on_event_handlers[])(void* context, SceneManagerEvent event) =
{
#include "nfc_rfid_detector_scene_config.h"
};
#undef ADD_SCENE

// Generate scene on_exit handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
void (*const nfc_rfid_detector_scene_on_exit_handlers[])(void* context) = {
#include "nfc_rfid_detector_scene_config.h"
};
#undef ADD_SCENE

// Initialize scene handlers configuration structure
const SceneManagerHandlers nfc_rfid_detector_scene_handlers = {
.on_enter_handlers = nfc_rfid_detector_scene_on_enter_handlers,
.on_event_handlers = nfc_rfid_detector_scene_on_event_handlers,
.on_exit_handlers = nfc_rfid_detector_scene_on_exit_handlers,
.scene_num = NfcRfidDetectorSceneNum,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <gui/scene_manager.h>

// Generate scene id and total number
#define ADD_SCENE(prefix, name, id) NfcRfidDetectorScene##id,
typedef enum {
#include "nfc_rfid_detector_scene_config.h"
NfcRfidDetectorSceneNum,
} NfcRfidDetectorScene;
#undef ADD_SCENE

extern const SceneManagerHandlers nfc_rfid_detector_scene_handlers;

// Generate scene on_enter handlers declaration
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
#include "nfc_rfid_detector_scene_config.h"
#undef ADD_SCENE

// Generate scene on_event handlers declaration
#define ADD_SCENE(prefix, name, id) \
bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
#include "nfc_rfid_detector_scene_config.h"
#undef ADD_SCENE

// Generate scene on_exit handlers declaration
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
#include "nfc_rfid_detector_scene_config.h"
#undef ADD_SCENE
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include "../nfc_rfid_detector_app_i.h"

void nfc_rfid_detector_scene_about_widget_callback(
GuiButtonType result,
InputType type,
void* context) {
NfcRfidDetectorApp* app = context;
if(type == InputTypeShort) {
view_dispatcher_send_custom_event(app->view_dispatcher, result);
}
}

void nfc_rfid_detector_scene_about_on_enter(void* context) {
NfcRfidDetectorApp* app = context;

FuriString* temp_str;
temp_str = furi_string_alloc();
furi_string_printf(temp_str, "\e#%s\n", "Information");

furi_string_cat_printf(temp_str, "Version: %s\n", NFC_RFID_DETECTOR_VERSION_APP);
furi_string_cat_printf(temp_str, "Developed by: %s\n", NFC_RFID_DETECTOR_DEVELOPED);
furi_string_cat_printf(temp_str, "Github: %s\n\n", NFC_RFID_DETECTOR_GITHUB);

furi_string_cat_printf(temp_str, "\e#%s\n", "Description");
furi_string_cat_printf(
temp_str,
"This application allows\nyou to determine what\ntype of electromagnetic\nfield the reader is using.\nFor LF RFID you can also\nsee the carrier frequency\n\n");

widget_add_text_box_element(
app->widget,
0,
0,
128,
14,
AlignCenter,
AlignBottom,
"\e#\e! \e!\n",
false);
widget_add_text_box_element(
app->widget,
0,
2,
128,
14,
AlignCenter,
AlignBottom,
"\e#\e! NFC/RFID detector \e!\n",
false);
widget_add_text_scroll_element(app->widget, 0, 16, 128, 50, furi_string_get_cstr(temp_str));
furi_string_free(temp_str);

view_dispatcher_switch_to_view(app->view_dispatcher, NfcRfidDetectorViewWidget);
}

bool nfc_rfid_detector_scene_about_on_event(void* context, SceneManagerEvent event) {
NfcRfidDetectorApp* app = context;
bool consumed = false;
UNUSED(app);
UNUSED(event);

return consumed;
}

void nfc_rfid_detector_scene_about_on_exit(void* context) {
NfcRfidDetectorApp* app = context;

// Clear views
widget_reset(app->widget);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ADD_SCENE(nfc_rfid_detector, start, Start)
ADD_SCENE(nfc_rfid_detector, about, About)
ADD_SCENE(nfc_rfid_detector, field_presence, FieldPresence)
Loading