|
|
|
#include "KeyboardioFirmware.h"
|
|
|
|
#include "TestMode.h"
|
|
|
|
#include "LED-RainbowEffect.h"
|
|
|
|
|
|
|
|
cRGB red;
|
|
|
|
cRGB blue;
|
|
|
|
|
|
|
|
#define LED_TEST_DELAY 2000
|
|
|
|
|
|
|
|
TestMode_::TestMode_(void) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestMode_::TestLEDs(void) {
|
|
|
|
// make all LEDs dim red
|
|
|
|
LEDControl.set_all_leds_to(50,0,0);
|
|
|
|
led_sync();
|
|
|
|
delay(LED_TEST_DELAY);
|
|
|
|
// make all LEDs dim blue
|
|
|
|
LEDControl.set_all_leds_to(0,50,0);
|
|
|
|
led_sync();
|
|
|
|
delay(LED_TEST_DELAY);
|
|
|
|
// make all LEDs dim green
|
|
|
|
LEDControl.set_all_leds_to(0,0,50);
|
|
|
|
led_sync();
|
|
|
|
delay(LED_TEST_DELAY);
|
|
|
|
// make all LEDs dim white
|
|
|
|
LEDControl.set_all_leds_to(50,50,50);
|
|
|
|
led_sync();
|
|
|
|
delay(LED_TEST_DELAY);
|
|
|
|
// make all the LEDs bright red
|
|
|
|
LEDControl.set_all_leds_to(200,0,0);
|
|
|
|
led_sync();
|
|
|
|
delay(LED_TEST_DELAY);
|
|
|
|
// make all the LEDs bright green
|
|
|
|
LEDControl.set_all_leds_to(0,200,0);
|
|
|
|
led_sync();
|
|
|
|
delay(LED_TEST_DELAY);
|
|
|
|
// make all the LEDs bright blue
|
|
|
|
LEDControl.set_all_leds_to(0,0,200);
|
|
|
|
led_sync();
|
|
|
|
delay(LED_TEST_DELAY);
|
|
|
|
// make all the LEDs bright white (1.6A)
|
|
|
|
LEDControl.set_all_leds_to(160,160,160);
|
|
|
|
led_sync();
|
|
|
|
delay(LED_TEST_DELAY);
|
|
|
|
// rainbow for 10 seconds
|
|
|
|
for(auto i=0; i<1000; i++ ) {
|
Rework the hook handling
We can't register hooks from constructors, because there is no guaranteed order
in which the objects will be created. So it may well happen that the Keyboardio
object gets created later, and zeroes out everything. Or it gets created first,
and registers the default handler as the first one, making all the others
pointless.
Instead, we create a KeyboardioPlugin class, that has a `begin` method. This is
responsible for setting up the hooks and whatnot. To make things simpler (for
some values of simple), a `Keyboardio.use` method is introduced, which, when
given a NULL-terminated list of plugin object pointers, will call the begin
method of each.
All LED effects and other plugins that used to register a static object now use
an extern, and had their initialization moved to the `begin` method.
The end result is not the nicest thing, but it works. We can try figuring out
something nicer later.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
8 years ago
|
|
|
LEDRainbowEffect.update();
|
|
|
|
led_sync();
|
|
|
|
}
|
|
|
|
// set all the keys to red
|
|
|
|
LEDControl.set_all_leds_to(50,0,0);
|
|
|
|
// make all LEDs dim blue
|
|
|
|
// as you hit each key, set it to blue
|
|
|
|
// as you hit each key a second time, set it to green
|
|
|
|
// as you hit each key a third time, set it to off
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TestMode_::TestMatrix () {
|
|
|
|
while(1) {
|
|
|
|
KeyboardHardware.read_matrix();
|
|
|
|
for (byte row = 0; row < 4; row++) {
|
|
|
|
for (byte col = 0; col < 8; col++) {
|
|
|
|
|
|
|
|
uint8_t keynum = (row*8)+(col);
|
|
|
|
|
|
|
|
uint8_t keyState = (bitRead(KeyboardHardware.previousLeftHandState.all, keynum) << 0) |
|
|
|
|
(bitRead(KeyboardHardware.leftHandState.all, keynum) << 1);
|
|
|
|
|
|
|
|
if(keyState ==3 ) {
|
|
|
|
Serial.print(" Key: ");
|
|
|
|
Serial.print(keynum);
|
|
|
|
Serial.print(" value ");
|
|
|
|
Serial.println(keyState);
|
|
|
|
KeyboardHardware.led_set_crgb_at(row, 7-col, red);
|
|
|
|
} else if (keyState ==1) {
|
|
|
|
KeyboardHardware.led_set_crgb_at(row,7-col, blue);
|
|
|
|
}
|
|
|
|
|
|
|
|
keyState = (bitRead(KeyboardHardware.previousRightHandState.all, keynum) << 0) |
|
|
|
|
(bitRead(KeyboardHardware.rightHandState.all, keynum) << 1);
|
|
|
|
|
|
|
|
if(keyState ==3 ) {
|
|
|
|
Serial.print(" Key: ");
|
|
|
|
Serial.print(keynum);
|
|
|
|
Serial.print(" value ");
|
|
|
|
Serial.println(keyState);
|
|
|
|
KeyboardHardware.led_set_crgb_at(row, 15-col, red);
|
|
|
|
} else if (keyState ==1) {
|
|
|
|
KeyboardHardware.led_set_crgb_at(row,15-col, blue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
KeyboardHardware.led_sync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestMode_::setup() {
|
|
|
|
red.r=101;
|
|
|
|
blue.b=101;
|
|
|
|
// TestLEDs();
|
|
|
|
eventHandlers[0] = handle_key_event_test;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestMode_::loop() {
|
|
|
|
TestMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool handle_key_event_test(Key mappedKey, byte row, byte col, uint8_t keyState) {
|
|
|
|
Serial.write(row);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
TestMode_ TestMode;
|