📄 ipaq.c
字号:
/*
** $Id: ipaq.c,v 1.22 2003/12/07 03:27:44 snig Exp $
**
** ipaq.c: Low Level Input Engine for iPAQ H3600/H3800
**
** Copyright (C) 2003, Feynman Software.
**
** The device driver of iPAQ H3600 touch screen is compliant to
** the Specification for Generic Touch Screen Driver.
** Please see the file: spec_general_ts_drv.html in this directory.
**
** So this IAL engine can be a good template of your new IAL engines,
** which compliant to the specification.
**
** Created by Wei Yongming, 2001/08/20
*/
/*
** 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"
#define uchar unsigned char
#define UWORD unsigned short
#ifdef _IPAQ_IAL
#ifdef __ECOS
#define TS_DEVICE "/dev/ts"
#define KBD_DEVICE "/dev/kbd"
#include <sys/select.h>
#else /* LINUX */
#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>
#define TS_DEVICE "/dev/h3600_ts"
#define KBD_DEVICE "/dev/h3600_key"
#endif
//#include "misc.h"
#include "ial.h"
#include "ipaq.h"
#define NOBUTTON 0x0000
#define LEFTBUTTON 0x0001
#define RIGHTBUTTON 0x0002
#define MIDBUTTON 0x0004
#define MOUSEBUTTONMASK 0x00FF
#define SHIFTBUTTON 0x0100
#define CONTROLBUTTON 0x0200
#define ALTBUTTON 0x0400
#define METABUTTON 0x0800
#define KEYBUTTONMASK 0x0FFF
#define KEYPAD 0x4000
//serial0 ioctrl
#define US_EMPTY_R_PDC 1
#define US_SET_RECV_TIMEOUT 2
#define US_SET_APPFLAG 3
#define US_GET_APPFLAG 4
//FPGA ioctrl cmd
#define FPGA_IO_CHGPORT 1
#define FPGA_IO_ASKMODE 2
#define FPGA_IO_ASKFRMDATA 3
#define FPGA_IO_READOVER 4
#define FPGA_IO_LSW 5
//RS485 IOCTRL CMD
#define RS485_EMPTY_R_PDC 1
#define RS485_UNLOCK_RX 2
#define RS485_LOCK_SEND 3
#define RS485_LOCK_RECV 4
uchar CurLPort;
int mouse_buttons;
short mouse_x,mouse_y;
//static struct QVFbKeyData kbd_data;
static unsigned char kbd_state [NR_KEYS];
//static unsigned char keycode_scancode [256];
//************ zdq *************************
typedef struct{ uchar msgtype; uchar downflag; UWORD key; }t_vnc_key;
typedef struct{uchar msgtype;uchar btnmask;uchar xpos;uchar ypos;}t_vnc_mouse;
int FD_2114,fd_RS485 ;
uchar ps2_recv_buff[20];
static unsigned char keycode_to_scancode (unsigned short keycode);
void SwitchLToHost(uchar id);
void StreamTo485(uchar *ps2_recv_buff,uchar Port);
//************** 需调整 ********************************
#define ACTMENUKEY 0xff14 //scoll_lock
#define ESCCHAR 0X10
//*********************************************************
#define KEYDOWNFLAG 1
/************************ Low Level Input Operations **********************/
/*
* Mouse operations -- Event
*/
static int mouse_update (void) //回调
{
short tmpx,tmpy;
t_vnc_mouse *pmouse = (t_vnc_mouse*)ps2_recv_buff;
// printf(" \n mouse_update5(xpos:%x ypos:%x btnmask:%x ) ",pmouse->xpos,pmouse->ypos,pmouse->btnmask);
tmpx=0;
tmpy=0;
if (pmouse->xpos & 0x80)
{
tmpx -= (uchar) ((~pmouse->xpos)+1);
}
else
{
tmpx += (uchar) pmouse->xpos;
}
if (pmouse->ypos &0x80)
{
tmpy -= (uchar) ((~pmouse->ypos)+1);
}
else
{
tmpy += (uchar) pmouse->ypos;
}
// printf("\n tmpx:%x,tmpy:%x ",tmpx,tmpy);
mouse_x += tmpx;
mouse_y -= tmpy;// mouse_y += pmouse->ypos; //鼠标移动以右上位正 ,而屏幕以右下为正
if (mouse_x<0)
mouse_x = 0;
if (mouse_y<0)
mouse_y = 0;
if (mouse_x>799)
mouse_x = 799;
if (mouse_y>599)
mouse_y = 599;
mouse_buttons = 0;
if (pmouse->btnmask & 0x01)
mouse_buttons |= IAL_MOUSE_LEFTBUTTON;
if (pmouse->btnmask & 0x02)
mouse_buttons |= IAL_MOUSE_MIDDLEBUTTON ;
if (pmouse->btnmask & 0x04)
mouse_buttons |= IAL_MOUSE_RIGHTBUTTON;
// printf (" \n mouse_x:%x,mouse_y:%x,mouse_buttons:%x ",mouse_x,mouse_y,mouse_buttons );
return 1;
}
static void mouse_getxy (int *x, int* y)
{
// printf("\n mouse_getxy ");
*x = mouse_x;
*y = mouse_y;
}
static int mouse_getbutton (void)
{
// printf("\n mouse_getbutton ");
return mouse_buttons;
}
static int keyboard_update (void)
{
t_vnc_key *pkey = (t_vnc_key*)ps2_recv_buff;
uchar scancode;
scancode = keycode_to_scancode(pkey->key);
if (scancode >= NR_KEYS)
return 0;
kbd_state[scancode] = pkey->downflag;
return NR_KEYS;
}
static const char* keyboard_getstate (void)
{
return kbd_state;
}
#define ACT_INTERVAL_ms 2000
struct timeval LastActTime;
int IsMenuAct(uchar *ps2_recv_buff)
{
struct timeval timetmp;
struct timezone tz;
int timems;
t_vnc_key * pkey = (t_vnc_key *)ps2_recv_buff;
// printf("\nkey is:%x ",pkey->key);
if (( pkey->key==ACTMENUKEY) && (pkey->downflag == KEYDOWNFLAG))
{
gettimeofday(&timetmp,&tz);
timems = (timetmp.tv_sec - LastActTime.tv_sec) *1000
+ (timetmp.tv_usec + LastActTime.tv_usec)/1000;
LastActTime.tv_sec = timetmp.tv_sec;
LastActTime.tv_usec = timetmp.tv_usec;
//printf("\n actmenu timems:%d \n",timems);
if ( timems < ACT_INTERVAL_ms)
{
return 1 ;//true;
}
else
{
return 0;//false;
}
}
return 0;
}
/* NOTE by weiym: Do not ignore the fd_set in, out, and except */
#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
{
int retcnt,tmp;
int retvalue = 0;
loop:
//接收串口数据
retcnt = 0;
tmp = read(FD_2114,&ps2_recv_buff[retcnt],1);
// printf("[%x]",ps2_recv_buff[0]);
if ((ps2_recv_buff[0]!=0x04)&&(ps2_recv_buff[0]!=0x05) &&( ) )
{
printf("error char[%x]",ps2_recv_buff[0]);
goto loop;
}
retcnt=1;
while(retcnt<4)
{
tmp = read(FD_2114,&ps2_recv_buff[retcnt],4-retcnt);
retcnt+=tmp;
if (retcnt<=0)
{
retcnt=0;
goto loop;
}
if ((ps2_recv_buff[0]!=0x04)&&(ps2_recv_buff[0]!=0x05))
goto loop;
}
//判定由谁处理
if ( !(CurLPort & 0xf0 ))
{ //主机态
// printf("state host ");
if (ps2_recv_buff[0]==0x05) //键盘
{
if (IsMenuAct(ps2_recv_buff))
{
SwitchLToHost(16);
goto loop;
}
}
//printf("streamTo485");
printf("\n<[%x][%x][%x][%x]>",ps2_recv_buff[0],ps2_recv_buff[1],ps2_recv_buff[2],ps2_recv_buff[3]);
StreamTo485(ps2_recv_buff,CurLPort);
goto loop;
}
else
{ //菜单窗口态
// printf("state menu ");
if (ps2_recv_buff[0]==0x05) //键盘
retvalue |= IAL_KEYEVENT;
if (ps2_recv_buff[0]==0x04) //鼠标
retvalue |= IAL_MOUSEEVENT;
return retvalue;
}
return 0; //永远不会执行
}
BOOL InitIPAQInput (INPUT* input, const char* mdev, const char* mtype)
{
printf(" zdq: InitIPAQInput() ");
if ((FD_2114 = open("/dev/ps2", O_RDWR )) == -1)
{
printf("open /dev/ps2 fail");
return FALSE;
}
if ((fd_RS485 = open("/dev/rs485", O_RDWR )) == -1)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -