Added the ability to report back individual IR sensors as keyboard keys

Uncomment IR_SENSOR_KEY in Config.h to use
This commit is contained in:
veroxzik
2019-12-23 13:57:11 -05:00
committed by Jonathan Montineri
parent dd95237f2e
commit bed1de1e0b
7 changed files with 61 additions and 2 deletions
+10
View File
@@ -207,6 +207,16 @@ float AirSensor::getHandPosition()
return highestTriggered == -1 ? 0 : ((float)highestTriggered / 6.0f);
}
uint8_t AirSensor::getSensorReadings()
{
uint8_t reading = 0;
for (int i = 0; i < 6; i++)
{
reading |= ((int)getSensorState(i) << i);
}
return reading;
}
void AirSensor::setDeadzone(int deadzone)
{
this->deadzone = deadzone;
+1
View File
@@ -38,6 +38,7 @@ class AirSensor
bool getSensorState(int sensor);
int getValue(int sensor, bool light);
float getHandPosition();
uint8_t getSensorReadings();
void setDeadzone(int deadzone);
void setAlpha(float alpha);
+4
View File
@@ -15,6 +15,10 @@
// Uncomment this line if your IR sensors will be used in analog mode (Confirm pinout on PinConfig.h)
//#define IR_SENSOR_ANALOG
// Comment this line for default Seaurchin air sensor bindings
// Uncomment this line if your IR sensors will each be mapped to separate keyboard key
//#define IR_SENSOR_KEY
// Uncomment this line to output the RAW touch values to the Serial port (for use with Arduino's Serial Plotter)
//#define SERIAL_PLOT
// Define PLOT_PIN as -1 to print all key's values, otherwise define as 0-15 for an individual key
+10 -1
View File
@@ -277,7 +277,7 @@ void loop() {
Serial.print("\t");
Serial.print(touchboard->getNeutralValue(PLOT_PIN));
Serial.print("\t");
Serial.println(touchboard->getNeutralValue(PLOT_PIN) + touchboard->getDeadzone());
Serial.print(touchboard->getNeutralValue(PLOT_PIN) + touchboard->getDeadzone());
}
#endif
@@ -286,11 +286,20 @@ void loop() {
if (newPosition != sensorPosition)
{
#if !defined(SERIAL_PLOT) || defined(USB)
#ifdef IR_SENSOR_KEY
output->sendSensor(sensor->getSensorReadings());
#else
output->sendSensorEvent(newPosition);
#endif
#endif
sensorPosition = newPosition;
}
#if defined(SERIAL_PLOT)
Serial.print("\t");
Serial.println(sensor->getSensorReadings());
#endif
// If the air sensor is calibrated, update lights. The lights will stay red as long as the air sensor is not calibrated.
if (sensor->isCalibrated())
FastLED.show();
+1
View File
@@ -8,6 +8,7 @@ class Output
public:
virtual void sendKeyEvent(int key, bool pressed, bool doublePressed);
virtual void sendSensorEvent(float position);
virtual void sendSensor(int sensor);
};
#endif
+34 -1
View File
@@ -6,18 +6,22 @@
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'};
uint16_t airKeys[] = { KEY_SLASH, KEY_PERIOD, KEY_QUOTE , KEY_SEMICOLON, KEY_RIGHT_BRACE , KEY_LEFT_BRACE };
void USBOutput::sendKeyEvent(int key, bool pressed, bool doublePressed)
{
if (pressed) {
if (doublePressed) {
writeKey(topRow[key]);
pressKey(topRow[key]);
}
else {
pressKey(bottomRow[key]);
releaseKey(topRow[key]);
}
}
else {
releaseKey(bottomRow[key]);
releaseKey(topRow[key]);
}
}
@@ -58,6 +62,17 @@ void USBOutput::sendSensorEvent(float position)
lastPosition = position;
}
void USBOutput::sendSensor(int sensor)
{
for (int i = 0; i < 6; i++)
{
if (bitRead(sensor, i))
pressKey(airKeys[i]);
else
releaseKey(airKeys[i]);
}
}
USBOutput::USBOutput()
{
#ifndef TEENSY
@@ -77,6 +92,12 @@ void USBOutput::writeKey(uint16_t key)
case KEY_PAGE_DOWN:
case KEY_HOME:
case KEY_END:
case KEY_SLASH:
case KEY_PERIOD:
case KEY_QUOTE:
case KEY_SEMICOLON:
case KEY_RIGHT_BRACE:
case KEY_LEFT_BRACE:
// Don't use ASCII method
Nkro.set_key(key);
Nkro.send_nkro_now();
@@ -105,6 +126,12 @@ void USBOutput::pressKey(uint16_t key)
case KEY_PAGE_DOWN:
case KEY_HOME:
case KEY_END:
case KEY_SLASH:
case KEY_PERIOD:
case KEY_QUOTE:
case KEY_SEMICOLON:
case KEY_RIGHT_BRACE:
case KEY_LEFT_BRACE:
// Don't use ASCII method
Nkro.set_key(key);
Nkro.send_nkro_now();
@@ -129,6 +156,12 @@ void USBOutput::releaseKey(uint16_t key)
case KEY_PAGE_DOWN:
case KEY_HOME:
case KEY_END:
case KEY_SLASH:
case KEY_PERIOD:
case KEY_QUOTE:
case KEY_SEMICOLON:
case KEY_RIGHT_BRACE:
case KEY_LEFT_BRACE:
// Don't use ASCII method
Nkro.reset_key(key);
Nkro.send_nkro_now();
+1
View File
@@ -27,6 +27,7 @@ class USBOutput : public Output
public:
void sendKeyEvent(int key, bool pressed, bool doublePressed) override;
void sendSensorEvent(float position) override;
void sendSensor(int sensor) override;
USBOutput();
};