Skip to content

Commit

Permalink
Notes, improved info scene
Browse files Browse the repository at this point in the history
Initial NFC testing results and leftover kruft
Improved info scene for saved cards
Beginnings of manual-input code
  • Loading branch information
zacharyweiss committed Jan 1, 2023
1 parent 3e646d9 commit 5d6168e
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 47 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ Other misc things to investigate / build:


HF coil notes:
NFC reader field can be turned on / off with `furi_hal_nfc_field_on();` and `furi_hal_nfc_field_off();` respectively, as seen in nfc_scene_field.c (used for debug purposes). Initial tests with `furi_hal_nfc_field_on();` are promising signal-wise, but the delay introduced by the wake/sleep initialization renders it impossible to toggle rapidly. At a lower level, that consists of `furi_hal_nfc_exit_sleep();` and `st25r3916TxRxOn();` to turn on, and `st25r3916TxRxOff();` and `furi_hal_nfc_start_sleep();` to turn off. May be worth trying directly (wake from sleep at setup, toggle on and off corresponding with bit direction, send to sleep on exit). Initial tests have been difficult to get work as some of the st25r3916 symbols are unresolved; need to figure out how to import/call it properly, or how to get another layer lower of control.
~~NFC reader field can be turned on / off with `furi_hal_nfc_field_on();` and `furi_hal_nfc_field_off();` respectively, as seen in nfc_scene_field.c (used for debug purposes). Initial tests with `furi_hal_nfc_field_on();` are promising signal-wise, but the delay introduced by the wake/sleep initialization renders it impossible to toggle rapidly. At a lower level, that consists of `furi_hal_nfc_exit_sleep();` and `st25r3916TxRxOn();` to turn on, and `st25r3916TxRxOff();` and `furi_hal_nfc_start_sleep();` to turn off. May be worth trying directly (wake from sleep at setup, toggle on and off corresponding with bit direction, send to sleep on exit). Initial tests have been difficult to get work as some of the st25r3916 symbols are unresolved; need to figure out how to import/call it properly, or how to get another layer lower of control.~~ Testing with furi_hal_nfc_ll_rxtx_on(); and furi_hal_nfc_ll_rxtx_off(); does indeed create a nice strong signal on my 'scope (thanks @dlz#7721 for finding the wrapped functions), but no response from a mag reader; makes sense, was a long shot -- next step NFC testing would be lower-level control that lets us pull the coil high/low, rather than just producing the standard 13.56MHz signal and OOK modulating it.

1 change: 0 additions & 1 deletion mag_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ static bool mag_device_save_file(
furi_string_free(temp_str);
flipper_format_free(file);

// TODO. Extrapolating from the picopass app
return saved;
}

Expand Down
4 changes: 2 additions & 2 deletions scenes/mag_scene_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ ADD_SCENE(mag, emulate_test, EmulateTest)
ADD_SCENE(mag, file_select, FileSelect)
ADD_SCENE(mag, saved_menu, SavedMenu)
ADD_SCENE(mag, saved_info, SavedInfo)
ADD_SCENE(mag, save_data, SaveData)
ADD_SCENE(mag, save_name, SaveName)
ADD_SCENE(mag, input_name, InputName)
ADD_SCENE(mag, input_value, InputValue)
ADD_SCENE(mag, save_success, SaveSuccess)
ADD_SCENE(mag, delete_success, DeleteSuccess)
ADD_SCENE(mag, delete_confirm, DeleteConfirm)
Expand Down
5 changes: 3 additions & 2 deletions scenes/mag_scene_delete_confirm.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "../mag_i.h"
#include "../mag_device.h"
#include <toolbox/path.h>

void mag_scene_delete_confirm_on_enter(void* context) {
Mag* mag = context;
Expand All @@ -12,6 +11,8 @@ void mag_scene_delete_confirm_on_enter(void* context) {

furi_string_printf(tmp_str, "\e#Delete %s?\e#", mag_dev->dev_name);

//TODO: print concise summary of data on card? Would need to vary by card/track type

widget_add_text_box_element(
widget, 0, 0, 128, 27, AlignCenter, AlignCenter, furi_string_get_cstr(tmp_str), true);
widget_add_button_element(widget, GuiButtonTypeLeft, "Cancel", mag_widget_callback, mag);
Expand Down Expand Up @@ -45,4 +46,4 @@ bool mag_scene_delete_confirm_on_event(void* context, SceneManagerEvent event) {
void mag_scene_delete_confirm_on_exit(void* context) {
Mag* mag = context;
widget_reset(mag->widget);
}
}
15 changes: 6 additions & 9 deletions scenes/mag_scene_emulate_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#define PIN_A 0
#define PIN_B 1 // currently unused
#define CLOCK_US 240 // typically set between 200-500us
#define TEST_STR "%%B123456781234567^LASTNAME/FIRST^YYMMSSSDDDDDDDDDDDDDDDDDDDDDDDDD?;1234567812?"
#define TEST_STR "%%B123456781234567^LASTNAME/FIRST^YYMMSSSDDDDDDDDDDDDDDDDDDDDDDDDD?"
#define TEST_TRACK 0
// TODO: better way of setting temp test str,
// text wrapping on screen? (Will be relevant for any loaded data too)
Expand All @@ -28,17 +28,15 @@ static void play_bit(uint8_t send_bit) {
gpio_item_set_rfid_pin(PIN_B, !magspoof_bit_dir);
furi_delay_us(CLOCK_US);

// NFC tests
//(magspoof_bit_dir) ? st25r3916TxRxOn() : st25r3916TxRxOff();
//(magspoof_bit_dir) ? furi_hal_nfc_field_on() : furi_hal_nfc_field_off();
// NFC TEST
//(magspoof_bit_dir) ? furi_hal_nfc_ll_txrx_on() : furi_hal_nfc_ll_txrx_off();

if(send_bit) {
magspoof_bit_dir ^= 1;
gpio_item_set_rfid_pin(PIN_A, magspoof_bit_dir);
gpio_item_set_rfid_pin(PIN_B, !magspoof_bit_dir);

//(magspoof_bit_dir) ? st25r3916TxRxOn() : st25r3916TxRxOff();
//(magspoof_bit_dir) ? furi_hal_nfc_field_on() : furi_hal_nfc_field_off();
//(magspoof_bit_dir) ? furi_hal_nfc_ll_txrx_on() : furi_hal_nfc_ll_txrx_off();
}
furi_delay_us(CLOCK_US);
}
Expand Down Expand Up @@ -140,8 +138,7 @@ static void mag_spoof(FuriString* track_str, uint8_t track) {
gpio_item_set_rfid_pin(PIN_A, 0);
gpio_item_set_rfid_pin(PIN_B, 0);
// NFC TEST
//st25r3916TxRxOff();
//furi_hal_nfc_field_off();
//furi_hal_nfc_ll_txrx_off();

// end critical timing section
FURI_CRITICAL_EXIT();
Expand Down Expand Up @@ -204,4 +201,4 @@ bool mag_scene_emulate_test_on_event(void* context, SceneManagerEvent event) {
void mag_scene_emulate_test_on_exit(void* context) {
Mag* mag = context;
widget_reset(mag->widget);
}
}
2 changes: 1 addition & 1 deletion scenes/mag_scene_exit_confirm.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ bool mag_scene_exit_confirm_on_event(void* context, SceneManagerEvent event) {
void mag_scene_exit_confirm_on_exit(void* context) {
Mag* mag = context;
UNUSED(mag);
}
}
17 changes: 10 additions & 7 deletions scenes/mag_scene_save_name.c → scenes/mag_scene_input_name.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
#include <lib/toolbox/random_name.h>
#include "../mag_i.h"

void mag_scene_save_name_on_enter(void* context) {
void mag_scene_input_name_on_enter(void* context) {
Mag* mag = context;
TextInput* text_input = mag->text_input;
FuriString* folder_path;
folder_path = furi_string_alloc();

bool key_name_is_empty = furi_string_empty(mag->file_name);
//TODO: compatible types / etc
//bool name_is_empty = furi_string_empty(mag->mag_dev->dev_name);
bool name_is_empty = false;

if(key_name_is_empty) {
if(name_is_empty) {
furi_string_set(mag->file_path, MAG_APP_FOLDER);
set_random_name(mag->text_store, MAG_TEXT_STORE_SIZE);
furi_string_set(folder_path, MAG_APP_FOLDER);
} else {
mag_text_store_set(mag, "%s", furi_string_get_cstr(mag->file_name));
// TODO: compatible types etc
//mag_text_store_set(mag, "%s", furi_string_get_cstr(mag->mag_dev->dev_name));
path_extract_dirname(furi_string_get_cstr(mag->file_path), folder_path);
}

Expand All @@ -25,7 +28,7 @@ void mag_scene_save_name_on_enter(void* context) {
mag,
mag->text_store,
MAG_DEV_NAME_MAX_LEN,
key_name_is_empty);
name_is_empty);

FURI_LOG_I("", "%s %s", furi_string_get_cstr(folder_path), mag->text_store);

Expand All @@ -40,7 +43,7 @@ void mag_scene_save_name_on_enter(void* context) {
view_dispatcher_switch_to_view(mag->view_dispatcher, MagViewTextInput);
}

bool mag_scene_save_name_on_event(void* context, SceneManagerEvent event) {
bool mag_scene_input_name_on_event(void* context, SceneManagerEvent event) {
Mag* mag = context;
SceneManager* scene_manager = mag->scene_manager;
bool consumed = false;
Expand Down Expand Up @@ -76,7 +79,7 @@ bool mag_scene_save_name_on_event(void* context, SceneManagerEvent event) {
return consumed;
}

void mag_scene_save_name_on_exit(void* context) {
void mag_scene_input_name_on_exit(void* context) {
Mag* mag = context;
TextInput* text_input = mag->text_input;

Expand Down
28 changes: 28 additions & 0 deletions scenes/mag_scene_input_value.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "../mag_i.h"

void mag_scene_input_value_on_enter(void* context) {
Mag* mag = context;
TextInput* text_input = mag->text_input;

FuriString* tmp_str;
tmp_str = furi_string_alloc();
UNUSED(tmp_str);

text_input_set_header_text(text_input, "Enter track data (WIP)");
//text_input_set_result_callback(
// text_input, mag_text_input_callback, mag, mag->mag_dev->dev_data, )
}

bool mag_scene_input_value_on_event(void* context, SceneManagerEvent event) {
Mag* mag = context;
UNUSED(mag);
UNUSED(event);
bool consumed = false;

return consumed;
}

void mag_scene_input_value_on_exit(void* context) {
Mag* mag = context;
UNUSED(mag);
}
20 changes: 0 additions & 20 deletions scenes/mag_scene_save_data.c

This file was deleted.

13 changes: 10 additions & 3 deletions scenes/mag_scene_saved_info.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "../mag_i.h"
#include "mag_icons.h"

void mag_scene_saved_info_on_enter(void* context) {
Mag* mag = context;
Expand All @@ -7,11 +8,17 @@ void mag_scene_saved_info_on_enter(void* context) {
FuriString* tmp_str;
tmp_str = furi_string_alloc();

// Use strlcpy instead perhaps, to truncate to screen width, then add ellipses if needed?
furi_string_printf(tmp_str, "%s\r\n", mag->mag_dev->dev_name);
furi_string_cat_printf(tmp_str, furi_string_get_cstr(mag->mag_dev->dev_data));

widget_add_icon_element(widget, 1, 1, &I_mag_10px);
widget_add_string_element(
widget, 13, 2, AlignLeft, AlignTop, FontPrimary, furi_string_get_cstr(tmp_str));
furi_string_reset(tmp_str);

furi_string_printf(tmp_str, furi_string_get_cstr(mag->mag_dev->dev_data));
widget_add_string_multiline_element(
widget, 0, 1, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(tmp_str));
widget, 0, 15, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(tmp_str));

widget_add_button_element(widget, GuiButtonTypeLeft, "Back", mag_widget_callback, mag);

Expand All @@ -38,4 +45,4 @@ bool mag_scene_saved_info_on_event(void* context, SceneManagerEvent event) {
void mag_scene_saved_info_on_exit(void* context) {
Mag* mag = context;
widget_reset(mag->widget);
}
}
2 changes: 1 addition & 1 deletion scenes/mag_scene_saved_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ void mag_scene_saved_menu_on_exit(void* context) {
Mag* mag = context;

submenu_reset(mag->submenu);
}
}

0 comments on commit 5d6168e

Please sign in to comment.