forked from Yona-W/OpeNITHM
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented USB Keyboard output (untested)
- Loading branch information
Showing
3 changed files
with
84 additions
and
39 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,13 +1,52 @@ | ||
// | ||
// | ||
// | ||
// | ||
// | ||
// | ||
|
||
#include "USBOutput.h" | ||
|
||
char bottomRow[] = {'a', 'z', 's', 'x', 'd', 'c', 'f', 'v', 'g', 'b', 'h', 'n', 'j', 'm', 'k', ','}; | ||
char topRow[] = {'1', 'q', '2', 'w', '3', 'e', '4', 'r', '5', 't', '6', 'y', '7', 'u', '8', 'i'}; | ||
|
||
void USBOutput::sendKeyEvent(int key, bool pressed, bool doublePressed) | ||
{ | ||
if(pressed){ | ||
if(doublePressed){ | ||
NKROKeyboard.write(topRow[key]); | ||
} | ||
else{ | ||
NKROKeyboard.press(bottomRow[key]); | ||
} | ||
} | ||
else{ | ||
NKROKeyboard.release(bottomRow[key]); | ||
} | ||
} | ||
|
||
void USBOutput::sendSensorEvent(float position) | ||
{ | ||
// Send hand up / hand down key | ||
if(position > lastPosition){ | ||
NKROKeyboard.write(KEY_PAGE_UP); | ||
} | ||
if(position < lastPosition){ | ||
NKROKeyboard.write(KEY_PAGE_DOWN); | ||
} | ||
|
||
// Send hand seen / unseen key | ||
if(position > 0.05f){ | ||
NKROKeyboard.press(KEY_HOME); | ||
} | ||
else{ | ||
NKROKeyboard.release(KEY_HOME); | ||
} | ||
|
||
// Send hand moved key | ||
NKROKeyboard.write(KEY_END); | ||
|
||
} | ||
|
||
USBOutput::USBOutput(){ | ||
NKROKeyboard.begin(); | ||
lastPosition = 0; | ||
} | ||
|
||
#include "USBOutput.h" | ||
|
||
void USBOutput::sendKeyEvent(int key, bool pressed, bool doublePressed) | ||
{ | ||
} | ||
|
||
void USBOutput::sendSensorEvent(float position) | ||
{ | ||
} |
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 |
---|---|---|
@@ -1,21 +1,28 @@ | ||
// USBOutput.h | ||
|
||
#ifndef _USBOUTPUT_h | ||
#define _USBOUTPUT_h | ||
|
||
#if defined(ARDUINO) && ARDUINO >= 100 | ||
#include "arduino.h" | ||
#else | ||
#include "WProgram.h" | ||
#endif | ||
#include "Output.h" | ||
|
||
class USBOutput : public Output | ||
{ | ||
public: | ||
void sendKeyEvent(int key, bool pressed, bool doublePressed) override; | ||
void sendSensorEvent(float position) override; | ||
}; | ||
|
||
#endif | ||
#define USBCON | ||
#include <HID-Project.h> | ||
|
||
// USBOutput.h | ||
|
||
#ifndef _USBOUTPUT_h | ||
#define _USBOUTPUT_h | ||
|
||
#if defined(ARDUINO) && ARDUINO >= 100 | ||
#include "arduino.h" | ||
#else | ||
#include "WProgram.h" | ||
#endif | ||
#include "Output.h" | ||
|
||
|
||
class USBOutput : public Output | ||
{ | ||
private: | ||
float lastPosition; | ||
public: | ||
void sendKeyEvent(int key, bool pressed, bool doublePressed) override; | ||
void sendSensorEvent(float position) override; | ||
USBOutput(); | ||
}; | ||
|
||
#endif | ||
|