Skip to content

Commit

Permalink
Alternate move axes
Browse files Browse the repository at this point in the history
Previously the movement on the X axis was completed before starting the
Y axis movement. This could be problematic in situations where the
target coordinate was continually changing because that would cause only
movement on the X axis to occur and also results in less natural looking
movement. By alternating the axis of movement the move will be made to
target coordinate in both axes even if it's never reached. The 45 degree
movement with horizontal/vertical movement at the end is an aesthetic
improvement, though still not ideal. Unfortunately this causes an
increase of 24 bytes program memory and 1 byte SRAM due to the axis
switching code.
  • Loading branch information
per1234 committed Jan 31, 2017
1 parent 70e9afa commit 3713d07
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
22 changes: 13 additions & 9 deletions MouseTo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,19 @@ boolean MouseToClass::move() {
moveToTargetY = targetY;
}

if (positionX != moveToTargetX) {
const int moveX = moveToTargetX > positionX ? min(jumpDistance, moveToTargetX - positionX) : max(-jumpDistance, moveToTargetX - positionX);
Mouse.move(moveX, 0, 0);
positionX += moveX;
}
else if (positionY != moveToTargetY) {
const int moveY = moveToTargetY > positionY ? min(jumpDistance, moveToTargetY - positionY) : max(-jumpDistance, moveToTargetY - positionY);
Mouse.move(0, moveY, 0);
positionY += moveY;
if (positionX != moveToTargetX || positionY != moveToTargetY) {
if (positionX != moveToTargetX && (positionY == moveToTargetY || (positionY != moveToTargetY && moveAxisX == true))) {
const int moveX = moveToTargetX > positionX ? min(jumpDistance, moveToTargetX - positionX) : max(-jumpDistance, moveToTargetX - positionX);
Mouse.move(moveX, 0, 0);
positionX += moveX;
moveAxisX = false;
}
else {
const int moveY = moveToTargetY > positionY ? min(jumpDistance, moveToTargetY - positionY) : max(-jumpDistance, moveToTargetY - positionY);
Mouse.move(0, moveY, 0);
positionY += moveY;
moveAxisX = true;
}
}
else { //home or target position reached
if (homed == false) { //mouse is homed
Expand Down
1 change: 1 addition & 0 deletions MouseTo.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class MouseToClass {
int screenResolutionY;
float correctionFactor;
int8_t jumpDistance;
boolean moveAxisX;
};
extern MouseToClass MouseTo; //declare the class so it doesn't have to be done in the sketch
#endif //MouseTo_h
Expand Down

0 comments on commit 3713d07

Please sign in to comment.