소스 검색

Merge pull request #37 from plugz/keyboard_rawkeys

Keyboard rawkeys
main
Paul Stoffregen 4 년 전
부모
커밋
df0ef72d8d
No account linked to committer's email address
3개의 변경된 파일43개의 추가작업 그리고 0개의 파일을 삭제
  1. +4
    -0
      USBHost_t36.h
  2. +14
    -0
      examples/Test/Test/Test.ino
  3. +25
    -0
      keyboard.cpp

+ 4
- 0
USBHost_t36.h 파일 보기

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

+ 14
- 0
examples/Test/Test/Test.ino 파일 보기

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

+ 25
- 0
keyboard.cpp 파일 보기

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

Loading…
취소
저장