diff --git a/implementation/Model01.cpp b/implementation/Model01.cpp index 98cfb4c6..e6bb4138 100644 --- a/implementation/Model01.cpp +++ b/implementation/Model01.cpp @@ -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) { + 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(); + TWBR=12; } 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() { -} + 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() { - uint8_t key_data; - //scan the Keyboard matrix looking for connections + previousLeftHandState = leftHandState; + previousRightHandState = rightHandState; + + if (leftHand.readKeys()) { + leftHandState = leftHand.getKeyData(); + } + + if (rightHand.readKeys()) { + rightHandState = rightHand.getKeyData(); + } + for (byte row = 0; row < 4; row++) { + for (byte col = 0; col < 8; col++) { + + uint8_t keynum = (col*4+row); + + debug_key_event(leftHandState, previousLeftHandState,keynum, row, col); + handle_key_event(row, col, + bitRead(leftHandState.all, keynum), + bitRead(previousLeftHandState.all, keynum) + ); - for (byte col = 0; col < 4; col++) { - handle_key_event(row, col, &key_data); - handle_key_event(row, (8- 1) - col, &key_data); + 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 +} diff --git a/implementation/Model01.h b/implementation/Model01.h index 3390ef80..001e516c 100644 --- a/implementation/Model01.h +++ b/implementation/Model01.h @@ -24,11 +24,16 @@ class Model01 { void scan_matrix(void); void setup(); - + void enable_high_power_leds(void); + void enable_scanner_power(void); private: - static KeyboardioScanner leftHand; + static KeyboardioScanner leftHand; static KeyboardioScanner rightHand; + keydata_t leftHandState; + keydata_t rightHandState; + keydata_t previousLeftHandState; + keydata_t previousRightHandState; 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},