Bläddra i källkod

keyboard: forward raw key press/release

main
plugz 4 år sedan
förälder
incheckning
c3991c894d
2 ändrade filer med 29 tillägg och 0 borttagningar
  1. +4
    -0
      USBHost_t36.h
  2. +25
    -0
      keyboard.cpp

+ 4
- 0
USBHost_t36.h Visa fil

@@ -739,6 +739,8 @@ public:
uint8_t getOemKey() { return keyOEM; }
void attachPress(void (*f)(int unicode)) { keyPressedFunction = f; }
void attachRelease(void (*f)(int unicode)) { keyReleasedFunction = f; }
void attachRawPress(void (*f)(uint8_t keycode)) { rawKeyPressedFunction = f; }
void attachRawRelease(void (*f)(uint8_t keycode)) { rawKeyReleasedFunction = f; }
void LEDS(uint8_t leds);
uint8_t LEDS() {return leds_.byte;}
void updateLEDS(void);
@@ -785,6 +787,8 @@ private:
void key_release(uint32_t mod, uint32_t key);
void (*keyPressedFunction)(int unicode);
void (*keyReleasedFunction)(int unicode);
void (*rawKeyPressedFunction)(uint8_t keycode) = nullptr;
void (*rawKeyReleasedFunction)(uint8_t keycode) = nullptr;
Pipe_t *datapipe;
setup_t setup;
uint8_t report[8];

+ 25
- 0
keyboard.cpp Visa fil

@@ -248,12 +248,37 @@ void KeyboardController::new_data(const Transfer_t *transfer)
uint32_t key = prev_report[i];
if (key >= 4 && !contains(key, report)) {
key_release(prev_report[0], key);
if (rawKeyReleasedFunction) {
rawKeyReleasedFunction(key);
}
}
}
if (rawKeyReleasedFunction) {
// each modifier key is represented by a bit in the first byte
for (int i = 0; i < 8; ++i)
{
uint8_t keybit = 1 << i;
if ((prev_report[0] & keybit) && !(report[0] & keybit)) {
rawKeyReleasedFunction(103 + i);
}
}
}
for (int i=2; i < 8; i++) {
uint32_t key = report[i];
if (key >= 4 && !contains(key, prev_report)) {
key_press(report[0], key);
if (rawKeyPressedFunction) {
rawKeyPressedFunction(key);
}
}
}
if (rawKeyPressedFunction) {
for (int i = 0; i < 8; ++i)
{
uint8_t keybit = 1 << i;
if (!(prev_report[0] & keybit) && (report[0] & keybit)) {
rawKeyPressedFunction(103 + i);
}
}
}
memcpy(prev_report, report, 8);

Laddar…
Avbryt
Spara