Chumby device settings information on /dev

From Chumby Wiki
Revision as of 14:38, 15 May 2008 by Kit (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

/dev/fb

/dev/accel

/dev/ts

How to read /dev/ts in C

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

short *buf;

int read_coor()
{
    int fd;
    int n = 0;

    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");
        printf("read n[%d] p[%d] x[%d] y[%d] unknown[%d]\n",
                 n, buf[0], buf[1], buf[2], 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;
}