You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
120 lines
2.6 KiB
120 lines
2.6 KiB
10 years ago
|
|
||
|
// Mouse-related methods
|
||
|
//
|
||
|
//
|
||
9 years ago
|
#include "MouseWrapper.h"
|
||
9 years ago
|
|
||
|
|
||
9 years ago
|
MouseWrapper_::MouseWrapper_(void) {
|
||
|
Mouse.begin();
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
void MouseWrapper_::press_button(uint8_t button) {
|
||
9 years ago
|
Mouse.press(button);
|
||
|
end_warping();
|
||
9 years ago
|
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
9 years ago
|
void MouseWrapper_::release_button(uint8_t button) {
|
||
9 years ago
|
Mouse.release(button);
|
||
9 years ago
|
}
|
||
|
|
||
|
|
||
9 years ago
|
void MouseWrapper_::warp_jump(long left, long top, long height, long width) {
|
||
10 years ago
|
long x_center = left + width/2;
|
||
|
long y_center = top + height/2;
|
||
9 years ago
|
AbsoluteMouse.moveTo(x_center,y_center);
|
||
10 years ago
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
9 years ago
|
void MouseWrapper_::begin_warping() {
|
||
|
section_left = WARP_ABS_LEFT;
|
||
|
section_top = WARP_ABS_TOP;
|
||
9 years ago
|
next_width = MAX_WARP_WIDTH;
|
||
|
next_height = MAX_WARP_HEIGHT;
|
||
9 years ago
|
is_warping = true;
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
void MouseWrapper_::end_warping() {
|
||
10 years ago
|
is_warping= false;
|
||
|
}
|
||
|
|
||
9 years ago
|
void MouseWrapper_::warp(uint8_t warp_cmd) {
|
||
9 years ago
|
if (is_warping == false) {
|
||
|
begin_warping();
|
||
10 years ago
|
}
|
||
|
|
||
|
|
||
9 years ago
|
if ( warp_cmd & WARP_END) {
|
||
9 years ago
|
end_warping();
|
||
|
return;
|
||
|
}
|
||
10 years ago
|
|
||
|
|
||
9 years ago
|
next_width = next_width / 2;
|
||
|
next_height = next_height/2;
|
||
10 years ago
|
|
||
9 years ago
|
if (warp_cmd & WARP_UP) {
|
||
10 years ago
|
// Serial.print(" - up ");
|
||
9 years ago
|
} else if (warp_cmd & WARP_DOWN) {
|
||
9 years ago
|
// Serial.print(" - down ");
|
||
|
section_top = section_top + next_height;
|
||
|
}
|
||
|
|
||
9 years ago
|
if (warp_cmd & WARP_LEFT) {
|
||
9 years ago
|
// Serial.print(" - left ");
|
||
9 years ago
|
} else if (warp_cmd & WARP_RIGHT) {
|
||
9 years ago
|
// Serial.print(" - right ");
|
||
|
section_left = section_left + next_width;
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
warp_jump(section_left, section_top, next_height,next_width);
|
||
10 years ago
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
9 years ago
|
double MouseWrapper_::acceleration (double cycles) {
|
||
9 years ago
|
double accel = (atan((cycles * ACCELERATION_CLIMB_SPEED)-ACCELERATION_RUNWAY) + ATAN_LIMIT) * ACCELERATION_MULTIPLIER;
|
||
|
if (accel < ACCELERATION_FLOOR) {
|
||
|
accel = ACCELERATION_FLOOR;
|
||
10 years ago
|
}
|
||
9 years ago
|
return accel;
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
void MouseWrapper_::move( int8_t x, int8_t y) {
|
||
9 years ago
|
|
||
|
if (x != 0 || y != 0) {
|
||
|
mouseActiveForCycles++;
|
||
9 years ago
|
double accel = (double) acceleration(mouseActiveForCycles);
|
||
9 years ago
|
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;
|
||
|
}
|
||
|
end_warping();
|
||
|
|
||
|
Mouse.move(moveX, moveY, 0);
|
||
|
} else {
|
||
|
mouseActiveForCycles = 0;
|
||
10 years ago
|
}
|
||
|
|
||
|
}
|
||
|
|
||
9 years ago
|
MouseWrapper_ MouseWrapper;
|