6
6
#include <gui/modules/popup.h>
7
7
#include <gui/modules/submenu.h>
8
8
#include <gui/modules/text_input.h>
9
+ #include <gui/modules/byte_input.h>
9
10
#include <gui/modules/widget.h>
10
11
#include <gui/modules/variable_item_list.h>
11
12
#include <notification/notification.h>
@@ -34,58 +35,69 @@ typedef enum {
34
35
T5577WriterSubmenuIndexAbout ,
35
36
} T5577WriterSubmenuIndex ;
36
37
38
+ // Each view is a screen we show the user.
37
39
typedef enum {
38
- T5577WriterViewSubmenu ,
39
- T5577WriterViewTextInput ,
40
+ T5577WriterViewSubmenu , // The menu when the app starts
41
+ T5577WriterViewTextInput , // Input for configuring text settings
42
+ T5577WriterViewByteInput ,
40
43
T5577WriterViewLoad ,
41
44
T5577WriterViewSave ,
42
- T5577WriterViewConfigure_i , // The configuration screen that's recreated every time we enter it
43
- T5577WriterViewConfigure_e , // The configuration screen store front that's constantly there
44
- T5577WriterViewWrite ,
45
- T5577WriterViewAbout ,
45
+ T5577WriterViewPopup ,
46
+ T5577WriterViewConfigure_i , // The configuration screen
47
+ T5577WriterViewConfigure_e , // The configuration screen
48
+ T5577WriterViewWrite , // The main screen
49
+ T5577WriterViewAbout , // The about screen with directions, link to social channel, etc.
46
50
} T5577WriterView ;
47
51
48
52
typedef enum {
49
- T5577WriterEventIdRepeatWriting = 0 , // Custom event to repeat sending writing commands
50
- T5577WriterEventIdMaxWriteRep = 42 , // Custom event to exit writing view
53
+ T5577WriterEventIdRepeatWriting = 0 , // Custom event to redraw the screen
54
+ T5577WriterEventIdMaxWriteRep = 42 , // Custom event to process OK button getting pressed down
51
55
} T5577WriterEventId ;
52
56
53
57
typedef struct {
54
58
ViewDispatcher * view_dispatcher ; // Switches between our views
55
59
NotificationApp * notifications ; // Used for controlling the backlight
56
60
Submenu * submenu ; // The application menu
61
+
57
62
TextInput * text_input ; // The text input screen
58
- VariableItemList * variable_item_list_config ; // The internal configuration view
59
- View * view_config_e ; // The external configuration view
60
- View * view_save ; // The save view
61
- View * view_write ; // The writing view
63
+ Popup * popup ;
64
+ VariableItemList * variable_item_list_config ; // The configuration screen
65
+ View * view_config_e ; // The configuration screen
66
+ View * view_save ;
67
+ View * view_write ; // The main screen
62
68
Widget * widget_about ; // The about screen
63
69
View * view_load ; // The load view
64
70
65
- VariableItem * mod_item ;
66
- VariableItem * clock_item ;
67
- VariableItem * block_num_item ;
68
- VariableItem * block_slc_item ;
71
+ VariableItem * mod_item ; //
72
+ VariableItem * clock_item ; //
73
+ VariableItem * block_num_item ; //
74
+ VariableItem * block_slc_item ; //
75
+ VariableItem * byte_buffer_item ; //
76
+ ByteInput * byte_input ; // The byte input view
77
+ uint8_t bytes_buffer [4 ];
78
+ uint8_t bytes_count ;
79
+
69
80
char * temp_buffer ; // Temporary buffer for text input
70
81
uint32_t temp_buffer_size ; // Size of temporary buffer
71
82
72
- DialogsApp * dialogs ; // dialog for file browser
73
- FuriString * file_path ; // apps_data/t5577_writer
83
+ DialogsApp * dialogs ;
84
+ FuriString * file_path ;
74
85
FuriTimer * timer ; // Timer for redrawing the screen
86
+ ViewNavigationCallback config_enter_callback ;
75
87
} T5577WriterApp ;
76
88
77
89
78
90
typedef struct {
79
- uint8_t modulation_index ; // The index for modulation
80
- uint8_t rf_clock_index ; // The index for RF clock
91
+ uint8_t modulation_index ; // The index for total number of pins
92
+ uint8_t rf_clock_index ; // The index for total number of pins
81
93
FuriString * tag_name_str ; // The name setting
82
- uint8_t user_block_num ; // The total number of blocks to be used, i.e. signal length
83
- uint32_t * content ; // The content, 8 blocks of uint32
94
+ uint8_t user_block_num ; // The total number of pins we are adjusting
95
+ uint32_t content [ LFRFID_T5577_BLOCK_COUNT ] ; // The cutting content
84
96
t5577_modulation modulation ;
85
97
t5577_rf_clock rf_clock ;
86
- bool data_loaded [3 ]; // The on/off knobs recording whether the config screen is showing loaded data
87
- uint8_t edit_block_slc ; // Select the block to edit
88
- uint8_t writing_repeat_times ; // How many times have the write command been sent
98
+ bool data_loaded [3 ];
99
+ uint8_t edit_block_slc ;
100
+ uint8_t writing_repeat_times ;
89
101
} T5577WriterModel ;
90
102
91
103
void initialize_config (T5577WriterModel * model ) {
@@ -96,14 +108,10 @@ void initialize_config(T5577WriterModel* model) {
96
108
}
97
109
98
110
void initialize_model (T5577WriterModel * model ) {
99
- if (model -> content != NULL ) {
100
- free (model -> content );
101
- }
102
111
initialize_config (model );
103
112
model -> user_block_num = 1 ;
104
113
model -> edit_block_slc = 1 ;
105
114
model -> writing_repeat_times = 0 ;
106
- model -> content = (uint32_t * )malloc (LFRFID_T5577_BLOCK_COUNT * sizeof (uint32_t ));
107
115
for (uint32_t i = 0 ; i < LFRFID_T5577_BLOCK_COUNT ; i ++ ) {
108
116
model -> content [i ] = 0 ;
109
117
}
@@ -150,6 +158,11 @@ static uint32_t t5577_writer_navigation_submenu_callback(void* _context) {
150
158
return T5577WriterViewSubmenu ;
151
159
}
152
160
161
+ static uint32_t t5577_writer_navigation_config_e_callback (void * _context ) {
162
+ UNUSED (_context );
163
+ return T5577WriterViewConfigure_e ;
164
+ }
165
+
153
166
/**
154
167
* @brief Handle submenu item selection.
155
168
* @details This function is called when user selects an item from the submenu.
@@ -243,6 +256,10 @@ static void t5577_writer_edit_block_slc_change(VariableItem* item) {
243
256
FuriString * buffer = furi_string_alloc ();
244
257
furi_string_printf (buffer , "%u" , model -> edit_block_slc );
245
258
variable_item_set_current_value_text (item , furi_string_get_cstr (buffer ));
259
+
260
+ furi_string_printf (buffer , "%08lX" , model -> content [model -> edit_block_slc ]);
261
+ variable_item_set_current_value_text (app -> byte_buffer_item , furi_string_get_cstr (buffer ));
262
+
246
263
furi_string_free (buffer );
247
264
}
248
265
@@ -342,13 +359,75 @@ void t5577_writer_update_config_from_load(void* context) {
342
359
my_model -> rf_clock = all_rf_clocks [my_model -> rf_clock_index ];
343
360
}
344
361
}
345
-
346
362
my_model -> user_block_num = (my_model -> content [0 ] >> LFRFID_T5577_MAXBLOCK_SHIFT ) & 0xF ;
347
-
348
363
memset (my_model -> data_loaded , true, sizeof (my_model -> data_loaded )); // Everything is loaded
364
+ }
349
365
366
+ static const char * edit_block_data_config_label = "Block Data" ;
367
+ void uint32_to_byte_buffer (uint32_t block_data , uint8_t byte_buffer [4 ]) {
368
+ byte_buffer [0 ] = (block_data >> 24 ) & 0xFF ;
369
+ byte_buffer [1 ] = (block_data >> 16 ) & 0xFF ;
370
+ byte_buffer [2 ] = (block_data >> 8 ) & 0xFF ;
371
+ byte_buffer [3 ] = block_data & 0xFF ;
372
+ }
373
+
374
+ uint32_t byte_buffer_to_uint32 (uint8_t byte_buffer [4 ]) {
375
+ uint32_t block_data = 0 ;
376
+ block_data |= ((uint32_t )byte_buffer [0 ] << 24 );
377
+ block_data |= ((uint32_t )byte_buffer [1 ] << 16 );
378
+ block_data |= ((uint32_t )byte_buffer [2 ] << 8 );
379
+ block_data |= ((uint32_t )byte_buffer [3 ]);
380
+ return block_data ;
381
+ }
382
+
383
+
384
+ static void t5577_writer_content_byte_input_confirmed (void * context ) {
385
+ T5577WriterApp * app = (T5577WriterApp * )context ;
386
+ T5577WriterModel * my_model = view_get_model (app -> view_write );
387
+ my_model -> content [my_model -> edit_block_slc ] = byte_buffer_to_uint32 (app -> bytes_buffer );
388
+ view_dispatcher_switch_to_view (app -> view_dispatcher , T5577WriterViewConfigure_e );
350
389
}
351
390
391
+ static void t5577_writer_content_byte_changed (void * context ) {
392
+ UNUSED (context );
393
+ }
394
+ static void t5577_writer_config_item_clicked (void * context , uint32_t index ) {
395
+ T5577WriterApp * app = (T5577WriterApp * )context ;
396
+ T5577WriterModel * my_model = view_get_model (app -> view_write );
397
+ FuriString * buffer = furi_string_alloc ();
398
+ furi_string_printf (buffer , "Enter Block %u Data" , my_model -> edit_block_slc );
399
+ // Our hex input UI is the 5th in the config menue.
400
+ if (index == 4 ) {
401
+ // Header to display on the text input screen.
402
+ byte_input_set_header_text (app -> byte_input , furi_string_get_cstr (buffer ));
403
+
404
+ // Copy the current name into the temporary buffer.
405
+ bool redraw = false;
406
+ with_view_model (
407
+ app -> view_write ,
408
+ T5577WriterModel * model ,
409
+ {
410
+ uint32_to_byte_buffer (model -> content [model -> edit_block_slc ],app -> bytes_buffer );
411
+ },
412
+ redraw );
413
+
414
+ // Configure the text input. When user enters text and clicks OK, key_copier_setting_text_updated be called.
415
+ byte_input_set_result_callback (
416
+ app -> byte_input ,
417
+ t5577_writer_content_byte_input_confirmed ,
418
+ t5577_writer_content_byte_changed ,
419
+ app ,
420
+ app -> bytes_buffer ,
421
+ app -> bytes_count
422
+ );
423
+
424
+ // Pressing the BACK button will reload the configure screen.
425
+ view_set_previous_callback (byte_input_get_view (app -> byte_input ), t5577_writer_navigation_config_e_callback );
426
+
427
+ // Show text input dialog.
428
+ view_dispatcher_switch_to_view (app -> view_dispatcher , T5577WriterViewByteInput );
429
+ }
430
+ }
352
431
static void t5577_writer_config_enter_callback (void * context ) {
353
432
T5577WriterApp * app = (T5577WriterApp * )context ;
354
433
T5577WriterModel * my_model = view_get_model (app -> view_write );
@@ -378,6 +457,14 @@ static void t5577_writer_config_enter_callback(void* context) {
378
457
LFRFID_T5577_BLOCK_COUNT - 1 ,
379
458
t5577_writer_edit_block_slc_change ,
380
459
app );
460
+ app -> byte_buffer_item = variable_item_list_add (
461
+ app -> variable_item_list_config ,
462
+ edit_block_data_config_label ,
463
+ 1 ,
464
+ NULL ,
465
+ app );
466
+ variable_item_list_set_enter_callback (app -> variable_item_list_config , t5577_writer_config_item_clicked , app );
467
+
381
468
View * view_config_i = variable_item_list_get_view (app -> variable_item_list_config );
382
469
383
470
variable_item_set_current_value_index (app -> mod_item ,my_model -> modulation_index );
@@ -687,7 +774,12 @@ static T5577WriterApp* t5577_writer_app_alloc() {
687
774
T5577WriterViewSave ,
688
775
app -> view_save );
689
776
690
-
777
+ app -> bytes_count = 4 ;
778
+ memset (app -> bytes_buffer , 0 , sizeof (app -> bytes_buffer ));
779
+
780
+ app -> byte_input = byte_input_alloc ();
781
+ view_dispatcher_add_view (
782
+ app -> view_dispatcher , T5577WriterViewByteInput , byte_input_get_view (app -> byte_input ));
691
783
app -> variable_item_list_config = variable_item_list_alloc ();
692
784
693
785
app -> view_config_e = view_alloc ();
@@ -747,20 +839,12 @@ static void t5577_writer_app_free(T5577WriterApp* app) {
747
839
view_dispatcher_remove_view (app -> view_dispatcher , T5577WriterViewAbout );
748
840
widget_free (app -> widget_about );
749
841
view_dispatcher_remove_view (app -> view_dispatcher , T5577WriterViewWrite );
750
- with_view_model (
751
- app -> view_write ,
752
- T5577WriterModel * model ,
753
- {
754
- if (model -> content != NULL ) {
755
- free (model -> content );
756
- }
757
- },
758
- false);
759
842
view_free (app -> view_write );
760
843
view_dispatcher_remove_view (app -> view_dispatcher , T5577WriterViewLoad );
761
844
view_free (app -> view_load );
762
845
view_dispatcher_remove_view (app -> view_dispatcher , T5577WriterViewConfigure_i );
763
846
view_dispatcher_remove_view (app -> view_dispatcher , T5577WriterViewConfigure_e );
847
+ view_dispatcher_remove_view (app -> view_dispatcher ,T5577WriterViewByteInput );
764
848
variable_item_list_free (app -> variable_item_list_config );
765
849
view_dispatcher_remove_view (app -> view_dispatcher , T5577WriterViewSave );
766
850
view_free (app -> view_save );
0 commit comments