40 #include <nuttx/config.h> 46 #include <sys/prctl.h> 53 #include <nuttx/nx/nxglib.h> 70 #if !defined(CONFIG_DEBUG_INPUT) && !defined(CONFIG_DEBUG_GRAPHICS) 73 # ifdef CONFIG_CPP_HAVE_VARARGS 133 (void)pthread_kill(
m_thread, CONFIG_NXWM_TOUCHSCREEN_SIGNO);
157 _info(
"Starting listener\n");
161 (void)pthread_attr_init(&attr);
163 struct sched_param param;
164 param.sched_priority = CONFIG_NXWM_TOUCHSCREEN_LISTENERPRIO;
165 (void)pthread_attr_setschedparam(&attr, ¶m);
167 (void)pthread_attr_setstacksize(&attr, CONFIG_NXWM_TOUCHSCREEN_LISTENERSTACK);
174 ginfo(
"CTouchscreen::start: pthread_create failed: %d\n", ret);
196 _info(
"Listener m_state=%d\n", (
int)
m_state);
223 (void)pthread_kill(
m_thread, CONFIG_NXWM_TOUCHSCREEN_SIGNO);
238 _info(
"Capturing touch input\n");
249 (void)pthread_kill(
m_thread, CONFIG_NXWM_TOUCHSCREEN_SIGNO);
257 DEBUGASSERT(ret == 0 || errno == EINTR);
264 _info(
"Returning touch input: %d\n", ret);
281 #if CONFIG_TASK_NAME_SIZE > 0 282 prctl(PR_SET_NAME,
"CTouchScreen::listener", 0);
285 _info(
"Listener started\n");
289 This->
m_touchFd = std::open(CONFIG_NXWM_TOUCHSCREEN_DEVPATH, O_RDONLY);
292 gerr(
"ERROR Failed to open %s for reading: %d\n",
293 CONFIG_NXWM_TOUCHSCREEN_DEVPATH, errno);
296 return (FAR
void *)0;
336 struct touch_sample_s *sample = This->
m_touch;
340 _info(
"Listening for sample %p\n", sample);
342 ssize_t nbytes = read(This->
m_touchFd, sample,
343 sizeof(
struct touch_sample_s));
350 #if defined(CONFIG_DEBUG_GRAPHICS_ERROR) || defined(CONFIG_DEBUG_ASSERTIONS) 353 gerr(
"ERROR: read %s failed: %d\n",
354 CONFIG_NXWM_TOUCHSCREEN_DEVPATH, errval);
355 DEBUGASSERT(errval == EINTR);
364 else if (nbytes >= (ssize_t)
sizeof(
struct touch_sample_s))
372 gerr(
"ERROR Unexpected read size=%d, expected=%d\n",
373 nbytes,
sizeof(
struct touch_sample_s));
380 _info(
"Listener exiting\n");
382 return (FAR
void *)0;
391 _info(
"Touch id: %d flags: %02x x: %d y: %d h: %d w: %d pressure: %d\n",
392 sample->point[0].id, sample->point[0].flags, sample->point[0].x,
393 sample->point[0].y, sample->point[0].h, sample->point[0].w,
394 sample->point[0].pressure);
398 if (sample->npoints < 1 ||
399 ((sample->point[0].flags & TOUCH_POS_VALID) == 0 &&
400 (sample->point[0].flags & TOUCH_UP) == 0))
445 if ((sample->point[0].flags & (TOUCH_DOWN | TOUCH_MOVE)) != 0)
447 buttons = NX_MOUSE_LEFTBUTTON;
449 else if ((sample->point[0].flags & TOUCH_UP) != 0)
451 buttons = NX_MOUSE_NOBUTTONS;
465 if ((sample->point[0].flags & TOUCH_POS_VALID) == 0)
472 #ifdef CONFIG_NXWM_CALIBRATION_ANISOTROPIC 476 float rawX = (float)sample->point[0].x;
477 float rawY = (
float)sample->point[0].y;
526 float scaledY = rawY * yLine.slope + yLine.offset;
528 x = (nxgl_coord_t)scaledX;
529 y = (nxgl_coord_t)scaledY;
531 _info(
"raw: (%6.2f, %6.2f) scaled: (%6.2f, %6.2f) (%d, %d)\n",
532 rawX, rawY, scaledX, scaledY, x, y);
537 uint32_t rawX = (uint32_t)sample->point[0].x;
538 uint32_t rawY = (uint32_t)sample->point[0].y;
548 int32_t bigX = b16toi(scaledX + b16HALF);
549 int32_t bigY = b16toi(scaledY + b16HALF);
563 x = (nxgl_coord_t)bigX;
576 y = (nxgl_coord_t)bigY;
579 _info(
"raw: (%d, %d) scaled: (%d, %d)\n", rawX, rawY, x, y);
586 (void)nx_mousein(handle, x, y, buttons);
struct SCalibrationLine left
struct SCalibrationLine right
struct touch_sample_s * m_touch
NXWidgets::CNxServer * m_server
bool waitRawTouchData(struct touch_sample_s *touch)
volatile bool m_calibrated
struct SCalibrationData m_calibData
struct SCalibrationLine top
enum EListenerState m_state
struct SCalibrationLine bottom
static FAR void * listener(FAR void *arg)
void handleMouseInput(struct touch_sample_s *sample)
CTouchscreen(NXWidgets::CNxServer *server, struct nxgl_size_s *windowSize)
struct nxgl_size_s m_windowSize
void setCalibrationData(const struct SCalibrationData &caldata)
struct touch_sample_s m_sample