diff --git a/OpeNITHM.ino b/OpeNITHM.ino index a98f726..baade89 100644 --- a/OpeNITHM.ino +++ b/OpeNITHM.ino @@ -1,17 +1,16 @@ #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega32u4__) -#include "USBOutput.h" +#include "USBOutput.h" #define USB #endif #ifdef USB #include "USBOutput.h" -#else +#else #include "SerialOutput.h" -#endif -#include "AirSensor.h" -#include "Touchboard.h" +#endif +#include "AirSensor.h" +#include "Touchboard.h" #include -#include CRGB leds[16]; @@ -158,4 +157,4 @@ void loop() { parseCommand(); } } - + diff --git a/USBOutput.cpp b/USBOutput.cpp index 3e45730..2b26021 100644 --- a/USBOutput.cpp +++ b/USBOutput.cpp @@ -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) -{ -} diff --git a/USBOutput.h b/USBOutput.h index 0bf76ed..1388954 100644 --- a/USBOutput.h +++ b/USBOutput.h @@ -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 + +// 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