/*
** $Id: 2410.c,v 1.6 2004/04/01 08:57:13 weiym Exp $
**
** 2410.c: Low Level Input Engine for SMDK2410 Dev Board.
**
** Copyright (C) 2003 Feynman Software.
*/
/*
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include "common.h"
//#include "tslib.h"
#ifdef _SMDK2410_IAL
#include <sys/ioctl.h>
#include <sys/poll.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/kd.h>
#include "ial.h"
#include "2410.h"
//#ifndef _DEBUG
//#define _DEBUG // for debugging
//#endif
#ifdef _DEBUG
#undef _DEBUG // for release
#endif
/* for storing data reading from /dev/touchScreen/0raw */
typedef struct {
unsigned short pressure;
unsigned short x;
unsigned short y;
unsigned short pad;
} TS_EVENT;
static unsigned char state [NR_KEYS];
static int mousex = 0;
static int mousey = 0;
static TS_EVENT ts_event;
//static struct tsdev *ts;
static int fd=-1;
/************************ Low Level Input Operations **********************/
/*
* Mouse operations -- Event
*/
static int mouse_update(void)
{
return 1;
}
static void mouse_getxy(int *x, int* y)
{
if (mousex < 0) mousex = 0;
if (mousey < 0) mousey = 0;
// if (mousex > 239) mousex = 239;
// if (mousey > 319) mousey = 319;
#ifdef _DEBUG
printf ("mousex = %d, mousey = %d\n", mousex, mousey);
#endif
*x = mousex;
*y = mousey;
}
static int mouse_getbutton(void)
{
return ts_event.pressure;
}
#ifdef _LITE_VERSION
static int wait_event (int which, int maxfd, fd_set *in, fd_set *out, fd_set *except,
struct timeval *timeout)
#else
static int wait_event (int which, fd_set *in, fd_set *out, fd_set *except,
struct timeval *timeout)
#endif
{
// struct ts_sample sample;
int ret = 0;
while(1){
ts_event.x=0;
ts_event.y=0;
ret = read(fd, (char *)&ts_event, sizeof(TS_EVENT));
if (ret != sizeof(TS_EVENT))
{
printf("read touch screen error!");
close(fd);
exit(-1);
}
// ts_event.pressure = (ts_event.pressure > 0 ? 4:0);
if (ts_event.pressure > 0){
ts_event.pressure=4;
mousex = 320-(980-ts_event.x)*320/900;
mousey = (930-ts_event.y)*240/820;
//mousex = ts_event.x;
//mousey = ts_event.y;
//printf("x=%d,y=%d,p=%d\n",ts_event.x,ts_event.y,ts_event.pressure);
printf("x=%d,y=%d,p=%d\n",mousex,mousey,ts_event.pressure);
}else
printf("up\n");
ret |= IAL_MOUSEEVENT;
return (ret);
}
return (ret);
}
BOOL Init2410Input (INPUT* input, const char* mdev, const char* mtype)
{
fd = open("/dev/ts", O_RDWR);
if(fd == -1)
{
printf("\nCan't open touchscreen device!\n");
exit(-1);
}
input->update_mouse = mouse_update;
input->get_mouse_xy = mouse_getxy;
input->set_mouse_xy = NULL;
input->get_mouse_button = mouse_getbutton;
input->set_mouse_range = NULL;
input->wait_event = wait_event;
mousex = 0;
mousey = 0;
ts_event.x = ts_event.y = ts_event.pressure = 0;
return TRUE;
}
void Term2410Input(void)
{
if (fd>0)
close(fd);
}
#endif
评论0