← Back to team overview

ubuntu-chumby-hackers team mailing list archive

reading the touchscreen in C

 

Hi, 

I'm working on using the Chumby as an audio player for an elderly person
with low vision and no background in using any of the media player after
the 80s. So we're talking the experience with the basics of a tv remote.
I'm hoping a simple UI to play pre-loaded audio using large pause, play,
next channel, previous channel, louder, and softer buttons with some
bright visual activation feedback will work. 

Also I want to try is to attach some audio feedback to different
positioning on the touchscreen, as well as having the buttons activation
be dependent on pressure. I understand your suppose to be able to get a
pressure reading and I've tried the following C example based on the
example found at http://forum.chumby.com/viewtopic.php?id=2367: 

#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/time.h>
#include <time.h>

short *buf;

int read_coor() {
int fd;
int n = 0;
int l = 0;
long int first = 0;

struct timeval tv, tvs;  //tv[LOOP];
struct timezone tz;

if (0 > (fd = open("/dev/ts", O_RDONLY))) {
	perror("file ");
	return 0;
	}
buf = (short *)malloc(4 * sizeof(short));
do {
	if((n = read(fd, buf, 4 * sizeof(short))) < 0)
		perror("read");
	else {
		gettimeofday(&tv, &tz);
		if(!first)     // set it to start the time at 0 seconds
			first = tv.tv_sec;
//		printf("%6d: read n[%d] p[%d] x[%d] y[%d] unknown[%d] %ld:%06ld\n",
l++, n, buf[0], buf[1], buf[2], buf[3], tv.tv_sec-first, tv.tv_usec);
		printf("{%ld.%ld, %d, %d, %d, %d, %d, %d} \n", tv.tv_sec-first,
tv.tv_usec, buf[1], buf[2], buf[0], l++, n, buf[3]);
		}
	}while(n > 0);
free(buf);
buf = 0;
return close(fd);
}

void killall(int t)
{
   printf("clean exit\n");
   if (buf)
        free(buf);
    buf = 0;
    exit(0);
}

int main()
{
    signal(SIGINT, killall);
    read_coor();
    return 0;
}



This is a section of the output I got from a diagonal swipe by my
finger: 

0.930174 2405 2687 5015 48 8 9301 
0.940064 2375 2687 5030 49 8 9400 
0.950044 2337 2689 5015 50 8 9500 
0.973514 2293 2681 5030 51 8 9602 
0.973574 2259 2670 5015 52 8 9702 
0.984863 2233 2649 5030 53 8 9802 
0.994933 2204 2624 5015 54 8 9902 
1.393 2175 2601 5030 55 8 3 
1.12353 2141 2568 5015 56 8 102 
1.20322 2095 2516 5030 57 8 202 
1.30182 2037 2455 5015 58 8 301 
1.40162 1972 2377 5030 59 8 401 
1.54962 1894 2316 5015 60 8 503 
1.64941 1826 2248 5030 61 8 603 
1.74951 1746 2181 5015 62 8 703 
1.84991 1668 2120 5030 63 8 803 
1.95001 1597 2048 5015 64 8 903 
1.105130 1539 1993 5030 65 8 1003 
1.110470 1483 1948 5015 66 8 1103 


The x y values seem to come out appropriately but the pressured is to be
a constant 5015 or 5030. Any comments why the pressure doesn't change?
And how can one change the touch sampling rate from C?  

Rick