A generic touchscreen calibration program for X.Org
Révision | d76117be4fb6032849130b97f1063684d8d83003 (tree) |
---|---|
l'heure | 2010-08-16 06:52:23 |
Auteur | Tias Guns <tias@ulys...> |
Commiter | Tias Guns |
sysfs name detection, checks whether device name is sysfs name
@@ -21,6 +21,12 @@ | ||
21 | 21 | * THE SOFTWARE. |
22 | 22 | */ |
23 | 23 | #include <algorithm> |
24 | +#include <sys/types.h> | |
25 | +#include <dirent.h> | |
26 | +#include <iostream> | |
27 | +#include <fstream> | |
28 | +#include <string> | |
29 | + | |
24 | 30 | #include "calibrator.hh" |
25 | 31 | |
26 | 32 | Calibrator::Calibrator(const char* const device_name0, const XYinfo& axys0, |
@@ -160,3 +166,50 @@ bool Calibrator::finish(int width, int height) | ||
160 | 166 | // finish the data, driver/calibrator specific |
161 | 167 | return finish_data(axys, swap_xy); |
162 | 168 | } |
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 | +} |
@@ -51,6 +51,9 @@ public: | ||
51 | 51 | bool add_click(int x, int y); |
52 | 52 | // calculate and apply the calibration |
53 | 53 | 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(); | |
54 | 57 | |
55 | 58 | protected: |
56 | 59 | // check whether the coordinates are along the respective axis |
@@ -78,6 +81,9 @@ protected: | ||
78 | 81 | // A lower value forces more precise calibration |
79 | 82 | // Set to zero if you don't want this check |
80 | 83 | int threshold_misclick; |
84 | + | |
85 | + // Check whether the given name is a sysfs device name | |
86 | + bool is_sysfs_name(const char* name); | |
81 | 87 | }; |
82 | 88 | |
83 | 89 | #endif |