You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
3.0 KiB
113 lines
3.0 KiB
9 years ago
|
#include "Model01.h"
|
||
9 years ago
|
KeyboardioScanner Model01::leftHand(0);
|
||
|
KeyboardioScanner Model01::rightHand(3);
|
||
9 years ago
|
|
||
9 years ago
|
Model01::Model01(void) {
|
||
9 years ago
|
|
||
|
}
|
||
|
|
||
9 years ago
|
void Model01::enable_scanner_power(void) {
|
||
|
pinMode(13, OUTPUT);
|
||
|
digitalWrite(13, HIGH);
|
||
|
}
|
||
|
|
||
|
// This lets the keyboard pull up to 1.6 amps from
|
||
|
// the host. That violates the USB spec. But it sure
|
||
|
// is pretty looking
|
||
|
void Model01::enable_high_power_leds(void) {
|
||
|
pinMode(7, OUTPUT);
|
||
|
digitalWrite(7, LOW);
|
||
|
}
|
||
|
|
||
9 years ago
|
void Model01::setup(void) {
|
||
9 years ago
|
enable_scanner_power();
|
||
|
|
||
|
// Consider not doing this until 30s after keyboard
|
||
|
// boot up, to make it easier to rescue things
|
||
|
// in case of power draw issues.
|
||
|
enable_high_power_leds();
|
||
9 years ago
|
leftHandState.all = 0;
|
||
|
rightHandState.all = 0;
|
||
9 years ago
|
|
||
9 years ago
|
Wire.begin();
|
||
9 years ago
|
TWBR=12;
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
|
||
9 years ago
|
void Model01::led_set_crgb_at(uint8_t i, cRGB crgb) {
|
||
9 years ago
|
if(i<32) {
|
||
|
leftHand.ledData.leds[i] = crgb;
|
||
9 years ago
|
} else if (i<64) {
|
||
9 years ago
|
rightHand.ledData.leds[i-32] = crgb;
|
||
9 years ago
|
} else {
|
||
|
// TODO how do we want to handle debugging assertions about crazy user
|
||
|
// code that would overwrite other memory?
|
||
9 years ago
|
}
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
cRGB Model01::led_get_crgb_at(uint8_t i) {
|
||
|
if(i<32) {
|
||
|
return leftHand.ledData.leds[i];
|
||
|
} else if (i<64) {
|
||
|
return rightHand.ledData.leds[i-32] ;
|
||
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
void Model01::led_sync() {
|
||
9 years ago
|
rightHand.sendLEDData();
|
||
|
rightHand.sendLEDData();
|
||
|
rightHand.sendLEDData();
|
||
|
rightHand.sendLEDData();
|
||
|
leftHand.sendLEDData();
|
||
|
leftHand.sendLEDData();
|
||
|
leftHand.sendLEDData();
|
||
|
leftHand.sendLEDData();
|
||
9 years ago
|
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
9 years ago
|
void debug_key_event(keydata_t state, keydata_t previousState, uint8_t keynum, uint8_t row, uint8_t col) {
|
||
9 years ago
|
if (bitRead(state.all, keynum) != bitRead(previousState.all, keynum )) {
|
||
|
Serial.print("Looking at row ");
|
||
|
Serial.print(row);
|
||
|
Serial.print(", col ");
|
||
|
Serial.print(col);
|
||
|
Serial.print(" key # ");
|
||
|
Serial.print(keynum);
|
||
|
Serial.print(" ");
|
||
|
Serial.print(bitRead(previousState.all, keynum));
|
||
|
Serial.print(" -> ");
|
||
|
Serial.print(bitRead(state.all, keynum ));
|
||
|
Serial.println();
|
||
|
}
|
||
9 years ago
|
}
|
||
9 years ago
|
void Model01::scan_matrix() {
|
||
9 years ago
|
previousLeftHandState = leftHandState;
|
||
|
previousRightHandState = rightHandState;
|
||
|
|
||
|
if (leftHand.readKeys()) {
|
||
|
leftHandState = leftHand.getKeyData();
|
||
|
}
|
||
|
|
||
|
if (rightHand.readKeys()) {
|
||
|
rightHandState = rightHand.getKeyData();
|
||
|
}
|
||
|
|
||
9 years ago
|
for (byte row = 0; row < 4; row++) {
|
||
9 years ago
|
for (byte col = 0; col < 8; col++) {
|
||
|
|
||
|
uint8_t keynum = (col*4+row);
|
||
|
|
||
|
handle_key_event(row, col,
|
||
|
bitRead(leftHandState.all, keynum),
|
||
|
bitRead(previousLeftHandState.all, keynum)
|
||
|
);
|
||
9 years ago
|
|
||
9 years ago
|
handle_key_event(row, (8+ col),
|
||
|
bitRead(rightHandState.all, keynum),
|
||
|
bitRead(previousRightHandState.all, keynum)
|
||
|
);
|
||
9 years ago
|
}
|
||
9 years ago
|
}
|
||
9 years ago
|
//scan the Keyboard matrix looking for connections
|
||
|
}
|