Use touch screen to get event coordinates

Source: Internet
Author: User
Tags touch

have been doing SDL things for some time, using 51 of small fake, do a few small games ..., let's talk about the experience here.

Think that the thing to do is to work on the Development Board ... So it's a bit of a touch-screen piece.

Let's start by saying how to make our own programs enjoy the touch screen.

I use the s3c6410 Development Board, in/dev under the touch screen equipment event1 or event0 this is the specific circumstances.

We all know that under Linux, all devices are files, and when we understand this, you will find that the problem is not as complicated as we think ... We can view our touch screen header file Tslib.h, which has a very detailed content, which has two structures that we need to use in the program. About its specific introduction in my another article has a detailed introduction, http://3417300.blog.51cto.com/3407300/837248

Interested to see, I will no longer be here to drag.

Of course, we have to operate this device, then we naturally have to open the file mode.

There is a function ts_open in the tslib.h; If you open it successfully, return a handle, of course, that's my understanding.

And then the configuration, Ts_config function;

The rest of the work is that we read the touch screen information building. Naturally we would have thought of Ts_read. It's all done, but after the program runs on our Development Board, we find that the results are not what we want.

Because we did not shake, we feel the press once, but in the program came out many times. This is a normal phenomenon, but in our procedures do not need this normal phenomenon, then what to do?

You can design a new algorithm, to get an appropriate amount of value, my method is to take only the first value, the rest of the values are discarded, two of the best way to achieve this method is marked, the following procedures to explain the specific problem ...

void *getctrlmessage (void *junk)   
{   
 int Flag = 1;    
    ts = Ts_open ("/dev/event1", 0);   
 Ts_config (TS) for    
 (;;)   
 {   
  if (ts_read (TS, &sample, 1))   
  {   
   if (sample.pressure) && (Flag = = 1))   
   {   
    comparison ( Sample, Rectarray, &virtualvalue);   
       Flag = 0; Prevents processing of those touch-point information generated by dithering      
   }   
   if (sample.pressure = 0)   
    Flag = 1;   
  }   
 Ts_close (TS);          
}

At the end of the last thing to remind is that when the program is over, be sure to remember close yo ....

This article is from the "Late Evening" blog, please be sure to keep this source http://yiluohuanghun.blog.51cto.com/3407300/850080

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.