📄 2410.c
字号:
/*** $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 "common.h"#ifdef _SMDK2410_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 "ial.h"#include "2410.h"/* for data reading from /dev/ts */typedef struct { unsigned short pressure; unsigned short x; unsigned short y; unsigned short pad;} TS_EVENT;static unsigned char state [NR_KEYS];static int get_state[6];static int get_flag[6];static int ts = -1;static int btn_fd = -1;static int mousex = 0;static int mousey = 0;static TS_EVENT ts_event;#undef _DEBUG/************************ Low Level Input Operations **********************/static int keyboard_update(void){ unsigned char i; for (i=0; i < 6; i++) { if (get_flag[i]) { //映射键值,K1~K6分别映射为Enter键,B键,Tab键,BackSpace键,A键,Esc键 switch(i) { case 0: state[SCANCODE_ENTER] = get_state[0]&KEY_RELEASED?0:1; break; case 1: state[SCANCODE_B] = get_state[1]&KEY_RELEASED?0:1; break; case 2: state[SCANCODE_TAB] = get_state[2]&KEY_RELEASED?0:1; break; case 3: state[SCANCODE_A] = get_state[3]&KEY_RELEASED?0:1; break; case 4: state[SCANCODE_BACKSPACE] = get_state[4]&KEY_RELEASED?0:1; break; case 5: state[SCANCODE_ESCAPE] = get_state[5]&KEY_RELEASED?0:1; break; } } } memset(get_flag,0,sizeof(get_flag)); return NR_KEYS;}static const char* keyboard_getstate(void){ return (char *)state;}/* * 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 if (mousex < 0) mousex = 0; if (mousey < 0) mousey = 0; if (mousex > 239) mousex = 239; if (mousey > 319) mousey = 319; *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)#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)) { int rs; FD_CLR (ts, in); ts_event.x=0; ts_event.y=0; printf ("begin to read\n"); rs = read (ts, &ts_event, sizeof (TS_EVENT)); printf ("rs = %d\n", rs); if (rs != sizeof(TS_EVENT)) return -1; if (ts_event.pressure > 0) { mousex = ts_event.x; mousey = 319 - ts_event.y; }#ifdef _DEBUG if (ts_event.pressure > 0) { printf ("mouse down: ts_event.x = %d, ts_event.y = %d\n", ts_event.x, ts_event.y); }#endif ts_event.pressure = ( ts_event.pressure > 0 ? 4:0); retvalue |= IAL_MOUSEEVENT; } //----------------------------------- if (btn_fd >= 0 && FD_ISSET(btn_fd, in)) { unsigned char key, i; FD_CLR(btn_fd, in); read(btn_fd, &get_state, sizeof(get_state)); /* printf("key1 = %d\nkey2 = %d\nkey3 = %d\nkey4 = %d\nkey5 = %d\nkey6 = %d\n\n", get_state[0],get_state[1],get_state[2], get_state[3],get_state[4],get_state[5]); */ for(i=0; i < 6; i++) { if (get_state[i]) get_flag[i] = 1; } retvalue |= IAL_KEYEVENT; } //----------------------------------- } else if (e < 0) { return -1; } return retvalue;}BOOL Init2410Input (INPUT* input, const char* mdev, const char* mtype){ /* mdev should be /dev/ts */ ts = open (mdev, O_RDONLY); if (ts < 0) { fprintf (stderr, "2410: Can not open touch screen: %s!\n", mdev); return FALSE; } /* KBD_DEVICE为/dev/buttons */ btn_fd = open (KBD_DEVICE, O_RDONLY | O_NONBLOCK); if (btn_fd < 0 ) { fprintf (stderr, "2410: Can not open keyboard!\n"); return FALSE; } printf ("In 2410 engine\n"); 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; ts_event.x = ts_event.y = ts_event.pressure = 0; return TRUE;}void Term2410Input(void) { if (ts >= 0) close(ts); if (btn_fd >= 0) close(btn_fd);}#endif /* _SMDK2410_IAL */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -