X-Git-Url: https://git.rohieb.name/hackover2013-badge-firmware.git/blobdiff_plain/d265161cb9c1651b365e447a654c6eabe6b5470d..637dcc82c8595130b3627c526126946b43c0707a:/badge/ui/font.c?ds=sidebyside diff --git a/badge/ui/font.c b/badge/ui/font.c index 2b60477..4721132 100644 --- a/badge/ui/font.c +++ b/badge/ui/font.c @@ -1,7 +1,32 @@ #include "font.h" #include "sprite.h" +#ifdef __linux__ +#include +typedef FILE *FIL; +typedef uint8_t FRESULT; +typedef unsigned UINT; +enum { FR_OK = 0 }; + +void f_close(FIL *fd) { fclose(*fd); *fd = NULL; } +FRESULT f_lseek(FIL *fd, unsigned pos) { return fseek(*fd, pos, SEEK_SET); } +FRESULT f_read(FIL *fd, unsigned char *buffer, size_t buflen, UINT *bytes) { + *bytes = fread(buffer, 1, buflen, *fd); + return *bytes == 0; +} + +#else #include +#endif + +static FRESULT open_font_file(FIL *fd) { +#ifdef __linux__ + *fd = fopen("../sprites/font.dat", "r"); + return fd ? 0 : -1; +#else + return f_open(fd, "font.dat", FA_OPEN_EXISTING | FA_READ); +#endif +} 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; @@ -21,10 +46,6 @@ static uint8_t badge_framebuffer_render_char_with_fd(badge_framebuffer *fb, int8 return 0; } -static FRESULT open_font_file(FIL *fd) { - return f_open(fd, "font.dat", FA_OPEN_EXISTING | FA_READ); -} - uint8_t badge_framebuffer_render_char(badge_framebuffer *fb, int8_t pos_x, int8_t pos_y, char c) { FIL fd; @@ -59,7 +80,7 @@ uint8_t badge_framebuffer_render_text(badge_framebuffer *fb, int8_t pos_x, int8_ } static uint8_t badge_framebuffer_render_number_with_fd(badge_framebuffer *fb, int8_t *pos_x, int8_t pos_y, uint8_t number, FIL *fd) { - if(number > 10) { + if(number >= 10) { badge_framebuffer_render_number_with_fd(fb, pos_x, pos_y, number / 10, fd); }