}
RenderThread:
:
~RenderThread()
{
close(buttons_fd);
}
voidRenderThread:
:
run()
{
intret;
intkey_value;
forever{
fd_setrds;
FD_ZERO(&rds);
FD_SET(buttons_fd,&rds);
ret=select(buttons_fd+1,&rds,NULL,NULL,NULL);
if(ret<0){perror("select");exit
(1);
}
if(ret==0){printf("Timeout.\n");
}elseif(FD_ISSET(buttons_fd,&rds)){
ret=read(buttons_fd,&key_value,sizeofkey_value);if(ret!
=sizeofkey_value){if(errno!
=EAGAIN)perror("readbuttons\n");continue;
}
}
emitsendKey(key_value);
}
}
完成对按
在主线程中通过启动该线程,并将该线程的触发的信号与相应的槽进行连接,键操作的相应,具体代码在gameboard.cpp文件中,文件的具体内容如下:
GameBoard:
:
GameBoard(QWidget*parent)
:
QWidget(parent)
{
connect(&thread,SIGNAL(sendKey(int)),this,SLOT(readKey(int)));thread.start();
newGame();
}
voidGameBoard:
:
readKey(intkey_value){
if(cannonField->gameOver()||cannonField->isShooting())return;
intvalue;
switch(key_value){case1:
value=angle->value();
value=value+1;
angle->setValue(value);
break;
case2:
value=angle->value();value=value-1;angle->setValue(value);break;
case3:
value=force->value();
value=value+1;force->setValue(value);break;
case4:
value=force->value();
value=value-1;force->setValue(value);break;
case5:
fire();
}
}程序的运行需要在程序运行前加载按钮的驱动程序,该驱动程序代码如下:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#defineDEVICE_NAME"buttons"
#defineBUTTON_MAJOR232structbutton_irq_desc{intirq;intpin;intpin_setting;
intnumber;
char*name;
};
#if1
staticstructbutton_irq_descbutton_irqs[]={
{IRQ_EINT3,S3C2410_GPF3,S3C2410_GPF3_EINT3,0,"KEY1"},/*K1*/{IRQ_EINT11,S3C2410_GPG3,S3C2410_GPG3_EINT11,1,"KEY2"},/*K5*/{IRQ_EINT9,S3C2410_GPG1,S3C2410_GPG1_EINT9,2,"KEY3"},/*K4*/{IRQ_EINT5,S3C2410_GPF5,S3C2410_GPF5_EINT5,3,"KEY4"},/*K3*/{IRQ_EINT12,S3C2410_GPG4,S3C2410_GPG4_EINT12,4,"KEY5"},/*K2*/};
#endif
staticDECLARE_WAIT_QUEUE_HEAD(button_waitq);
staticirqreturn_tbuttons_interrupt(intirq,void*dev_id)
{
structbutton_irq_desc*button_irqs=(structbutton_irq_desc*)dev_id;
intup=s3c2410_gpio_getpin(button_irqs->pin);
if(up)
key_values[button_irqs->number]=(button_irqs->number+
1);
else
key_values[button_irqs->number]=(button_irqs->number+
1)+0x80;
//savenumlabel
key_values[5]=button_irqs->number;
ev_press=1;
if(up)//modifybylyj
wake_up_interruptible(&button_waitq);
returnIRQ_RETVAL(IRQ_HANDLED);
}
staticintqq2440_buttons_open(structinode*inode,structfile*file)
{
inti;
interr;
for(i=0;ibreak;
}
if(err){
i--;
for(;i>=0;i--){disable_irq(button_irqs[i].irq);free_irq(button_irqs[i].irq,(void*)&button_irqs[i]);
}
return-EBUSY;
}
return0;
}
staticintqq2440_buttons_close(structinode*inode,structfile*file)
{
inti;
for(i=0;ifree_irq(button_irqs[i].irq,(void*)&button_irqs[i]);
}
return0;
}
staticintqq2440_buttons_read(structfile*filp,char__user*buff,size_tcount,loff_t*offp)
{
unsignedlongerr;
inti=0;
if(!
ev_press){
if(filp->f_flags&O_NONBLOCK)
return-EAGAIN;
else
wait_event_interruptible(button_waitq,ev_press);
}
ev_press=0;
err=copy_to_user(buff,(constvoid*)&(key_values[key_values[5]]),min(sizeof(key_values),count));//modifybylyjmemset((void*)key_values,0,sizeof(key_values));
returnerr?
-EFAULT:
min(sizeof(key_values),count);
}
staticunsignedintqq2440_buttons_poll(
structfile*file,
structpoll_table_struct*wait)
{
unsignedintmask=0;
poll_wait(file,&button_waitq,wait);
if(ev_press)
mask|=POLLIN|POLLRDNORM;
returnmask;
staticstructfile_operationsqq2440_buttons_fops={
•owner=THIS_MODULE,
.open=qq2440_buttons_open,
.release=qq2440_buttons_close,
.read=qq2440_buttons_read,
.poll=qq2440_buttons_poll,
};
staticint__initqq2440_buttons_init(void)
{
intret;
ret=register_chrdev(BUTTON_MAJOR,DEVICE_NAME,
&qq2440_buttons_fops);
if(ret<0){
printk(DEVICE_NAME"can'tregistermajornumber\n");
returnret;
}
printk(DEVICE_NAME"initialized\n”);
return0;
}
staticvoid__exitqq2440_buttons_exit(void)
{
unregister_chrdev(BUTTON_MAJOR,DEVICE_NAME);
}
module_init(qq2440_buttons_init);
module_exit(qq2440_buttons_exit);
MODULE_AUTHOR("http:
//www.arm9.net");
MODULE_DESCRIPTION("S3C2410/S3C2440BUTTONDriver");
MODULE_LICENSE("GPL");
在使用该QT程序是应当先加载按钮的驱动程序,加载的设备文件名应当为/dev/buttons。
在程序中指定插件目录,通过QApplication:
:
addLibraryPath(QString)或者QApplication:
:
setLibraryPath(Q
StringList)来设置
比如你把imageformats文件夹拷贝到当前目录下,在main()函数中加1行
QApplication:
:
addLibraryPath("./");
QT-embedded-4.5forarm的安装和使用
2009-06-1213:
38:
26|分类:
技术相关|标签:
|字号大中小订阅
以下是详细的安装过程,如果想避免漫长的编译过程,可以下载已经编译安装好的压缩包QtEmbedded-4.5.1-arm.tar.gz,解压缩到/usr/local/Trolltech目录下(若无Trolltech则创建此目录),直接从step3开始。
#tarzxvfQtEmbedded-4.5.1-arm.tar.gz-C/usr/local/Trolltech
完整安装过程:
step1.将qt-embedded-linux-opensource-src-4.5.1.tar.gz拷贝到Linux下,解压缩:
#tarzxvfqt-embedded-linux-opensource-src-4.5.1.tar.gz
#cdqt-embedded-linux-opensource-src-4.5.1
修改qt-embedded-linux-opensource-src-4.5.1/src/gui/embedded/qmouselinuxtp_qws.h,在头文件处加入:
#defineQT_QWS_IPAQ
#defineQT_QWS_IPAQ_RAW
step2.配置选项并安装,也可以下载安装脚本qte_for_arm.sh:
#./configure\
-embeddedarm\
-qt-sql-sqlite\
-plugin-sql-sqlite\
-no-scripttools\
-no-nis\
-exceptions\
-xmlpatterns\
-no-largefile\
-no-libmng\
-no-accessibility\
-depths16\
-nomakedocs\
-maketools\
-makelibs\
-qt-zlib\
-feature-THREAD\
-feature-CONCURRENT\
-feature-SOUND\
-feature-EFFECTS\-feature-QWS_MULTIPROCESS\
-silent>log_cfg2>&1
#make&&makeinstall
step3.设置环境变量(两种方法):
仅当前用户有效(其他用户无效):
修改$HOME/.bash_profile,加入:
PATH=/usr/local/Trolltech/QtEmbedded-4.5.1-arm/bin:
$PATH立即生效:
#source$HOME/.bash_profile
所有用户有效(包括root和普通用户):
修改/etc/profile,加入以下行(一般在最后一行添加):
exportPATH=/usr/local/Trolltech/QtEmbedded-4.5.1-arm/bin:
$PATH立即生效:
#source/etc/profile
step4.要移植Qt-embedded到开发板上,需要拷贝的Qte基本库文件、图片插件库和字体文件:
1)QtEmbedded-4.5.1-arm/lib/libQtGui.so.4.5.1
2)QtEmbedded-4.5.1-arm/lib/libQtNetwork.so.4.5.1
3)QtEmbedded-4.5.1-arm/lib/libQtCore.so.4.5.1
4)QtEmbedded-4.5.1-arm/lib/libQtSql.so.4.5.1
5)QtEmbedded-4.5.1-arm/plugins/imageformats
6)QtEmbedded-4.5.1-arm/lib/fonts
在LinuxPC上建立文件夹,将上述文件拷入:
#mkdiroptqtlibplugins
#mvpluginsqt
#mvlibqt
#mvqtopt
#cpopt/qt/lib