mirror of
https://github.com/skogaby/OpeNITHM.git
synced 2026-09-22 22:58:16 +03:00
Correction to USBOutput.h/.cpp
This commit is contained in:
committed by
Jonathan Montineri
parent
2d83975395
commit
0d1744196a
@@ -24,62 +24,121 @@ void USBOutput::sendKeyEvent(int key, bool pressed, bool doublePressed)
|
||||
void USBOutput::sendSensorEvent(float position)
|
||||
{
|
||||
// Send hand up / hand down key
|
||||
if (position > lastPosition) {
|
||||
if (position > lastPosition)
|
||||
{
|
||||
writeKey(KEY_PAGE_UP);
|
||||
if (wasAirHeld)
|
||||
{
|
||||
// Send Air Action
|
||||
writeKey(KEY_END);
|
||||
}
|
||||
}
|
||||
if (position < lastPosition) {
|
||||
if (position < lastPosition)
|
||||
{
|
||||
writeKey(KEY_PAGE_DOWN);
|
||||
if (wasAirHeld)
|
||||
{
|
||||
// Send Air Action
|
||||
writeKey(KEY_END);
|
||||
}
|
||||
}
|
||||
|
||||
// Send hand seen / unseen key
|
||||
if (position > 0.05f) {
|
||||
if (position > 0.05f)
|
||||
{
|
||||
pressKey(KEY_HOME);
|
||||
wasAirHeld = true;
|
||||
}
|
||||
else {
|
||||
releaseKey(KEY_HOME);
|
||||
wasAirHeld = false;
|
||||
}
|
||||
|
||||
// Send hand moved key
|
||||
writeKey(KEY_END);
|
||||
|
||||
// Save last position for next loop
|
||||
lastPosition = position;
|
||||
}
|
||||
|
||||
USBOutput::USBOutput() {
|
||||
USBOutput::USBOutput()
|
||||
{
|
||||
#ifndef TEENSY
|
||||
NKROKeyboard.begin();
|
||||
#endif
|
||||
lastPosition = 0;
|
||||
}
|
||||
|
||||
void USBOutput::writeKey(char key)
|
||||
void USBOutput::writeKey(uint16_t key)
|
||||
{
|
||||
#ifndef TEENSY
|
||||
NKROKeyboard.write(key);
|
||||
#else
|
||||
Nkro.set_key_ascii((uint8_t)key);
|
||||
Nkro.send_nkro_now();
|
||||
Nkro.reset_key_ascii((uint8_t)key);
|
||||
Nkro.send_nkro_now();
|
||||
switch (key)
|
||||
{
|
||||
case KEY_PAGE_UP:
|
||||
case KEY_PAGE_DOWN:
|
||||
case KEY_HOME:
|
||||
case KEY_END:
|
||||
// Don't use ASCII method
|
||||
Nkro.set_key(key);
|
||||
Nkro.send_nkro_now();
|
||||
Nkro.reset_key(key);
|
||||
Nkro.send_nkro_now();
|
||||
break;
|
||||
default:
|
||||
// Use NKRO for ASCII
|
||||
Nkro.set_key_ascii(key);
|
||||
Nkro.send_nkro_now();
|
||||
Nkro.reset_key_ascii(key);
|
||||
Nkro.send_nkro_now();
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void USBOutput::pressKey(char key)
|
||||
void USBOutput::pressKey(uint16_t key)
|
||||
{
|
||||
#ifndef TEENSY
|
||||
pressKey(key);
|
||||
#else
|
||||
Nkro.set_key_ascii((uint8_t)key);
|
||||
Nkro.send_nkro_now();
|
||||
switch (key)
|
||||
{
|
||||
case KEY_PAGE_UP:
|
||||
case KEY_PAGE_DOWN:
|
||||
case KEY_HOME:
|
||||
case KEY_END:
|
||||
// Don't use ASCII method
|
||||
Nkro.set_key(key);
|
||||
Nkro.send_nkro_now();
|
||||
break;
|
||||
default:
|
||||
// Use NKRO for ASCII
|
||||
Nkro.set_key_ascii(key);
|
||||
Nkro.send_nkro_now();
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void USBOutput::releaseKey(char key)
|
||||
void USBOutput::releaseKey(uint16_t key)
|
||||
{
|
||||
#ifndef TEENSY
|
||||
NKROKeyboard.release(key);
|
||||
#else
|
||||
Nkro.reset_key_ascii((uint8_t)key);
|
||||
Nkro.send_nkro_now();
|
||||
switch (key)
|
||||
{
|
||||
case KEY_PAGE_UP:
|
||||
case KEY_PAGE_DOWN:
|
||||
case KEY_HOME:
|
||||
case KEY_END:
|
||||
// Don't use ASCII method
|
||||
Nkro.reset_key(key);
|
||||
Nkro.send_nkro_now();
|
||||
break;
|
||||
default:
|
||||
// Use NKRO for ASCII
|
||||
Nkro.reset_key_ascii(key);
|
||||
Nkro.send_nkro_now();
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -20,9 +20,10 @@ class USBOutput : public Output
|
||||
{
|
||||
private:
|
||||
float lastPosition;
|
||||
void writeKey(char key);
|
||||
void pressKey(char key);
|
||||
void releaseKey(char key);
|
||||
bool wasAirHeld;
|
||||
void writeKey(uint16_t key);
|
||||
void pressKey(uint16_t key);
|
||||
void releaseKey(uint16_t key);
|
||||
public:
|
||||
void sendKeyEvent(int key, bool pressed, bool doublePressed) override;
|
||||
void sendSensorEvent(float position) override;
|
||||
|
||||
Reference in New Issue
Block a user