|
|
@ -62,53 +62,45 @@ static const Key keymaps[LAYERS][ROWS][COLS] = {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void reset_matrix() {
|
|
|
|
boolean key_was_pressed (byte keyState) {
|
|
|
|
for (int col = 0; col < COLS; col++) {
|
|
|
|
if ( byte((keyState >> 4)) ^ B00001111 ) {
|
|
|
|
for (int row = 0; row < ROWS; row++) {
|
|
|
|
return false;
|
|
|
|
matrixState[row][col] <<= 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void send_key_event() {
|
|
|
|
}
|
|
|
|
//for every newly pressed button, figure out what logical key it is and send a key down event
|
|
|
|
|
|
|
|
// for every newly released button, figure out what logical key it is and send a key up event
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO:switch to sending raw HID packets
|
|
|
|
|
|
|
|
for (int row = 0; row < ROWS; row++) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int col = 0; col < COLS; col++) {
|
|
|
|
boolean key_was_not_pressed (byte keyState) {
|
|
|
|
if (key_toggled_on (matrixState[row][col])) {
|
|
|
|
if ( byte((keyState >> 4)) ^ B00000000 ) {
|
|
|
|
Keyboard.press(keymaps[current_keymap][row][col].rawKey);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (key_toggled_off (matrixState[row][col])) {
|
|
|
|
|
|
|
|
Keyboard.release(keymaps[current_keymap][row][col].rawKey);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
boolean key_was_pressed (byte keyState) {
|
|
|
|
boolean key_is_pressed (byte keyState) {
|
|
|
|
if ( byte((keyState >> 4)) ^ B00001111 ){
|
|
|
|
|
|
|
|
|
|
|
|
if ( byte((keyState << 4)) ^ B11110000 ) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean key_is_not_pressed (byte keyState) {
|
|
|
|
|
|
|
|
|
|
|
|
boolean key_was_not_pressed (byte keyState) {
|
|
|
|
if ( byte((keyState << 4)) ^ B00000000 ) {
|
|
|
|
if ( byte((keyState >> 4)) ^ B00000000 ){
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean key_toggled_on(byte keyState) {
|
|
|
|
boolean key_toggled_on(byte keyState) {
|
|
|
|
if (key_is_pressed(keyState) && ( key_was_not_pressed(keyState))) {
|
|
|
|
if (key_is_pressed(keyState) && ( key_was_not_pressed(keyState))) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
@ -129,25 +121,56 @@ boolean key_toggled_off(byte keyState) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean key_is_pressed (byte keyState) {
|
|
|
|
void reset_matrix() {
|
|
|
|
|
|
|
|
for (int col = 0; col < COLS; col++) {
|
|
|
|
if ( byte((keyState << 4)) ^ B11110000 ){
|
|
|
|
for (int row = 0; row < ROWS; row++) {
|
|
|
|
return false;
|
|
|
|
matrixState[row][col] <<= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
boolean key_is_not_pressed (byte keyState) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( byte((keyState << 4)) ^ B00000000 ){
|
|
|
|
void send_key_event() {
|
|
|
|
return false;
|
|
|
|
//for every newly pressed button, figure out what logical key it is and send a key down event
|
|
|
|
|
|
|
|
// for every newly released button, figure out what logical key it is and send a key up event
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO:switch to sending raw HID packets
|
|
|
|
|
|
|
|
for (int row = 0; row < ROWS; row++) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int col = 0; col < COLS; col++) {
|
|
|
|
|
|
|
|
int x = 0;
|
|
|
|
|
|
|
|
int y = 0;
|
|
|
|
|
|
|
|
if (keymaps[current_keymap][row][col].flags & MOUSE_KEY ) {
|
|
|
|
|
|
|
|
if (keymaps[current_keymap][row][col].rawKey & MOUSE_UP) {
|
|
|
|
|
|
|
|
y--;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keymaps[current_keymap][row][col].rawKey & MOUSE_DN) {
|
|
|
|
|
|
|
|
y++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keymaps[current_keymap][row][col].rawKey & MOUSE_L) {
|
|
|
|
|
|
|
|
x--;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (keymaps[current_keymap][row][col].rawKey & MOUSE_R) {
|
|
|
|
|
|
|
|
x++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Mouse.move(x, y, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (key_toggled_on (matrixState[row][col])) {
|
|
|
|
|
|
|
|
Keyboard.press(keymaps[current_keymap][row][col].rawKey);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (key_toggled_off (matrixState[row][col])) {
|
|
|
|
|
|
|
|
Keyboard.release(keymaps[current_keymap][row][col].rawKey);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setup_matrix() {
|
|
|
|
void setup_matrix() {
|
|
|
|
//set up the row pins as outputs
|
|
|
|
//set up the row pins as outputs
|
|
|
|
for (int row = 0; row < ROWS; row++) {
|
|
|
|
for (int row = 0; row < ROWS; row++) {
|
|
|
@ -171,7 +194,7 @@ void setup_matrix() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void scan_matrix() {
|
|
|
|
void scan_matrix() {
|
|
|
|
//scan the keyboard matrix looking for connections
|
|
|
|
//scan the Keyboard matrix looking for connections
|
|
|
|
for (int row = 0; row < ROWS; row++) {
|
|
|
|
for (int row = 0; row < ROWS; row++) {
|
|
|
|
digitalWrite(rowPins[row], LOW);
|
|
|
|
digitalWrite(rowPins[row], LOW);
|
|
|
|
for (int col = 0; col < COLS; col++) {
|
|
|
|
for (int col = 0; col < COLS; col++) {
|
|
|
@ -184,18 +207,18 @@ void scan_matrix() {
|
|
|
|
matrixState[row][col] |= 1; // noop. just here for clarity
|
|
|
|
matrixState[row][col] |= 1; // noop. just here for clarity
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// while we're inspecting the electrical matrix, we look
|
|
|
|
// while we're inspecting the electrical matrix, we look
|
|
|
|
// to see if the key being held is a firmware level
|
|
|
|
// to see if the Key being held is a firmware level
|
|
|
|
// metakey, so we can act on it, lest we only discover
|
|
|
|
// metakey, so we can act on it, lest we only discover
|
|
|
|
// that we should be looking at a seconary keymap halfway through the matrix scan
|
|
|
|
// that we should be looking at a seconary Keymap halfway through the matrix scan
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( keymaps[current_keymap][row][col].flags & MOMENTARY ) {
|
|
|
|
if ( keymaps[current_keymap][row][col].flags & MOMENTARY ) {
|
|
|
|
|
|
|
|
|
|
|
|
if (key_toggled_on(matrixState[row][col]) ){
|
|
|
|
if (key_toggled_on(matrixState[row][col]) ) {
|
|
|
|
current_keymap++;
|
|
|
|
current_keymap++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key_toggled_off(matrixState[row][col]) ){
|
|
|
|
else if (key_toggled_off(matrixState[row][col]) ) {
|
|
|
|
current_keymap--;
|
|
|
|
current_keymap--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -240,7 +263,7 @@ void report(int row, int col, boolean value) {
|
|
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
void setup() {
|
|
|
|
Keyboard.begin();
|
|
|
|
Keyboard.begin();
|
|
|
|
|
|
|
|
Mouse.begin();
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.begin(115200);
|
|
|
|
setup_matrix();
|
|
|
|
setup_matrix();
|
|
|
|
}
|
|
|
|
}
|
|
|
|