-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdemo-trs-fs.c
62 lines (46 loc) · 1.1 KB
/
demo-trs-fs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "demo.h"
#include <trs-lib.h>
static window_t wnd;
static char name[20 + 1] = {""};
static form_item_t my_form_items[] = {
FORM_ITEM_INPUT("Filename", name, sizeof(name) - 1, 0, NULL),
FORM_ITEM_END
};
static form_t my_form = {
.title = "TRS-FS Demo",
.form_items = my_form_items
};
void demo_trs_fs()
{
static const char* path = "CAT.BAS";
static char buf[256];
int8_t fd;
uint16_t br;
uint8_t status;
int i;
set_screen_to_background();
init_window(&wnd, 0, 3, 0, 0);
header(my_form.title);
wnd_print(&wnd, "This demo uses TRS-FS's file system API to print the contents of "
"a file residing on the SMB share or MicroSD card.\n\n");
status = form_inline(&wnd, &my_form, false);
if (status == FORM_ABORT) {
return;
}
wnd_cls(&wnd);
fd = trs_fs_open(name, FA_READ);
if (fd < 0) {
wnd_popup("File not found");
get_key();
return;
}
wnd_cls(&wnd);
do {
trs_fs_read(fd, buf, sizeof(buf), &br);
for(i = 0; i < br; i++) {
wnd_print(&wnd, "%c", buf[i]);
}
} while(br != 0);
trs_fs_close(fd);
get_key();
}