2424#ifndef _calibrator_hh
2525#define _calibrator_hh
2626
27- // Abstract base class for calculating new calibration parameters
27+ #include < stdexcept>
28+ #include < X11/Xlib.h>
29+
30+ /*
31+ * Number of blocks. We partition the screen into 'num_blocks' x 'num_blocks'
32+ * rectangles of equal size. We then ask the user to press points that are
33+ * located at the corner closes to the center of the four blocks in the corners
34+ * of the screen. The following ascii art illustrates the situation. We partition
35+ * the screen into 8 blocks in each direction. We then let the user press the
36+ * points marked with 'O'.
37+ *
38+ * +--+--+--+--+--+--+--+--+
39+ * | | | | | | | | |
40+ * +--O--+--+--+--+--+--O--+
41+ * | | | | | | | | |
42+ * +--+--+--+--+--+--+--+--+
43+ * | | | | | | | | |
44+ * +--+--+--+--+--+--+--+--+
45+ * | | | | | | | | |
46+ * +--+--+--+--+--+--+--+--+
47+ * | | | | | | | | |
48+ * +--+--+--+--+--+--+--+--+
49+ * | | | | | | | | |
50+ * +--+--+--+--+--+--+--+--+
51+ * | | | | | | | | |
52+ * +--O--+--+--+--+--+--O--+
53+ * | | | | | | | | |
54+ * +--+--+--+--+--+--+--+--+
55+ */
56+ const int num_blocks = 8 ;
57+
58+ // / struct to hold min/max info of the X and Y axis
59+ struct XYinfo {
60+ int x_min;
61+ int x_max;
62+ int y_min;
63+ int y_max;
64+ XYinfo () : x_min(-1 ), x_max(-1 ), y_min(-1 ), y_max(-1 ) {}
65+ XYinfo (int xmi, int xma, int ymi, int yma) :
66+ x_min (xmi), x_max(xma), y_min(ymi), y_max(yma) {}
67+ };
68+
69+ // / Names of the points
70+ enum {
71+ UL = 0 , // Upper-left
72+ UR = 1 , // Upper-right
73+ LL = 2 , // Lower-left
74+ LR = 3 , // Lower-right
75+ NUM_POINTS
76+ };
77+
78+ // / Output types
79+ enum OutputType {
80+ OUTYPE_AUTO,
81+ OUTYPE_XORGCONFD,
82+ OUTYPE_HAL,
83+ OUTYPE_XINPUT
84+ };
85+
86+ class WrongCalibratorException : public std ::invalid_argument {
87+ public:
88+ WrongCalibratorException (const std::string& msg = " " ) :
89+ std::invalid_argument (msg) {}
90+ };
91+
92+ // / Base class for calculating new calibration parameters
2893class Calibrator
2994{
3095public:
31- /* Constructor for a specific calibrator
32- *
33- * The constructor will throw an exception,
34- * if the touchscreen is not of the type it supports
35- */
36- Calibrator (const char * const device_name, const XYinfo& axys,
37- const bool verbose, const int thr_misclick=0 , const int thr_doubleclick=0 , const OutputType output_type=OUTYPE_AUTO, const char * geometry=0 );
96+ // / Parse arguments and create calibrator
97+ static Calibrator* make_calibrator (int argc, char ** argv);
98+
99+ // / Constructor
100+ // /
101+ // / The constructor will throw an exception,
102+ // / if the touchscreen is not of the type it supports
103+ Calibrator (const char * const device_name,
104+ const XYinfo& axys,
105+ const bool verbose,
106+ const int thr_misclick=0 ,
107+ const int thr_doubleclick=0 ,
108+ const OutputType output_type=OUTYPE_AUTO,
109+ const char * geometry=0 );
110+
38111 ~Calibrator () {}
39112
40- // set the doubleclick treshold
113+ // / set the doubleclick treshold
41114 void set_threshold_doubleclick (int t);
42- // set the misclick treshold
115+
116+ // / set the misclick treshold
43117 void set_threshold_misclick (int t);
44- // get the number of clicks already registered
118+
119+ // / get the number of clicks already registered
45120 int get_numclicks ();
46- // return geometry string or NULL
121+
122+ // / return geometry string or NULL
47123 const char * get_geometry ();
48- // reset clicks
124+
125+ // / reset clicks
49126 void reset () {
50127 num_clicks = 0 ;
51128 }
52- // add a click with the given coordinates
129+
130+ // / add a click with the given coordinates
53131 bool add_click (int x, int y);
54- // calculate and apply the calibration
132+ // / calculate and apply the calibration
55133 bool finish (int width, int height);
56- // get the sysfs name of the device,
57- // returns NULL if it can not be found
134+ // / get the sysfs name of the device,
135+ // / returns NULL if it can not be found
58136 const char * get_sysfs_name ();
59137
60138protected:
@@ -73,7 +151,7 @@ protected:
73151 // nr of clicks registered
74152 int num_clicks;
75153 // click coordinates
76- int clicked_x[4 ], clicked_y[4 ];
154+ int clicked_x[NUM_POINTS ], clicked_y[NUM_POINTS ];
77155
78156 // Threshold to keep the same point from being clicked twice.
79157 // Set to zero if you don't want this check
0 commit comments