Hackio-Credits.
[hackover2013-badge-firmware.git] / badge / fahrplan.c
1 #include "fahrplan.h"
2 #include "ui/browser.h"
3
4 #include <drivers/fatfs/ff.h>
5
6 #define FAHRPLAN_PATH "/fahrplan"
7 #define FAHRPLAN_MENUFILE "fahrplan.lst"
8 #define FAHRPLAN_POSFILE "selected.dat"
9
10 static size_t badge_load_fahrplan_pos(void) {
11 size_t pos = 0;
12 FIL fd;
13
14 if(FR_OK == f_open(&fd, FAHRPLAN_POSFILE, FA_OPEN_EXISTING | FA_READ)) {
15 UINT bytes;
16 size_t buf;
17 if(FR_OK == f_read(&fd, &buf, sizeof(buf), &bytes) && bytes == sizeof(buf)) {
18 pos = buf;
19 }
20
21 f_close(&fd);
22 }
23
24 return pos;
25 }
26
27 static void badge_save_fahrplan_pos(size_t pos) {
28 FIL fd;
29
30 if(FR_OK == f_open(&fd, FAHRPLAN_POSFILE, FA_CREATE_ALWAYS | FA_WRITE)) {
31 UINT bytes;
32 f_write(&fd, &pos, sizeof(pos), &bytes);
33 f_close(&fd);
34 }
35 }
36
37 void badge_fahrplan(void) {
38 f_chdir(FAHRPLAN_PATH);
39
40 size_t oldpos = badge_load_fahrplan_pos();
41 size_t pos = oldpos;
42
43 badge_browse_textfiles(FAHRPLAN_MENUFILE, &pos);
44
45 if(oldpos != pos) {
46 badge_save_fahrplan_pos(pos);
47 }
48 }
This page took 0.043063 seconds and 5 git commands to generate.