2011-07-09 18:19:05 +00:00
|
|
|
#include <sysinit.h>
|
|
|
|
|
|
|
|
#include "basic/basic.h"
|
2011-08-04 23:58:12 +00:00
|
|
|
#include "basic/config.h"
|
2011-07-09 18:19:05 +00:00
|
|
|
|
2011-07-12 23:13:19 +00:00
|
|
|
#include "lcd/print.h"
|
2011-07-09 18:19:05 +00:00
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2011-08-02 18:49:55 +00:00
|
|
|
uint8_t menuflags=0;
|
|
|
|
|
2011-07-09 18:19:05 +00:00
|
|
|
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;
|
2011-07-09 18:19:05 +00:00
|
|
|
uint8_t visible_lines = 0;
|
|
|
|
uint8_t current_offset = 0;
|
|
|
|
|
|
|
|
if (the_menu == NULL) return;
|
|
|
|
|
2011-08-01 22:03:37 +00:00
|
|
|
setSystemFont();
|
2011-07-09 18:19:05 +00:00
|
|
|
|
2011-08-02 11:31:57 +00:00
|
|
|
for (numentries = 0; the_menu->entries[numentries].text != NULL ; numentries++);
|
2011-07-09 18:19:05 +00:00
|
|
|
|
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;
|
|
|
|
|
2011-07-09 18:19:05 +00:00
|
|
|
#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);
|
2011-07-09 18:19:05 +00:00
|
|
|
|
|
|
|
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();
|
2011-07-09 18:19:05 +00:00
|
|
|
if (i == menuselection) {
|
2011-08-01 03:10:37 +00:00
|
|
|
lcdPrint("*");
|
2011-07-09 18:19:05 +00:00
|
|
|
}
|
2011-08-01 03:10:37 +00:00
|
|
|
lcdSetCrsrX(14);
|
2011-08-02 11:31:57 +00:00
|
|
|
lcdPrintln(the_menu->entries[i].text);
|
2011-07-09 18:19:05 +00:00
|
|
|
}
|
2011-08-01 03:10:37 +00:00
|
|
|
lcdRefresh();
|
2011-07-09 18:19:05 +00:00
|
|
|
|
2011-08-04 22:24:50 +00:00
|
|
|
switch (getInputWaitTimeout((menuflags&MENU_TIMEOUT)?15000:0)) {
|
2011-07-09 18:19:05 +00:00
|
|
|
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:
|
2011-08-02 11:31:57 +00:00
|
|
|
if (the_menu->entries[menuselection].callback!=NULL)
|
|
|
|
the_menu->entries[menuselection].callback();
|
2011-08-05 08:25:31 +00:00
|
|
|
|
|
|
|
setSystemFont();
|
2011-08-04 14:29:13 +00:00
|
|
|
|
|
|
|
if (menuflags&MENU_JUSTONCE)
|
|
|
|
return;
|
|
|
|
|
2011-07-09 18:19:05 +00:00
|
|
|
break;
|
|
|
|
case BTN_ENTER:
|
2011-07-12 23:13:19 +00:00
|
|
|
lcdClear();
|
2011-08-04 23:58:12 +00:00
|
|
|
// lcdPrintln("Called...");
|
|
|
|
// lcdRefresh();
|
2011-07-26 22:58:48 +00:00
|
|
|
getInputWaitRelease();
|
2011-08-02 11:31:57 +00:00
|
|
|
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();
|
2011-08-04 14:29:13 +00:00
|
|
|
|
|
|
|
if (menuflags&MENU_JUSTONCE)
|
|
|
|
return;
|
|
|
|
|
2011-08-04 23:58:12 +00:00
|
|
|
// getInputWait();
|
2011-07-09 18:19:05 +00:00
|
|
|
|
|
|
|
break;
|
2011-08-02 18:49:55 +00:00
|
|
|
case BTN_NONE: /* timeout */
|
|
|
|
return;
|
2011-07-09 18:19:05 +00:00
|
|
|
default:
|
2011-08-02 18:49:55 +00:00
|
|
|
/* NOTREACHED */
|
2011-07-09 18:19:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-07-26 22:58:48 +00:00
|
|
|
getInputWaitRelease();
|
2011-07-09 18:19:05 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|