分类: 嵌入式
2013-04-02 23:01:29
1.设置LED测试程序的UI界面
复制上篇文章说做的Helloworld.ui,改名leds.ui并修改其caption为My leds,同时删除掉原来界面上所有的控件。
点击check Box,在窗体上放置4个check Box控件,其name属性为m_ledx(x=1,2,3,4),caption为LEDx(x=1,2,3,4)。保存后退出。
2.编写代码,还是需要3个文件:main.cpp, main_form.cpp, main_form.h
main.cpp
#include "main_form.h" #includemain_form.cppQTOPIA_ADD_APPLICATION("leds",TMainForm) QTOPIA_MAIN
#include "main_form.h" //#includemain_form.h#include #include #include #include #include #include #include TMainForm::TMainForm(QWidget * parent, const char * name, WFlags f) : TMainFormBase(parent, name, f) { //::system("insmod /lib/modules/ok6410_leds.ko"); //因为我的LED驱动是做成模块,所以需要先加载模块, //但在此处加载后点击QT界面却没法控制板上的LED亮灭, //据说是system这个方法会导致阻塞??希望您能帮我解答! //所以我把led模块的加载放到了启动led的脚本上了 m_fd = ::open("/dev/leds0", O_RDONLY); if (m_fd < 0) { m_fd = ::open("/dev/leds", O_RDONLY); } connect(m_led1, SIGNAL(clicked()), this, SLOT(checkBoxClicked()) ); connect(m_led2, SIGNAL(clicked()), this, SLOT(checkBoxClicked()) ); connect(m_led3, SIGNAL(clicked()), this, SLOT(checkBoxClicked()) ); connect(m_led4, SIGNAL(clicked()), this, SLOT(checkBoxClicked()) ); checkBoxClicked(); } TMainForm::~TMainForm() { ::close(m_fd); ::system("rmmod ok6410_leds");//这里移除掉led模块 } void TMainForm::checkBoxClicked() { ioctl(m_fd, int(!m_led1->isChecked()), 0); ioctl(m_fd, int(!m_led2->isChecked()), 1); ioctl(m_fd, int(!m_led3->isChecked()), 2); ioctl(m_fd, int(!m_led4->isChecked()), 3); }
#if !defined (__MAIN_FORM_H__) # define __MAIN_FORM_H__ #include "leds.h" //#include3.还需要一个leds.pro文件,内容如下:class TMainForm: public TMainFormBase { Q_OBJECT public: TMainForm(QWidget * parent = 0, const char * name = 0, WFlags f = WType_TopLevel) ; virtual ~TMainForm(); //public slots: // void closeButtonClicked(); private slots: void checkBoxClicked(); private: int m_fd; }; #endif
CONFIG += qtopiaapp
CONFIG -= buildQuicklaunch
HEADERS = main_form.h
SOURCES = main_form.cpp main.cpp
INTERFACES = leds.ui
TARGET = leds
4.编写交叉编译的脚本buildarm.sh
#!/bin/bash source /home/my/qtopia2.2.0/arm-qtopia2.2.0/qtopia-free-2.2.0/setQpeEnv qmake -spec qws/linux-arm-g++ -o Makefile.target *.pro make -f Makefile.target clean make -f Makefile.target运行buildarm.sh生成leds的可执行文件,拷贝到开发板根目录下/opt/Qtopia/bin目录下
5.编写启动led测试程序的脚本,放在开发板根目录下/bin/里面
如下:
#!/bin/sh export TSLIB_ROOT=/usr/local/tslib export TSLIB_TSDEVICE=/dev/event0 export TSLIB_TSEVENTTYPE=H3600 export TSLIB_CONFFILE=/usr/local/tslib/etc/ts.conf export TSLIB_PLUGINDIR=/usr/local/tslib/lib/ts export TSLIB_CALIBFILE=/etc/pointercal export TSLIB_PLUGINDIR=$TSLIB_ROOT/lib/ts export TSLIB_CONSOLEDEVICE=none export TSLIB_FBDEVICE=/dev/fb0 export QWS_MOUSE_PROTO=Tslib:/dev/event0 #export QWS_MOUSE_PROTO=TPanel:/dev/input/event1 #export QWS_MOUSE_PROTO="Tslib:/dev/input/event1 MouseMan:/dev/input/mice" #export QWS_MOUSE_PROTO=MouseMan:/dev/input/mice export QWS_KEYBOARD="TTY:/dev/tty1" export KDEDIR=/opt/konqueror if [ -c /dev/event0 ]; then echo "touch..." export QWS_MOUSE_PROTO='TPanel:/dev/event0' if [ ! -e /etc/pointercal ]; then /bin/calibrate fi if [ -e /etc/pointercal -a ! -s /etc/pointercal ] ; then rm /mnt/disk/pointercal /bin/calibrate fi else echo "mouse..." export QWS_MOUSE_PROTO="MouseMan:/dev/mice" >/etc/pointercal fi export QTDIR=/opt/Qtopia export QPEDIR=/opt/Qtopia export PATH=$QTDIR/bin:$PATH export QT_PLUGIN_PATH=$QTDIR/plugins:$QTDIR/qt_plugins/ export QT_QWS_FONTDIR=$QPEDIR/lib/fonts/ export LD_LIBRARY_PATH=$QTDIR/plugins/qtopialmigrate/:$QTDIR/qt_plugins/imageformats/:$QTDIR/lib:/usr/local/tslib/lib:$LD_LIBRARY_PATH FB_SIZE=$(cat /sys/class/graphics/fb0/virtual_size) #export QWS_DISPLAY="LinuxFb:mmWidth76:mmHeight44:1" case "$FB_SIZE" in 800,480) export QWS_DISPLAY="LinuxFb:mmWidth91:mmHeight53:1" ;; 480,272) export QWS_DISPLAY="LinuxFb:mmWidth76:mmHeight44:1" ;; *) export QWS_DISPLAY="LinuxFb:mmWidth91:mmHeight53:1" ;; esac export HOME=/root/QtopiaHome if [ ! -e $HOME ]; then mkdir -p $HOME; fi if [ ! -e /usr/share ]; then mkdir /usr/share; fi if [ ! -e $HOME/Settings/Trolltech/qpe.conf ]; then mkdir -p $HOME/Settings/Trolltech/ cp $QPEDIR/etc/default/qpe.conf $HOME/Settings/Trolltech/qpe.conf -f fi export LANG="en_US" #temp if [ ! -e $HOME/Documents ]; then mkdir -p $HOME/Documents; fi # make link file for Documents of Qtopia #if [ ! -h $HOME/Documents/grassland.jpg -o ! -h $HOME/Documents/panda.mpg -o ! -h $HOME/Documents/青花瓷.mp3 ]; then # ln -s /root/QtopiaHome/Documents/grassland.jpg $HOME/Documents # ln -s /root/QtopiaHome/Documents/青花瓷.mp3 $HOME/Documents # ln -s /root/QtopiaHome/Documents/panda.mpg $HOME/Documents #fi # insmod /lib/modules/ok6410_leds.ko #注意这里需要先加载led驱动模块,因为我编译linux的时候并没有把led驱动编译到内核里 exec $QPEDIR/bin/leds启动开发板,进入系统后输入# leds & 即可看到led测试界面,点击上面的LED可以控制板上LED的亮灭。