extract the mouse movement code and remove a variable we don't really need

pull/18/head
jesse 11 years ago
parent 22372f8b0d
commit e688c80b58

@ -68,7 +68,6 @@ static const Key keymaps[LAYERS][ROWS][COLS] = {
};
void release_keys_not_being_pressed()
{
@ -133,6 +132,48 @@ double mouse_accel (double cycles)
return accel;
}
void handle_mouse_movement( int x, int y) {
if (x!=0 && y!=0) {
mouseActiveForCycles++;
double accel = (double) mouse_accel(mouseActiveForCycles);
float moveX=0;
float moveY=0;
if (x>0) {
moveX = (x*accel) + carriedOverX;
carriedOverX = moveX - floor(moveX);
} else if(x<0) {
moveX = (x*accel) - carriedOverX;
carriedOverX = ceil(moveX) - moveX;
}
if (y >0) {
moveY = (y*accel) + carriedOverY;
carriedOverY = moveY - floor(moveY);
} else if (y<0) {
moveY = (y*accel) - carriedOverY;
carriedOverY = ceil(moveY) - moveY;
}
Serial.println();
Serial.print("cycles: ");
Serial.println(mouseActiveForCycles);
Serial.print("Accel: ");
Serial.print(accel);
Serial.print(" moveX is ");
Serial.print(moveX);
Serial.print(" moveY is ");
Serial.print(moveY);
Serial.print(" carriedoverx is ");
Serial.print(carriedOverX);
Serial.print(" carriedOverY is ");
Serial.println(carriedOverY);
Mouse.move(moveX,moveY, 0);
} else {
mouseActiveForCycles=0;
}
}
void send_key_events(int layer)
{
//for every newly pressed button, figure out what logical key it is and send a key down event
@ -142,7 +183,6 @@ void send_key_events(int layer)
// TODO:switch to sending raw HID packets
bool mouseActiveThisCycle = false;
int x = 0;
int y = 0;
@ -153,7 +193,6 @@ void send_key_events(int layer)
Key mappedKey = keymaps[layer][row][col];
if (mappedKey.flags & MOUSE_KEY ) {
if (key_is_pressed(switchState)) {
mouseActiveThisCycle = true;
if (mappedKey.rawKey & MOUSE_UP) {
y-=1;
}
@ -189,47 +228,12 @@ void send_key_events(int layer)
}
}
}
if (mouseActiveThisCycle) {
mouseActiveForCycles++;
double accel = (double) mouse_accel(mouseActiveForCycles);
float moveX=0;
float moveY=0;
if (x>0) {
moveX = (x*accel) + carriedOverX;
carriedOverX = moveX - floor(moveX);
} else if(x<0) {
moveX = (x*accel) - carriedOverX;
carriedOverX = ceil(moveX) - moveX;
}
if (y >0) {
moveY = (y*accel) + carriedOverY;
carriedOverY = moveY - floor(moveY);
} else if (y<0) {
moveY = (y*accel) - carriedOverY;
carriedOverY = ceil(moveY) - moveY;
}
Serial.println();
Serial.print("cycles: ");
Serial.println(mouseActiveForCycles);
Serial.print("Accel: ");
Serial.print(accel);
Serial.print(" moveX is ");
Serial.print(moveX);
Serial.print(" moveY is ");
Serial.print(moveY);
Serial.print(" carriedoverx is ");
Serial.print(carriedOverX);
Serial.print(" carriedOverY is ");
Serial.println(carriedOverY);
Mouse.move(moveX,moveY, 0);
} else {
mouseActiveForCycles=0;
}
handle_mouse_movement(x,y);
release_keys_not_being_pressed();
}
void setup_matrix()
{
//set up the row pins as outputs

Loading…
Cancel
Save