/*
** $Id: dummy.c 7335 2007-08-16 03:38:27Z xgwang $
**
** dummy.c: The dummy IAL engine.
**
** Copyright (C) 2003 ~ 2007 Feynman Software.
** Copyright (C) 2001 ~ 2002 Wei Yongming.
**
** Created by Wei Yongming, 2001/09/13
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include "common.h"
#include "tslib.h"
#ifdef _DUMMY_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 "dummy.h"
/* 2440 button add */
#include <sys/select.h>
#include <sys/types.h>
#include <errno.h>
#ifndef _DEBUG
#define _DEBUG // for debugging
#endif
/* for storing data reading from /dev/touchScreen/0 */
typedef struct
{
unsigned short pressure;
unsigned short x;
unsigned short y;
unsigned short pad;
} TS_EVENT;
/* 2440 button add */
static unsigned char state[NR_KEYS] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0};
static int buttons_fd = -1;
static int key_value = -1;
static int mousex = 0;
static int mousey = 0;
static TS_EVENT ts_event;
static struct tsdev *ts;
/************************ Low Level Input Operations **********************/
static int keyboard_update(void)
{
#if 1
if(key_value > 0)
{
memset(state , 0, NR_KEYS);
//printf("key_value= %d\n", key_value);
switch(key_value)
{
case 16://0
{
state[SCANCODE_Q] = 1;
//t = 0;
break;
}
case 18:// 1
{
state[SCANCODE_E] = 1;
//t = 1;
break;
}
case 30://A
{
state[SCANCODE_A] = 1;
//t = 10;
break;
}
case 48:// F1
{
state[SCANCODE_B] = 1;
//t = 16;
break;
}
case 41:// ESCAPE
{
state[SCANCODE_GRAVE] = 1;
//t = 24;
break;
}
case 12:// 2
{
state[SCANCODE_MINUS] = 1;
//t = 2;
break;
}
case 6:// 3
{
state[SCANCODE_5] = 1;
//t = 3;
break;
}
case 45:// 4
{
state[SCANCODE_X] = 1;
//t = 4;
break;
}
case 4:// 5
{
state[SCANCODE_3] = 1;
//t = 5;
break;
}
case 24:// B
{
state[SCANCODE_O] = 1;
//t = 11;
break;
}
case 10:// 6
{
state[SCANCODE_9] = 1;
//t = 6;
break;
}
case 26:// 7
{
state[SCANCODE_BRACKET_LEFT] = 1;
//t = 7;
break;
}
case 20:// 8
{
state[SCANCODE_T] = 1;
//t = 8;
break;
}
case 14:// 9
{
state[SCANCODE_BACKSPACE] = 1;
//t = 9;
break;
}
case 33:// C
{
state[SCANCODE_F] = 1;
//t = 12;
break;
}
case 39:// D
{
state[SCANCODE_SEMICOLON] = 1;
//t = 13;
break;
}
case 38:// E
{
state[SCANCODE_L] = 1;
//t = 14;
break;
}
case 32:// F
{
state[SCANCODE_D] = 1;
//t = 15;
break;
}
case 42:// F2
{
state[SCANCODE_LEFTSHIFT] = 1;
//t = 17;
break;
}
case 15://F3
{
state[SCANCODE_TAB] = 1;
//t = 18;
break;
}
case 21:// F4
{
state[SCANCODE_Y] = 1;
//t = 19;
break;
}
case 9://F5
{
state[SCANCODE_8] = 1;
//t = 20;
break;
}
case 3:// F6
{
state[SCANCODE_2] = 1;
//t = 21;
break;
}
case 22:// BACKSPACE
{
state[SCANCODE_U] = 1;
//t = 22;
break;
}
case 2:// ENTER
{
state[SCANCODE_1] = 1;
//t = 23;
break;
}
case 8:// PERIOD
{
state[SCANCODE_7] = 1;
//t = 25;
break;
}
case 29:// CURSORUP
{
state[SCANCODE_LEFTCONTROL] = 1;
//t = 26;
break;
}
case 37:// CURSORDOWN
{
state[SCANCODE_K] = 1;
//t = 27;
break;
}
case 28:// CURSORLEFT
{
state[SCANCODE_ENTER] = 1;
//t = 28;
break;
}
case 40:// CURSORRIGHT
{
state[SCANCODE_APOSTROPHE] = 1;
//t = 29;
break;
}
case 34:// RIGHTSHIFT
{
state[SCANCODE_G] = 1;
//t = 30;
break;
}
case 47: // R (+/-)
{
state[SCANCODE_V] = 1;
//t = 31;
break;
}
case 36:// S (存储)
{
state[SCANCODE_J] = 1;
//t = 32;
break;
}
case 27:// M (维护)
{
state[SCANCODE_BRACKET_RIGHT] = 1;
//t = 33;
break;
}
case 44:// H (手指)
{
state[SCANCODE_Z] = 1;
//t = 34;
break;
}
case 11:// PAGEUP
{
state[SCANCODE_0] = 1;
//t = 35;
break;
}
case 17:// PAGEDOWN
{
state[SCANCODE_W] = 1;
//t = 36;
break;
}
}
}
#endif
return NR_KEYS;
}
static const char* keyboard_getstate(void)
{
return (const char *)state;
}
/*
* 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 > 799) mousex = 799;
if (mousey > 479) mousey = 479;
#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 = -1;
int fd = -1;
fd_set rfds;
int e = -1;
if (!in)
{
in = &rfds;
FD_ZERO (in);
}
fd = ts_fd(ts);
if ((which & IAL_MOUSEEVENT) && (fd >= 0))
{
FD_SET (fd, in);
#ifdef _LITE_VERSION
if (fd > maxfd)
maxfd = fd;
#endif
}
#if 1
/* 2440 button add */
if ((which & IAL_KEYEVENT) && (buttons_fd >= 0))
{
FD_SET (buttons_fd, in);
#ifdef _LITE_VERSION
if(buttons_fd > maxfd)
maxfd = buttons_fd;
#endif
}
#endif
#ifdef _LITE_VERSION
e = select (maxfd + 1, in, out, except, timeout) ;
#else
e = select (MAX (fd, buttons_fd) + 1, in, out, except, timeout) ;
//e = select (fd + 1, in, out, except, timeout) ;
#endif
if (e > 0)
{
// input events is coming
if ((fd > 0) && FD_ISSET (fd, in))
{
FD_CLR (fd, in);
ts_event.x=0;
ts_event.y=0;
ret = ts_read(ts, &sample, 1);
if (ret < 0)
{
perror("ts_read()");
exit(-1);
}
ts_event.x = sample.x;
ts_event.y = sample.y;
ts_event.pressure = (sample.pressure > 0 ? 4:0);
if((ts_event.x >= 0 && ts_event.x <= 799)
&& (ts_event.y >= 0 && ts_event.y <= 479))
{
mousex = ts_event.x;
mousey = ts_event.y;
}
ret |= IAL_MOUSEEVENT;
return ret;
}
#if 1
/* 2440 button add */
if ((buttons_fd > 0) && FD_ISSET(buttons_fd, in))
{
FD_CLR(buttons_fd, in);
ret = read(buttons_fd, &key_value, sizeof(key_value));
if (ret < 0)
{
perror("read()");
exit(-1);
}
ret |= IAL_KEYEVENT;
return ret;
}
#endif
}
else if (e < 0)
{
return -1;
}
return (ret);
}
BOOL InitDummyInput(INPUT* input, const char* mdev, const char* mtype)
{
#if 1
/* 2440 button add */
buttons_fd = open (KBD_DEVICE, O_RDONLY | O_NONBLOCK);
if(buttons_fd < 0)
{
perror("open()");
exit(-1);
}
else
{
#ifdef _DEBUG
printf ("kbd_m6x8 is open!!!!!!!!!!!\n");
#endif
}
#endif
char *ts_device = NULL;
if ((ts_device = getenv("TSLIB_TSDEVICE")) != NULL)
{
// open touch screen event device in blocking mode
ts = ts_open(ts_device, 0);
#ifdef _DEBUG
printf ("TSLIB_TSDEVICE is open!!!!!!!!!!!\n");
#endif
}
else
{
#ifdef USE_INPUT_API
ts = ts_open("/dev/input/0raw", 0);
#else
ts = ts_open("/dev/touchscreen/ucb1x00", 0);
#endif
}
if (!ts)
{
perror("ts_open()");