我的链接中“如何用MiniGUI设计小键盘输入”讲解了如何编写自己的小键盘并注册到minigui中,而我要觉得根本就不必那么麻烦。我用的是libminigui-1.3.0,首先我们要正确配置minigui,由于我是修改minigui自带的ipaq引擎,所以我们只需要正确映射我们的键值,并在交叉编译之前配置输入引擎为ipaq,就可以识别我们的小键盘了,这里我就不讲如何编写小键盘的驱动了。我的资源中“key.tar.gz”为我的小键盘驱动,“ial-of-minigui.tar.gz”为我配置的minigui键盘输入引擎。
<1>首先修改libminigui/src/ial/ipaq.c ,
下面我修改的部分源代码:
其中在below 和 above之间是我添加或取消注释的。
#define KEY_RELEASED 0x80
#define KEY_NUM 0x0f//这里我修改了原程序,因为我只有16个键值,所以4位就够了,原程序为:0x7f
#define MAX_KEY_EVENTS 4
上面的宏定义在ipaq.h中定义
ipaq.c
#include "ial.h"
#include "ipaq.h"
#include "common.h"
static unsigned char btn_state=0;
.
.
.
static int keyboard_update(void)
{
char *statinfo;
int status;
unsigned char key;
//Attention!
//below
statinfo = (btn_state & KEY_RELEASED)? "UP":"DOWN";//判断按键是按下还是抬起
status = (btn_state & KEY_RELEASED)? 0 : 1;//获得bit状态,和上面一样,看你用哪个
key = btn_state & KEY_NUM;//获得键值
//above
#ifdef _DEBUG
fprintf(stderr, "key %d is %s", key, statinfo);
#endif
//bellow
switch (key)
{
case 0:
state[SCANCODE_0] = status;//case X state[Y]
break; //其中X为我键盘传过来的数值
case 1: //Y为common.h中系统默认的键值
state[SCANCODE_1] = status;//有个说Y可以自己设定,不过我觉得不行
break; //最起码像"回车"这种事件minigui就无法捕捉了
case 2:
state[SCANCODE_2] = status;
break;
case 3:
state[SCANCODE_3] = status;
break;
case 4:
state[SCANCODE_4] = status;
break;
case 5:
state[SCANCODE_5] = status;
break;
case 6:
state[SCANCODE_6] = status;
break;
case 7:
state[SCANCODE_7] = status;
break;
case 8:
state[SCANCODE_8] = status;
break;
case 9:
state[SCANCODE_9] = status;
break;
case 10:
state[SCANCODE_A] = status;
break;
case 11:
state[SCANCODE_B] = status;
break;
case 12:
state[SCANCODE_C] = status;
break;
case 13:
state[SCANCODE_D] = status;
break;
case 14:
state[SCANCODE_BACKSPACE] = status;
break;
case 15:
state[SCANCODE_ENTER] = status;
break;
}
return NR_KEYS;
//return 1;
}
static const char* keyboard_getstate(void)
{
return (char *)state;
}
#ifdef _LITE_VERSION //select查询函数,这就要求你的键盘驱动要有poll方法和read方法
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
{
fd_set rfds;
int retvalue = 0;
int e;
if (!in)
{
in = &rfds;
FD_ZERO (in);
} //判断是不是键盘事件
if ((which & IAL_KEYEVENT) && btn_fd >= 0)
{
FD_SET (btn_fd, in);
#ifdef _LITE_VERSION
if(btn_fd > maxfd) maxfd = btn_fd;
#endif
}
//判断是不是鼠标事件
if ((which & IAL_MOUSEEVENT) && ts >= 0)
{
FD_SET (ts, in);
#ifdef _LITE_VERSION
if (ts > maxfd) maxfd = ts;
#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 (btn_fd >= 0 && FD_ISSET(btn_fd, in))
{
unsigned char key;
FD_CLR(btn_fd, in);
read(btn_fd, &key, sizeof(key));
btn_state = key;
retvalue |= IAL_KEYEVENT;
}
//鼠标事件,读取键值
if (ts >= 0 && FD_ISSET (ts, in))
{
FD_CLR (ts, in);
pos.x=0;
pos.y=0;
// FIXME: maybe failed due to the struct alignment.
//read (ts, &pos, sizeof (POS));
//qiyao add code
read(ts,&tsPos,sizeof(tsEvent));
//transform the data
pos.b=(unsigned short)tsPos.pressure;
pos.x=(unsigned short)tsPos.x;
pos.y=(unsigned short)tsPos.y;
pos.pad=0;//i dont know the meaning of pad
printf("x=%d,y=%d,b=%x\n",pos.x,pos.y,pos.b);
//if (pos.x != -1 && pos.y != -1) {
if (pos.b > 0)
if(tsPos.pressure>0)
{
mousex = pos.x;
mousey = pos.y;
}
//}
#ifdef _DEBUG
if (pos.b > 0)
if(tsPos.pressure>0)
{
printf ("mouse down: pos.x = %d, pos.y = %d\n", pos.x, pos.y);
}
#endif
pos.b = ( pos.b > 0 ? 4:0);
retvalue |= IAL_MOUSEEVENT;
}
} else if (e < 0) {
return -1;
}
return retvalue;
}
BOOL InitIPAQInput (INPUT* input, const char* mdev, const char* mtype)
{
ts = open ("/dev/h3600_ts", O_RDONLY);
if (ts < 0)
{
fprintf (stderr, "MX1: Can not open touch screen!\n");
return FALSE;
}
//now just open it ,but do nothing to it
btn_fd = open ("/dev/key", O_RDONLY);
if (btn_fd < 0 ) //注意这里,要正确设置你的键盘路径
{
fprintf (stderr, "MX1: Can not open button key!\n");
return FALSE;
}
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;
//now ignore the keyborad
//bellow
input->update_keyboard = keyboard_update;//初始还键盘更新函数
input->get_keyboard_state = keyboard_getstate;//初始还键盘获取状态函数
input->set_leds = NULL; //这些是minigui输入引擎提供的接口函数
//above
input->wait_event = wait_event;
mousex = 0;
mousey = 0;
pos.x = pos.y = pos.b = 0;
return TRUE;
}
void TermIPAQInput (void)
{
if (ts >= 0)
close(ts);
if (btn_fd >= 0)
close(btn_fd);
}
#endif /* _IPAQ_IAL */
<2>正确配置minigui
make menuconfig
System wide options --->
[*] Build MiniGUI-Lite
IAL engine options --->
[*] iPAQ H3600 (also H3800)
Font options --->
[ ] Var bitmap font//注意这项不能选
Image options --->
[*] Includes SaveBitmap-related functions
[ ] PCX file support
[ ] LBM/PBM file support
[ ] TGA file support
[*] GIF file support
[*] JPG file support//注意这些图形格式是必选的,不然会有问题,如果系统没有这些
[*] PNG file support//库的话可以从新安装一下
Development environment options --->
(Linux) platform
(arm-linux-gcc) compiler
(glibc) libc //这里一定要配置正确,默认的是PC版本
--- Installation options
install prefix: "/usr/local/arm-linux/arm-linux"//编译完输出路径
阅读(2052) | 评论(3) | 转发(0) |