used the arduino standard astyle invocation

pull/18/head
Jesse Vincent 11 years ago
parent 48a21e3492
commit 21d337fd05

@ -48,7 +48,7 @@ void release_keys_not_being_pressed()
// we use charsReportedLastTime to figure out what we might not be holding anymore and can now release. this is destructive to charsReportedLastTime // we use charsReportedLastTime to figure out what we might not be holding anymore and can now release. this is destructive to charsReportedLastTime
for (byte i=0; i<KEYS_HELD_BUFFER; i++) { for (byte i = 0; i < KEYS_HELD_BUFFER; i++) {
// for each key we were holding as of the end of the last cycle // for each key we were holding as of the end of the last cycle
// see if we're still holding it // see if we're still holding it
// if we're not, call an explicit Release // if we're not, call an explicit Release
@ -56,7 +56,7 @@ void release_keys_not_being_pressed()
if (charsReportedLastTime[i] != 0x00) { if (charsReportedLastTime[i] != 0x00) {
// if there _was_ a character in this slot, go check the // if there _was_ a character in this slot, go check the
// currently held characters // currently held characters
for (byte j=0; j<KEYS_HELD_BUFFER; j++) { for (byte j = 0; j < KEYS_HELD_BUFFER; j++) {
if (charsReportedLastTime[i] == charsBeingReported[j]) { if (charsReportedLastTime[i] == charsBeingReported[j]) {
// if's still held, we don't need to do anything. // if's still held, we don't need to do anything.
charsReportedLastTime[i] = 0x00; charsReportedLastTime[i] = 0x00;
@ -66,7 +66,7 @@ void release_keys_not_being_pressed()
} }
} }
for (byte i=0; i<KEYS_HELD_BUFFER; i++) { for (byte i = 0; i < KEYS_HELD_BUFFER; i++) {
if (charsReportedLastTime[i] != 0x00) { if (charsReportedLastTime[i] != 0x00) {
Keyboard.release(charsReportedLastTime[i]); Keyboard.release(charsReportedLastTime[i]);
} }
@ -75,7 +75,7 @@ void release_keys_not_being_pressed()
void record_key_being_pressed(byte character) void record_key_being_pressed(byte character)
{ {
for (byte i=0; i<KEYS_HELD_BUFFER; i++) { for (byte i = 0; i < KEYS_HELD_BUFFER; i++) {
// todo - deal with overflowing the 12 key buffer here // todo - deal with overflowing the 12 key buffer here
if (charsBeingReported[i] == 0x00) { if (charsBeingReported[i] == 0x00) {
charsBeingReported[i] = character; charsBeingReported[i] = character;
@ -91,7 +91,7 @@ void reset_matrix()
matrixState[row][col] <<= 1; matrixState[row][col] <<= 1;
} }
} }
for (byte i=0; i<KEYS_HELD_BUFFER; i++) { for (byte i = 0; i < KEYS_HELD_BUFFER; i++) {
charsReportedLastTime[i] = charsBeingReported[i]; charsReportedLastTime[i] = charsBeingReported[i];
charsBeingReported[i] = 0x00; charsBeingReported[i] = 0x00;
} }
@ -100,18 +100,18 @@ void reset_matrix()
void handle_synthetic_key_press(byte switchState,Key mappedKey) { void handle_synthetic_key_press(byte switchState, Key mappedKey) {
if(mappedKey.flags & IS_CONSUMER) { if (mappedKey.flags & IS_CONSUMER) {
if (key_toggled_on (switchState)) { if (key_toggled_on (switchState)) {
Keyboard.consumerControl(mappedKey.rawKey); Keyboard.consumerControl(mappedKey.rawKey);
} }
} }
else if(mappedKey.flags & IS_SYSCTL) { else if (mappedKey.flags & IS_SYSCTL) {
if (key_toggled_on (switchState)) { if (key_toggled_on (switchState)) {
Keyboard.systemControl(mappedKey.rawKey); Keyboard.systemControl(mappedKey.rawKey);
} }
} }
else if(mappedKey.flags & IS_MACRO) { else if (mappedKey.flags & IS_MACRO) {
if (key_toggled_on (switchState)) { if (key_toggled_on (switchState)) {
if (mappedKey.rawKey == 1) { if (mappedKey.rawKey == 1) {
Keyboard.print("Keyboard.IO keyboard driver v0.00"); Keyboard.print("Keyboard.IO keyboard driver v0.00");
@ -127,25 +127,25 @@ void reset_matrix()
Mouse.release(mappedKey.rawKey); Mouse.release(mappedKey.rawKey);
} }
} }
} }
void handle_mouse_key_press(byte switchState, Key mappedKey, char &x, char &y) { void handle_mouse_key_press(byte switchState, Key mappedKey, char &x, char &y) {
if (key_is_pressed(switchState)) { if (key_is_pressed(switchState)) {
if (mappedKey.rawKey & MOUSE_UP) { if (mappedKey.rawKey & MOUSE_UP) {
y-=1; y -= 1;
} }
if (mappedKey.rawKey & MOUSE_DN) { if (mappedKey.rawKey & MOUSE_DN) {
y+= 1; y += 1;
} }
if (mappedKey.rawKey & MOUSE_L) { if (mappedKey.rawKey & MOUSE_L) {
x-= 1; x -= 1;
} }
if (mappedKey.rawKey & MOUSE_R) { if (mappedKey.rawKey & MOUSE_R) {
x+= 1 ; x += 1 ;
}
} }
} }
}
void send_key_events(byte layer) void send_key_events(byte layer)
{ {
@ -165,7 +165,7 @@ void send_key_events(byte layer)
byte switchState = matrixState[row][col]; byte switchState = matrixState[row][col];
Key mappedKey = keymaps[layer][row][col]; Key mappedKey = keymaps[layer][row][col];
if (mappedKey.flags & MOUSE_KEY ) { if (mappedKey.flags & MOUSE_KEY ) {
handle_mouse_key_press(matrixState[row][col], keymaps[layer][row][col],x,y); handle_mouse_key_press(matrixState[row][col], keymaps[layer][row][col], x, y);
} else if (mappedKey.flags & SYNTHETIC_KEY) { } else if (mappedKey.flags & SYNTHETIC_KEY) {
@ -183,7 +183,7 @@ void send_key_events(byte layer)
} }
} }
} }
handle_mouse_movement(x,y); handle_mouse_movement(x, y);
release_keys_not_being_pressed(); release_keys_not_being_pressed();
} }
void setup_matrix() void setup_matrix()
@ -266,8 +266,8 @@ void setup()
Serial.begin(115200); Serial.begin(115200);
Keyboard.begin(); Keyboard.begin();
Mouse.begin(); Mouse.begin();
//#ifdef DEBUG_SERIAL //#ifdef DEBUG_SERIAL
//#endif //#endif
setup_matrix(); setup_matrix();
Serial.println("loaded the matrix"); Serial.println("loaded the matrix");
current_layer = load_current_layer(); current_layer = load_current_layer();

@ -3,10 +3,10 @@
void report_matrix() void report_matrix()
{ {
#ifdef DEBUG_SERIAL #ifdef DEBUG_SERIAL
if (reporting_counter++ %100 == 0 ) { if (reporting_counter++ % 100 == 0 ) {
for (byte row = 0; row < ROWS; row++) { for (byte row = 0; row < ROWS; row++) {
for (byte col = 0; col < COLS; col++) { for (byte col = 0; col < COLS; col++) {
Serial.print(matrixState[row][col],HEX); Serial.print(matrixState[row][col], HEX);
Serial.print(", "); Serial.print(", ");
} }

@ -1,14 +1,14 @@
double mouseActiveForCycles = 0; double mouseActiveForCycles = 0;
float carriedOverX =0; float carriedOverX = 0;
float carriedOverY =0; float carriedOverY = 0;
double mouse_accel (double cycles) double mouse_accel (double cycles)
{ {
double accel = atan((cycles/50)-5); double accel = atan((cycles / 50) - 5);
accel += 1.5707963267944; // we want the whole s curve, not just the bit that's usually above the x and y axes; accel += 1.5707963267944; // we want the whole s curve, not just the bit that's usually above the x and y axes;
accel = accel *0.85; accel = accel * 0.85;
if (accel<0.25) { if (accel < 0.25) {
accel =0.25; accel = 0.25;
} }
return accel; return accel;
} }
@ -16,24 +16,24 @@ double mouse_accel (double cycles)
void handle_mouse_movement( char x, char y) void handle_mouse_movement( char x, char y)
{ {
if (x!=0 || y!=0) { if (x != 0 || y != 0) {
mouseActiveForCycles++; mouseActiveForCycles++;
double accel = (double) mouse_accel(mouseActiveForCycles); double accel = (double) mouse_accel(mouseActiveForCycles);
float moveX=0; float moveX = 0;
float moveY=0; float moveY = 0;
if (x>0) { if (x > 0) {
moveX = (x*accel) + carriedOverX; moveX = (x * accel) + carriedOverX;
carriedOverX = moveX - floor(moveX); carriedOverX = moveX - floor(moveX);
} else if(x<0) { } else if (x < 0) {
moveX = (x*accel) - carriedOverX; moveX = (x * accel) - carriedOverX;
carriedOverX = ceil(moveX) - moveX; carriedOverX = ceil(moveX) - moveX;
} }
if (y >0) { if (y > 0) {
moveY = (y*accel) + carriedOverY; moveY = (y * accel) + carriedOverY;
carriedOverY = moveY - floor(moveY); carriedOverY = moveY - floor(moveY);
} else if (y<0) { } else if (y < 0) {
moveY = (y*accel) - carriedOverY; moveY = (y * accel) - carriedOverY;
carriedOverY = ceil(moveY) - moveY; carriedOverY = ceil(moveY) - moveY;
} }
#ifdef DEBUG_SERIAL #ifdef DEBUG_SERIAL
@ -51,9 +51,9 @@ void handle_mouse_movement( char x, char y)
Serial.print(" carriedOverY is "); Serial.print(" carriedOverY is ");
Serial.println(carriedOverY); Serial.println(carriedOverY);
#endif #endif
Mouse.move(moveX,moveY, 0); Mouse.move(moveX, moveY, 0);
} else { } else {
mouseActiveForCycles=0; mouseActiveForCycles = 0;
} }
} }

Loading…
Cancel
Save