@@ -150,24 +150,6 @@ static uint32_t t5577_writer_navigation_submenu_callback(void* _context) {
150
150
return T5577WriterViewSubmenu ;
151
151
}
152
152
153
-
154
- /**
155
- * @brief Callback for returning to configure screen.
156
- * @details This function is called when user press back button. We return VIEW_NONE to
157
- * indicate that we want to navigate to the configure screen.
158
- * @param _context The context - unused
159
- * @return next view id
160
- */
161
- //static uint32_t t5577_writer_navigation_configure_callback(void* _context) {
162
- // UNUSED(_context);
163
- // return T5577WriterViewConfigure_i;
164
- //}
165
-
166
- static uint32_t t5577_writer_navigation_file_callback (void * _context ) {
167
- UNUSED (_context );
168
- return T5577WriterViewSubmenu ;
169
- }
170
-
171
153
/**
172
154
* @brief Handle submenu item selection.
173
155
* @details This function is called when user selects an item from the submenu.
@@ -197,21 +179,13 @@ static void t5577_writer_submenu_callback(void* context, uint32_t index) {
197
179
}
198
180
}
199
181
200
- /**
201
- * Our 1st sample setting is a team color. We have 3 options: red, green, and blue.
202
- */
203
182
static const char * modulation_config_label = "Modulation" ;
204
- //static char* modulation_names[] = {"Direct", "PSK1", "PSK2", "PSK3", "FSK1", "FSK2", "FSK1a", "FSK2a","ASK/Man","Biphase","Diphase"};
205
183
static void t5577_writer_modulation_change (VariableItem * item ) {
206
184
T5577WriterApp * app = variable_item_get_context (item );
207
- FURI_LOG_D (TAG ,"app defined" );
208
185
T5577WriterModel * model = view_get_model (app -> view_write );
209
- FURI_LOG_D (TAG ,"model defined" );
210
186
if (model -> data_loaded [0 ]) {
211
- FURI_LOG_D (TAG ,"loaded entered" );
212
187
variable_item_set_current_value_index (item ,model -> modulation_index );
213
188
} else {
214
- FURI_LOG_D (TAG ,"else entered" );
215
189
uint8_t modulation_index = variable_item_get_current_value_index (item );
216
190
model -> modulation_index = modulation_index ;
217
191
model -> modulation = all_mods [modulation_index ];
@@ -224,7 +198,6 @@ static const char* rf_clock_config_label = "RF Clock";
224
198
static void t5577_writer_rf_clock_change (VariableItem * item ) {
225
199
T5577WriterApp * app = variable_item_get_context (item );
226
200
T5577WriterModel * model = view_get_model (app -> view_write );
227
-
228
201
if (model -> data_loaded [1 ]) {
229
202
variable_item_set_current_value_index (item ,model -> rf_clock_index );
230
203
} else {
@@ -255,7 +228,7 @@ static void t5577_writer_user_block_num_change(VariableItem* item) {
255
228
furi_string_printf (buffer , "%u" , model -> user_block_num );
256
229
variable_item_set_current_value_text (item , furi_string_get_cstr (buffer ));
257
230
for (uint8_t i = model -> user_block_num ; i < LFRFID_T5577_BLOCK_COUNT ; i ++ ) {
258
- model -> content [i ] = 0 ;
231
+ model -> content [i ] = 0 ; // pad the unneeded blocks with zeros
259
232
}
260
233
furi_string_free (buffer );
261
234
}
@@ -286,7 +259,7 @@ void ensure_dir_exists(Storage *storage)
286
259
FURI_LOG_I (TAG , "Directory exists: %s" , T5577_WRITER_APPS_DATA_FOLDER );
287
260
}
288
261
289
- // If wiegand directory doesn't exist, create it.
262
+ // If t5577_writer directory doesn't exist, create it.
290
263
if (!storage_dir_exists (storage , T5577_WRITER_FILE_FOLDER ))
291
264
{
292
265
FURI_LOG_I (TAG , "Creating directory: %s" , T5577_WRITER_FILE_FOLDER );
@@ -297,17 +270,13 @@ void ensure_dir_exists(Storage *storage)
297
270
FURI_LOG_I (TAG , "Directory exists: %s" , T5577_WRITER_FILE_FOLDER );
298
271
}
299
272
}
300
- /**
301
- * Our 2nd sample setting is a text field. When the user clicks OK on the configuration
302
- * setting we use a text input screen to allow the user to enter a name. This function is
303
- * called when the user clicks OK on the text input screen.
304
- */
273
+
305
274
static const char * tag_name_entry_text = "Enter name" ;
306
275
static const char * tag_name_default_value = "Tag_1" ;
307
276
static void t5577_writer_file_saver (void * context ) {
308
277
T5577WriterApp * app = (T5577WriterApp * )context ;
309
278
T5577WriterModel * model = view_get_model (app -> view_write );
310
- model -> content [0 ] = 0 ;
279
+ model -> content [0 ] = 0 ; // clean up first block before deciding to write or save
311
280
model -> content [0 ] |= model -> modulation .mod_page_zero ;
312
281
model -> content [0 ] |= model -> rf_clock .clock_page_zero ;
313
282
model -> content [0 ] |= (model -> user_block_num << LFRFID_T5577_MAXBLOCK_SHIFT );
@@ -353,7 +322,7 @@ static void t5577_writer_file_saver(void* context) {
353
322
furi_string_push_back (buffer , '\n' );
354
323
storage_file_write (data_file , furi_string_get_cstr (buffer ), furi_string_size (buffer ));
355
324
storage_file_close (data_file );
356
- view_dispatcher_switch_to_view (app -> view_dispatcher , T5577WriterViewSubmenu );
325
+ view_dispatcher_switch_to_view (app -> view_dispatcher , T5577WriterViewSubmenu ); // maybe add a pop up later
357
326
}
358
327
}
359
328
@@ -374,16 +343,17 @@ void t5577_writer_update_config_from_load(void* context) {
374
343
}
375
344
}
376
345
377
- my_model -> user_block_num = (my_model -> content [0 ] >> LFRFID_T5577_MAXBLOCK_SHIFT ) & 0xE ;
346
+ my_model -> user_block_num = (my_model -> content [0 ] >> LFRFID_T5577_MAXBLOCK_SHIFT ) & 0xF ;
378
347
379
- memset (my_model -> data_loaded , true, sizeof (my_model -> data_loaded ));
348
+ memset (my_model -> data_loaded , true, sizeof (my_model -> data_loaded )); // Everything is loaded
380
349
381
350
}
382
351
383
352
static void t5577_writer_config_enter_callback (void * context ) {
384
353
T5577WriterApp * app = (T5577WriterApp * )context ;
385
354
T5577WriterModel * my_model = view_get_model (app -> view_write );
386
- variable_item_list_reset (app -> variable_item_list_config );
355
+ variable_item_list_reset (app -> variable_item_list_config );
356
+ // Recreate this view every time we enter it so that it's always updated
387
357
app -> mod_item = variable_item_list_add (
388
358
app -> variable_item_list_config ,
389
359
modulation_config_label ,
@@ -422,13 +392,12 @@ static void t5577_writer_config_enter_callback(void* context) {
422
392
view_set_previous_callback (
423
393
view_config_i ,
424
394
t5577_writer_navigation_submenu_callback );
425
- view_dispatcher_remove_view (app -> view_dispatcher , T5577WriterViewConfigure_i );
395
+ view_dispatcher_remove_view (app -> view_dispatcher , T5577WriterViewConfigure_i ); // delete the last one
426
396
view_dispatcher_add_view (
427
397
app -> view_dispatcher ,
428
398
T5577WriterViewConfigure_i ,
429
399
view_config_i );
430
- view_dispatcher_switch_to_view (app -> view_dispatcher ,T5577WriterViewConfigure_i );
431
- FURI_LOG_D (TAG ,"enter_callback_finished" );
400
+ view_dispatcher_switch_to_view (app -> view_dispatcher ,T5577WriterViewConfigure_i ); // recreate it
432
401
}
433
402
434
403
void t5577_writer_view_load_callback (void * context ) {
@@ -438,13 +407,11 @@ void t5577_writer_view_load_callback(void* context) {
438
407
Storage * storage = furi_record_open (RECORD_STORAGE );
439
408
ensure_dir_exists (storage );
440
409
File * data_file = storage_file_alloc (storage );
441
- dialog_file_browser_set_basic_options (& browser_options , T5577_WRITER_FILE_EXTENSION , NULL );
410
+ dialog_file_browser_set_basic_options (& browser_options , T5577_WRITER_FILE_EXTENSION , & I_icon );
442
411
browser_options .base_path = T5577_WRITER_FILE_FOLDER ;
443
412
furi_string_set (app -> file_path , browser_options .base_path );
444
413
FuriString * buffer = furi_string_alloc ();
445
-
446
414
if (dialog_file_browser_show (app -> dialogs , app -> file_path , app -> file_path , & browser_options )) {
447
-
448
415
if (storage_file_open (
449
416
data_file , furi_string_get_cstr (app -> file_path ), FSAM_READ , FSOM_OPEN_EXISTING )) {
450
417
while (!storage_file_eof (data_file )) { // fill buffer with every line because ch == '\n'
@@ -466,7 +433,8 @@ void t5577_writer_view_load_callback(void* context) {
466
433
int i = 0 ;
467
434
while (i < length ) {
468
435
if (furi_string_get_char (buffer , i ) == ':' ) {
469
- row_num_char_buffer [0 ] = furi_string_get_char (buffer , i - 1 ); //the number before ":" is block num
436
+ row_num_char_buffer [0 ] = furi_string_get_char (buffer , i - 1 );
437
+ //the number before ":" is block num
470
438
i += 2 ; // skip a space
471
439
for (size_t j = 0 ; j < sizeof (row_data_char_buffer ); j ++ ) {
472
440
ch = furi_string_get_char (buffer , i );
@@ -494,8 +462,7 @@ void t5577_writer_view_load_callback(void* context) {
494
462
495
463
/**
496
464
* @brief Callback when item in configuration screen is clicked.
497
- * @details This function is called when user clicks OK on an item in the configuration screen.
498
- * If the item clicked is our text field then we switch to the text input screen.
465
+ * @details This function is called when user clicks OK on an item in the text input screen.
499
466
* @param context The context - T5577WriterApp object.
500
467
* @param index - The index of the item that was clicked.
501
468
*/
@@ -524,18 +491,17 @@ static void t5577_writer_view_save_callback(void* context) {
524
491
app -> temp_buffer ,
525
492
app -> temp_buffer_size ,
526
493
clear_previous_text );
527
- // Pressing the BACK button will reload the configure screen .
494
+ // Pressing the BACK button will return to the main menu .
528
495
view_set_previous_callback (
529
- text_input_get_view (app -> text_input ), t5577_writer_navigation_file_callback );
496
+ text_input_get_view (app -> text_input ), t5577_writer_navigation_submenu_callback );
530
497
531
498
// Show text input dialog.
532
499
view_dispatcher_switch_to_view (app -> view_dispatcher , T5577WriterViewTextInput );
533
-
534
500
}
535
501
536
502
static void t5577_writer_actual_writing (void * model ) {
537
503
T5577WriterModel * my_model = (T5577WriterModel * )model ;
538
- my_model -> content [0 ] = 0 ;
504
+ my_model -> content [0 ] = 0 ; // clear up block 0
539
505
my_model -> content [0 ] |= my_model -> modulation .mod_page_zero ;
540
506
my_model -> content [0 ] |= my_model -> rf_clock .clock_page_zero ;
541
507
my_model -> content [0 ] |= (my_model -> user_block_num << LFRFID_T5577_MAXBLOCK_SHIFT );
@@ -549,8 +515,8 @@ static void t5577_writer_actual_writing(void* model) {
549
515
}
550
516
551
517
/**
552
- * @brief Callback for drawing the game screen.
553
- * @details This function is called when the screen needs to be redrawn, like when the model gets updated .
518
+ * @brief Callback for drawing the writing screen.
519
+ * @details This function is called when the screen needs to be redrawn, so that the writing command is repeated .
554
520
* @param canvas The canvas to draw on.
555
521
* @param model The model - MyModel object.
556
522
*/
@@ -576,7 +542,6 @@ static void t5577_writer_view_write_callback(Canvas* canvas, void* model) {
576
542
* @details This function is called when the timer is elapsed. We use this to queue a redraw event.
577
543
* @param context The context - T5577WriterApp object.
578
544
*/
579
-
580
545
static void t5577_writer_view_write_timer_callback (void * context ) {
581
546
T5577WriterApp * app = (T5577WriterApp * )context ;
582
547
T5577WriterModel * model = view_get_model (app -> view_write );
@@ -589,9 +554,9 @@ static void t5577_writer_view_write_timer_callback(void* context) {
589
554
}
590
555
591
556
/**
592
- * @brief Callback when the user starts the game screen.
593
- * @details This function is called when the user enters the game screen. We start a timer to
594
- * redraw the screen periodically (so the random number is refreshed).
557
+ * @brief Callback when the user starts the writing screen.
558
+ * @details This function is called when the user enters the writing screen. We start a timer to
559
+ * redraw the screen periodically. (exactly like PsychToolBox lol)
595
560
* @param context The context - T5577WriterApp object.
596
561
*/
597
562
static void t5577_writer_view_write_enter_callback (void * context ) {
@@ -605,8 +570,8 @@ static void t5577_writer_view_write_enter_callback(void* context) {
605
570
}
606
571
607
572
/**
608
- * @brief Callback when the user exits the game screen.
609
- * @details This function is called when the user exits the game screen. We stop the timer.
573
+ * @brief Callback when the user exits the writing screen.
574
+ * @details This function is called when the user exits the writing screen. We stop the timer.
610
575
* @param context The context - T5577WriterApp object.
611
576
*/
612
577
static void t5577_writer_view_write_exit_callback (void * context ) {
@@ -644,27 +609,6 @@ static bool t5577_writer_view_write_custom_event_callback(uint32_t event, void*
644
609
}
645
610
}
646
611
647
- /**
648
- * @brief Callback for game screen input.
649
- * @details This function is called when the user presses a button while on the game screen.
650
- * @param event The event - InputEvent object.
651
- * @param context The context - T5577WriterApp object.
652
- * @return true if the event was handled, false otherwise.
653
- */
654
- static bool t5577_writer_view_write_input_callback (InputEvent * event , void * context ) {
655
- T5577WriterApp * app = (T5577WriterApp * )context ;
656
- if (event -> type == InputTypeShort ) {
657
- if (event -> key == InputKeyOk ) {
658
- // We choose to send a custom event when user presses OK button. t5577_writer_custom_event_callback will
659
- // handle our T5577WriterEventIdMaxWriteRep event. We could have just put the code from
660
- // t5577_writer_custom_event_callback here, it's a matter of preference.
661
- view_dispatcher_send_custom_event (app -> view_dispatcher , T5577WriterEventIdMaxWriteRep );
662
- return true;
663
- }
664
- }
665
- return false;
666
- }
667
-
668
612
/**
669
613
* @brief Allocate the t5577_writer application.
670
614
* @details This function allocates the t5577_writer application resources.
@@ -716,7 +660,6 @@ static T5577WriterApp* t5577_writer_app_alloc() {
716
660
717
661
app -> view_write = view_alloc ();
718
662
view_set_draw_callback (app -> view_write , t5577_writer_view_write_callback );
719
- view_set_input_callback (app -> view_write , t5577_writer_view_write_input_callback );
720
663
view_set_previous_callback (app -> view_write , t5577_writer_navigation_submenu_callback );
721
664
view_set_enter_callback (app -> view_write , t5577_writer_view_write_enter_callback );
722
665
view_set_exit_callback (app -> view_write , t5577_writer_view_write_exit_callback );
0 commit comments