11 #include "ecore_fb_private.h"
13 typedef struct _Ecore_Fb_Ts_Event Ecore_Fb_Ts_Event;
14 typedef struct _Ecore_Fb_Ts_Calibrate Ecore_Fb_Ts_Calibrate;
15 typedef struct _Ecore_Fb_Ts_Backlight Ecore_Fb_Ts_Backlight;
16 typedef struct _Ecore_Fb_Ts_Contrast Ecore_Fb_Ts_Contrast;
17 typedef struct _Ecore_Fb_Ts_Led Ecore_Fb_Ts_Led;
18 typedef struct _Ecore_Fb_Ts_Flite Ecore_Fb_Ts_Flite;
20 struct _Ecore_Fb_Ts_Event
22 unsigned short pressure;
25 unsigned short _unused;
28 struct _Ecore_Fb_Ts_Calibrate
37 struct _Ecore_Fb_Ts_Backlight
40 unsigned char brightness;
43 struct _Ecore_Fb_Ts_Contrast
45 unsigned char contrast;
48 struct _Ecore_Fb_Ts_Led
51 unsigned char blink_time;
52 unsigned char on_time;
53 unsigned char off_time;
56 struct _Ecore_Fb_Ts_Flite
60 unsigned char brightness;
63 static Eina_Bool _ecore_fb_ts_fd_handler(void *data, Ecore_Fd_Handler *fd_handler);
64 static int _ecore_fb_ts_fd = -1;
65 static int _ecore_fb_ts_event_byte_count = 0;
66 static int _ecore_fb_ts_apply_cal = 0;
67 static Ecore_Fb_Ts_Event _ecore_fb_ts_event;
68 static Ecore_Fb_Ts_Calibrate _ecore_fb_ts_cal = {1,1,0,0,0};
69 static Ecore_Fd_Handler *_ecore_fb_ts_fd_handler_handle = NULL;
72 struct tsdev *_ecore_fb_tslib_tsdev = NULL;
73 struct ts_sample _ecore_fb_tslib_event;
76 static double _ecore_fb_double_click_time = 0.25;
77 static void *_ecore_fb_ts_event_window = NULL;
80 ecore_fb_ts_init(void)
83 char *tslib_tsdevice = NULL;
84 if ( (tslib_tsdevice = getenv("TSLIB_TSDEVICE")) )
86 printf( "ECORE_FB: TSLIB_TSDEVICE = '%s'\n", tslib_tsdevice );
87 _ecore_fb_tslib_tsdev = ts_open( tslib_tsdevice, 1 ); /* 1 = nonblocking, 0 = blocking */
89 if ( !_ecore_fb_tslib_tsdev )
91 printf( "ECORE_FB: Can't ts_open (%s)\n", strerror( errno ) );
95 if ( ts_config( _ecore_fb_tslib_tsdev ) )
97 printf( "ECORE_FB: Can't ts_config (%s)\n", strerror( errno ) );
100 _ecore_fb_ts_fd = ts_fd( _ecore_fb_tslib_tsdev );
101 if ( _ecore_fb_ts_fd < 0 )
103 printf( "ECORE_FB: Can't open touchscreen (%s)\n", strerror( errno ) );
108 _ecore_fb_ts_fd = open("/dev/touchscreen/0", O_RDONLY);
110 if (_ecore_fb_ts_fd >= 0)
112 _ecore_fb_ts_fd_handler_handle = ecore_main_fd_handler_add(_ecore_fb_ts_fd,
114 _ecore_fb_ts_fd_handler, NULL,
116 if (!_ecore_fb_ts_fd_handler_handle)
118 close(_ecore_fb_ts_fd);
121 // FIXME _ecore_fb_kbd_fd = open("/dev/touchscreen/key", O_RDONLY);
128 ecore_fb_ts_shutdown(void)
130 if (_ecore_fb_ts_fd_handler_handle)
131 ecore_main_fd_handler_del(_ecore_fb_ts_fd_handler_handle);
132 if (_ecore_fb_ts_fd >= 0) close(_ecore_fb_ts_fd);
133 _ecore_fb_ts_fd = -1;
134 _ecore_fb_ts_fd_handler_handle = NULL;
135 _ecore_fb_ts_event_window = NULL;
139 ecore_fb_ts_event_window_set(void *window)
141 _ecore_fb_ts_event_window = window;
145 ecore_fb_ts_event_window_get(void)
147 return _ecore_fb_ts_event_window;
151 * @defgroup Ecore_FB_Calibrate_Group Framebuffer Calibration Functions
153 * Functions that calibrate the screen.
158 * Calibrates the touschreen using the given parameters.
159 * @param xscale X scaling, where 256 = 1.0
160 * @param xtrans X translation.
161 * @param yscale Y scaling.
162 * @param ytrans Y translation.
163 * @param xyswap Swap X & Y flag.
164 * @ingroup Ecore_FB_Calibrate_Group
167 ecore_fb_touch_screen_calibrate_set(int xscale, int xtrans, int yscale, int ytrans, int xyswap)
169 Ecore_Fb_Ts_Calibrate cal;
171 if (_ecore_fb_ts_fd < 0) return;
177 if (ioctl(_ecore_fb_ts_fd, TS_SET_CAL, (void *)&cal))
179 _ecore_fb_ts_cal = cal;
180 _ecore_fb_ts_apply_cal = 1;
185 * Retrieves the calibration parameters of the touchscreen.
186 * @param xscale Pointer to an integer in which to store the X scaling.
187 * Note that 256 = 1.0.
188 * @param xtrans Pointer to an integer in which to store the X translation.
189 * @param yscale Pointer to an integer in which to store the Y scaling.
190 * @param ytrans Pointer to an integer in which to store the Y translation.
191 * @param xyswap Pointer to an integer in which to store the Swap X & Y flag.
192 * @ingroup Ecore_FB_Calibrate_Group
195 ecore_fb_touch_screen_calibrate_get(int *xscale, int *xtrans, int *yscale, int *ytrans, int *xyswap)
197 Ecore_Fb_Ts_Calibrate cal;
199 if (_ecore_fb_ts_fd < 0) return;
200 if (!_ecore_fb_ts_apply_cal)
202 if (ioctl(_ecore_fb_ts_fd, TS_GET_CAL, (void *)&cal))
203 _ecore_fb_ts_cal = cal;
206 cal = _ecore_fb_ts_cal;
207 if (xscale) *xscale = cal.xscale;
208 if (xtrans) *xtrans = cal.xtrans;
209 if (yscale) *yscale = cal.yscale;
210 if (ytrans) *ytrans = cal.ytrans;
211 if (xyswap) *xyswap = cal.xyswap;
215 _ecore_fb_ts_fd_handler(void *data __UNUSED__, Ecore_Fd_Handler *fd_handler __UNUSED__)
217 static int prev_x = 0, prev_y = 0, prev_pressure = 0;
218 static double last_time = 0;
219 static double last_last_time = 0;
228 static int did_double = 0;
229 static int did_triple = 0;
232 if (_ecore_fb_ts_apply_cal)
233 num = ts_read_raw(_ecore_fb_tslib_tsdev, &_ecore_fb_tslib_event, 1);
235 num = ts_read(_ecore_fb_tslib_tsdev, &_ecore_fb_tslib_event, 1);
236 if (num != 1) return 1; /* no more samples at this time */
237 x = _ecore_fb_tslib_event.x;
238 y = _ecore_fb_tslib_event.y;
239 pressure = _ecore_fb_tslib_event.pressure;
240 v = 1; /* loop, there might be more samples */
242 ptr = (char *)&(_ecore_fb_ts_event);
243 ptr += _ecore_fb_ts_event_byte_count;
244 num = sizeof(Ecore_Fb_Ts_Event) - _ecore_fb_ts_event_byte_count;
245 v = read(_ecore_fb_ts_fd, ptr, num);
247 _ecore_fb_ts_event_byte_count += v;
248 if (v < num) return 1;
249 _ecore_fb_ts_event_byte_count = 0;
250 if (_ecore_fb_ts_apply_cal)
252 x = ((_ecore_fb_ts_cal.xscale * _ecore_fb_ts_event.x) >> 8) + _ecore_fb_ts_cal.xtrans;
253 y = ((_ecore_fb_ts_cal.yscale * _ecore_fb_ts_event.y) >> 8) + _ecore_fb_ts_cal.ytrans;
257 x = _ecore_fb_ts_event.x;
258 y = _ecore_fb_ts_event.y;
260 pressure = _ecore_fb_ts_event.pressure;
262 t = ecore_loop_time_get();
263 /* add event to queue */
264 /* always add a move event */
265 if ((pressure) || (prev_pressure))
267 /* MOVE: mouse is down and was */
268 Ecore_Event_Mouse_Move *e;
270 e = calloc(1, sizeof(Ecore_Event_Mouse_Move));
277 e->event_window = e->window;
278 e->root_window = e->window;
280 e->timestamp = ecore_loop_time_get() * 1000.0;
281 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, e, NULL, NULL);
283 if ((pressure) && (!prev_pressure))
285 /* DOWN: mouse is down, but was not now */
286 Ecore_Event_Mouse_Button *e;
288 e = calloc(1, sizeof(Ecore_Event_Mouse_Button));
295 if ((t - last_time) <= _ecore_fb_double_click_time)
305 if ((t - last_last_time) <= (2 * _ecore_fb_double_click_time))
315 e->event_window = e->window;
316 e->root_window = e->window;
318 e->timestamp = ecore_loop_time_get() * 1000.0;
319 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, e, NULL, NULL);
321 else if ((!pressure) && (prev_pressure))
323 /* UP: mouse was down, but is not now */
324 Ecore_Event_Mouse_Button *e;
326 e = calloc(1, sizeof(Ecore_Event_Mouse_Button));
338 e->event_window = e->window;
339 e->root_window = e->window;
341 e->timestamp = ecore_loop_time_get() * 1000.0;
342 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, e, NULL, NULL);
351 last_last_time = last_time;
357 prev_pressure = pressure;