grininmonkey
Posts: 92
Joined: Mon Jul 30, 2018 3:44 pm

Adafruit resistive TS issues in non DE

Sun Oct 14, 2018 3:37 am

So I have one of these https://www.adafruit.com/product/2260 5" resistive touch screens... up to this point, I have really only used the touch feature when in a Desktop Environment where it actually works as expected... where ever you press on the screen... the mouse cursor moves to that position and a click event is registered.

My issue is... I thought it would great to look for and respond to click event in my experimental C Framebuffer exercise. I got as far as experimenting with this http://blog.eihis.com/2014/06/26/linux- ... nts-datas/

The issue I find is.... No matter where you tap on the screen it appears to be a random X or Y or both that register a movement of 255 or -255...
When I plug in a real mouse.... and change the code to use /dev/input/mouse1... it works flawlessly...

So I then installed gpm in order to see a cursor or pointer in the console... with just the touch screen.... I see the effect I saw in the values from the example above.... the cursor (no matter where you tap) randomly jumps 255 on X, Y or both .... never lands underneath your finger. With real mouse plugged in... gpm cursor tracks correctly etc... etc..

Snippet of output from the blocking example from the link when touching the screen... multiple different positions... etc..

Code: Select all

bLEFT:1, bMIDDLE: 0, bRIGHT: 0, rx: 255  ry=255
Absolute coords from TOP_LEFT= 255 -255
Absolute x,y coords origin recorded

bLEFT:1, bMIDDLE: 0, bRIGHT: 0, rx: 255  ry=255
Absolute coords from TOP_LEFT= 255 -255
Absolute x,y coords origin recorded

bLEFT:1, bMIDDLE: 0, bRIGHT: 0, rx: 255  ry=255
Absolute coords from TOP_LEFT= 255 -255
Absolute x,y coords origin recorded

bLEFT:1, bMIDDLE: 0, bRIGHT: 0, rx: 255  ry=0
Absolute coords from TOP_LEFT= 255 0
Absolute x,y coords origin recorded

bLEFT:1, bMIDDLE: 0, bRIGHT: 0, rx: 255  ry=0
Absolute coords from TOP_LEFT= 255 0
Absolute x,y coords origin recorded

bLEFT:1, bMIDDLE: 0, bRIGHT: 0, rx: 0  ry=255
Absolute coords from TOP_LEFT= 0 255
Absolute x,y coords origin recorded

So what I am trying to find out on the interwebs is.... what is xserver doing to figure out the correct mouse movement from the touch screen mouse device....

When reading the raw device file.... it's just 255 movements ... well... reading the dev file using the example I mentioned above...

grininmonkey
Posts: 92
Joined: Mon Jul 30, 2018 3:44 pm

Re: Adafruit resistive TS issues in non DE

Sun Oct 14, 2018 8:29 pm

Ok... after paying attention to raw output ... I realized a pattern and now have something very close to understandable for me... now I just need to figure out what is causing what appears to be a linear increase in movement value the further away from center...

When pressing near the center... I get X Y positions that I expect.... however the further away from center there is an increase is what I would call an offset?

Meaning... on launch X and Y is at half screen width and height... resolution is 800x480... but pressing the screen on far edge gives -80 (left) 880 (right) and y has -110 (top) and 600 (bottom).... utilizing the following test code

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <linux/input.h>
#include <unistd.h>

#define MOUSEFILE "/dev/input/mouse0"

int main()
{
    int fd;
    struct input_event ie;
    unsigned char button,bLeft,bMiddle,bRight;
    char x,y;
    int absolute_x,absolute_y;
	int position_x,position_y;
	int screen_width=800;
	int screen_height=480;

    if((fd = open(MOUSEFILE, O_RDONLY)) == -1) {
        printf("Device open ERROR\n");
        exit(EXIT_FAILURE);
    }
    else
    {
        printf("Device open OK\n");
    }

	position_x = screen_width/2;
	position_y = screen_height/2;

    while(read(fd, &ie, sizeof(struct input_event)))
    {
        unsigned char *ptr = (unsigned char*)&ie;
        int i;       

        button	= ptr[0];
        bLeft 	= button & 0x1;
        bMiddle = ( button & 0x4 ) > 0;
        bRight 	= ( button & 0x2 ) > 0;
        x		= (char) ptr[1];
        y		= (char) ptr[2];

	if (x > 127) // Movement Left ?? 
		absolute_x -= 256 - x;

	if (x < 129) // Movement Right ??
		absolute_x += x;
		
	if (y > 127) // Movement Up ??
		absolute_y += 256 - y;

	if (y < 129) // Movement Down ??
		absolute_y -= y;


        if (bLeft==1)
        {
		position_x += absolute_x;
		position_y += absolute_y;
		absolute_x=0;
		absolute_y=0;
	} 		
		
	printf("bLEFT:%d, rx=%d  ry=%d, AbX=%i AbY=%i, PX=%i PY=%i\n",bLeft,x,y,absolute_x,absolute_y,position_x,position_y);

        //printf("Absolute coords from TOP_LEFT= %i %i\n",absolute_x,absolute_y);
        //for(i=0; i<sizeof(ie); i++)
        //{
        //    printf("%02X ", i, *ptr++);
        //}
        //printf("\n");
    }

return 0;
}

So I am pondering if this is an effect of dpi mix match between device and screen resolution that I need to adjust for in the calculated values or something else?

I shall continue to hack away at this.... getting much closer....

Return to “C/C++”