-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
294 additions
and
60 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "Wire.h" | ||
#include "../Serial.h" | ||
#include "TDeckKeyboard.h" | ||
|
||
TDeckKeyboard::TDeckKeyboard(KeyEventType keyEvent, KeyPressedEventType keyPressedEvent) : m_keyEvent(keyEvent), m_keyPressedEvent(keyPressedEvent) | ||
{ | ||
} | ||
|
||
bool TDeckKeyboard::start() { | ||
Wire.begin(GPIO_NUM_18, GPIO_NUM_8); | ||
Wire.requestFrom(0x55, 1); | ||
if (Wire.read() == -1) { | ||
Serial.println("LILYGO Keyboad not online ."); | ||
return false; | ||
} | ||
// kick off a task to read the keyboard | ||
xTaskCreate(readKeyboardTask, "readKeyboardTask", 4096, this, 5, NULL); | ||
return true; | ||
} | ||
|
||
void TDeckKeyboard::readKeyboardTask(void *pvParameters) { | ||
TDeckKeyboard *self = (TDeckKeyboard *)pvParameters; | ||
self->readKeyboard(); | ||
} | ||
|
||
void TDeckKeyboard::readKeyboard() { | ||
SpecKeys lastKey = SpecKeys::SPECKEY_NONE; | ||
unsigned long lastKeyPress = 0; | ||
while(true) { | ||
char keyValue = 0; | ||
Wire.requestFrom(0x55, 1); | ||
while (Wire.available() > 0) { | ||
keyValue = Wire.read(); | ||
if (keyValue != (char)0x00) { | ||
// is it a valid spec key? | ||
// convert to uppercase | ||
if (letterToSpecKey.find(keyValue) != letterToSpecKey.end()) { | ||
SpecKeys key = letterToSpecKey.at(keyValue); | ||
m_keyPressedEvent(key); | ||
m_keyEvent(key, true); | ||
lastKey = key; | ||
lastKeyPress = millis(); | ||
} | ||
} | ||
// release any pressed keys | ||
if (lastKey != SpecKeys::SPECKEY_NONE && millis() - lastKeyPress > 100) { | ||
m_keyEvent(lastKey, false); | ||
lastKey = SpecKeys::SPECKEY_NONE; | ||
} | ||
} | ||
vTaskDelay(10); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
#include <functional> | ||
#include "../Emulator/keyboard_defs.h" | ||
|
||
class TDeckKeyboard | ||
{ | ||
private: | ||
// this is used for key down and key up events | ||
using KeyEventType = std::function<void(SpecKeys keyCode, bool isPressed)>; | ||
KeyEventType m_keyEvent; | ||
// this is used for key pressed evens and supports repeating keys | ||
using KeyPressedEventType = std::function<void(SpecKeys keyCode)>; | ||
KeyPressedEventType m_keyPressedEvent; | ||
public: | ||
TDeckKeyboard(KeyEventType keyEvent, KeyPressedEventType keyPressedEvent); | ||
bool start(); | ||
static void readKeyboardTask(void *pvParameters); | ||
void readKeyboard(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.