From: Wintermate Date: Tue, 22 Oct 2013 23:20:38 +0000 (+0200) Subject: Textdateiankuckdingviech. X-Git-Url: https://git.rohieb.name/hackover2013-badge-firmware.git/commitdiff_plain/05db94c84b6f7e4ee91fd67d6e1a8d97a2b97f2e Textdateiankuckdingviech. --- diff --git a/Makefile b/Makefile index b6d9f6a..6f4fafb 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,7 @@ SRCS = \ badge/jumpnrun/starter.c \ badge/jumpnrun/stats.c \ badge/jumpnrun/tiles.c \ + badge/ui/browser.c \ badge/ui/display.c \ badge/ui/event.c \ badge/ui/font.c \ diff --git a/badge/main.c b/badge/main.c index c225b4e..774649d 100644 --- a/badge/main.c +++ b/badge/main.c @@ -199,45 +199,7 @@ void usbmode(void) { } void scrolltest(void) { - char menu_buf[][15] = { - "foo", - "bar", - "baz", - "qux", - "foo", - "bar", - "baz", - "qux", - "foo", - "bar", - "baz", - "qux", - "foo", - "bar", - "baz", - "qux", - }; - - char const * menu_index[] = { - menu_buf[0], - menu_buf[1], - menu_buf[2], - menu_buf[3], - menu_buf[4], - menu_buf[5], - menu_buf[6], - menu_buf[7], - menu_buf[8], - menu_buf[9], - menu_buf[10], - menu_buf[11], - menu_buf[12], - menu_buf[13], - menu_buf[14], - menu_buf[15] - }; - - badge_scroll_text(menu_index, 16); + badge_browse_textfile("/fahrplan/test.txt"); } int main(void) diff --git a/badge/ui/browser.c b/badge/ui/browser.c index 4c37f94..39a4d8a 100644 --- a/badge/ui/browser.c +++ b/badge/ui/browser.c @@ -1,6 +1,41 @@ #include "browser.h" #include "menu.h" -void badge_browse_textfile(char const *fname) { +#include + +enum { + LINE_LENGTH = 16 +}; + +static void badge_browse_textfile_fd(FIL *fd) { + unsigned linecount = 0; + + { + char buf[LINE_LENGTH]; + while(f_gets(buf, LINE_LENGTH, fd)) { + ++linecount; + } + } + + if(FR_OK != f_lseek(fd, 0)) { + return; + } + char lines_buf[linecount][LINE_LENGTH]; + char const *lines[linecount]; + unsigned i; + + for(i = 0; i < linecount && f_gets(lines_buf[i], LINE_LENGTH, fd); ++i) { + lines[i] = lines_buf[i]; + } + + badge_scroll_text(lines, i); +} + +void badge_browse_textfile(char const *fname) { + FIL fd; + if(FR_OK == f_open(&fd, fname, FA_OPEN_EXISTING | FA_READ)) { + badge_browse_textfile_fd(&fd); + f_close(&fd); + } } diff --git a/fahrplan/test.txt b/fahrplan/test.txt new file mode 100644 index 0000000..6d2612b --- /dev/null +++ b/fahrplan/test.txt @@ -0,0 +1,27 @@ +Sa. 14:00 +--------- +Quantentroll- +ierung im 21. +Jahrhundert + +Speaker: +Lubiana + +Wenn die Viel- +welteninter- +pretation der +Quantenphysik +korrekt ist, +so hat jeder +von uns eine +unendlich +große Zahl an +Paralleltrol- +len. + +Es ist nur ei- +ne Frage der +Zeit, bis wir +alle von uns +selbst ge- +trollt werden.