2011-06-13 21:53:02 +00:00
|
|
|
#include <sysinit.h>
|
|
|
|
#include "basic/basic.h"
|
|
|
|
|
2011-07-21 18:37:04 +00:00
|
|
|
uint8_t getInputRaw(void) {
|
2011-06-13 21:53:02 +00:00
|
|
|
uint8_t result = BTN_NONE;
|
|
|
|
|
|
|
|
if (gpioGetValue(RB_BTN3)==0) {
|
2011-07-21 18:37:04 +00:00
|
|
|
result |= BTN_UP;
|
2011-06-13 21:53:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gpioGetValue(RB_BTN2)==0) {
|
2011-07-21 18:37:04 +00:00
|
|
|
result |= BTN_DOWN;
|
2011-06-13 21:53:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gpioGetValue(RB_BTN4)==0) {
|
2011-07-21 18:37:04 +00:00
|
|
|
result |= BTN_ENTER;
|
2011-06-13 21:53:02 +00:00
|
|
|
}
|
|
|
|
|
2011-06-26 09:45:05 +00:00
|
|
|
if (gpioGetValue(RB_BTN0)==0) {
|
2011-07-21 18:37:04 +00:00
|
|
|
result |= BTN_LEFT;
|
2011-06-26 09:45:05 +00:00
|
|
|
}
|
2011-06-13 21:53:02 +00:00
|
|
|
|
|
|
|
if (gpioGetValue(RB_BTN1)==0) {
|
2011-07-21 18:37:04 +00:00
|
|
|
result |= BTN_RIGHT;
|
2011-06-13 21:53:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-07-21 18:37:04 +00:00
|
|
|
uint8_t getInput(void) {
|
|
|
|
uint8_t key = BTN_NONE;
|
2011-07-04 20:49:35 +00:00
|
|
|
|
2011-07-21 18:37:04 +00:00
|
|
|
key=getInputRaw();
|
2011-07-24 14:03:19 +00:00
|
|
|
/* XXX: we should probably debounce the joystick.
|
|
|
|
Any ideas how to do this properly?
|
|
|
|
For now wait for any release.
|
|
|
|
*/
|
2011-07-21 18:37:04 +00:00
|
|
|
if(key != BTN_NONE)
|
2011-07-24 14:03:19 +00:00
|
|
|
while(key==getInputRaw())
|
|
|
|
work_queue();
|
2011-07-04 20:49:35 +00:00
|
|
|
|
2011-07-21 18:37:04 +00:00
|
|
|
return key;
|
2011-07-04 20:49:35 +00:00
|
|
|
}
|
|
|
|
|
2011-07-09 18:19:05 +00:00
|
|
|
uint8_t getInputWait(void) {
|
|
|
|
uint8_t key;
|
2011-07-25 23:55:33 +00:00
|
|
|
while ((key=getInputRaw())==BTN_NONE)
|
2011-07-24 13:54:18 +00:00
|
|
|
work_queue();
|
2011-07-24 14:03:19 +00:00
|
|
|
delayms_queue(10); /* Delay a little more to debounce */
|
2011-07-09 18:19:05 +00:00
|
|
|
return key;
|
|
|
|
};
|
|
|
|
|
2011-08-02 18:49:55 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2011-08-02 21:34:13 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2011-07-25 23:55:33 +00:00
|
|
|
void getInputWaitRelease(void) {
|
|
|
|
while (getInputRaw()!=BTN_NONE)
|
|
|
|
work_queue();
|
|
|
|
delayms_queue(10); /* Delay a little more to debounce */
|
|
|
|
};
|
|
|
|
|
2011-07-09 18:19:05 +00:00
|
|
|
|