| 22 | | #define ROUTE_FILE "tag.data" |
| 23 | | |
| 24 | | #define TEST_DATA "print hello world\nmove A,B 100 1500\nwait 2000\nplay 1500 1000 sync\nprint done" |
| 25 | | #define DATA_SIZE strlen(TEST_DATA) |
| 26 | | |
| 27 | | void record(char *filename); |
| 28 | | void replay(char *filename); |
| 29 | | void defrag(void); |
| 30 | | void stats(void); |
| 31 | | |
| 32 | | void record(char *filename) { |
| 33 | | fs_fd_t fd; |
| 34 | | fs_err_t err; |
| 35 | | size_t i; |
| 36 | | |
| 37 | | nx_display_clear(); |
| 38 | | nx_display_string("Creating file...\n"); |
| 39 | | |
| 40 | | err = nx_fs_open(filename, FS_FILE_MODE_CREATE, &fd); |
| 41 | | if (err == FS_ERR_FILE_ALREADY_EXISTS) { |
| 42 | | if (nx_gui_text_menu_yesno("Overwrite?")) { |
| 43 | | nx_display_clear(); |
| 44 | | |
| 45 | | nx_fs_open(filename, FS_FILE_MODE_OPEN, &fd); |
| 46 | | if (nx_fs_unlink(fd) != FS_ERR_NO_ERROR) { |
| 47 | | nx_display_string("Erase error.\n"); |
| 48 | | return; |
| 49 | | } |
| 50 | | |
| 51 | | if (nx_fs_open(filename, FS_FILE_MODE_CREATE, &fd) != FS_ERR_NO_ERROR) { |
| 52 | | nx_display_string("Create error.\n"); |
| 53 | | return; |
| 54 | | } |
| 55 | | } else { |
| 56 | | nx_display_string("Aborting.\n"); |
| 57 | | return; |
| 58 | | } |
| 59 | | } |
| 60 | | |
| 61 | | nx_display_string("File opened.\n\n"); |
| 62 | | nx_display_string("Writing...\n"); |
| 63 | | |
| 64 | | for (i=0; i<DATA_SIZE; i++) { |
| 65 | | err = nx_fs_write(fd, (U8)TEST_DATA[i]); |
| 66 | | |
| 67 | | if (err != FS_ERR_NO_ERROR) { |
| 68 | | nx_display_string("Err: "); |
| 69 | | nx_display_uint(err); |
| 70 | | nx_display_end_line(); |
| 71 | | } |
| 72 | | } |
| 73 | | |
| 74 | | nx_display_uint(nx_fs_get_filesize(fd)); |
| 75 | | nx_display_string("/"); |
| 76 | | nx_display_uint(DATA_SIZE); |
| 77 | | nx_display_string("B written.\n"); |
| 78 | | nx_fs_close(fd); |
| 79 | | } |
| 80 | | |
| 81 | | void replay(char *filename) { |
| 82 | | nx_display_clear(); |
| 83 | | nx_rcmd_parse(filename); |
| 84 | | } |
| 85 | | |
| 86 | | void defrag(void) { |
| 87 | | nx_display_clear(); |
| 88 | | nx_display_string("- Defrag -\n\n"); |
| 89 | | nx_fs_defrag_best_overall(); |
| 90 | | nx_display_string("Done.\n"); |
| 91 | | |
| 92 | | while (nx_avr_get_button() != BUTTON_CANCEL); |
| 93 | | } |
| 94 | | |
| 95 | | void stats(void) { |
| 96 | | U32 files = 0, used = 0, free_pages = 0, wasted = 0; |
| 97 | | |
| 98 | | nx_display_clear(); |
| 99 | | nx_display_string("- FS stats -\n\n"); |
| 100 | | |
| 101 | | nx_fs_get_occupation(&files, &used, &free_pages, &wasted); |
| 102 | | |
| 103 | | nx_display_uint(files); |
| 104 | | nx_display_string(" file(s).\n"); |
| 105 | | |
| 106 | | nx_display_uint(used); |
| 107 | | nx_display_string("B used.\n"); |
| 108 | | |
| 109 | | nx_display_uint(free_pages); |
| 110 | | nx_display_string(" free page(s).\n"); |
| 111 | | |
| 112 | | nx_display_uint(wasted); |
| 113 | | nx_display_string("B wasted.\n"); |
| 114 | | } |
| | 18 | #include "main.h" |