• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

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

Révisiond76117be4fb6032849130b97f1063684d8d83003 (tree)
l'heure2010-08-16 06:52:23
AuteurTias Guns <tias@ulys...>
CommiterTias Guns

Message de Log

sysfs name detection, checks whether device name is sysfs name

Change Summary

Modification

--- a/src/calibrator.cpp
+++ b/src/calibrator.cpp
@@ -21,6 +21,12 @@
2121 * THE SOFTWARE.
2222 */
2323 #include <algorithm>
24+#include <sys/types.h>
25+#include <dirent.h>
26+#include <iostream>
27+#include <fstream>
28+#include <string>
29+
2430 #include "calibrator.hh"
2531
2632 Calibrator::Calibrator(const char* const device_name0, const XYinfo& axys0,
@@ -160,3 +166,50 @@ bool Calibrator::finish(int width, int height)
160166 // finish the data, driver/calibrator specific
161167 return finish_data(axys, swap_xy);
162168 }
169+
170+const char* Calibrator::get_sysfs_name()
171+{
172+ if (is_sysfs_name(device_name))
173+ return device_name;
174+
175+ // TODO: more mechanisms
176+
177+ return NULL;
178+}
179+
180+bool Calibrator::is_sysfs_name(const char* name) {
181+ const char* SYSFS_INPUT="/sys/class/input";
182+ const char* SYSFS_DEVNAME="device/name";
183+
184+ DIR* dp = opendir(SYSFS_INPUT);
185+ if (dp == NULL)
186+ return false;
187+
188+ while (dirent* ep = readdir(dp)) {
189+ if (strncmp(ep->d_name, "event", strlen("event")) == 0) {
190+ // got event name, get its sysfs device name
191+ char filename[40]; // actually 35, but hey...
192+ (void) sprintf(filename, "%s/%s/%s", SYSFS_INPUT, ep->d_name, SYSFS_DEVNAME);
193+
194+ std::ifstream ifile(filename);
195+ if (ifile.is_open()) {
196+ if (!ifile.eof()) {
197+ std::string devname;
198+ std::getline(ifile, devname);
199+ if (devname == name) {
200+ if (verbose)
201+ printf("DEBUG: Found that '%s' is a sysfs name.\n", name);
202+ return true;
203+ }
204+ }
205+ ifile.close();
206+ }
207+ }
208+ }
209+ (void) closedir(dp);
210+
211+ if (verbose)
212+ printf("DEBUG: Name '%s' does not match any in '%s/event*/%s'\n",
213+ name, SYSFS_INPUT, SYSFS_DEVNAME);
214+ return false;
215+}
--- a/src/calibrator.hh
+++ b/src/calibrator.hh
@@ -51,6 +51,9 @@ public:
5151 bool add_click(int x, int y);
5252 // calculate and apply the calibration
5353 bool finish(int width, int height);
54+ // get the sysfs name of the device,
55+ // returns NULL if it can not be found
56+ const char* get_sysfs_name();
5457
5558 protected:
5659 // check whether the coordinates are along the respective axis
@@ -78,6 +81,9 @@ protected:
7881 // A lower value forces more precise calibration
7982 // Set to zero if you don't want this check
8083 int threshold_misclick;
84+
85+ // Check whether the given name is a sysfs device name
86+ bool is_sysfs_name(const char* name);
8187 };
8288
8389 #endif