Textdateiankuckdingviech.
authorWintermate <wintermute@hannover.ccc.de>
Tue, 22 Oct 2013 23:20:38 +0000 (01:20 +0200)
committerWintermate <wintermute@hannover.ccc.de>
Tue, 22 Oct 2013 23:20:38 +0000 (01:20 +0200)
Makefile
badge/main.c
badge/ui/browser.c
fahrplan/test.txt [new file with mode: 0644]

index b6d9f6a..6f4fafb 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -45,6 +45,7 @@ SRCS = \
   badge/jumpnrun/starter.c \\r
   badge/jumpnrun/stats.c \\r
   badge/jumpnrun/tiles.c \\r
   badge/jumpnrun/starter.c \\r
   badge/jumpnrun/stats.c \\r
   badge/jumpnrun/tiles.c \\r
+  badge/ui/browser.c \\r
   badge/ui/display.c \\r
   badge/ui/event.c \\r
   badge/ui/font.c \\r
   badge/ui/display.c \\r
   badge/ui/event.c \\r
   badge/ui/font.c \\r
index c225b4e..774649d 100644 (file)
@@ -199,45 +199,7 @@ void usbmode(void) {
 }
 
 void scrolltest(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)
 }
 
 int main(void)
index 4c37f94..39a4d8a 100644 (file)
@@ -1,6 +1,41 @@
 #include "browser.h"
 #include "menu.h"
 
 #include "browser.h"
 #include "menu.h"
 
-void badge_browse_textfile(char const *fname) {
+#include <drivers/fatfs/ff.h>
+
+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 (file)
index 0000000..6d2612b
--- /dev/null
@@ -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.
This page took 0.034938 seconds and 4 git commands to generate.