Add first-pass implementation of Model 01 spring 2016 prototype

pull/18/head
Jesse Vincent 9 years ago
parent 5e49c8fef3
commit 06383e8c3d

@ -6,27 +6,113 @@ Model01::Model01(void) {
} }
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);
}
void Model01::setup(void) { void Model01::setup(void) {
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();
Wire.begin(); Wire.begin();
TWBR=12;
} }
void Model01::led_set_crgb_at(uint8_t i, cRGB crgb) { void Model01::led_set_crgb_at(uint8_t i, cRGB crgb) {
if(i<32) {
leftHand.ledData.leds[i] = crgb;
// controller2.ledData.leds[i] = color;
} else {
rightHand.ledData.leds[i-32] = crgb;
}
} }
void Model01::led_sync() { void Model01::led_sync() {
} rightHand.sendLEDData();
rightHand.sendLEDData();
rightHand.sendLEDData();
rightHand.sendLEDData();
rightHand.sendLEDData();
rightHand.sendLEDData();
rightHand.sendLEDData();
rightHand.sendLEDData();
leftHand.sendLEDData();
leftHand.sendLEDData();
leftHand.sendLEDData();
leftHand.sendLEDData();
leftHand.sendLEDData();
leftHand.sendLEDData();
leftHand.sendLEDData();
leftHand.sendLEDData();
}
void debug_key_event(keydata_t state, keydata_t previousState, uint8_t keynum, uint8_t row, uint8_t col) {
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();
}
}
void Model01::scan_matrix() { void Model01::scan_matrix() {
uint8_t key_data; previousLeftHandState = leftHandState;
//scan the Keyboard matrix looking for connections previousRightHandState = rightHandState;
if (leftHand.readKeys()) {
leftHandState = leftHand.getKeyData();
}
if (rightHand.readKeys()) {
rightHandState = rightHand.getKeyData();
}
for (byte row = 0; row < 4; row++) { for (byte row = 0; row < 4; row++) {
for (byte col = 0; col < 8; col++) {
for (byte col = 0; col < 4; col++) { uint8_t keynum = (col*4+row);
handle_key_event(row, col, &key_data);
handle_key_event(row, (8- 1) - col, &key_data); debug_key_event(leftHandState, previousLeftHandState,keynum, row, col);
handle_key_event(row, col,
bitRead(leftHandState.all, keynum),
bitRead(previousLeftHandState.all, keynum)
);
debug_key_event(rightHandState, previousRightHandState,keynum, row,col);
handle_key_event(row, (8+ col),
bitRead(rightHandState.all, keynum),
bitRead(previousRightHandState.all, keynum)
);
} }
} }
}
//scan the Keyboard matrix looking for connections
}

@ -24,11 +24,16 @@ class Model01 {
void scan_matrix(void); void scan_matrix(void);
void setup(); void setup();
void enable_high_power_leds(void);
void enable_scanner_power(void);
private: private:
static KeyboardioScanner leftHand; static KeyboardioScanner leftHand;
static KeyboardioScanner rightHand; static KeyboardioScanner rightHand;
keydata_t leftHandState;
keydata_t rightHandState;
keydata_t previousLeftHandState;
keydata_t previousRightHandState;
static constexpr uint8_t key_led_map[4][16] = { static constexpr uint8_t key_led_map[4][16] = {
{3,4,11,12,19,20,26,27, 36,37,43,44,51,52,59,60}, {3,4,11,12,19,20,26,27, 36,37,43,44,51,52,59,60},

Loading…
Cancel
Save