📄 fft9200.c
字号:
/*
create in 2005.4.10 FFT
*/
#include <stdio.h>#include <stdlib.h>#include <string.h>#include "common.h"#ifdef _FFT9200_IAL#include <unistd.h>#include <fcntl.h>#include <sys/ioctl.h>#include <sys/poll.h>#include <sys/types.h>#include <sys/stat.h>#include <linux/kd.h>#include <linux/h3600_ts.h>#include <time.h>#define TS_DEVICE "/dev/h3600_ts"#define KBD_DEVICE "/dev/kb9200"#include "ial.h"#include "fft9200.h"#define N_KEYS 64/* for data reading from /dev/hs3600_ts */typedef struct { short b; short x; short y; short pad;} POS;
static time_t last_time;
static unsigned char oldkey=0;static unsigned char state[N_KEYS];
static unsigned char status1=0; // different number and alphabetic
static unsigned char status2=0; // different alphabetic1 .. alphabetic3 static int ts = -1;static int btn_fd = -1;static unsigned char btn_state=0;static int mousex = 0;static int mousey = 0;static POS pos;#undef _DEBUG/************************ Low Level Input Operations **********************//* * Mouse operations -- Event */static int mouse_update(void){ return 1;}static void mouse_getxy(int *x, int* y){#ifdef _DEBUG printf ("mousex = %d, mousey = %d\n", mousex, mousey);#endif *x = mousex; *y = mousey;}static int mouse_getbutton(void){ return pos.b;}static int keyboard_update(void){ int status; int key; int index;
unsigned long time_interval;
time_t now_time; /*int code_map[N_KEYS+1]={0x10, 0x11,0x12,0x13,0x14,0x15,0x16, 0x21,0x22,0x23,0x24,0x25,0x26, 0x31,0x32,0x33,0x34,0x35,0x36, 0x41,0x42,0x43,0x44,0x45,0x46, 0x51,0x52,0x53,0x54,0x55,0x56, 0x61,0x62,0x63,0x64,0x65,0x66 };
*/ //Attention! status = (btn_state & 0x80)? 0 : 1;//KEY_RELEASE = 0x80 //key = btn_state & KEY_NUM; key = btn_state & 0x7f; printf("IAL:update key =0x%x \n",key);
if(status) //if press down key
{
if(key == 0x66) // switch number and alphabetic
{
if(status1)
status1 =0;
else
status1 =1;
}
time(&now_time); //get current time
time_interval = now_time - last_time; // compute interval between two time
last_time = now_time;
printf("time_interval = %d \n",time_interval);
if(time_interval > 2)
{
status2 = 0; //reset
}
else
{
if((key==0x11 ||key==0x12 ||key==0x13 ||key==0x21 ||
key==0x22 ||key==0x23 ||key==0x31 ||
key==0x32 ||key==0x33)&&(status1==1)) // alphabetic status
{
status2++;
if(status2 > 2)
{
status2=0;
}
}
}
}
if(key != oldkey)
{
status2 = 0;
}
switch(key)
{
case 0x11:
printf("enter in 0x11 process ... \n");
if(!status1) //number
{
state[1] = status;
}
else
{
if(status2 == 0)
state[55] = status ;
else
{
if(status2 == 1)
state[63] = status ;
else
state[57] = status ;
}
}
break;
case 0x12:
if(!status1) //number
{
state[2] = status;
}
else
{
if(status2 == 0)
state[58] = status ;
else
{
if(status2 == 1)
state[59] = status ;
else
state[60] = status ;
}
}
break;
case 0x13:
if(!status1) //number
{
state[3] = status;
}
else
{
if(status2 == 0)
state[61] = status ;
else
{
if(status2 == 1)
state[62] = status ;
else
state[48] = status ;
}
}
break;
case 0x21:
if(!status1) //number
{
state[4] = status;
}
else
{
if(status2 == 0)
state[37] = status ;
else
{
if(status2 == 1)
state[38] = status ;
else
state[39] = status ;
}
}
break;
case 0x22:
if(!status1) //number
{
state[5] = status;
}
else
{
if(status2 == 0)
state[40] = status ;
else
{
if(status2 == 1)
state[41] = status ;
else
state[42] = status ;
}
}
break;
case 0x23:
if(!status1) //number
{
state[6] = status;
}
else
{
if(status2 == 0)
state[43] = status ;
else
{
if(status2 == 1)
state[44] = status ;
else
state[45] = status ;
}
}
break;
case 0x31:
if(!status1) //number
{
state[7] = status;
}
else
{
if(status2 == 0)
state[46] = status ;
else
{
if(status2 == 1)
state[47] = status ;
else
state[47] = status ;
}
}
break;
case 0x32:
if(!status1) //number
{
state[8] = status;
}
else
{
if(status2 == 0)
state[49] = status ;
else
{
if(status2 == 1)
state[50] = status ;
else
state[51] = status ;
}
}
break;
case 0x33:
if(!status1) //number
{
state[9] = status;
}
else
{
if(status2 == 0)
state[52] = status ;
else
{
if(status2 == 1)
state[53] = status ;
else
state[54] = status ;
}
}
break;
case 0x66:
state[10] = status;
break;
case 0x14:
state[11] = status;
break;
case 0x15:
state[12] = status;
break;
case 0x16:
state[13] = status;
break;
case 0x24:
state[14] = status;
break;
case 0x25:
state[15] = status;
break;
case 0x26:
state[16] = status;
break;
case 0x34:
state[17] = status;
break;
case 0x35:
state[18] = status;
break;
case 0x36:
state[19] = status;
break;
case 0x41:
state[20] = status;
break;
case 0x42:
state[21] = status;
break;
case 0x43:
state[22] = status;
break;
case 0x44:
state[23] = status;
break;
case 0x45:
state[24] = status;
break;
case 0x46:
state[25] = status;
break;
case 0x51:
state[26] = status;
break;
case 0x52:
state[27] = status;
break;
case 0x53:
state[28] = status;
break;
case 0x54:
state[29] = status;
break;
case 0x55:
state[30] = status;
break;
case 0x56:
state[31] = status;
break;
case 0x61:
state[32] = status;
break;
case 0x62:
state[33] = status;
break;
case 0x63:
state[34] = status;
break;
case 0x64:
state[35] = status;
break;
case 0x65:
state[36] = status;
break;
}
/*for(index=0;index<N_KEYS+1;index++) { if(code_map[index]==key) state[index]=status; //else // state[index]=0; }*/
oldkey = key;
return N_KEYS;}static const char* keyboard_getstate(void){ return (char *)state;}#ifdef _LITE_VERSION static int wait_event (int which, int maxfd, fd_set *in, fd_set *out, fd_set *except, struct timeval *timeout)#elsestatic int wait_event (int which, fd_set *in, fd_set *out, fd_set *except, struct timeval *timeout)#endif{ fd_set rfds; int retvalue = 0; int e; if (!in) { in = &rfds; FD_ZERO (in); } if ((which & IAL_MOUSEEVENT) && ts >= 0) { FD_SET (ts, in);#ifdef _LITE_VERSION if (ts > maxfd) maxfd = ts;#endif } if ((which & IAL_KEYEVENT) && btn_fd >= 0){ FD_SET (btn_fd, in);#ifdef _LITE_VERSION if(btn_fd > maxfd) maxfd = btn_fd;#endif }#ifdef _LITE_VERSION e = select (maxfd + 1, in, out, except, timeout) ;#else e = select (FD_SETSIZE, in, out, except, timeout) ;#endif if (e > 0) { if (ts >= 0 && FD_ISSET (ts, in)) { short data [4]; FD_CLR (ts, in); read (ts, data, sizeof (data)); if (data[0]) { mousex = pos.x = data[1]; mousey = pos.y = data[2]; }#ifdef _DEBUG if (data[0]) { printf ("mouse down: pos.x = %d, pos.y = %d\n", pos.x, pos.y); }#endif pos.b = (data[0] ? 4 : 0); retvalue |= IAL_MOUSEEVENT; } if (btn_fd >= 0 && FD_ISSET(btn_fd, in)) { unsigned char key; FD_CLR(btn_fd, in); read(btn_fd, &key, sizeof(key)); printf("IAL:read key:0x%x \n",key); btn_state = key; retvalue |= IAL_KEYEVENT; } } else if (e < 0) { return -1; } return retvalue;}BOOL InitFFT9200Input (INPUT* input, const char* mdev, const char* mtype){ printf("init FFT9200 input ... \n"); btn_fd = open (KBD_DEVICE, O_RDONLY); if (btn_fd < 0 ) { printf (stderr, "kb9200: Can not open button key!\n"); return FALSE; }/* { int i; for(i=0;i<N_KEYS+1;i++) { state[i]=0; } }*/ 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->update_keyboard = keyboard_update; input->get_keyboard_state = keyboard_getstate; input->set_leds = NULL; input->wait_event = wait_event; mousex = 0; mousey = 0; pos.x = pos.y = pos.b = 0; return TRUE;}void TermFFT9200Input (void){ if (ts >= 0) close(ts); if (btn_fd >= 0) close(btn_fd);}#endif /* _IPAQ_IAL */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -