分类: LINUX
2009-07-07 18:50:12
第二十步:tslib和minigui的链接
我们需要将tslib和minigui进行链接,则可以通过改写MiniGUI 的 IAL 引擎。MiniGUI自带的 IAL 输入引擎中,有一个叫做 dummy.c。存在于/root/cross/libminigui-1.3.3/src/ial中,为了尽可能简单,在这里为简单起见就在其基础上稍作修改,使之符合我们的要求即可。其内容如下:
[root@localhost libminigui-1.3.3]# cd src/ial/
[root@localhost ial]# gedit dummy.c
写入以下内容:
#include
#include
#include
#include
#include
#include "common.h"
#include "tslib.h"
#ifdef _DUMMY_IAL
#include
#include
#include
#include
#include
#include "ial.h"
#include "dummy.h"
#ifndef _DEBUG
#define _DEBUG // for debugging
#endif
/* for storing data reading from /dev/touchScreen/0raw */
typedef struct {
unsigned short pressure;
unsigned short x;
unsigned short y;
unsigned short pad;
} TS_EVENT;
static unsigned char state [NR_KEYS];
static int mousex = 0;
static int mousey = 0;
static TS_EVENT ts_event;
static struct tsdev *ts;
/************************ Low Level Input Operations **********************/
/*
* 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 > 639) mousex = 639;
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 = 0;
int fd;
fd_set rfds;
int e;
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
}
#ifdef _LITE_VERSION
e = select (maxfd + 1, in, out, except, timeout) ;
#else
e = select (FD_SETSIZE, 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.pressure > 0 &&
if((ts_event.x >= 0 && ts_event.x <= 639) &&
(ts_event.y >= 0 && ts_event.y <= 479)) {
mousex = ts_event.x;
mousey = ts_event.y;
// printf("ts_event.x is %d, ts_event.y is %d------------------------------------->\n",ts_event.x ,ts_event.y);
}
//#ifdef _DEBUG
// if (ts_event.pressure > 0) {
// printf ("mouse down: ts_event.x = %d, ts_event.y = %d,ts_event.pressure = %d\n",ts_event.x,ts_event.y,ts_event.pressure);
// }
//#endif
ret |= IAL_MOUSEEVENT;
return (ret);
}
}
else if (e < 0) {
return -1;
}
return (ret);
}BOOL InitDummyInput(INPUT* input, const char* mdev, const char* mtype)
{
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);
} else {
#ifdef USE_INPUT_API
ts = ts_open("/dev/input/0raw", 0);
#else
ts = ts_open("/dev/touchscreen/ucb1x00", 0);
#endif
}
#ifdef _DEBUG
printf ("TSLIB_TSDEVICE is open!!!!!!!!!!!\n");
#endif
if (!ts) {
perror("ts_open()");
exit(-1);
}
if (ts_config(ts)) {
perror("ts_config()");
exit(-1);
}
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->wait_event = wait_event;
mousex = 0;
mousey = 0;
ts_event.x = ts_event.y = ts_event.pressure = 0;
return TRUE;
}
void TermDummyInput(void)
{
if (ts)
ts_close(ts);
}
#endif /* _DUMMY_IAL */
将dummy.c修改好以后就可以对minigui进行重新编译了,因为用到了 tslib 库,所以必须在编译的时候告诉 MiniGUI 到哪里去找到 tslib 相关的头文件和共享库文件。具体做法如下所示:
第二十一步:重新配置编译安装 MiniGUI
[root@localhost cross]# cd /usr/lib
[root@localhost lib]# mv libjpeg.so libjpeg.so_back
[root@localhost lib]# mv libpng.so libpng.so_back
[root@localhost lib]# mv libttf.so libttf.so_back
[root@localhost lib]# ln -s /usr/local/arm/3.4.1/arm-linux/lib/libttf.so ./libttf.so
[root@localhost lib]# ln -s /usr/local/arm/3.4.1/arm-linux/lib/libpng.so ./libpng.so
[root@localhost lib]# ln -s /usr/local/arm/3.4.1/arm-linux/lib/libjpeg.so ./libjpeg.so
[root@localhost lib]# cd /root/cross/libminigui-1.3.3
[root@localhost libminigui-1.3.3]# ./configure CC=arm-linux-gcc --build=i686-pc-linux --target=arm-linux --host=arm-linux --disable-galqvfb --disable-galecoslcd --disable-vbfsupport --disable-ttfsupport --disable-type1support --prefix=/usr/local/arm/3.4.1/arm-linux CFLAGS="-I/usr/local/arm/3.4.1/arm-linux/include -L/usr/local/arm/3.4.1/arm-linux/lib -lts"
[root@localhost libminigui-1.3.3]# make
[root@localhost libminigui-1.3.3]# make install
注意:现在不要忘记把前面刚刚备份的改回来。
[root@localhost libminigui-1.3.3]# cd /usr/lib
[root@localhost lib]# mv libjpeg.so_back libjpeg.so
mv:是否覆盖“libjpeg.so”? y
[root@localhost lib]# mv libpng.so_back libpng.so
mv:是否覆盖“libpng.so”? y
[root@localhost lib]# mv libttf.so_back libttf.so
mv:是否覆盖“libttf.so”? y
第二十二步:重新配置编译安装 mde-1.3.0
[root@localhost lib]# cd /root/cross/mde-1.3.0
[root@localhost mde-1.3.0]# ./configure CC=arm-linux-gcc --build=i686-pc-linux --target=arm-linux --host=arm-linux CFLAGS="-I/usr/local/arm/3.4.1/arm-linux/include -L/usr/local/arm/3.4.1/arm-linux/lib -lts"
[root@localhost mde-1.3.0]# make
[root@localhost mde-1.3.0]# make install
第二十三步:重新拷贝并实验
编译完以上两个,再把/usr/local/arm/3.4.1/arm-linux 下的lib文件夹复制到/nfs/下面。由于以前已将拷贝过一部分,现在可以将以前的苦删除掉然后重新拷贝。同理先删除demo下的实例然后重新拷贝。
[root@localhost mde-1.3.0]# rm -rf /nfs/lib
[root@localhost mde-1.3.0]# cp -rf /usr/local/arm/3.4.1/arm-linux/lib /nfs/
[root@localhost mde-1.3.0]# rm -rf /nfs/lib/*.a
[root@localhost mde-1.3.0]# rm -rf /nfs/lib/minigui/
[root@localhost mde-1.3.0]# cp -ar /usr/local/lib/minigui/ /nfs/lib/
[root@localhost mde-1.3.0]# rm -rf /nfs/demo/mde-1.3.0/
[root@localhost mde-1.3.0]# cp -ar ../mde-1.3.0 /nfs/demo/
好了,重新启动开发板,现在就可以利用触摸屏来控制MiniGUI中的控件了。