Add getInputWaitRepeat, to support key repeat

This commit is contained in:
Stefan `Sec` Zehl 2011-08-02 23:34:13 +02:00
parent f57e0a9e90
commit 691fa7d09b
2 changed files with 34 additions and 0 deletions

View File

@ -152,6 +152,7 @@ char isNight(void);
uint8_t getInput(void);
uint8_t getInputRaw(void);
uint8_t getInputWait(void);
uint8_t getInputWaitRepeat(void);
uint8_t getInputWaitTimeout(int timeout);
void getInputWaitRelease(void);

View File

@ -62,6 +62,39 @@ uint8_t getInputWaitTimeout(int timeout) {
return key;
};
uint8_t getInputWaitRepeat(void) {
static uint8_t oldkey=BTN_NONE;
static int repeatctr=0;
uint8_t key=getInputRaw();
if (key != BTN_NONE && key==oldkey){
int dtime;
if(!repeatctr)
dtime=600;
else if(repeatctr<5)
dtime=250;
else if(repeatctr<30)
dtime=150;
else
dtime=80;
repeatctr++;
int end=_timectr+(dtime/SYSTICKSPEED);
while(_timectr<end && key==getInputRaw())
work_queue();
key=getInputRaw();
if (key==oldkey)
return key;
};
repeatctr=0;
while ((key=getInputRaw())==BTN_NONE){
work_queue();
};
delayms_queue(10); /* Delay a little more to debounce */
oldkey=key;
return key;
};
void getInputWaitRelease(void) {
while (getInputRaw()!=BTN_NONE)
work_queue();