Reduced IR sensor delay, Minimized NKRO calls, Rewrote NKRO key commands

This commit is contained in:
veroxzik
2019-12-23 13:57:11 -05:00
committed by Jonathan Montineri
parent eeedc87200
commit 819a550007
8 changed files with 29 additions and 76 deletions
+3 -2
View File
@@ -93,6 +93,9 @@ int AirSensor::getValue(int sensor, bool light)
turnOffLight();
}
// Delay required because the read may occur faster than the physical light turning on
delayMicroseconds(150);
#ifdef IR_SENSOR_MULTIPLEXED
// Set multiplexer to corresponding sensor
digitalWrite(MUX_A, bitRead(sensor, 0));
@@ -102,14 +105,12 @@ int AirSensor::getValue(int sensor, bool light)
#ifdef IR_SENSOR_ANALOG
return analogRead(SENSOR_IN);
#else
delay(1);
return digitalRead(SENSOR_IN);
#endif
#else
#ifdef IR_SENSOR_ANALOG
return analogRead(ir_sensor_pins[sensor]);
#else
delay(1);
return digitalRead(ir_sensor_pins[sensor]);
#endif
#endif
-2
View File
@@ -12,8 +12,6 @@
#include "PinConfig.h"
#include <EEPROM.h>
class AirSensor
{
private:
+5
View File
@@ -356,6 +356,11 @@ void loop() {
sensorPosition = newPosition;
}
// Send update
#if !defined(SERIAL_PLOT) && defined(USB)
output->sendUpdate();
#endif
//#if defined(SERIAL_PLOT)
// Serial.print("\t");
// Serial.println(sensor->getSensorReadings());
+1
View File
@@ -9,6 +9,7 @@ class Output
virtual void sendKeyEvent(int key, bool pressed, bool doublePressed);
virtual void sendSensorEvent(float position);
virtual void sendSensor(int sensor);
virtual void sendUpdate();
};
#endif
+5
View File
@@ -32,3 +32,8 @@ void SerialOutput::sendSensorEvent(float position)
void SerialOutput::sendSensor(int sensor)
{
}
// Implement at a later date
void SerialOutput::sendUpdate()
{
}
+1
View File
@@ -37,6 +37,7 @@ class SerialOutput : public Output
void sendKeyEvent(int key, bool pressed, bool doublePressed) override;
void sendSensorEvent(float position) override;
void sendSensor(int sensor) override;
void sendUpdate() override;
};
#endif
+13 -72
View File
@@ -3,8 +3,8 @@
#ifdef USB
#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'};
char bottomRow[] = {KEY_A, KEY_Z, KEY_S, KEY_X, KEY_D, KEY_C, KEY_F, KEY_V, KEY_G, KEY_B, KEY_H, KEY_N, KEY_J, KEY_M, KEY_K, KEY_COMMA};
char topRow[] = {KEY_1, KEY_Q, KEY_2, KEY_W, KEY_3, KEY_E, KEY_4, KEY_R, KEY_5, KEY_T, KEY_6, KEY_Y, KEY_7, KEY_U, KEY_8, KEY_I};
uint16_t airKeys[] = { KEY_SLASH, KEY_PERIOD, KEY_QUOTE , KEY_SEMICOLON, KEY_RIGHT_BRACE , KEY_LEFT_BRACE };
@@ -86,32 +86,10 @@ void USBOutput::writeKey(uint16_t key)
#ifndef TEENSY
NKROKeyboard.write(key);
#else
switch (key)
{
case KEY_PAGE_UP:
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();
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;
}
Nkro.set_key(key);
Nkro.send_nkro_now();
Nkro.reset_key(key);
Nkro.send_nkro_now();
#endif
}
@@ -120,28 +98,7 @@ void USBOutput::pressKey(uint16_t key)
#ifndef TEENSY
pressKey(key);
#else
switch (key)
{
case KEY_PAGE_UP:
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();
break;
default:
// Use NKRO for ASCII
Nkro.set_key_ascii(key);
Nkro.send_nkro_now();
break;
}
Nkro.set_key(key);
#endif
}
@@ -150,29 +107,13 @@ void USBOutput::releaseKey(uint16_t key)
#ifndef TEENSY
NKROKeyboard.release(key);
#else
switch (key)
{
case KEY_PAGE_UP:
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();
break;
default:
// Use NKRO for ASCII
Nkro.reset_key_ascii(key);
Nkro.send_nkro_now();
break;
}
Nkro.reset_key(key);
#endif
}
void USBOutput::sendUpdate()
{
Nkro.send_nkro_now();
}
#endif
+1
View File
@@ -28,6 +28,7 @@ class USBOutput : public Output
void sendKeyEvent(int key, bool pressed, bool doublePressed) override;
void sendSensorEvent(float position) override;
void sendSensor(int sensor) override;
void sendUpdate() override;
USBOutput();
};