pull/18/head
Jesse Vincent 10 years ago
parent 34a2f989c7
commit e79dd812d7

@ -30,8 +30,8 @@ const byte RIGHT_SX1509_ADDRESS = 0x71; // SX1509 I2C address (11)
sx1509Class leftsx1509(LEFT_SX1509_ADDRESS); sx1509Class leftsx1509(LEFT_SX1509_ADDRESS);
sx1509Class rightsx1509(RIGHT_SX1509_ADDRESS); sx1509Class rightsx1509(RIGHT_SX1509_ADDRESS);
int right_initted = 0; int right_initted = 0;
int left_initted =0; int left_initted = 0;
#define TS(X) //Serial.print(micros() );Serial.print("\t");Serial.println(X); #define TS(X) //Serial.print(micros() );Serial.print("\t");Serial.println(X);
@ -77,31 +77,31 @@ void set_keymap(Key keymapEntry, byte matrixStateEntry) {
void scan_matrix() void scan_matrix()
{ {
x=0; x = 0;
y=0; y = 0;
//scan the Keyboard matrix looking for connections //scan the Keyboard matrix looking for connections
for (byte row = 0; row < LEFT_ROWS; row++) { for (byte row = 0; row < LEFT_ROWS; row++) {
TS("Scanning row ") TS("Scanning row ")
if (left_initted) { if (left_initted) {
leftsx1509.updatePinState(left_rowpins[row], LOW); leftsx1509.updatePinState(left_rowpins[row], LOW);
leftsx1509.sendPinStates(); leftsx1509.sendPinStates();
leftsx1509.fetchPinStates(); leftsx1509.fetchPinStates();
} }
if (right_initted) { if (right_initted) {
rightsx1509.updatePinState(right_rowpins[row], LOW); rightsx1509.updatePinState(right_rowpins[row], LOW);
rightsx1509.sendPinStates(); rightsx1509.sendPinStates();
rightsx1509.fetchPinStates(); rightsx1509.fetchPinStates();
} }
for (byte col = 0; col < LEFT_COLS; col++) { for (byte col = 0; col < LEFT_COLS; col++) {
TS("Scanning col") TS("Scanning col")
//If we see an electrical connection on I->J, //If we see an electrical connection on I->J,
matrixState[row][col] <<= 1; matrixState[row][col] <<= 1;
matrixState[row][(COLS-1)-col] <<= 1; matrixState[row][(COLS - 1) - col] <<= 1;
TS("Reading left pin") TS("Reading left pin")
if (left_initted && leftsx1509.readPrefetchedPin(left_colpins[col])) { if (left_initted && leftsx1509.readPrefetchedPin(left_colpins[col])) {
@ -129,8 +129,8 @@ void scan_matrix()
set_keymap(keymaps[active_keymap][row][(COLS - 1) - col], matrixState[row][(COLS - 1) - col]); set_keymap(keymaps[active_keymap][row][(COLS - 1) - col], matrixState[row][(COLS - 1) - col]);
TS("calling send_key_event") TS("calling send_key_event")
send_key_event(row, col); send_key_event(row, col);
if(right_initted) if (right_initted)
send_key_event(row, (COLS-1)-col); send_key_event(row, (COLS - 1) - col);
} }
TS("clearing output pins") TS("clearing output pins")
@ -139,13 +139,13 @@ void scan_matrix()
if (right_initted) if (right_initted)
rightsx1509.updatePinState(right_rowpins[row], HIGH); rightsx1509.updatePinState(right_rowpins[row], HIGH);
} }
TS("Releasing keys not being pressed") TS("Releasing keys not being pressed")
release_keys_not_being_pressed(); release_keys_not_being_pressed();
TS("Sending key report"); TS("Sending key report");
Keyboard.sendCurrentReport(); Keyboard.sendCurrentReport();
TS("clearing internal key report") TS("clearing internal key report")
reset_key_report(); reset_key_report();
handle_mouse_movement(x, y); handle_mouse_movement(x, y);
} }
// Command mode // Command mode
@ -273,7 +273,7 @@ void setup()
setup_command_mode(); setup_command_mode();
setup_matrix(); setup_matrix();
setup_pins(); setup_pins();
rightsx1509.fetchPinStates(); rightsx1509.fetchPinStates();
primary_keymap = load_primary_keymap(); primary_keymap = load_primary_keymap();
} }
@ -392,9 +392,9 @@ void record_key_being_pressed(byte character)
void reset_key_report() void reset_key_report()
{ {
memcpy( charsReportedLastTime,charsBeingReported, KEYS_HELD_BUFFER); memcpy( charsReportedLastTime, charsBeingReported, KEYS_HELD_BUFFER);
memset(charsBeingReported,0,KEYS_HELD_BUFFER); memset(charsBeingReported, 0, KEYS_HELD_BUFFER);
} }
@ -439,42 +439,42 @@ void send_key_event(byte row, byte col)
// TODO:switch to sending raw HID packets // TODO:switch to sending raw HID packets
// really, these are signed small ints // really, these are signed small ints
byte switchState = matrixState[row][col];
Key mappedKey = keymaps[active_keymap][row][col];
if (mappedKey.flags & MOUSE_KEY ) {
if (mappedKey.rawKey & MOUSE_WARP) {
if (key_toggled_on(switchState)) {
warp_mouse(mappedKey);
}
} else {
handle_mouse_key_press(switchState, mappedKey, x, y);
}
} else if (mappedKey.flags & SYNTHETIC_KEY) { byte switchState = matrixState[row][col];
handle_synthetic_key_press(switchState, mappedKey); Key mappedKey = keymaps[active_keymap][row][col];
if (mappedKey.flags & MOUSE_KEY ) {
if (mappedKey.rawKey & MOUSE_WARP) {
if (key_toggled_on(switchState)) {
warp_mouse(mappedKey);
} }
else { } else {
if (String("Slack") == myApp) { handle_mouse_key_press(switchState, mappedKey, x, y);
if (key_is_pressed(switchState)) { }
record_key_being_pressed(mappedKey.rawKey);
if (key_toggled_on (switchState)) { } else if (mappedKey.flags & SYNTHETIC_KEY) {
Keyboard.print("Never gonna give you up!"); handle_synthetic_key_press(switchState, mappedKey);
} }
} else {
} else { if (String("Slack") == myApp) {
if (key_is_pressed(switchState)) { if (key_is_pressed(switchState)) {
record_key_being_pressed(mappedKey.rawKey); record_key_being_pressed(mappedKey.rawKey);
if (key_toggled_on (switchState)) { if (key_toggled_on (switchState)) {
press_key(mappedKey); Keyboard.print("Never gonna give you up!");
} }
} else if (key_toggled_off (switchState)) {
release_key(mappedKey);
}
} }
} else {
if (key_is_pressed(switchState)) {
record_key_being_pressed(mappedKey.rawKey);
if (key_toggled_on (switchState)) {
press_key(mappedKey);
}
} else if (key_toggled_off (switchState)) {
release_key(mappedKey);
} }
}
}
} }
void press_key(Key mappedKey) { void press_key(Key mappedKey) {
@ -514,42 +514,42 @@ void make_output(sx1509Class sx1509, int pin) {
void setup_pins() { void setup_pins() {
right_initted= setup_sx1509(rightsx1509, right_colpins, right_rowpins); right_initted = setup_sx1509(rightsx1509, right_colpins, right_rowpins);
left_initted= setup_sx1509(leftsx1509, left_colpins, left_rowpins); left_initted = setup_sx1509(leftsx1509, left_colpins, left_rowpins);
} }
int setup_sx1509 (sx1509Class sx1509, int colpins[], int rowpins[]) { int setup_sx1509 (sx1509Class sx1509, int colpins[], int rowpins[]) {
byte initted; byte initted;
for(int counter = 0; counter< 10;counter++) { for (int counter = 0; counter < 10; counter++) {
initted = sx1509.init(); initted = sx1509.init();
if (initted) if (initted)
break; break;
} }
if (initted) { // init ok if (initted) { // init ok
// In order to use the keypad, the clock must first be // In order to use the keypad, the clock must first be
// configured. We can call configureClock() with the default // configured. We can call configureClock() with the default
// parameters (2MHz internal oscillator, no clock in/out). // parameters (2MHz internal oscillator, no clock in/out).
sx1509.configClock(); sx1509.configClock();
// the debounceConfig function sets the debounce time. This // the debounceConfig function sets the debounce time. This
// function's parameter should be a 3-bit value. // function's parameter should be a 3-bit value.
// 0: 0.5ms * 2MHz/fOSC // 0: 0.5ms * 2MHz/fOSC
// 1: 1ms * 2MHz/fOSC // 1: 1ms * 2MHz/fOSC
// 2: 2ms * 2MHz/fOSC // 2: 2ms * 2MHz/fOSC
// 3: 4ms * 2MHz/fOSC // 3: 4ms * 2MHz/fOSC
// 4: 8ms * 2MHz/fOSC // 4: 8ms * 2MHz/fOSC
// 5: 16ms * 2MHz/fOSC // 5: 16ms * 2MHz/fOSC
// 6: 32ms * 2MHz/fOSC // 6: 32ms * 2MHz/fOSC
// 7: 64ms * 2MHz/fOSC // 7: 64ms * 2MHz/fOSC
sx1509.debounceConfig(4); // maximum debuonce time sx1509.debounceConfig(4); // maximum debuonce time
for (int i = 0; i < LEFT_ROWS; i++) { for (int i = 0; i < LEFT_ROWS; i++) {
make_output(sx1509, rowpins[i]); make_output(sx1509, rowpins[i]);

Loading…
Cancel
Save