Support menu timeout

This commit is contained in:
Stefan `Sec` Zehl 2011-08-02 20:49:55 +02:00
parent f7fcaf0ab8
commit a267e2caf6
4 changed files with 32 additions and 3 deletions

View File

@ -13,9 +13,19 @@
void init_nick();
void fancyNickname();
#include "lcd/allfonts.h"
void forLoadables(int i){
if(i){
lcdSetPixel(0,0);
font=&Font_Invaders;
};
};
void main_final(void) {
//checkFirstBoot();
init_final();
forLoadables(0);
menuflags|=MENU_TIMEOUT;
while(1){
#ifndef FINAL

View File

@ -152,6 +152,7 @@ char isNight(void);
uint8_t getInput(void);
uint8_t getInputRaw(void);
uint8_t getInputWait(void);
uint8_t getInputWaitTimeout(int timeout);
void getInputWaitRelease(void);
// stringin.c
@ -177,6 +178,9 @@ struct MENU {
struct MENU_DEF entries[];
};
#define MENU_TIMEOUT (1<<0)
extern uint8_t menuflags;
void handleMenu(const struct MENU *the_menu);

View File

@ -50,6 +50,18 @@ uint8_t getInputWait(void) {
return key;
};
uint8_t getInputWaitTimeout(int timeout) {
uint8_t key;
int end=_timectr+timeout*(1000/SYSTICKSPEED);
while ((key=getInputRaw())==BTN_NONE){
if(_timectr>end)
break;
work_queue();
};
delayms_queue(10); /* Delay a little more to debounce */
return key;
};
void getInputWaitRelease(void) {
while (getInputRaw()!=BTN_NONE)
work_queue();

View File

@ -6,6 +6,8 @@
/**************************************************************************/
uint8_t menuflags=0;
void handleMenu(const struct MENU *the_menu) {
uint8_t back = 0;
int8_t menuselection = 0;
@ -38,7 +40,7 @@ void handleMenu(const struct MENU *the_menu) {
}
lcdRefresh();
switch (getInputWait()) {
switch (getInputWaitTimeout((menuflags&MENU_TIMEOUT)?15:0)) {
case BTN_UP:
menuselection--;
if (menuselection < current_offset) {
@ -78,12 +80,13 @@ void handleMenu(const struct MENU *the_menu) {
getInputWait();
break;
case BTN_NONE: /* timeout */
return;
default:
/* no button pressed */
/* NOTREACHED */
break;
}
getInputWaitRelease();
}
return;
}