• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A generic touchscreen calibration program for X.Org


Commit MetaInfo

Revisionf984959413ee7f0a2b1004730382f3731a1f47ee (tree)
Time2010-01-24 07:16:49
AuthorTias Guns <tias@ulys...>
CommiterTias Guns

Log Message

make finish() and finish_data() return a boolean
also add comments to calibrator.hh

Change Summary

Incremental Difference

--- a/calibrator.cpp
+++ b/calibrator.cpp
@@ -48,8 +48,12 @@ bool Calibrator::add_click(double x, double y)
4848 return true;
4949 }
5050
51-void Calibrator::finish(int width, int height)
51+bool Calibrator::finish(int width, int height)
5252 {
53+ if (get_numclicks() != 4) {
54+ return false;
55+ }
56+
5357 // Should x and y be swapped?
5458 const bool swap_xy = (abs (clicked_x [UL] - clicked_x [UR]) < abs (clicked_y [UL] - clicked_y [UR]));
5559 if (swap_xy) {
@@ -83,6 +87,6 @@ void Calibrator::finish(int width, int height)
8387 std::swap(axys.y_min, axys.x_max);
8488 }
8589
86- // finish the data, driver specific
87- finish_data(axys, swap_xy);
90+ // finish the data, driver/calibrator specific
91+ return finish_data(axys, swap_xy);
8892 }
--- a/calibrator.hh
+++ b/calibrator.hh
@@ -28,19 +28,32 @@
2828 class Calibrator
2929 {
3030 public:
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+ */
3136 Calibrator(const char* const drivername, const XYinfo& axys);
3237 ~Calibrator() {}
3338
39+ // get the number of clicks already registered
3440 int get_numclicks();
41+ // add a click with the given coordinates
3542 bool add_click(double x, double y);
36- void finish(int width, int height);
43+ // calculate and apply the calibration
44+ bool finish(int width, int height);
3745
3846 protected:
39- virtual void finish_data(const XYinfo new_axys, int swap_xy) =0;
47+ // overloaded function that applies the new calibration
48+ virtual bool finish_data(const XYinfo new_axys, int swap_xy) =0;
4049
50+ // name of the device (driver)
4151 const char* const drivername;
52+ // original axys values
4253 XYinfo old_axys;
54+ // nr of clicks registered
4355 int num_clicks;
56+ // click coordinates
4457 double clicked_x[4], clicked_y[4];
4558 };
4659
--- a/calibrators/calibratorEvdev.cpp
+++ b/calibrators/calibratorEvdev.cpp
@@ -47,7 +47,7 @@ public:
4747 CalibratorEvdev(const char* const drivername, const XYinfo& axys);
4848 ~CalibratorEvdev();
4949
50- virtual void finish_data(const XYinfo new_axys, int swap_xy);
50+ virtual bool finish_data(const XYinfo new_axys, int swap_xy);
5151
5252 static Bool check_driver(const char* const name);
5353
@@ -121,13 +121,15 @@ CalibratorEvdev::~CalibratorEvdev () {
121121 XCloseDisplay(display);
122122 }
123123
124-void CalibratorEvdev::finish_data(const XYinfo new_axys, int swap_xy)
124+bool CalibratorEvdev::finish_data(const XYinfo new_axys, int swap_xy)
125125 {
126126 printf("\nTo make the settings permanent, create add a startup script for your window manager with the following command(s):\n");
127127 if (swap_xy)
128128 printf(" xinput set-int-prop \"%s\" \"Evdev Axes Swap\" 8 %d\n", drivername, swap_xy);
129129 printf(" xinput set-int-prop \"%s\" \"Evdev Axis Calibration\" 32 %d %d %d %d\n", drivername, new_axys.x_min, new_axys.x_max, new_axys.y_min, new_axys.y_max);
130130
131+ bool success = true;
132+
131133 printf("\nDoing dynamic recalibration:\n");
132134 // Evdev Axes Swap
133135 if (swap_xy) {
@@ -142,7 +144,8 @@ void CalibratorEvdev::finish_data(const XYinfo new_axys, int swap_xy)
142144 sprintf(str_swap_xy, "%d", swap_xy);
143145 arr_cmd[2] = str_swap_xy;
144146
145- do_set_prop(display, XA_INTEGER, 8, 3, arr_cmd);
147+ int ret = xinput_do_set_prop(display, XA_INTEGER, 8, 3, arr_cmd);
148+ success &= (ret == EXIT_SUCCESS);
146149 }
147150
148151 // Evdev Axis Calibration
@@ -166,10 +169,13 @@ void CalibratorEvdev::finish_data(const XYinfo new_axys, int swap_xy)
166169 sprintf(str_max_y, "%d", new_axys.y_max);
167170 arr_cmd[5] = str_max_y;
168171
169- do_set_prop(display, XA_INTEGER, 32, 6, arr_cmd);
172+ int ret = xinput_do_set_prop(display, XA_INTEGER, 32, 6, arr_cmd);
173+ success &= (ret == EXIT_SUCCESS);
170174
171175 // close
172176 XSync(display, False);
177+
178+ return success;
173179 }
174180
175181 Bool CalibratorEvdev::check_driver(const char *name) {
--- a/calibrators/calibratorUsbtouchscreen.cpp
+++ b/calibrators/calibratorUsbtouchscreen.cpp
@@ -54,7 +54,7 @@ public:
5454 CalibratorUsbtouchscreen(const char* const drivername, const XYinfo& axys);
5555 ~CalibratorUsbtouchscreen();
5656
57- virtual void finish_data(const XYinfo new_axys, int swap_xy);
57+ virtual bool finish_data(const XYinfo new_axys, int swap_xy);
5858
5959 protected:
6060 // Globals for kernel parameters from startup.
@@ -156,7 +156,7 @@ CalibratorUsbtouchscreen::~CalibratorUsbtouchscreen()
156156 write_bool_parameter (p_swap_xy, val_swap_xy);
157157 }
158158
159-void CalibratorUsbtouchscreen::finish_data(const XYinfo new_axys, int swap_xy)
159+bool CalibratorUsbtouchscreen::finish_data(const XYinfo new_axys, int swap_xy)
160160 {
161161 // New ranges
162162 const int range_x = (new_axys.x_max - new_axys.x_min);
@@ -183,7 +183,7 @@ void CalibratorUsbtouchscreen::finish_data(const XYinfo new_axys, int swap_xy)
183183 if (fid == NULL) {
184184 fprintf(stderr, "Error: Can't open '%s' for reading. Make sure you have the necesary rights\n", modprobe_conf_local);
185185 fprintf(stderr, "New calibration data NOT saved\n");
186- return;
186+ return false;
187187 }
188188
189189 std::string new_contents;
@@ -213,8 +213,10 @@ void CalibratorUsbtouchscreen::finish_data(const XYinfo new_axys, int swap_xy)
213213 if (fid == NULL) {
214214 fprintf(stderr, "Error: Can't open '%s' for writing. Make sure you have the necesary rights\n", modprobe_conf_local);
215215 fprintf(stderr, "New calibration data NOT saved\n");
216- return;
216+ return false;
217217 }
218218 fprintf(fid, "%s", new_contents.c_str ());
219219 fclose(fid);
220+
221+ return true;
220222 }
--- a/calibrators/calibratorXorgPrint.cpp
+++ b/calibrators/calibratorXorgPrint.cpp
@@ -29,7 +29,7 @@ class CalibratorXorgPrint: public Calibrator
2929 public:
3030 CalibratorXorgPrint(const char* const drivername, const XYinfo& axys);
3131
32- virtual void finish_data(const XYinfo new_axys, int swap_xy);
32+ virtual bool finish_data(const XYinfo new_axys, int swap_xy);
3333 };
3434
3535 CalibratorXorgPrint::CalibratorXorgPrint(const char* const drivername0, const XYinfo& axys0)
@@ -41,7 +41,7 @@ CalibratorXorgPrint::CalibratorXorgPrint(const char* const drivername0, const XY
4141 printf("\tIf the current calibration data is estimated wrong then either supply it manually with --precalib <minx> <maxx> <miny> <maxy> or run the 'get_precalib.sh' script to automatically get it from your current Xorg configuration (through hal).\n");
4242 }
4343
44-void CalibratorXorgPrint::finish_data(const XYinfo new_axys, int swap_xy)
44+bool CalibratorXorgPrint::finish_data(const XYinfo new_axys, int swap_xy)
4545 {
4646 // FDI policy output
4747 printf("\nNew method for making the calibration permanent: create an FDI policy file like /etc/hal/fdi/policy/touchscreen.fdi with:\n\
@@ -67,4 +67,6 @@ void CalibratorXorgPrint::finish_data(const XYinfo new_axys, int swap_xy)
6767 new_axys.y_max, old_axys.y_max);
6868 if (swap_xy != 0)
6969 printf("\tOption\t\"SwapXY\"\t\"%d\"\n", swap_xy);
70+
71+ return true;
7072 }
--- a/gui_gtkmm.cpp
+++ b/gui_gtkmm.cpp
@@ -213,9 +213,15 @@ bool CalibrationArea::on_button_press_event(GdkEventButton *event)
213213 // Are we done yet?
214214 if (calibrator->get_numclicks() >= 4) {
215215 // Recalibrate
216- calibrator->finish(display_width, display_height);
217-
218- exit(0);
216+ bool success = calibrator->finish(display_width, display_height);
217+
218+ if (success) {
219+ exit(0);
220+ } else {
221+ // TODO, in GUI ?
222+ fprintf(stderr, "Error: unable to apply or save configuration values");
223+ exit(1);
224+ }
219225 }
220226
221227 // Force a redraw
--- a/gui_x11.cpp
+++ b/gui_x11.cpp
@@ -265,9 +265,15 @@ bool GuiCalibratorX11::on_button_press_event(XEvent event)
265265 // Are we done yet?
266266 if (calibrator->get_numclicks() >= 4) {
267267 // Recalibrate
268- calibrator->finish(display_width, display_height);
269-
270- exit(0);
268+ bool success = calibrator->finish(display_width, display_height);
269+
270+ if (success) {
271+ exit(0);
272+ } else {
273+ // TODO, in GUI ?
274+ fprintf(stderr, "Error: unable to apply or save configuration values");
275+ exit(1);
276+ }
271277 }
272278
273279 // Force a redraw