Skip to content

Commit

Permalink
Implemented USB Keyboard output (untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yona-W committed Jan 25, 2019
1 parent 2355187 commit 1f01c4c
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 39 deletions.
13 changes: 6 additions & 7 deletions OpeNITHM.ino
Original file line number Diff line number Diff line change
@@ -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 <FastLED.h>
#include <Keyboard.h>

CRGB leds[16];

Expand Down Expand Up @@ -158,4 +157,4 @@ void loop() {
parseCommand();
}
}


63 changes: 51 additions & 12 deletions USBOutput.cpp
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)
{
}
47 changes: 27 additions & 20 deletions USBOutput.h
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

0 comments on commit 1f01c4c

Please sign in to comment.