Schrift. TODO?: Umlaute
authorWintermute <wintermute@hannover.ccc.de>
Tue, 15 Oct 2013 21:07:45 +0000 (23:07 +0200)
committerWintermute <wintermute@hannover.ccc.de>
Tue, 15 Oct 2013 21:07:45 +0000 (23:07 +0200)
Makefile
badge/jumpnrun/enemies.c
badge/main.c
badge/ui/font.c [new file with mode: 0644]
badge/ui/font.dat [new file with mode: 0644]
badge/ui/font.h [new file with mode: 0644]

index 7c8a681..9d1938d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -41,6 +41,7 @@ SRCS = \
   badge/jumpnrun/tiles.c \\r
   badge/ui/display.c \\r
   badge/ui/event.c \\r
+  badge/ui/font.c \\r
   badge/ui/sprite.c\r
 \r
 SRCS += \\r
index c06df53..0277db7 100644 (file)
@@ -27,10 +27,10 @@ static badge_sprite const anim_bunny[] = {
 };
 
 static badge_sprite const anim_snake[] = {
-  { 10, 6, (uint8_t const *) "\x10\x86\x83\x30\x04\x83\xa2\x0f" },
-  { 10, 6, (uint8_t const *) "\x10\x86\x83\x20\x0c\xc1\xa2\x0f" },
-  { 10, 6, (uint8_t const *) "\x10\x86\x83\x20\x08\x82\xe0\x0f" },
-  { 10, 6, (uint8_t const *) "\x10\x86\x83\x20\x08\x86\xe1\x0f" }
+  { 10, 6, (uint8_t const *) "\x10\x86\x83\x30\x04\x83\xa2\x07" },
+  { 10, 6, (uint8_t const *) "\x10\x86\x83\x20\x0c\xc1\xa2\x07" },
+  { 10, 6, (uint8_t const *) "\x10\x86\x83\x20\x08\x82\xe0\x07" },
+  { 10, 6, (uint8_t const *) "\x10\x86\x83\x20\x08\x86\xe1\x07" }
 };
 
 static badge_sprite const anim_spiral[] = {
index 4e878f5..be4ad7a 100644 (file)
@@ -57,6 +57,7 @@
 #include "ui/display.h"
 #include "ui/sprite.h"
 #include "ui/event.h"
+#include "ui/font.h"
 #include "util/util.h"
 #include "jumpnrun/jumpnrun.h"
 
@@ -127,7 +128,7 @@ void rbInit() {
     { RB_PWR_CHRG, &RB_PWR_CHRG_IO, gpioPullupMode_PullUp }
 #endif
   };
-    
+
   for(int i = 0; i < ARRAY_SIZE(input_pins); ++i) {
     gpioSetDir(input_pins[i].port, input_pins[i].pin, gpioDirection_Input);
     gpioSetPullup(input_pins[i].reg, input_pins[i].mode);
@@ -223,25 +224,13 @@ int main(void)
   }
   */
 
-  {
-    //    f_mkfs(0, 1, 0);
-    badge_framebuffer fb;
-    int res = 0;
-    FATFS fatvol;
-
-    while(FR_OK != f_mount(0, &fatvol)) {
-      f_mkfs(0, 1, 0);
-    }
-
-    FIL fil;
-    if(FR_OK == (res = f_open(&fil, "sshot.dat", FA_OPEN_EXISTING | FA_READ))) {
-      UINT readbytes;
+  FATFS fs;
+  f_mount(0, &fs);
 
-      if(FR_OK != f_read(&fil, &fb, sizeof(fb), &readbytes)) {
-      }
+  {
+    badge_framebuffer fb = { { { 0 } } };
 
-      f_close(&fil);
-    }
+    fb.data[0][0] = badge_framebuffer_render_text(&fb, 2, 10, "foobar");
 
     badge_framebuffer_flush(&fb);
   }
diff --git a/badge/ui/font.c b/badge/ui/font.c
new file mode 100644 (file)
index 0000000..1ea57ad
--- /dev/null
@@ -0,0 +1,55 @@
+#include "font.h"
+#include "sprite.h"
+
+#include <drivers/fatfs/ff.h>
+
+static uint8_t badge_framebuffer_render_char_with_fd(badge_framebuffer *fb, int8_t pos_x, int8_t pos_y, char c, FIL *fd) {
+  UINT readbytes;
+  uint8_t buffer[BADGE_FONT_WIDTH];
+
+  if(c == 32) {
+    // intentionally left empty.
+  } else if(c >= 32 &&
+     FR_OK == f_lseek(fd, (c - 33) * BADGE_FONT_WIDTH) &&
+     FR_OK == f_read(fd, buffer, sizeof(buffer), &readbytes)) {
+    badge_sprite sp = { BADGE_FONT_WIDTH, BADGE_FONT_HEIGHT, buffer };
+    badge_framebuffer_blt(fb, pos_x, pos_y, &sp, 0);
+  } else {
+    return -1;
+  }
+
+  return 0;
+}
+
+uint8_t badge_framebuffer_render_char(badge_framebuffer *fb, int8_t pos_x, int8_t pos_y, char c) {
+  FIL fd;
+
+  if(FR_OK == f_open(&fd, "font.dat", FA_OPEN_EXISTING | FA_READ)) {
+    badge_framebuffer_render_char_with_fd(fb, pos_x, pos_y, c, &fd);
+    f_close(&fd);
+    return 0;
+  }
+
+  return -1;
+}
+
+uint8_t badge_framebuffer_render_text(badge_framebuffer *fb, int8_t pos_x, int8_t pos_y, char const *text) {
+  uint8_t count = 0;
+  FIL fd;
+
+  if(FR_OK == f_open(&fd, "font.dat", FA_OPEN_EXISTING | FA_READ)) {
+    while(*text) {
+      if(0 != badge_framebuffer_render_char_with_fd(fb, pos_x, pos_y, *text, &fd)) {
+        break;
+      }
+
+      ++count;
+      ++text;
+      pos_x += BADGE_FONT_WIDTH;
+    }
+
+    f_close(&fd);
+  }
+
+  return count;
+}
diff --git a/badge/ui/font.dat b/badge/ui/font.dat
new file mode 100644 (file)
index 0000000..6897b39
Binary files /dev/null and b/badge/ui/font.dat differ
diff --git a/badge/ui/font.h b/badge/ui/font.h
new file mode 100644 (file)
index 0000000..12b43a1
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef INCLUDED_BADGE_UI_FONT_H
+#define INCLUDED_BADGE_UI_FONT_H
+
+#include "display.h"
+
+enum {
+  BADGE_FONT_WIDTH  = 6,
+  BADGE_FONT_HEIGHT = 8
+};
+
+uint8_t badge_framebuffer_render_char(badge_framebuffer *fb, int8_t pos_x, int8_t pos_y, char c);
+uint8_t badge_framebuffer_render_text(badge_framebuffer *fb, int8_t pos_x, int8_t pos_y, char const *text);
+
+#endif
This page took 0.035918 seconds and 4 git commands to generate.