Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Commit

Permalink
NFC Maker add contact vcard support
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy-JL committed Jul 12, 2023
1 parent 99b6a6a commit e448f5a
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
ADD_SCENE(nfc_maker, start, Start)
ADD_SCENE(nfc_maker, bluetooth, Bluetooth)
ADD_SCENE(nfc_maker, contact, Contact)
ADD_SCENE(nfc_maker, contact_last, ContactLast)
ADD_SCENE(nfc_maker, contact_mail, ContactMail)
ADD_SCENE(nfc_maker, contact_phone, ContactPhone)
ADD_SCENE(nfc_maker, contact_url, ContactUrl)
ADD_SCENE(nfc_maker, https, Https)
ADD_SCENE(nfc_maker, mail, Mail)
ADD_SCENE(nfc_maker, phone, Phone)
Expand Down
53 changes: 53 additions & 0 deletions applications/external/nfc_maker/scenes/nfc_maker_scene_contact.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "../nfc_maker.h"

enum TextInputResult {
TextInputResultOk,
};

static void nfc_maker_scene_contact_text_input_callback(void* context) {
NfcMaker* app = context;

view_dispatcher_send_custom_event(app->view_dispatcher, TextInputResultOk);
}

void nfc_maker_scene_contact_on_enter(void* context) {
NfcMaker* app = context;
TextInput* text_input = app->text_input;

text_input_set_header_text(text_input, "Enter First Name:");

strlcpy(app->small_buf1, "Ben", SMALL_INPUT_LEN);

text_input_set_result_callback(
text_input,
nfc_maker_scene_contact_text_input_callback,
app,
app->small_buf1,
SMALL_INPUT_LEN,
true);

view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);
}

bool nfc_maker_scene_contact_on_event(void* context, SceneManagerEvent event) {
NfcMaker* app = context;
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
switch(event.event) {
case TextInputResultOk:
scene_manager_next_scene(app->scene_manager, NfcMakerSceneContactLast);
break;
default:
break;
}
}

return consumed;
}

void nfc_maker_scene_contact_on_exit(void* context) {
NfcMaker* app = context;
text_input_reset(app->text_input);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "../nfc_maker.h"

enum TextInputResult {
TextInputResultOk,
};

static void nfc_maker_scene_contact_last_text_input_callback(void* context) {
NfcMaker* app = context;

view_dispatcher_send_custom_event(app->view_dispatcher, TextInputResultOk);
}

void nfc_maker_scene_contact_last_on_enter(void* context) {
NfcMaker* app = context;
TextInput* text_input = app->text_input;

text_input_set_header_text(text_input, "Enter Last Name:");

strlcpy(app->small_buf2, "Dover", SMALL_INPUT_LEN);

text_input_set_result_callback(
text_input,
nfc_maker_scene_contact_last_text_input_callback,
app,
app->small_buf2,
SMALL_INPUT_LEN,
true);

text_input_set_minimum_length(text_input, 0);

view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);
}

bool nfc_maker_scene_contact_last_on_event(void* context, SceneManagerEvent event) {
NfcMaker* app = context;
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
switch(event.event) {
case TextInputResultOk:
scene_manager_next_scene(app->scene_manager, NfcMakerSceneContactMail);
break;
default:
break;
}
}

return consumed;
}

void nfc_maker_scene_contact_last_on_exit(void* context) {
NfcMaker* app = context;
text_input_reset(app->text_input);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "../nfc_maker.h"

enum TextInputResult {
TextInputResultOk,
};

static void nfc_maker_scene_contact_mail_text_input_callback(void* context) {
NfcMaker* app = context;

view_dispatcher_send_custom_event(app->view_dispatcher, TextInputResultOk);
}

void nfc_maker_scene_contact_mail_on_enter(void* context) {
NfcMaker* app = context;
TextInput* text_input = app->text_input;

text_input_set_header_text(text_input, "Enter Mail Address:");

strlcpy(app->mail_buf, "[email protected]", MAIL_INPUT_LEN);

text_input_set_result_callback(
text_input,
nfc_maker_scene_contact_mail_text_input_callback,
app,
app->mail_buf,
MAIL_INPUT_LEN,
true);

text_input_set_minimum_length(text_input, 0);

view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);
}

bool nfc_maker_scene_contact_mail_on_event(void* context, SceneManagerEvent event) {
NfcMaker* app = context;
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
switch(event.event) {
case TextInputResultOk:
scene_manager_next_scene(app->scene_manager, NfcMakerSceneContactPhone);
break;
default:
break;
}
}

return consumed;
}

void nfc_maker_scene_contact_mail_on_exit(void* context) {
NfcMaker* app = context;
text_input_reset(app->text_input);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "../nfc_maker.h"

enum TextInputResult {
TextInputResultOk,
};

static void nfc_maker_scene_contact_phone_text_input_callback(void* context) {
NfcMaker* app = context;

view_dispatcher_send_custom_event(app->view_dispatcher, TextInputResultOk);
}

void nfc_maker_scene_contact_phone_on_enter(void* context) {
NfcMaker* app = context;
TextInput* text_input = app->text_input;

text_input_set_header_text(text_input, "Enter Phone Number:");

strlcpy(app->phone_buf, "+", PHONE_INPUT_LEN);

text_input_set_result_callback(
text_input,
nfc_maker_scene_contact_phone_text_input_callback,
app,
app->phone_buf,
PHONE_INPUT_LEN,
false);

text_input_set_minimum_length(text_input, 0);

view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);
}

bool nfc_maker_scene_contact_phone_on_event(void* context, SceneManagerEvent event) {
NfcMaker* app = context;
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
switch(event.event) {
case TextInputResultOk:
scene_manager_next_scene(app->scene_manager, NfcMakerSceneContactUrl);
break;
default:
break;
}
}

return consumed;
}

void nfc_maker_scene_contact_phone_on_exit(void* context) {
NfcMaker* app = context;
text_input_reset(app->text_input);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "../nfc_maker.h"

enum TextInputResult {
TextInputResultOk,
};

static void nfc_maker_scene_contact_url_text_input_callback(void* context) {
NfcMaker* app = context;

view_dispatcher_send_custom_event(app->view_dispatcher, TextInputResultOk);
}

void nfc_maker_scene_contact_url_on_enter(void* context) {
NfcMaker* app = context;
TextInput* text_input = app->text_input;

text_input_set_header_text(text_input, "Enter URL Link:");

strlcpy(app->big_buf, "flipper-xtre.me", BIG_INPUT_LEN);

text_input_set_result_callback(
text_input,
nfc_maker_scene_contact_url_text_input_callback,
app,
app->big_buf,
BIG_INPUT_LEN,
true);

text_input_set_minimum_length(text_input, 0);

view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);
}

bool nfc_maker_scene_contact_url_on_event(void* context, SceneManagerEvent event) {
NfcMaker* app = context;
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
switch(event.event) {
case TextInputResultOk:
scene_manager_next_scene(app->scene_manager, NfcMakerSceneSave);
break;
default:
break;
}
}

return consumed;
}

void nfc_maker_scene_contact_url_on_exit(void* context) {
NfcMaker* app = context;
text_input_reset(app->text_input);
}
31 changes: 31 additions & 0 deletions applications/external/nfc_maker/scenes/nfc_maker_scene_result.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,37 @@ void nfc_maker_scene_result_on_enter(void* context) {
j += data_len;
break;
}
case NfcMakerSceneContact: {
tnf = 0x02; // Media-type [RFC 2046]
type = "text/vcard";

FuriString* vcard = furi_string_alloc_set("BEGIN:VCARD\r\nVERSION:3.0\r\n");
furi_string_cat_printf(
vcard, "PRODID:-//Flipper Xtreme//%s//EN\r\n", version_get_version(NULL));
furi_string_cat_printf(vcard, "N:%s;%s;;;\r\n", app->small_buf2, app->small_buf1);
furi_string_cat_printf(
vcard,
"FN:%s%s%s\r\n",
app->small_buf1,
strnlen(app->small_buf2, SMALL_INPUT_LEN) ? " " : "",
app->small_buf2);
if(strnlen(app->mail_buf, MAIL_INPUT_LEN)) {
furi_string_cat_printf(vcard, "EMAIL:%s\r\n", app->mail_buf);
}
if(strnlen(app->phone_buf, PHONE_INPUT_LEN)) {
furi_string_cat_printf(vcard, "TEL:%s\r\n", app->phone_buf);
}
if(strnlen(app->big_buf, BIG_INPUT_LEN)) {
furi_string_cat_printf(vcard, "URL:%s\r\n", app->big_buf);
}
furi_string_cat_printf(vcard, "END:VCARD\r\n");

payload_len = furi_string_size(vcard);
payload = malloc(payload_len);
memcpy(payload, furi_string_get_cstr(vcard), payload_len);
furi_string_free(vcard);
break;
}
case NfcMakerSceneHttps: {
tnf = 0x01; // NFC Forum well-known type [NFC RTD]
type = "\x55";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ void nfc_maker_scene_start_on_enter(void* context) {
nfc_maker_scene_start_submenu_callback,
app);

submenu_add_item(
submenu,
"Contact Vcard",
NfcMakerSceneContact,
nfc_maker_scene_start_submenu_callback,
app);

submenu_add_item(
submenu, "HTTPS Link", NfcMakerSceneHttps, nfc_maker_scene_start_submenu_callback, app);

Expand Down

0 comments on commit e448f5a

Please sign in to comment.