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;
79 ecore_fb_ts_init(void)
82 char *tslib_tsdevice = NULL;
83 if ( (tslib_tsdevice = getenv("TSLIB_TSDEVICE")) )
85 printf( "ECORE_FB: TSLIB_TSDEVICE = '%s'\n", tslib_tsdevice );
86 _ecore_fb_tslib_tsdev = ts_open( tslib_tsdevice, 1 ); /* 1 = nonblocking, 0 = blocking */
88 if ( !_ecore_fb_tslib_tsdev )
90 printf( "ECORE_FB: Can't ts_open (%s)\n", strerror( errno ) );
94 if ( ts_config( _ecore_fb_tslib_tsdev ) )
96 printf( "ECORE_FB: Can't ts_config (%s)\n", strerror( errno ) );
99 _ecore_fb_ts_fd = ts_fd( _ecore_fb_tslib_tsdev );
100 if ( _ecore_fb_ts_fd < 0 )
102 printf( "ECORE_FB: Can't open touchscreen (%s)\n", strerror( errno ) );
107 _ecore_fb_ts_fd = open("/dev/touchscreen/0", O_RDONLY);
109 if (_ecore_fb_ts_fd >= 0)
111 _ecore_fb_ts_fd_handler_handle = ecore_main_fd_handler_add(_ecore_fb_ts_fd,
113 _ecore_fb_ts_fd_handler, NULL,
115 if (!_ecore_fb_ts_fd_handler_handle)
117 close(_ecore_fb_ts_fd);
120 // FIXME _ecore_fb_kbd_fd = open("/dev/touchscreen/key", O_RDONLY);
127 ecore_fb_ts_shutdown(void)
129 if (_ecore_fb_ts_fd_handler_handle)
130 ecore_main_fd_handler_del(_ecore_fb_ts_fd_handler_handle);
131 if (_ecore_fb_ts_fd >= 0) close(_ecore_fb_ts_fd);
132 _ecore_fb_ts_fd = -1;
133 _ecore_fb_ts_fd_handler_handle = NULL;
137 * @defgroup Ecore_FB_Calibrate_Group Framebuffer Calibration Functions
139 * Functions that calibrate the screen.
144 * Calibrates the touschreen using the given parameters.
145 * @param xscale X scaling, where 256 = 1.0
146 * @param xtrans X translation.
147 * @param yscale Y scaling.
148 * @param ytrans Y translation.
149 * @param xyswap Swap X & Y flag.
150 * @ingroup Ecore_FB_Calibrate_Group
153 ecore_fb_touch_screen_calibrate_set(int xscale, int xtrans, int yscale, int ytrans, int xyswap)
155 Ecore_Fb_Ts_Calibrate cal;
157 if (_ecore_fb_ts_fd < 0) return;
163 if (ioctl(_ecore_fb_ts_fd, TS_SET_CAL, (void *)&cal))
165 _ecore_fb_ts_cal = cal;
166 _ecore_fb_ts_apply_cal = 1;
172 * Retrieves the calibration parameters of the touchscreen.
173 * @param xscale Pointer to an integer in which to store the X scaling.
174 * Note that 256 = 1.0.
175 * @param xtrans Pointer to an integer in which to store the X translation.
176 * @param yscale Pointer to an integer in which to store the Y scaling.
177 * @param ytrans Pointer to an integer in which to store the Y translation.
178 * @param xyswap Pointer to an integer in which to store the Swap X & Y flag.
179 * @ingroup Ecore_FB_Calibrate_Group
182 ecore_fb_touch_screen_calibrate_get(int *xscale, int *xtrans, int *yscale, int *ytrans, int *xyswap)
184 Ecore_Fb_Ts_Calibrate cal;
186 if (_ecore_fb_ts_fd < 0) return;
187 if (!_ecore_fb_ts_apply_cal)
189 if (ioctl(_ecore_fb_ts_fd, TS_GET_CAL, (void *)&cal))
190 _ecore_fb_ts_cal = cal;
194 cal = _ecore_fb_ts_cal;
195 if (xscale) *xscale = cal.xscale;
196 if (xtrans) *xtrans = cal.xtrans;
197 if (yscale) *yscale = cal.yscale;
198 if (ytrans) *ytrans = cal.ytrans;
199 if (xyswap) *xyswap = cal.xyswap;
203 _ecore_fb_ts_fd_handler(void *data __UNUSED__, Ecore_Fd_Handler *fd_handler __UNUSED__)
205 static int prev_x = 0, prev_y = 0, prev_pressure = 0;
206 static double last_time = 0;
207 static double last_last_time = 0;
219 if (_ecore_fb_ts_apply_cal)
220 num = ts_read_raw(_ecore_fb_tslib_tsdev, &_ecore_fb_tslib_event, 1);
222 num = ts_read(_ecore_fb_tslib_tsdev, &_ecore_fb_tslib_event, 1);
223 if (num != 1) return 1; /* no more samples at this time */
224 x = _ecore_fb_tslib_event.x;
225 y = _ecore_fb_tslib_event.y;
226 pressure = _ecore_fb_tslib_event.pressure;
227 v = 1; /* loop, there might be more samples */
228 t = ecore_time_get();
230 ptr = (char *)&(_ecore_fb_ts_event);
231 ptr += _ecore_fb_ts_event_byte_count;
232 num = sizeof(Ecore_Fb_Ts_Event) - _ecore_fb_ts_event_byte_count;
233 v = read(_ecore_fb_ts_fd, ptr, num);
235 _ecore_fb_ts_event_byte_count += v;
236 if (v < num) return 1;
237 _ecore_fb_ts_event_byte_count = 0;
238 if (_ecore_fb_ts_apply_cal)
240 x = ((_ecore_fb_ts_cal.xscale * _ecore_fb_ts_event.x) >> 8) + _ecore_fb_ts_cal.xtrans;
241 y = ((_ecore_fb_ts_cal.yscale * _ecore_fb_ts_event.y) >> 8) + _ecore_fb_ts_cal.ytrans;
245 x = _ecore_fb_ts_event.x;
246 y = _ecore_fb_ts_event.y;
248 pressure = _ecore_fb_ts_event.pressure;
250 /* add event to queue */
251 /* always add a move event */
252 if ((pressure) || (prev_pressure))
254 /* MOVE: mouse is down and was */
255 Ecore_Fb_Event_Mouse_Move *e;
257 e = calloc(1, sizeof(Ecore_Fb_Event_Mouse_Move));
261 ecore_event_add(ECORE_FB_EVENT_MOUSE_MOVE, e, NULL, NULL);
263 if ((pressure) && (!prev_pressure))
265 /* DOWN: mouse is down, but was not now */
266 Ecore_Fb_Event_Mouse_Button_Down *e;
268 e = calloc(1, sizeof(Ecore_Fb_Event_Mouse_Button_Down));
273 if ((t - last_time) <= _ecore_fb_double_click_time)
275 if ((t - last_last_time) <= (2 * _ecore_fb_double_click_time))
280 ecore_event_add(ECORE_FB_EVENT_MOUSE_BUTTON_DOWN, e, NULL, NULL);
282 else if ((!pressure) && (prev_pressure))
284 /* UP: mouse was down, but is not now */
285 Ecore_Fb_Event_Mouse_Button_Up *e;
287 e = calloc(1, sizeof(Ecore_Fb_Event_Mouse_Button_Up));
292 ecore_event_add(ECORE_FB_EVENT_MOUSE_BUTTON_UP, e, NULL, NULL);
301 last_last_time = last_time;
307 prev_pressure = pressure;