touch_sample.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2023-05-26 Chushicheng the first version
  9. */
  10. /*
  11. * Program listing: This is a touch device usage routine
  12. * The routine exports touch_sample commands to the control terminal
  13. * Command invocation format: touch_sample
  14. * Program function: The terminal prints the coordinates of the touch point
  15. */
  16. #include <rtdevice.h>
  17. #include "drv_gt911.h"
  18. static int touch_sample(void)
  19. {
  20. gt911_input_t ctp_input;
  21. rt_device_t dev = rt_device_find("capt");
  22. RT_ASSERT(dev != RT_NULL);
  23. capt_t *capt = (capt_t*)dev->user_data;
  24. while(1)
  25. {
  26. gt911_ctp_read(&capt->gt911, &ctp_input);
  27. for (rt_uint8_t i = 0; i < ctp_input.num_pos; i++)
  28. {
  29. /* Found track ID #0 */
  30. if (ctp_input.pos[i].id == 0)
  31. {
  32. rt_kprintf("x:%d, y:%d\r\n", capt->gt911.pos_y_max - ctp_input.pos[i].pos_y, ctp_input.pos[i].pos_x);
  33. }
  34. }
  35. rt_thread_mdelay(16);
  36. }
  37. return RT_EOK;
  38. }
  39. MSH_CMD_EXPORT(touch_sample, the capt touch test);