2011-07-09 18:19:05 +00:00
|
|
|
#include <sysinit.h>
|
|
|
|
|
|
|
|
#include "basic/basic.h"
|
|
|
|
|
2011-07-12 23:13:19 +00:00
|
|
|
#include "lcd/print.h"
|
2011-07-09 18:19:05 +00:00
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
void handleMenu(const struct MENU *the_menu) {
|
|
|
|
uint8_t back = 0;
|
|
|
|
int8_t menuselection = 0;
|
|
|
|
uint8_t numentries = 0;
|
|
|
|
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
|
|
|
|
|
|
|
for (numentries = 0; the_menu->entries[numentries] != NULL; numentries++);
|
|
|
|
|
2011-08-01 22:03:37 +00:00
|
|
|
visible_lines = lcdGetVisibleLines()-1; // subtract title line
|
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++) {
|
|
|
|
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);
|
|
|
|
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-07-24 13:54:18 +00:00
|
|
|
switch (getInputWait()) {
|
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:
|
|
|
|
if (the_menu->entries[menuselection]->callback!=NULL)
|
|
|
|
the_menu->entries[menuselection]->callback();
|
|
|
|
break;
|
|
|
|
case BTN_ENTER:
|
2011-07-12 23:13:19 +00:00
|
|
|
lcdClear();
|
|
|
|
lcdPrintln("Called...");
|
|
|
|
lcdRefresh();
|
2011-07-26 22:58:48 +00:00
|
|
|
getInputWaitRelease();
|
2011-07-09 18:19:05 +00:00
|
|
|
if (the_menu->entries[menuselection]->callback!=NULL)
|
|
|
|
the_menu->entries[menuselection]->callback();
|
2011-08-01 22:03:37 +00:00
|
|
|
lcdRefresh();
|
2011-07-09 18:19:05 +00:00
|
|
|
getInputWait();
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* no button pressed */
|
|
|
|
break;
|
|
|
|
}
|
2011-07-26 22:58:48 +00:00
|
|
|
getInputWaitRelease();
|
2011-07-09 18:19:05 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|