4 #include <drivers/fatfs/ff.h>
10 BUFLEN
= LINE_LENGTH
+ 1 + FNAME_MAX
+ 1
13 static void badge_browse_textfile_fd(FIL
*fd
) {
14 unsigned linecount
= 0;
17 char buf
[LINE_LENGTH
];
18 while(f_gets(buf
, LINE_LENGTH
, fd
)) {
23 if(FR_OK
!= f_lseek(fd
, 0)) {
27 char lines_buf
[linecount
][LINE_LENGTH
];
28 char const *lines
[linecount
];
31 for(i
= 0; i
< linecount
&& f_gets(lines_buf
[i
], LINE_LENGTH
, fd
); ++i
) {
32 lines
[i
] = lines_buf
[i
];
35 badge_scroll_text(lines
, i
);
38 static uint8_t badge_count_lines_in_file(FIL
*fd
) {
41 if(FR_OK
== f_lseek(fd
, 0)) {
43 while(f_gets(buf
, BUFLEN
, fd
)) {
51 static uint8_t badge_browse_pick_filename_from_fd(char *buf
, uint8_t *first_visible
, uint8_t *selected
, FIL
*fd
) {
52 unsigned linecount
= badge_count_lines_in_file(fd
);
54 if(FR_OK
!= f_lseek(fd
, 0)) {
58 char menu_buf
[linecount
+ 1][BUFLEN
];
59 char const *menu_index
[linecount
+ 1];
60 char *fnames
[linecount
+ 1];
63 for(i
= 0; i
< linecount
&& f_gets(menu_buf
[i
], BUFLEN
, fd
); ++i
) {
64 menu_index
[i
] = menu_buf
[i
];
66 for(p
= menu_buf
[i
]; *p
&& *p
!= '|'; ++p
)
74 strcpy(menu_buf
[i
], "Zurück");
75 menu_index
[i
] = menu_buf
[i
];
76 uint8_t choice
= badge_menu(menu_index
, i
+ 1, first_visible
, *selected
);
78 if(choice
== linecount
) {
83 strncpy(buf
, fnames
[*selected
], FNAME_MAX
);
84 buf
[FNAME_MAX
] = '\0';
89 static uint8_t badge_pick_filename(char *buf
, char const *menufile
, uint8_t *first_visible
, uint8_t *selected
) {
93 if(FR_OK
== f_open(&fd
, menufile
, FA_OPEN_EXISTING
| FA_READ
)) {
94 err
= badge_browse_pick_filename_from_fd(buf
, first_visible
, selected
, &fd
);
101 void badge_browse_textfile(char const *fname
) {
104 if(FR_OK
== f_open(&fd
, fname
, FA_OPEN_EXISTING
| FA_READ
)) {
105 badge_browse_textfile_fd(&fd
);
110 void badge_browse_textfiles(char const *menufile
, uint8_t *selected
) {
111 char buf
[FNAME_MAX
+ 1];
112 uint8_t first_visible
= *selected
;
114 while(0 == badge_pick_filename(buf
, menufile
, &first_visible
, selected
)) {
115 badge_browse_textfile(buf
);
This page took 0.056639 seconds and 5 git commands to generate.