Pārlūkot izejas kodu

keyboard: forward raw key press/release

main
plugz pirms 4 gadiem
vecāks
revīzija
c3991c894d
2 mainītis faili ar 29 papildinājumiem un 0 dzēšanām
  1. +4
    -0
      USBHost_t36.h
  2. +25
    -0
      keyboard.cpp

+ 4
- 0
USBHost_t36.h Parādīt failu

@@ -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 Parādīt failu

@@ -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);

Notiek ielāde…
Atcelt
Saglabāt