From e448f5a315019ba5c6efac68b8456978f44a896a Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Wed, 12 Jul 2023 03:08:10 +0200 Subject: [PATCH] NFC Maker add contact vcard support --- .../nfc_maker/scenes/nfc_maker_scene_config.h | 5 ++ .../scenes/nfc_maker_scene_contact.c | 53 ++++++++++++++++++ .../scenes/nfc_maker_scene_contact_last.c | 55 +++++++++++++++++++ .../scenes/nfc_maker_scene_contact_mail.c | 55 +++++++++++++++++++ .../scenes/nfc_maker_scene_contact_phone.c | 55 +++++++++++++++++++ .../scenes/nfc_maker_scene_contact_url.c | 55 +++++++++++++++++++ .../nfc_maker/scenes/nfc_maker_scene_result.c | 31 +++++++++++ .../nfc_maker/scenes/nfc_maker_scene_start.c | 7 +++ 8 files changed, 316 insertions(+) create mode 100644 applications/external/nfc_maker/scenes/nfc_maker_scene_contact.c create mode 100644 applications/external/nfc_maker/scenes/nfc_maker_scene_contact_last.c create mode 100644 applications/external/nfc_maker/scenes/nfc_maker_scene_contact_mail.c create mode 100644 applications/external/nfc_maker/scenes/nfc_maker_scene_contact_phone.c create mode 100644 applications/external/nfc_maker/scenes/nfc_maker_scene_contact_url.c diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene_config.h b/applications/external/nfc_maker/scenes/nfc_maker_scene_config.h index 4a6da04d6..0ef4f021f 100644 --- a/applications/external/nfc_maker/scenes/nfc_maker_scene_config.h +++ b/applications/external/nfc_maker/scenes/nfc_maker_scene_config.h @@ -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) diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene_contact.c b/applications/external/nfc_maker/scenes/nfc_maker_scene_contact.c new file mode 100644 index 000000000..ecc054617 --- /dev/null +++ b/applications/external/nfc_maker/scenes/nfc_maker_scene_contact.c @@ -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); +} diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene_contact_last.c b/applications/external/nfc_maker/scenes/nfc_maker_scene_contact_last.c new file mode 100644 index 000000000..78f6ba712 --- /dev/null +++ b/applications/external/nfc_maker/scenes/nfc_maker_scene_contact_last.c @@ -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); +} diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene_contact_mail.c b/applications/external/nfc_maker/scenes/nfc_maker_scene_contact_mail.c new file mode 100644 index 000000000..07f9c3cb7 --- /dev/null +++ b/applications/external/nfc_maker/scenes/nfc_maker_scene_contact_mail.c @@ -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, "ben.dover@yourmom.zip", 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); +} diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene_contact_phone.c b/applications/external/nfc_maker/scenes/nfc_maker_scene_contact_phone.c new file mode 100644 index 000000000..e9d16a217 --- /dev/null +++ b/applications/external/nfc_maker/scenes/nfc_maker_scene_contact_phone.c @@ -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); +} diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene_contact_url.c b/applications/external/nfc_maker/scenes/nfc_maker_scene_contact_url.c new file mode 100644 index 000000000..1d2f61d28 --- /dev/null +++ b/applications/external/nfc_maker/scenes/nfc_maker_scene_contact_url.c @@ -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); +} diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene_result.c b/applications/external/nfc_maker/scenes/nfc_maker_scene_result.c index 18867dc44..ad7371b5c 100644 --- a/applications/external/nfc_maker/scenes/nfc_maker_scene_result.c +++ b/applications/external/nfc_maker/scenes/nfc_maker_scene_result.c @@ -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"; diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene_start.c b/applications/external/nfc_maker/scenes/nfc_maker_scene_start.c index 77b705630..e791b1284 100644 --- a/applications/external/nfc_maker/scenes/nfc_maker_scene_start.c +++ b/applications/external/nfc_maker/scenes/nfc_maker_scene_start.c @@ -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);