#include "ui/browser.h"
#include <drivers/fatfs/ff.h>
+#include <stdint.h>
#define FAHRPLAN_PATH "/fahrplan"
#define FAHRPLAN_MENUFILE "fahrplan.lst"
#define FAHRPLAN_POSFILE "selected.dat"
-static size_t badge_load_fahrplan_pos(void) {
- size_t pos = 0;
+static uint8_t badge_load_fahrplan_pos(void) {
+ uint8_t pos = 0;
FIL fd;
if(FR_OK == f_open(&fd, FAHRPLAN_POSFILE, FA_OPEN_EXISTING | FA_READ)) {
UINT bytes;
- size_t buf;
+ uint8_t buf;
if(FR_OK == f_read(&fd, &buf, sizeof(buf), &bytes) && bytes == sizeof(buf)) {
pos = buf;
}
return pos;
}
-static void badge_save_fahrplan_pos(size_t pos) {
+static void badge_save_fahrplan_pos(uint8_t pos) {
FIL fd;
if(FR_OK == f_open(&fd, FAHRPLAN_POSFILE, FA_CREATE_ALWAYS | FA_WRITE)) {
void badge_fahrplan(void) {
f_chdir(FAHRPLAN_PATH);
- size_t oldpos = badge_load_fahrplan_pos();
- size_t pos = oldpos;
+ uint8_t oldpos = badge_load_fahrplan_pos();
+ uint8_t pos = oldpos;
badge_browse_textfiles(FAHRPLAN_MENUFILE, &pos);
static uint8_t jumpnrun_load_progress(void ) { return read_byte_from_file(PROGRESS_FNAME ); }
static void jumpnrun_save_progress(uint8_t progress) { save_byte_to_file (PROGRESS_FNAME, progress); }
-static uint8_t jumpnrun_pick_level_from_fd(char *buf, size_t *first_visible, size_t *selected, uint8_t progress, FIL *fd) {
+static uint8_t jumpnrun_pick_level_from_fd(char *buf, uint8_t *first_visible, uint8_t *selected, uint8_t progress, FIL *fd) {
unsigned levelcount = 0;
{
return JUMPNRUN_ERROR;
}
- size_t menulen = levelcount + (levelcount <= progress) + 1;
+ uint8_t menulen = levelcount + (levelcount <= progress) + 1;
char menu_buf [menulen][MENU_BUFLEN];
char const *menu_index[menulen];
fnames[i] = p;
}
- size_t creditspos = -1;
- size_t exitpos = i;
+ uint8_t creditspos = -1;
+ uint8_t exitpos = i;
if(levelcount <= progress) {
creditspos = i;
strcpy(menu_buf[exitpos], "Zurück");
menu_index[exitpos] = menu_buf[exitpos];
- size_t choice = badge_menu(menu_index, exitpos + 1, first_visible, *selected);
+ uint8_t choice = badge_menu(menu_index, exitpos + 1, first_visible, *selected);
if(choice == exitpos) {
return CHOICE_EXIT;
return CHOICE_LEVEL;
}
-static uint8_t jumpnrun_pick_level(char *buf, size_t *first_visible, size_t *selected, uint8_t progress) {
+static uint8_t jumpnrun_pick_level(char *buf, uint8_t *first_visible, uint8_t *selected, uint8_t progress) {
FIL fd;
if(FR_OK != f_chdir(JUMPNRUN_PATH) ||
void jumpnrun_play(void) {
char buf[LEVELFILE_MAX + 1];
- size_t first_visible = 0;
- size_t selected = jumpnrun_load_selected();
+ uint8_t selected = jumpnrun_load_selected();
uint8_t progress = jumpnrun_load_progress();
+ uint8_t first_visible = selected;
uint8_t choice;
- size_t oldselected = selected;
+ uint8_t oldselected = selected;
do {
if(oldselected != selected) {
uint8_t main_menu_show(uint8_t selected) {
// first_visible = 0, weil das Menü so kurz ist. Sollte es
// größer werden: Parameter aus main_menu empfangen und merken.
- size_t first_visible = 0;
+ uint8_t first_visible = 0;
char const *const menu[] = {
"Vanity-Screen",
"Super Hackio",
badge_scroll_text(lines, i);
}
-static size_t badge_count_lines_in_file(FIL *fd) {
- size_t count = 0;
+static uint8_t badge_count_lines_in_file(FIL *fd) {
+ uint8_t count = 0;
if(FR_OK == f_lseek(fd, 0)) {
char buf[BUFLEN];
return count;
}
-static uint8_t badge_browse_pick_filename_from_fd(char *buf, size_t *first_visible, size_t *selected, FIL *fd) {
+static uint8_t badge_browse_pick_filename_from_fd(char *buf, uint8_t *first_visible, uint8_t *selected, FIL *fd) {
unsigned linecount = badge_count_lines_in_file(fd);
if(FR_OK != f_lseek(fd, 0)) {
strcpy(menu_buf[i], "Zurück");
menu_index[i] = menu_buf[i];
- size_t choice = badge_menu(menu_index, i + 1, first_visible, *selected);
+ uint8_t choice = badge_menu(menu_index, i + 1, first_visible, *selected);
if(choice == linecount) {
return 1; // exit
return 0;
}
-static uint8_t badge_pick_filename(char *buf, char const *menufile, size_t *first_visible, size_t *selected) {
+static uint8_t badge_pick_filename(char *buf, char const *menufile, uint8_t *first_visible, uint8_t *selected) {
FIL fd;
uint8_t err = 1;
}
}
-void badge_browse_textfiles(char const *menufile, size_t *selected) {
+void badge_browse_textfiles(char const *menufile, uint8_t *selected) {
char buf[FNAME_MAX + 1];
- size_t first_visible = 0;
+ uint8_t first_visible = *selected;
while(0 == badge_pick_filename(buf, menufile, &first_visible, selected)) {
badge_browse_textfile(buf);
#ifndef INCLUDED_BADGE_UI_BROWSER_H
#define INCLUDED_BADGE_UI_BROWSER_H
-#include <stddef.h>
+#include <stdint.h>
void badge_browse_textfile(char const *fname);
-void badge_browse_textfiles(char const *menufile, size_t *selected);
+void badge_browse_textfiles(char const *menufile, uint8_t *selected);
#endif
};
static void badge_menu_show(char const *const *menu,
- size_t n,
- size_t *first_visible,
- size_t selected,
+ uint8_t n,
+ uint8_t *first_visible,
+ uint8_t selected,
char selector)
{
badge_framebuffer fb = { { { 0 } } };
bool arrow_up = true;
bool arrow_down = true;
- size_t first_used_row = 0;
- size_t used_rows = MENU_ENTRIES_VISIBLE;
+ uint8_t first_used_row = 0;
+ uint8_t used_rows = MENU_ENTRIES_VISIBLE;
if(selected >= n) {
selected = n - 1;
*first_visible = 0;
used_rows = n;
first_used_row = (MENU_ENTRIES_VISIBLE - used_rows) / 2;
+ } else if(*first_visible + MENU_ENTRIES_VISIBLE > n) {
+ *first_visible = n - MENU_ENTRIES_VISIBLE;
} else if(selected + 1 == n) {
*first_visible = n - MENU_ENTRIES_VISIBLE;
} else if(selected <= *first_visible) {
arrow_down = false;
}
- for(size_t i = 0; i < used_rows; ++i) {
+ for(uint8_t i = 0; i < used_rows; ++i) {
badge_framebuffer_render_text(&fb,
(int8_t) (MENU_MARGIN_LEFT + BADGE_FONT_WIDTH),
(int8_t) (MENU_MARGIN_TOP + (first_used_row + i) * MENU_ENTRIES_HEIGHT),
badge_framebuffer_flush(&fb);
}
-size_t badge_menu(char const *const *menu,
- size_t n,
- size_t *first_visible,
- size_t selected)
+uint8_t badge_menu(char const *const *menu,
+ uint8_t n,
+ uint8_t *first_visible,
+ uint8_t selected)
{
unsigned scroll_ticks = 0;
int scroll_direction = 0;
}
}
-void badge_scroll_text(char const *const *lines, size_t n) {
- size_t first_visible = 0;
+void badge_scroll_text(char const *const *lines, uint8_t n) {
+ uint8_t first_visible = 0;
int scroll_direction = 0;
unsigned scroll_ticks = 0;
#include <stddef.h>
#include <stdint.h>
-size_t badge_menu(char const *const * menu,
- size_t n,
- size_t *first_visible,
- size_t preselected);
+uint8_t badge_menu(char const *const * menu,
+ uint8_t n,
+ uint8_t *first_visible,
+ uint8_t preselected);
-void badge_scroll_text(char const *const *lines, size_t n);
+void badge_scroll_text(char const *const *lines, uint8_t n);
#endif