Permalink
Browse files

Tester: test calibration routines and make assumptions explicit

The tester will serve to test the calibration code,
while doing so, it will make the assumptions about the calibration
in the driver (e.g. how it uses the calibration values, and
especially swap_xy and inversion and the like) explicit.

The goal is to give assurances about the correctness of the calibration,
without needing to have devices in all possible swapaxes/inversion
combinations.
  • Loading branch information...
tias committed Jun 13, 2012
1 parent 574f73f commit 0918b9aab65426dc1abd5f0af2387cdf4dbe12a1
Showing with 169 additions and 2 deletions.
  1. +5 −1 src/Makefile.am
  2. +2 −1 src/calibrator/Makefile.am
  3. +43 −0 src/calibrator/Tester.cpp
  4. +49 −0 src/calibrator/Tester.hpp
  5. +70 −0 src/tester.cpp
View
@@ -30,7 +30,7 @@ SUBDIRS = \
AM_CXXFLAGS = -Wall -ansi -pedantic
bin_PROGRAMS = xinput_calibrator
bin_PROGRAMS = xinput_calibrator tester
COMMON_SRCS=calibrator.cpp calibrator/XorgPrint.cpp calibrator/Evdev.cpp calibrator/Usbtouchscreen.cpp main_common.cpp
@@ -51,6 +51,10 @@ xinput_calibrator_CXXFLAGS = $(XINPUT_CFLAGS) $(GTKMM_CFLAGS) $(AM_CXXFLAGS)
xinput_calibrator_LDFLAGS = -Wl,--as-needed
endif
tester_SOURCES = tester.cpp calibrator.cpp calibrator/Tester.cpp
tester_LDADD = $(XINPUT_LIBS) $(XRANDR_LIBS) $(X11_LIBS)
tester_CXXFLAGS = $(XINPUT_CFLAGS) $(X11_CFLAGS) $(XRANDR_CFLAGS) $(AM_CXXFLAGS)
EXTRA_DIST = \
calibrator.cpp \
calibrator.hh \
@@ -1,4 +1,5 @@
EXTRA_DIST = \
Evdev.cpp \
Usbtouchscreen.cpp \
XorgPrint.cpp
XorgPrint.cpp \
Tester.cpp
View
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2009 Tias Guns
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "calibrator/Tester.hpp"
#include <cstdio>
CalibratorTester::CalibratorTester(const char* const device_name0, const XYinfo& axys0, const int thr_misclick, const int thr_doubleclick, const OutputType output_type, const char* geometry)
: Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry)
{
//printf("Starting test driver\n");
}
bool CalibratorTester::finish_data(const XYinfo axis)
{
new_axis = axis;
return true;
}
XYinfo CalibratorTester::emulate_driver(XYinfo raw, bool useNewAxis) {
// filler
return XYinfo(0,0,0,0);
}
View
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2009 Tias Guns
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef CALIBRATOR_TESTER_HPP
#define CALIBRATOR_TESTER_HPP
#include "calibrator.hh"
/***************************************
* Class for generic Xorg driver,
* outputs new Xorg.conf and FDI policy, on stdout
***************************************/
class CalibratorTester: public Calibrator
{
protected:
// store the new axis for use in driver emulation
XYinfo new_axis;
public:
CalibratorTester(const char* const device_name, const XYinfo& axys,
const int thr_misclick=0, const int thr_doubleclick=0,
const OutputType output_type=OUTYPE_AUTO, const char* geometry=0);
virtual bool finish_data(const XYinfo new_axis);
// emulate the driver processing the coordinates in 'raw'
XYinfo emulate_driver(XYinfo raw, bool useNewAxis);
};
#endif
View
@@ -0,0 +1,70 @@
#include <algorithm>
#include <stdio.h>
#include <vector>
#include "calibrator.hh"
#include "calibrator/Tester.hpp"
int main() {
// screen dimensions
int width = 800;
int height = 600;
XYinfo screen_res(0, width, 0, height);
int delta_x = width/(float)num_blocks;
int delta_y = height/(float)num_blocks;
XYinfo target(delta_x, width-delta_x, delta_y, height-delta_y);
int slack = 2; // amount of pixels result can be off target
XYinfo dev_res(0, 1000, 0, 1000);
XYinfo old_axis(0, 1000, 0, 1000);
// raw device coordinates to emulate
std::vector<XYinfo> raw_coords;
// normal
raw_coords.push_back( XYinfo(105, 783, 233, 883) );
// invert x, y, x+y
raw_coords.push_back( XYinfo(783, 105, 233, 883) );
raw_coords.push_back( XYinfo(105, 783, 883, 233) );
raw_coords.push_back( XYinfo(783, 105, 883, 233) );
// swap
raw_coords.push_back( XYinfo(233, 883, 105, 783) );
// swap and inverts
raw_coords.push_back( XYinfo(233, 883, 783, 105) );
raw_coords.push_back( XYinfo(883, 233, 105, 783) );
raw_coords.push_back( XYinfo(883, 233, 783, 105) );
CalibratorTester calib("Tester", old_axis);
for (unsigned c=0; c != raw_coords.size(); c++) {
XYinfo raw(raw_coords[c]);
printf("Raw: "); raw.print();
// clicked from raw
XYinfo clicked = calib.emulate_driver(raw, false);//false=old_axis, screen_res, dev_res);
printf("Clicked: "); clicked.print();
// emulate screen clicks
calib.add_click(clicked.x.min, clicked.y.min);
calib.add_click(clicked.x.max, clicked.y.min);
calib.add_click(clicked.x.min, clicked.y.max);
calib.add_click(clicked.x.max, clicked.y.max);
calib.finish(width, height);
// test result
XYinfo result = calib.emulate_driver(raw, true); // true=new_axis
if (abs(target.x.min - result.x.min) > slack ||
abs(target.x.max - result.x.max) > slack ||
abs(target.y.min - result.y.min) > slack ||
abs(target.y.max - result.y.max) > slack) {
printf("Error: difference between target and result > %i:\n", slack);
printf("\tTarget: "); target.print();
printf("\tResult: "); result.print();
exit(1);
}
printf("OK\n");
} // loop over raw_coords
}

0 comments on commit 0918b9a

Please sign in to comment.