Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix swapped axes #81

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/calibrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,21 @@ bool Calibrator::finish(int width, int height)
float y_min = (clicked.y[UL] + clicked.y[UR])/2.0;
float y_max = (clicked.y[LL] + clicked.y[LR])/2.0;

// Should x and y be swapped?
if (abs(clicked.x[UL] - clicked.x[UR]) < abs(clicked.y[UL] - clicked.y[UR])) {
// if axes are swaped we get the wrong min/max values
// so we calculate those values with swaped axes
if (abs(x_min - x_max) < 20 && abs(y_min - y_max) < 20) {
if(verbose)
printf("DEBUG: axes seem to be swaped\n");

new_axis.swap_xy = !new_axis.swap_xy;
std::swap(x_min, y_min);
std::swap(x_max, y_max);
std::swap(width, height);

x_min = (clicked.y[UL] + clicked.y[LL])/2.0;
x_max = (clicked.y[UR] + clicked.y[LR])/2.0;
y_min = (clicked.x[UL] + clicked.x[UR])/2.0;
y_max = (clicked.x[LL] + clicked.x[LR])/2.0;
}

// the screen was divided in num_blocks blocks, and the touch points were at
Expand Down
25 changes: 16 additions & 9 deletions src/calibrator/Evdev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,28 @@ bool CalibratorEvdev::finish(int width, int height)
// based on old_axys: inversion/swapping is relative to the old axis
XYinfo new_axis(old_axys);


// calculate average of clicks
float x_min = (clicked.x[UL] + clicked.x[LL])/2.0;
float x_max = (clicked.x[UR] + clicked.x[LR])/2.0;
float y_min = (clicked.y[UL] + clicked.y[UR])/2.0;
float y_max = (clicked.y[LL] + clicked.y[LR])/2.0;

// if axes are swaped we get the wrong min/max values
// so we calculate those values with swaped axes
if (abs(x_min - x_max) < 20 && abs(y_min - y_max) < 20) {
if(verbose)
printf("DEBUG: axes seem to be swaped\n");

new_axis.swap_xy = !new_axis.swap_xy;
std::swap(x_min, y_min);
std::swap(x_max, y_max);
std::swap(width, height);

x_min = (clicked.y[UL] + clicked.y[LL])/2.0;
x_max = (clicked.y[UR] + clicked.y[LR])/2.0;
y_min = (clicked.x[UL] + clicked.x[UR])/2.0;
y_max = (clicked.x[LL] + clicked.x[LR])/2.0;
}

// When evdev detects an invert_X/Y option,
// it performs the following *crazy* code just before returning
Expand All @@ -218,13 +233,6 @@ bool CalibratorEvdev::finish(int width, int height)
// end of evdev inversion crazyness


// Should x and y be swapped?
if (abs(clicked.x[UL] - clicked.x[UR]) < abs(clicked.y[UL] - clicked.y[UR])) {
new_axis.swap_xy = !new_axis.swap_xy;
std::swap(x_min, y_min);
std::swap(x_max, y_max);
}

// the screen was divided in num_blocks blocks, and the touch points were at
// one block away from the true edges of the screen.
const float block_x = width/(float)num_blocks;
Expand All @@ -248,7 +256,6 @@ bool CalibratorEvdev::finish(int width, int height)
y_min = scaleAxis(y_min, old_axys.y.max, old_axys.y.min, height, 0);
y_max = scaleAxis(y_max, old_axys.y.max, old_axys.y.min, height, 0);


// round and put in new_axis struct
new_axis.x.min = round(x_min); new_axis.x.max = round(x_max);
new_axis.y.min = round(y_min); new_axis.y.max = round(y_max);
Expand Down