crashtest-r0ket/firmware/basic/menu.c

114 lines
3.2 KiB
C
Raw Normal View History

#include <sysinit.h>
#include "basic/basic.h"
2011-08-04 23:58:12 +00:00
#include "basic/config.h"
2011-07-12 23:13:19 +00:00
#include "lcd/print.h"
/**************************************************************************/
2011-08-02 18:49:55 +00:00
uint8_t menuflags=0;
void handleMenu(const struct MENU *the_menu) {
uint8_t back = 0;
int8_t menuselection = 0;
2011-08-04 23:58:12 +00:00
uint8_t numentries;
uint8_t visible_lines = 0;
uint8_t current_offset = 0;
if (the_menu == NULL) return;
2011-08-01 22:03:37 +00:00
setSystemFont();
for (numentries = 0; the_menu->entries[numentries].text != NULL ; numentries++);
2011-08-04 23:58:12 +00:00
if(the_menu->entries[numentries-1].text[0]=='|' && !GLOBAL(develmode))
numentries--;
2011-08-01 22:03:37 +00:00
visible_lines = lcdGetVisibleLines()-1; // subtract title line
2011-08-04 19:41:51 +00:00
if(menuflags&MENU_BIG)
visible_lines/=2;
#ifdef SAFETY
if (visible_lines < 2) return;
#endif
while (!back) {
// Display current menu page
2011-08-01 03:10:37 +00:00
lcdClear();
lcdPrintln(the_menu->title);
for (uint8_t i = current_offset; i < (visible_lines + current_offset) && i < numentries; i++) {
2011-08-04 19:41:51 +00:00
if(menuflags&MENU_BIG)
lcdNl();
if (i == menuselection) {
2011-08-01 03:10:37 +00:00
lcdPrint("*");
}
2011-08-01 03:10:37 +00:00
lcdSetCrsrX(14);
lcdPrintln(the_menu->entries[i].text);
}
2011-08-01 03:10:37 +00:00
lcdRefresh();
switch (getInputWaitTimeout((menuflags&MENU_TIMEOUT)?15000:0)) {
case BTN_UP:
menuselection--;
if (menuselection < current_offset) {
if (menuselection < 0) {
menuselection = numentries-1;
current_offset = ((numentries-1)/visible_lines) * visible_lines;
} else {
current_offset -= visible_lines;
}
}
break;
case BTN_DOWN:
menuselection++;
if (menuselection > (current_offset + visible_lines-1) || menuselection >= numentries) {
if (menuselection >= numentries) {
menuselection = 0;
current_offset = 0;
} else {
current_offset += visible_lines;
}
}
break;
case BTN_LEFT:
return;
case BTN_RIGHT:
if (the_menu->entries[menuselection].callback!=NULL)
the_menu->entries[menuselection].callback();
2011-08-05 08:25:31 +00:00
setSystemFont();
if (menuflags&MENU_JUSTONCE)
return;
break;
case BTN_ENTER:
2011-07-12 23:13:19 +00:00
lcdClear();
2011-08-04 23:58:12 +00:00
// lcdPrintln("Called...");
// lcdRefresh();
getInputWaitRelease();
if (the_menu->entries[menuselection].callback!=NULL)
the_menu->entries[menuselection].callback();
2011-08-01 22:03:37 +00:00
lcdRefresh();
2011-08-05 08:25:31 +00:00
setSystemFont();
if (menuflags&MENU_JUSTONCE)
return;
2011-08-04 23:58:12 +00:00
// getInputWait();
break;
2011-08-02 18:49:55 +00:00
case BTN_NONE: /* timeout */
return;
default:
2011-08-02 18:49:55 +00:00
/* NOTREACHED */
break;
}
getInputWaitRelease();
}
return;
}