Skip to content

Commit 47e7438

Browse files
committed
clean up and update comments
1 parent 55538af commit 47e7438

File tree

1 file changed

+25
-82
lines changed

1 file changed

+25
-82
lines changed

t5577_writer.c

+25-82
Original file line numberDiff line numberDiff line change
@@ -150,24 +150,6 @@ static uint32_t t5577_writer_navigation_submenu_callback(void* _context) {
150150
return T5577WriterViewSubmenu;
151151
}
152152

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-
171153
/**
172154
* @brief Handle submenu item selection.
173155
* @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) {
197179
}
198180
}
199181

200-
/**
201-
* Our 1st sample setting is a team color. We have 3 options: red, green, and blue.
202-
*/
203182
static const char* modulation_config_label = "Modulation";
204-
//static char* modulation_names[] = {"Direct", "PSK1", "PSK2", "PSK3", "FSK1", "FSK2", "FSK1a", "FSK2a","ASK/Man","Biphase","Diphase"};
205183
static void t5577_writer_modulation_change(VariableItem* item) {
206184
T5577WriterApp* app = variable_item_get_context(item);
207-
FURI_LOG_D(TAG,"app defined");
208185
T5577WriterModel* model = view_get_model(app->view_write);
209-
FURI_LOG_D(TAG,"model defined");
210186
if (model->data_loaded[0]) {
211-
FURI_LOG_D(TAG,"loaded entered");
212187
variable_item_set_current_value_index(item,model->modulation_index);
213188
} else{
214-
FURI_LOG_D(TAG,"else entered");
215189
uint8_t modulation_index = variable_item_get_current_value_index(item);
216190
model->modulation_index = modulation_index;
217191
model->modulation = all_mods[modulation_index];
@@ -224,7 +198,6 @@ static const char* rf_clock_config_label = "RF Clock";
224198
static void t5577_writer_rf_clock_change(VariableItem* item) {
225199
T5577WriterApp* app = variable_item_get_context(item);
226200
T5577WriterModel* model = view_get_model(app->view_write);
227-
228201
if (model->data_loaded[1]) {
229202
variable_item_set_current_value_index(item,model->rf_clock_index);
230203
} else{
@@ -255,7 +228,7 @@ static void t5577_writer_user_block_num_change(VariableItem* item) {
255228
furi_string_printf(buffer, "%u", model->user_block_num);
256229
variable_item_set_current_value_text(item, furi_string_get_cstr(buffer));
257230
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
259232
}
260233
furi_string_free(buffer);
261234
}
@@ -286,7 +259,7 @@ void ensure_dir_exists(Storage *storage)
286259
FURI_LOG_I(TAG, "Directory exists: %s", T5577_WRITER_APPS_DATA_FOLDER);
287260
}
288261

289-
// If wiegand directory doesn't exist, create it.
262+
// If t5577_writer directory doesn't exist, create it.
290263
if (!storage_dir_exists(storage, T5577_WRITER_FILE_FOLDER))
291264
{
292265
FURI_LOG_I(TAG, "Creating directory: %s", T5577_WRITER_FILE_FOLDER);
@@ -297,17 +270,13 @@ void ensure_dir_exists(Storage *storage)
297270
FURI_LOG_I(TAG, "Directory exists: %s", T5577_WRITER_FILE_FOLDER);
298271
}
299272
}
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+
305274
static const char* tag_name_entry_text = "Enter name";
306275
static const char* tag_name_default_value = "Tag_1";
307276
static void t5577_writer_file_saver(void* context) {
308277
T5577WriterApp* app = (T5577WriterApp*)context;
309278
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
311280
model->content[0] |= model->modulation.mod_page_zero;
312281
model->content[0] |= model->rf_clock.clock_page_zero;
313282
model->content[0] |= (model->user_block_num << LFRFID_T5577_MAXBLOCK_SHIFT);
@@ -353,7 +322,7 @@ static void t5577_writer_file_saver(void* context) {
353322
furi_string_push_back(buffer, '\n');
354323
storage_file_write(data_file, furi_string_get_cstr(buffer), furi_string_size(buffer));
355324
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
357326
}
358327
}
359328

@@ -374,16 +343,17 @@ void t5577_writer_update_config_from_load(void* context) {
374343
}
375344
}
376345

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;
378347

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
380349

381350
}
382351

383352
static void t5577_writer_config_enter_callback(void* context) {
384353
T5577WriterApp* app = (T5577WriterApp*)context;
385354
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
387357
app->mod_item = variable_item_list_add(
388358
app->variable_item_list_config,
389359
modulation_config_label,
@@ -422,13 +392,12 @@ static void t5577_writer_config_enter_callback(void* context) {
422392
view_set_previous_callback(
423393
view_config_i,
424394
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
426396
view_dispatcher_add_view(
427397
app->view_dispatcher,
428398
T5577WriterViewConfigure_i,
429399
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
432401
}
433402

434403
void t5577_writer_view_load_callback(void* context) {
@@ -438,13 +407,11 @@ void t5577_writer_view_load_callback(void* context) {
438407
Storage* storage = furi_record_open(RECORD_STORAGE);
439408
ensure_dir_exists(storage);
440409
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);
442411
browser_options.base_path = T5577_WRITER_FILE_FOLDER;
443412
furi_string_set(app->file_path, browser_options.base_path);
444413
FuriString* buffer = furi_string_alloc();
445-
446414
if(dialog_file_browser_show(app->dialogs, app->file_path, app->file_path, &browser_options)) {
447-
448415
if(storage_file_open(
449416
data_file, furi_string_get_cstr(app->file_path), FSAM_READ, FSOM_OPEN_EXISTING)) {
450417
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) {
466433
int i = 0;
467434
while(i < length) {
468435
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
470438
i += 2; // skip a space
471439
for(size_t j = 0; j < sizeof(row_data_char_buffer); j++) {
472440
ch = furi_string_get_char(buffer, i);
@@ -494,8 +462,7 @@ void t5577_writer_view_load_callback(void* context) {
494462

495463
/**
496464
* @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.
499466
* @param context The context - T5577WriterApp object.
500467
* @param index - The index of the item that was clicked.
501468
*/
@@ -524,18 +491,17 @@ static void t5577_writer_view_save_callback(void* context) {
524491
app->temp_buffer,
525492
app->temp_buffer_size,
526493
clear_previous_text);
527-
// Pressing the BACK button will reload the configure screen.
494+
// Pressing the BACK button will return to the main menu.
528495
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);
530497

531498
// Show text input dialog.
532499
view_dispatcher_switch_to_view(app->view_dispatcher, T5577WriterViewTextInput);
533-
534500
}
535501

536502
static void t5577_writer_actual_writing(void* model) {
537503
T5577WriterModel* my_model = (T5577WriterModel*)model;
538-
my_model->content[0] = 0;
504+
my_model->content[0] = 0; // clear up block 0
539505
my_model->content[0] |= my_model->modulation.mod_page_zero;
540506
my_model->content[0] |= my_model->rf_clock.clock_page_zero;
541507
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) {
549515
}
550516

551517
/**
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.
554520
* @param canvas The canvas to draw on.
555521
* @param model The model - MyModel object.
556522
*/
@@ -576,7 +542,6 @@ static void t5577_writer_view_write_callback(Canvas* canvas, void* model) {
576542
* @details This function is called when the timer is elapsed. We use this to queue a redraw event.
577543
* @param context The context - T5577WriterApp object.
578544
*/
579-
580545
static void t5577_writer_view_write_timer_callback(void* context) {
581546
T5577WriterApp* app = (T5577WriterApp*)context;
582547
T5577WriterModel* model = view_get_model(app->view_write);
@@ -589,9 +554,9 @@ static void t5577_writer_view_write_timer_callback(void* context) {
589554
}
590555

591556
/**
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)
595560
* @param context The context - T5577WriterApp object.
596561
*/
597562
static void t5577_writer_view_write_enter_callback(void* context) {
@@ -605,8 +570,8 @@ static void t5577_writer_view_write_enter_callback(void* context) {
605570
}
606571

607572
/**
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.
610575
* @param context The context - T5577WriterApp object.
611576
*/
612577
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*
644609
}
645610
}
646611

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-
668612
/**
669613
* @brief Allocate the t5577_writer application.
670614
* @details This function allocates the t5577_writer application resources.
@@ -716,7 +660,6 @@ static T5577WriterApp* t5577_writer_app_alloc() {
716660

717661
app->view_write = view_alloc();
718662
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);
720663
view_set_previous_callback(app->view_write, t5577_writer_navigation_submenu_callback);
721664
view_set_enter_callback(app->view_write, t5577_writer_view_write_enter_callback);
722665
view_set_exit_callback(app->view_write, t5577_writer_view_write_exit_callback);

0 commit comments

Comments
 (0)