mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
NFC Maker add contact vcard support
This commit is contained in:
@@ -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)
|
||||
|
||||
53
applications/external/nfc_maker/scenes/nfc_maker_scene_contact.c
vendored
Normal file
53
applications/external/nfc_maker/scenes/nfc_maker_scene_contact.c
vendored
Normal file
@@ -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);
|
||||
}
|
||||
55
applications/external/nfc_maker/scenes/nfc_maker_scene_contact_last.c
vendored
Normal file
55
applications/external/nfc_maker/scenes/nfc_maker_scene_contact_last.c
vendored
Normal file
@@ -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);
|
||||
}
|
||||
55
applications/external/nfc_maker/scenes/nfc_maker_scene_contact_mail.c
vendored
Normal file
55
applications/external/nfc_maker/scenes/nfc_maker_scene_contact_mail.c
vendored
Normal file
@@ -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);
|
||||
}
|
||||
55
applications/external/nfc_maker/scenes/nfc_maker_scene_contact_phone.c
vendored
Normal file
55
applications/external/nfc_maker/scenes/nfc_maker_scene_contact_phone.c
vendored
Normal file
@@ -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);
|
||||
}
|
||||
55
applications/external/nfc_maker/scenes/nfc_maker_scene_contact_url.c
vendored
Normal file
55
applications/external/nfc_maker/scenes/nfc_maker_scene_contact_url.c
vendored
Normal file
@@ -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);
|
||||
}
|
||||
@@ -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";
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user