| @@ -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]; | |||
| @@ -18,6 +18,8 @@ void setup() | |||
| Serial.println("USB Host Testing"); | |||
| myusb.begin(); | |||
| keyboard1.attachPress(OnPress); | |||
| keyboard1.attachRawPress(OnRawPress); | |||
| keyboard1.attachRawRelease(OnRawRelease); | |||
| keyboard2.attachPress(OnPress); | |||
| midi1.setHandleNoteOff(OnNoteOff); | |||
| midi1.setHandleNoteOn(OnNoteOn); | |||
| @@ -45,6 +47,18 @@ void OnPress(int key) | |||
| //Serial.println(); | |||
| } | |||
| void OnRawPress(uint8_t keycode) | |||
| { | |||
| Serial.print("raw key press: "); | |||
| Serial.println((int)keycode); | |||
| } | |||
| void OnRawRelease(uint8_t keycode) | |||
| { | |||
| Serial.print("raw key release: "); | |||
| Serial.println((int)keycode); | |||
| } | |||
| void OnNoteOn(byte channel, byte note, byte velocity) | |||
| { | |||
| Serial.print("Note On, ch="); | |||
| @@ -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); | |||