mirror of
https://github.com/JorjBauer/aiie.git
synced 2024-11-25 19:31:36 +00:00
bugfix for usb keyboard auto-repeat
This commit is contained in:
parent
f57478f85d
commit
90270e126f
@ -33,18 +33,23 @@ uint8_t kbEventCount = 0;
|
||||
uint8_t kbEventHead = 0;
|
||||
uint8_t kbEventPtr = 0;
|
||||
|
||||
bool addEvent(uint8_t kc, bool pressed)
|
||||
bool TeensyKeyboard::addEvent(uint8_t kc, bool pressed)
|
||||
{
|
||||
if (kbEventCount >= MAXKBEVENTS)
|
||||
return false;
|
||||
|
||||
if (pressed && kbEventCount+numPressed >= MAXKBEVENTS) {
|
||||
// save space in the event queue for any keyup events that may come
|
||||
return false;
|
||||
}
|
||||
|
||||
keyboardEvents[kbEventPtr].keycode = kc;
|
||||
keyboardEvents[kbEventPtr++].pressedIfTrue = pressed;
|
||||
if (kbEventPtr >= MAXKBEVENTS) kbEventPtr = 0;
|
||||
kbEventCount++;
|
||||
}
|
||||
|
||||
bool popEvent(uint8_t *kc, bool *pressed)
|
||||
bool TeensyKeyboard::popEvent(uint8_t *kc, bool *pressed)
|
||||
{
|
||||
if (kbEventCount) {
|
||||
*kc = keyboardEvents[kbEventHead].keycode;
|
||||
@ -258,12 +263,8 @@ void TeensyKeyboard::maintainKeyboard()
|
||||
bool pressed;
|
||||
if (popEvent(&kc, &pressed)) {
|
||||
if (pressed) {
|
||||
sprintf(debugBuf, "%d press ", kc);
|
||||
g_display->debugMsg(debugBuf);
|
||||
vmkeyboard->keyDepressed(kc);
|
||||
} else {
|
||||
sprintf(debugBuf, "%d relsd ", kc);
|
||||
g_display->debugMsg(debugBuf);
|
||||
vmkeyboard->keyReleased(kc);
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,10 @@ class TeensyKeyboard : public PhysicalKeyboard {
|
||||
void pressedKey(uint8_t key);
|
||||
void releasedKey(uint8_t key);
|
||||
|
||||
private:
|
||||
bool addEvent(uint8_t kc, bool pressed);
|
||||
bool popEvent(uint8_t *kc, bool *pressed);
|
||||
|
||||
private:
|
||||
bool leftShiftPressed;
|
||||
bool rightShiftPressed;
|
||||
|
@ -124,20 +124,34 @@ static uint8_t usb_scanmap[256] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 240-249
|
||||
0, 0, 0, 0, 0, 0 // 250-255
|
||||
};
|
||||
|
||||
|
||||
uint8_t keysPressed[256]; // FIXME: if we need to save RAM, make this bitflags
|
||||
|
||||
void onKeypress(uint8_t keycode)
|
||||
{
|
||||
if (keysPressed[keycode])
|
||||
return; // defeat auto-repeat
|
||||
if (!usb_scanmap[keycode])
|
||||
return; // skip undefined keys
|
||||
|
||||
if (keycode == 67 || keycode == 70) {
|
||||
// F10 or PrtSc/SysRq are interrupt buttons. Probably needs to be
|
||||
// configurable somehow...
|
||||
g_biosInterrupt = true;
|
||||
} else {
|
||||
keysPressed[keycode] = 1;
|
||||
((TeensyKeyboard *)g_keyboard)->pressedKey(usb_scanmap[keycode]);
|
||||
}
|
||||
}
|
||||
|
||||
void onKeyrelease(uint8_t keycode)
|
||||
{
|
||||
if (!keysPressed[keycode])
|
||||
return; // defeat auto-repeat
|
||||
if (!usb_scanmap[keycode])
|
||||
return; // skip undefined keys
|
||||
|
||||
keysPressed[keycode] = 0;
|
||||
((TeensyKeyboard *)g_keyboard)->releasedKey(usb_scanmap[keycode]);
|
||||
}
|
||||
|
||||
@ -160,6 +174,7 @@ void setup()
|
||||
// enableFaultHandler();
|
||||
// SCB_SHCSR |= SCB_SHCSR_BUSFAULTENA | SCB_SHCSR_USGFAULTENA | SCB_SHCSR_MEMFAULTENA;
|
||||
|
||||
memset(keysPressed, 0, sizeof(keysPressed));
|
||||
|
||||
// set the Time library to use Teensy 3.0's RTC to keep time
|
||||
setSyncProvider(getTeensy3Time);
|
||||
|
Loading…
Reference in New Issue
Block a user