Skip to content

Commit e43e686

Browse files
committed
Managing correctly X/Y swap and X or Y inversion:
- detect swap and inversion modification - take into account for inversion in calibration computation since Evdev is doing inversion after calibration. - Mainly tested for Evdev based driver. To be tested for USB. Sorting outputs to stdout in such a way to only get calibration commands at output => scriptable.
1 parent b217e59 commit e43e686

File tree

12 files changed

+820
-642
lines changed

12 files changed

+820
-642
lines changed

src/calibrator.cpp

Lines changed: 220 additions & 120 deletions
Large diffs are not rendered by default.

src/calibrator.hh

Lines changed: 80 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* Copyright (c) 2009 Tias Guns
33
* Copyright (c) 2009 Soren Hauberg
4+
* Copyright (c) 2011 Antoine Hue
45
*
56
* Permission is hereby granted, free of charge, to any person obtaining a copy
67
* of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +27,7 @@
2627

2728
#include <stdexcept>
2829
#include <X11/Xlib.h>
30+
#include <vector>
2931

3032
/*
3133
* Number of blocks. We partition the screen into 'num_blocks' x 'num_blocks'
@@ -55,15 +57,23 @@
5557
*/
5658
const int num_blocks = 8;
5759

60+
struct AxisInfo {
61+
int min, max;
62+
bool invert;
63+
AxisInfo() : min(-1), max(-1), invert(false) { }
64+
};
65+
5866
/// struct to hold min/max info of the X and Y axis
5967
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) {}
68+
/// Axis swapped
69+
bool swap_xy;
70+
/// X, Y axis
71+
AxisInfo x, y;
72+
73+
XYinfo() : swap_xy(false) {}
74+
75+
XYinfo(int xmi, int xma, int ymi, int yma, bool swap_xy_ = false):
76+
swap_xy(swap_xy_) { x.min = xmi; x.max = xma; y.min = ymi; y.max = yma;}
6777
};
6878

6979
/// Names of the points
@@ -92,7 +102,7 @@ class WrongCalibratorException : public std::invalid_argument {
92102
/// Base class for calculating new calibration parameters
93103
class Calibrator
94104
{
95-
public:
105+
public:
96106
/// Parse arguments and create calibrator
97107
static Calibrator* make_calibrator(int argc, char** argv);
98108

@@ -102,30 +112,33 @@ public:
102112
/// if the touchscreen is not of the type it supports
103113
Calibrator(const char* const device_name,
104114
const XYinfo& axys,
105-
const bool verbose,
106115
const int thr_misclick=0,
107116
const int thr_doubleclick=0,
108117
const OutputType output_type=OUTYPE_AUTO,
109118
const char* geometry=0);
110119

111-
~Calibrator() {}
120+
~Calibrator()
121+
{}
112122

113-
/// set the doubleclick treshold
114-
void set_threshold_doubleclick(int t);
115-
123+
/// set the doubleclick treshold
124+
void set_threshold_doubleclick(int t)
125+
{ threshold_doubleclick = t; }
126+
116127
/// set the misclick treshold
117-
void set_threshold_misclick(int t);
118-
128+
void set_threshold_misclick(int t)
129+
{ threshold_misclick = t; }
130+
119131
/// get the number of clicks already registered
120-
int get_numclicks();
132+
int get_numclicks() const
133+
{ return clicked.num; }
121134

122135
/// return geometry string or NULL
123-
const char* get_geometry();
136+
const char* get_geometry() const
137+
{ return geometry; }
124138

125139
/// reset clicks
126-
void reset() {
127-
num_clicks = 0;
128-
}
140+
void reset()
141+
{ clicked.num = 0; clicked.x.clear(); clicked.y.clear();}
129142

130143
/// add a click with the given coordinates
131144
bool add_click(int x, int y);
@@ -136,22 +149,54 @@ public:
136149
const char* get_sysfs_name();
137150

138151
protected:
139-
// check whether the coordinates are along the respective axis
152+
/// check whether the coordinates are along the respective axis
140153
bool along_axis(int xy, int x0, int y0);
141154

142-
// overloaded function that applies the new calibration
143-
virtual bool finish_data(const XYinfo new_axys, int swap_xy) =0;
144-
155+
/// Apply new calibration, implementation dependent
156+
///\param[in] swap_xy if true, X and Y axes are swapped
157+
///\param[in] invert_x if true, X axis is inverted
158+
///\param[in] invert_y if true, Y axis is inverted
159+
virtual bool finish_data(const XYinfo new_axys ) =0;
160+
161+
/// Compute calibration on 1 axis
162+
void process_axys( int screen_dim, const AxisInfo &previous, std::vector<int> &clicked, AxisInfo &updated );
163+
164+
/// Check whether the given name is a sysfs device name
165+
bool is_sysfs_name(const char* name);
166+
167+
/// Check whether the X server has xorg.conf.d support
168+
bool has_xorgconfd_support(Display* display=NULL);
169+
170+
/// Write output calibration (to stdout)
171+
void output ( const char *format, ... );
172+
173+
/// Write information to user, if verbose mode activated
174+
static void info ( const char *format, ... );
175+
176+
/// Trace debug information if verbose activated
177+
static void trace ( const char *format, ...);
178+
179+
/// Write error (non fatal)
180+
static void error ( const char *format, ...);
181+
182+
static int find_device(const char* pre_device, bool list_devices,
183+
XID& device_id, const char*& device_name, XYinfo& device_axys);
184+
protected:
185+
// be verbose or not
186+
static bool verbose;
187+
145188
// name of the device (driver)
146189
const char* const device_name;
147-
// original axys values
148-
XYinfo old_axys;
149-
// be verbose or not
150-
bool verbose;
151-
// nr of clicks registered
152-
int num_clicks;
153-
// click coordinates
154-
int clicked_x[NUM_POINTS], clicked_y[NUM_POINTS];
190+
/// Original values
191+
XYinfo old_axys;
192+
193+
/// Clicked values (screen coordinates)
194+
struct {
195+
/// actual number of clicks registered
196+
int num;
197+
/// click coordinates
198+
std::vector<int> x, y;
199+
} clicked;
155200

156201
// Threshold to keep the same point from being clicked twice.
157202
// Set to zero if you don't want this check
@@ -162,17 +207,11 @@ protected:
162207
// Set to zero if you don't want this check
163208
int threshold_misclick;
164209

165-
// Type of output
210+
/// Format or type of output calibration
166211
OutputType output_type;
167212

168-
// manually specified geometry string
169-
const char* geometry;
170-
171-
// Check whether the given name is a sysfs device name
172-
bool is_sysfs_name(const char* name);
173-
174-
// Check whether the X server has xorg.conf.d support
175-
bool has_xorgconfd_support(Display* display=NULL);
213+
/// manually specified geometry string for the calibration pattern
214+
const char* geometry;
176215
};
177216

178217
#endif

0 commit comments

Comments
 (0)