18
18
#include <stdio.h>
19
19
#include <t5577_config.h>
20
20
#include <t5577_writer.h>
21
+ #include <dolphin/dolphin.h>
22
+
23
+
21
24
22
25
#define TAG "T5577 Writer"
26
+ #define MAX_REPEAT_WRITING_TIMES 15
23
27
24
28
// Change this to BACKLIGHT_AUTO if you don't want the backlight to be continuously on.
25
29
#define BACKLIGHT_AUTO 1
@@ -39,22 +43,24 @@ typedef enum {
39
43
T5577WriterViewTextInput , // Input for configuring text settings
40
44
T5577WriterViewLoad ,
41
45
T5577WriterViewSave ,
46
+ T5577WriterViewPopup ,
42
47
T5577WriterViewConfigure_i , // The configuration screen
43
48
T5577WriterViewConfigure_e , // The configuration screen
44
49
T5577WriterViewWrite , // The main screen
45
50
T5577WriterViewAbout , // The about screen with directions, link to social channel, etc.
46
51
} T5577WriterView ;
47
52
48
53
typedef enum {
49
- T5577WriterEventIdRedrawScreen = 0 , // Custom event to redraw the screen
50
- T5577WriterEventIdOkPressed = 42 , // Custom event to process OK button getting pressed down
54
+ T5577WriterEventIdRepeatWriting = 0 , // Custom event to redraw the screen
55
+ T5577WriterEventIdMaxWriteRep = 42 , // Custom event to process OK button getting pressed down
51
56
} T5577WriterEventId ;
52
57
53
58
typedef struct {
54
59
ViewDispatcher * view_dispatcher ; // Switches between our views
55
60
NotificationApp * notifications ; // Used for controlling the backlight
56
61
Submenu * submenu ; // The application menu
57
62
TextInput * text_input ; // The text input screen
63
+ Popup * popup ;
58
64
VariableItemList * variable_item_list_config ; // The configuration screen
59
65
View * view_config_e ; // The configuration screen
60
66
View * view_save ;
@@ -85,6 +91,7 @@ typedef struct {
85
91
t5577_rf_clock rf_clock ;
86
92
bool data_loaded [3 ];
87
93
uint8_t edit_block_slc ;
94
+ uint8_t writing_repeat_times ;
88
95
} T5577WriterModel ;
89
96
90
97
static inline int min (int a , int b ) {
@@ -109,6 +116,7 @@ void initialize_model(T5577WriterModel* model) {
109
116
initialize_config (model );
110
117
model -> user_block_num = 1 ;
111
118
model -> edit_block_slc = 1 ;
119
+ model -> writing_repeat_times = 0 ;
112
120
model -> content = (uint32_t * )malloc (LFRFID_T5577_BLOCK_COUNT * sizeof (uint32_t ));
113
121
for (uint32_t i = 0 ; i < LFRFID_T5577_BLOCK_COUNT ; i ++ ) {
114
122
model -> content [i ] = 0 ;
@@ -347,7 +355,7 @@ static void t5577_writer_file_saver(void* context) {
347
355
furi_string_printf (buffer , "Number of User Blocks: %u\n" , model -> user_block_num );
348
356
storage_file_write (data_file , furi_string_get_cstr (buffer ), furi_string_size (buffer ));
349
357
furi_string_printf (buffer , "\nRaw Data:\n" );
350
- for (int i = 0 ; i < model -> user_block_num ; i ++ )
358
+ for (int i = 0 ; i < LFRFID_T5577_BLOCK_COUNT ; i ++ )
351
359
{
352
360
furi_string_cat_printf (
353
361
buffer ,
@@ -366,8 +374,6 @@ static void t5577_writer_file_saver(void* context) {
366
374
void t5577_writer_update_config_from_load (void * context ) {
367
375
T5577WriterApp * app = (T5577WriterApp * )context ;
368
376
T5577WriterModel * my_model = view_get_model (app -> view_write );
369
-
370
-
371
377
for (size_t i = 0 ; i < COUNT_OF (all_mods ); i ++ ) {
372
378
if ((my_model -> content [0 ] & all_mods [i ].mod_page_zero ) == all_mods [i ].mod_page_zero ) {
373
379
my_model -> modulation_index = (uint8_t )i ;
@@ -390,7 +396,7 @@ void t5577_writer_update_config_from_load(void* context) {
390
396
391
397
static void t5577_writer_config_enter_callback (void * context ) {
392
398
T5577WriterApp * app = (T5577WriterApp * )context ;
393
-
399
+ T5577WriterModel * my_model = view_get_model ( app -> view_write );
394
400
variable_item_list_reset (app -> variable_item_list_config );
395
401
app -> mod_item = variable_item_list_add (
396
402
app -> variable_item_list_config ,
@@ -417,6 +423,12 @@ static void t5577_writer_config_enter_callback(void* context) {
417
423
t5577_writer_edit_block_slc_change ,
418
424
app );
419
425
View * view_config_i = variable_item_list_get_view (app -> variable_item_list_config );
426
+
427
+ variable_item_set_current_value_index (app -> mod_item ,my_model -> modulation_index );
428
+ variable_item_set_current_value_index (app -> clock_item ,my_model -> rf_clock_index );
429
+ variable_item_set_current_value_index (app -> block_num_item ,my_model -> user_block_num - 1 );
430
+ variable_item_set_current_value_index (app -> block_slc_item ,my_model -> edit_block_slc - 1 );
431
+
420
432
t5577_writer_modulation_change (app -> mod_item );
421
433
t5577_writer_rf_clock_change (app -> clock_item );
422
434
t5577_writer_user_block_num_change (app -> block_num_item );
@@ -535,28 +547,34 @@ static void t5577_writer_view_save_callback(void* context) {
535
547
536
548
}
537
549
538
- /**
539
- * @brief Callback for drawing the game screen.
540
- * @details This function is called when the screen needs to be redrawn, like when the model gets updated.
541
- * @param canvas The canvas to draw on.
542
- * @param model The model - MyModel object.
543
- */
544
- static void t5577_writer_view_write_callback (Canvas * canvas , void * model ) {
550
+ static void t5577_writer_actual_writing (void * model ) {
545
551
T5577WriterModel * my_model = (T5577WriterModel * )model ;
546
552
my_model -> content [0 ] = 0 ;
547
553
my_model -> content [0 ] |= my_model -> modulation .mod_page_zero ;
548
554
my_model -> content [0 ] |= my_model -> rf_clock .clock_page_zero ;
549
555
my_model -> content [0 ] |= (my_model -> user_block_num << LFRFID_T5577_MAXBLOCK_SHIFT );
550
-
551
556
LFRFIDT5577 * data = (LFRFIDT5577 * )malloc (sizeof (LFRFIDT5577 ));
552
557
data -> blocks_to_write = my_model -> user_block_num ;
553
558
for (size_t i = 0 ; i < data -> blocks_to_write ; i ++ ) {
554
559
data -> block [i ] = my_model -> content [i ];
555
560
}
556
561
t5577_write (data );
557
562
free (data );
563
+ }
558
564
559
- canvas_draw_str (canvas , 32 , 10 , "Writing..." );
565
+ /**
566
+ * @brief Callback for drawing the game screen.
567
+ * @details This function is called when the screen needs to be redrawn, like when the model gets updated.
568
+ * @param canvas The canvas to draw on.
569
+ * @param model The model - MyModel object.
570
+ */
571
+ static void t5577_writer_view_write_callback (Canvas * canvas , void * model ) {
572
+ t5577_writer_actual_writing (model );
573
+ canvas_set_bitmap_mode (canvas , true);
574
+ canvas_draw_icon (canvas , 0 , 8 , & I_NFC_manual_60x50 );
575
+ canvas_draw_str_aligned (canvas , 97 , 15 , AlignCenter , AlignTop , "Writing" );
576
+ canvas_draw_str_aligned (canvas , 94 , 27 , AlignCenter , AlignTop , "Hold card next" );
577
+ canvas_draw_str_aligned (canvas , 93 , 39 , AlignCenter , AlignTop , "to Flipper's back" );
560
578
}
561
579
562
580
/**
@@ -566,7 +584,13 @@ static void t5577_writer_view_write_callback(Canvas* canvas, void* model) {
566
584
*/
567
585
static void t5577_writer_view_write_timer_callback (void * context ) {
568
586
T5577WriterApp * app = (T5577WriterApp * )context ;
569
- view_dispatcher_send_custom_event (app -> view_dispatcher , T5577WriterEventIdRedrawScreen );
587
+ T5577WriterModel * model = view_get_model (app -> view_write );
588
+ if (model -> writing_repeat_times < MAX_REPEAT_WRITING_TIMES ){
589
+ model -> writing_repeat_times += 1 ;
590
+ view_dispatcher_send_custom_event (app -> view_dispatcher , T5577WriterEventIdRepeatWriting );
591
+ } else {
592
+ view_dispatcher_send_custom_event (app -> view_dispatcher , T5577WriterEventIdMaxWriteRep );
593
+ }
570
594
}
571
595
572
596
/**
@@ -576,12 +600,13 @@ static void t5577_writer_view_write_timer_callback(void* context) {
576
600
* @param context The context - T5577WriterApp object.
577
601
*/
578
602
static void t5577_writer_view_write_enter_callback (void * context ) {
579
- uint32_t period = furi_ms_to_ticks (500 );
603
+ uint32_t repeat_writing_period = furi_ms_to_ticks (200 );
580
604
T5577WriterApp * app = (T5577WriterApp * )context ;
581
605
furi_assert (app -> timer == NULL );
582
606
app -> timer =
583
607
furi_timer_alloc (t5577_writer_view_write_timer_callback , FuriTimerTypePeriodic , context );
584
- furi_timer_start (app -> timer , period );
608
+ furi_timer_start (app -> timer , repeat_writing_period );
609
+ dolphin_deed (DolphinDeedRfidEmulate );
585
610
}
586
611
587
612
/**
@@ -591,9 +616,11 @@ static void t5577_writer_view_write_enter_callback(void* context) {
591
616
*/
592
617
static void t5577_writer_view_write_exit_callback (void * context ) {
593
618
T5577WriterApp * app = (T5577WriterApp * )context ;
619
+ T5577WriterModel * model = view_get_model (app -> view_write );
594
620
furi_timer_stop (app -> timer );
595
621
furi_timer_free (app -> timer );
596
622
app -> timer = NULL ;
623
+ model -> writing_repeat_times = 0 ;
597
624
}
598
625
599
626
/**
@@ -605,15 +632,15 @@ static void t5577_writer_view_write_exit_callback(void* context) {
605
632
static bool t5577_writer_view_write_custom_event_callback (uint32_t event , void * context ) {
606
633
T5577WriterApp * app = (T5577WriterApp * )context ;
607
634
switch (event ) {
608
- case T5577WriterEventIdRedrawScreen :
635
+ case T5577WriterEventIdRepeatWriting :
609
636
// Redraw screen by passing true to last parameter of with_view_model.
610
637
{
611
638
bool redraw = true;
612
639
with_view_model (
613
- app -> view_write , T5577WriterModel * _model , { UNUSED (_model ); }, redraw );
640
+ app -> view_write , T5577WriterModel * _model , {UNUSED (_model );}, redraw );
614
641
return true;
615
642
}
616
- case T5577WriterEventIdOkPressed :
643
+ case T5577WriterEventIdMaxWriteRep :
617
644
// Process the OK button. We go to the saving scene.
618
645
view_dispatcher_switch_to_view (app -> view_dispatcher , T5577WriterViewSubmenu );
619
646
return true;
@@ -634,9 +661,9 @@ static bool t5577_writer_view_write_input_callback(InputEvent* event, void* cont
634
661
if (event -> type == InputTypeShort ) {
635
662
if (event -> key == InputKeyOk ) {
636
663
// We choose to send a custom event when user presses OK button. t5577_writer_custom_event_callback will
637
- // handle our T5577WriterEventIdOkPressed event. We could have just put the code from
664
+ // handle our T5577WriterEventIdMaxWriteRep event. We could have just put the code from
638
665
// t5577_writer_custom_event_callback here, it's a matter of preference.
639
- view_dispatcher_send_custom_event (app -> view_dispatcher , T5577WriterEventIdOkPressed );
666
+ view_dispatcher_send_custom_event (app -> view_dispatcher , T5577WriterEventIdMaxWriteRep );
640
667
return true;
641
668
}
642
669
}
@@ -679,6 +706,8 @@ static T5577WriterApp* t5577_writer_app_alloc() {
679
706
view_dispatcher_add_view (
680
707
app -> view_dispatcher , T5577WriterViewTextInput , text_input_get_view (app -> text_input ));
681
708
709
+ app -> popup = popup_alloc ();
710
+ view_dispatcher_add_view (app -> view_dispatcher ,T5577WriterViewPopup ,popup_get_view (app -> popup ));
682
711
683
712
app -> view_load = view_alloc ();
684
713
view_set_previous_callback (app -> view_load , t5577_writer_navigation_submenu_callback );
@@ -798,6 +827,8 @@ static void t5577_writer_app_free(T5577WriterApp* app) {
798
827
view_dispatcher_remove_view (app -> view_dispatcher , T5577WriterViewConfigure_i );
799
828
view_dispatcher_remove_view (app -> view_dispatcher , T5577WriterViewConfigure_e );
800
829
variable_item_list_free (app -> variable_item_list_config );
830
+ view_dispatcher_remove_view (app -> view_dispatcher , T5577WriterViewPopup );
831
+ popup_free (app -> popup );
801
832
view_dispatcher_remove_view (app -> view_dispatcher , T5577WriterViewSave );
802
833
view_free (app -> view_save );
803
834
view_dispatcher_remove_view (app -> view_dispatcher , T5577WriterViewSubmenu );
0 commit comments