2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
15 #include "ecore_fb_private.h"
17 typedef struct _Ecore_Fb_Ts_Event Ecore_Fb_Ts_Event;
18 typedef struct _Ecore_Fb_Ts_Calibrate Ecore_Fb_Ts_Calibrate;
19 typedef struct _Ecore_Fb_Ts_Backlight Ecore_Fb_Ts_Backlight;
20 typedef struct _Ecore_Fb_Ts_Contrast Ecore_Fb_Ts_Contrast;
21 typedef struct _Ecore_Fb_Ts_Led Ecore_Fb_Ts_Led;
22 typedef struct _Ecore_Fb_Ts_Flite Ecore_Fb_Ts_Flite;
24 struct _Ecore_Fb_Ts_Event
26 unsigned short pressure;
29 unsigned short _unused;
32 struct _Ecore_Fb_Ts_Calibrate
41 struct _Ecore_Fb_Ts_Backlight
44 unsigned char brightness;
47 struct _Ecore_Fb_Ts_Contrast
49 unsigned char contrast;
52 struct _Ecore_Fb_Ts_Led
55 unsigned char blink_time;
56 unsigned char on_time;
57 unsigned char off_time;
60 struct _Ecore_Fb_Ts_Flite
64 unsigned char brightness;
67 static int _ecore_fb_ts_fd_handler(void *data, Ecore_Fd_Handler *fd_handler);
68 static int _ecore_fb_ts_fd = -1;
69 static int _ecore_fb_ts_event_byte_count = 0;
70 static int _ecore_fb_ts_apply_cal = 0;
71 static Ecore_Fb_Ts_Event _ecore_fb_ts_event;
72 static Ecore_Fb_Ts_Calibrate _ecore_fb_ts_cal = {1,1,0,0,0};
73 static Ecore_Fd_Handler *_ecore_fb_ts_fd_handler_handle = NULL;
76 struct tsdev *_ecore_fb_tslib_tsdev = NULL;
77 struct ts_sample _ecore_fb_tslib_event;
80 static double _ecore_fb_double_click_time = 0.25;
83 ecore_fb_ts_init(void)
86 char *tslib_tsdevice = NULL;
87 if ( ( tslib_tsdevice = getenv("TSLIB_TSDEVICE") ) != NULL )
89 printf( "ECORE_FB: TSLIB_TSDEVICE = '%s'\n", tslib_tsdevice );
90 _ecore_fb_tslib_tsdev = ts_open( tslib_tsdevice, 1 ); /* 1 = nonblocking, 0 = blocking */
92 if ( !_ecore_fb_tslib_tsdev )
94 printf( "ECORE_FB: Can't ts_open (%s)\n", strerror( errno ) );
98 if ( ts_config( _ecore_fb_tslib_tsdev ) )
100 printf( "ECORE_FB: Can't ts_config (%s)\n", strerror( errno ) );
103 _ecore_fb_ts_fd = ts_fd( _ecore_fb_tslib_tsdev );
104 if ( _ecore_fb_ts_fd < 0 )
106 printf( "ECORE_FB: Can't open touchscreen (%s)\n", strerror( errno ) );
111 _ecore_fb_ts_fd = open("/dev/touchscreen/0", O_RDONLY);
113 if (_ecore_fb_ts_fd >= 0)
115 _ecore_fb_ts_fd_handler_handle = ecore_main_fd_handler_add(_ecore_fb_ts_fd,
117 _ecore_fb_ts_fd_handler, NULL,
119 if (!_ecore_fb_ts_fd_handler_handle)
121 close(_ecore_fb_ts_fd);
124 // FIXME _ecore_fb_kbd_fd = open("/dev/touchscreen/key", O_RDONLY);
131 ecore_fb_ts_shutdown(void)
133 if (_ecore_fb_ts_fd >= 0) close(_ecore_fb_ts_fd);
134 if (_ecore_fb_ts_fd_handler_handle)
135 ecore_main_fd_handler_del(_ecore_fb_ts_fd_handler_handle);
136 _ecore_fb_ts_fd = -1;
137 _ecore_fb_ts_fd_handler_handle = NULL;
141 * @defgroup Ecore_FB_Calibrate_Group Framebuffer Calibration Functions
143 * Functions that calibrate the screen.
148 * Calibrates the touschreen using the given parameters.
149 * @param xscale X scaling, where 256 = 1.0
150 * @param xtrans X translation.
151 * @param yscale Y scaling.
152 * @param ytrans Y translation.
153 * @param xyswap Swap X & Y flag.
154 * @ingroup Ecore_FB_Calibrate_Group
157 ecore_fb_touch_screen_calibrate_set(int xscale, int xtrans, int yscale, int ytrans, int xyswap)
159 Ecore_Fb_Ts_Calibrate cal;
161 if (_ecore_fb_ts_fd < 0) return;
167 if (ioctl(_ecore_fb_ts_fd, TS_SET_CAL, (void *)&cal))
169 _ecore_fb_ts_cal = cal;
170 _ecore_fb_ts_apply_cal = 1;
176 * Retrieves the calibration parameters of the touchscreen.
177 * @param xscale Pointer to an integer in which to store the X scaling.
178 * Note that 256 = 1.0.
179 * @param xtrans Pointer to an integer in which to store the X translation.
180 * @param yscale Pointer to an integer in which to store the Y scaling.
181 * @param ytrans Pointer to an integer in which to store the Y translation.
182 * @param xyswap Pointer to an integer in which to store the Swap X & Y flag.
183 * @ingroup Ecore_FB_Calibrate_Group
186 ecore_fb_touch_screen_calibrate_get(int *xscale, int *xtrans, int *yscale, int *ytrans, int *xyswap)
188 Ecore_Fb_Ts_Calibrate cal;
190 if (_ecore_fb_ts_fd < 0) return;
191 if (!_ecore_fb_ts_apply_cal)
193 if (ioctl(_ecore_fb_ts_fd, TS_GET_CAL, (void *)&cal))
194 _ecore_fb_ts_cal = cal;
198 cal = _ecore_fb_ts_cal;
199 if (xscale) *xscale = cal.xscale;
200 if (xtrans) *xtrans = cal.xtrans;
201 if (yscale) *yscale = cal.yscale;
202 if (ytrans) *ytrans = cal.ytrans;
203 if (xyswap) *xyswap = cal.xyswap;
207 _ecore_fb_ts_fd_handler(void *data __UNUSED__, Ecore_Fd_Handler *fd_handler __UNUSED__)
209 static int prev_x = 0, prev_y = 0, prev_pressure = 0;
210 static double last_time = 0;
211 static double last_last_time = 0;
223 if (_ecore_fb_ts_apply_cal)
224 num = ts_read_raw(_ecore_fb_tslib_tsdev, &_ecore_fb_tslib_event, 1);
226 num = ts_read(_ecore_fb_tslib_tsdev, &_ecore_fb_tslib_event, 1);
227 if (num != 1) return 1; /* no more samples at this time */
228 x = _ecore_fb_tslib_event.x;
229 y = _ecore_fb_tslib_event.y;
230 pressure = _ecore_fb_tslib_event.pressure;
231 v = 1; /* loop, there might be more samples */
232 t = ecore_time_get();
234 ptr = (char *)&(_ecore_fb_ts_event);
235 ptr += _ecore_fb_ts_event_byte_count;
236 num = sizeof(Ecore_Fb_Ts_Event) - _ecore_fb_ts_event_byte_count;
237 v = read(_ecore_fb_ts_fd, ptr, num);
239 _ecore_fb_ts_event_byte_count += v;
240 if (v < num) return 1;
241 _ecore_fb_ts_event_byte_count = 0;
242 if (_ecore_fb_ts_apply_cal)
244 x = ((_ecore_fb_ts_cal.xscale * _ecore_fb_ts_event.x) >> 8) + _ecore_fb_ts_cal.xtrans;
245 y = ((_ecore_fb_ts_cal.yscale * _ecore_fb_ts_event.y) >> 8) + _ecore_fb_ts_cal.ytrans;
249 x = _ecore_fb_ts_event.x;
250 y = _ecore_fb_ts_event.y;
252 pressure = _ecore_fb_ts_event.pressure;
254 /* add event to queue */
255 /* always add a move event */
256 if ((pressure) || (prev_pressure))
258 /* MOVE: mouse is down and was */
259 Ecore_Fb_Event_Mouse_Move *e;
261 e = calloc(1, sizeof(Ecore_Fb_Event_Mouse_Move));
265 ecore_event_add(ECORE_FB_EVENT_MOUSE_MOVE, e, NULL, NULL);
267 if ((pressure) && (!prev_pressure))
269 /* DOWN: mouse is down, but was not now */
270 Ecore_Fb_Event_Mouse_Button_Down *e;
272 e = calloc(1, sizeof(Ecore_Fb_Event_Mouse_Button_Down));
277 if ((t - last_time) <= _ecore_fb_double_click_time)
279 if ((t - last_last_time) <= (2 * _ecore_fb_double_click_time))
284 ecore_event_add(ECORE_FB_EVENT_MOUSE_BUTTON_DOWN, e, NULL, NULL);
286 else if ((!pressure) && (prev_pressure))
288 /* UP: mouse was down, but is not now */
289 Ecore_Fb_Event_Mouse_Button_Up *e;
291 e = calloc(1, sizeof(Ecore_Fb_Event_Mouse_Button_Up));
296 ecore_event_add(ECORE_FB_EVENT_MOUSE_BUTTON_UP, e, NULL, NULL);
305 last_last_time = last_time;
311 prev_pressure = pressure;