diff --git a/src/calibrator.cpp b/src/calibrator.cpp index cdbd461..62c0527 100644 --- a/src/calibrator.cpp +++ b/src/calibrator.cpp @@ -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 diff --git a/src/calibrator/Evdev.cpp b/src/calibrator/Evdev.cpp index 0889056..1a0dfde 100644 --- a/src/calibrator/Evdev.cpp +++ b/src/calibrator/Evdev.cpp @@ -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 @@ -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; @@ -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);