291306 views|0 replies

2

Posts

0

Resources
The OP
 

Using QtE to control LED on SBC-241OX [Copy link]

Abstract : QtE (Qt/Embedded) is a toolkit for graphical user interfaces (GUIs) designed by Trolltech, a Norwegian company, specifically for embedded systems. This article uses QtE programming to control the LEDs on the ARM9-based SBC-2410X development board, and details the process from program design, porting to operation. The program can run well on the development board, verifying the effectiveness and reliability of the program. The results show that the application interface developed with QtE is clear and beautiful, and the operation is simple and convenient.
Keywords : QtE ARM9 GUI SBC-2410X


introduction

In recent years, due to the advantages of ARM (Advanced RISC Machines) in performance, power consumption, cost and size, it has been developing rapidly in embedded systems. It has played a major role in industrial control, aerospace, military, consumer electronics, smart home appliances and video surveillance. Many people are eager to learn ARM. In my experience, starting from the most basic LED control is a good choice.

If you are not familiar with Linux, you may know little about the concept of QtE. It is a graphical user interface toolkit designed by Trolltech of Norway for various systems and is programmed in C++. The advantages of QtE include: cross-platform, easy connection to database, and integration of programs with Java. In fact, QtE has long been deeply rooted in the hearts of some high-end mobile handheld devices. Troll-tech has developed an application environment Qtopia based on QtE. At present, many companies have adopted Qtopia to develop their mainstream PDAs. Of course, Qt also has its shortcomings. It cannot provide IDE (integrated development environment), but this shortcoming is insignificant under the powerful Linux. Using gcc/g++, plus Qt's development tools: Qt Designer, tmake/qmake, UIC, etc., it will be very easy to develop visual programs.

To learn ARM, it is essential to choose a good development board. SBC-2410X is an ARM9-based development board designed by Guangzhou Friendly Arm Company, and its operating system is Korean mizi-linux. SBC-2410X is different from uClinux. It has rich interfaces and supports MMU, QtE2.3.7. It also provides a command line method to control LEDs.


1 System Requirements

◇Fully install RedHat9.0.
◇Create QtE compilation environment under Linux.
◇The LED device driver has been loaded on the development board.
Note: The QtE version you create must be consistent with the version supported by the development board.


2 Programming
Under Linux, use the system's built-in Qt Designer to write programs. Qt Designer is an excellent visual development tool, and it is very easy to design with it. Its interface is similar to Delphi, but it uses C++ language to write applications. One of the highlights of Qt programming is the Signal-Slot mechanism, which is somewhat similar to the message mechanism in VC++. When a component sends a signal, another component or multiple components can receive the sent signal through the slot, and the component itself can also receive its own signal, so it will be very easy to handle an event. The advantage of Qt Designer is not only that it can design graphical user interfaces very conveniently, but also that it can easily connect signals and slots with the connection tool. The program designed by the user is added to **.ui.h.

Open Qt Deslgner, select File/new C++Project, name it led.pro and save it. Then select File/new-Dialog and design your own user interface here. Finally, select File/new C++Main-File, and the system automatically generates a main.cpp file. The graphical user interface is shown in Figure 1. The Initialize button is mainly used to open the LED device, close the timer, and perform other initialization tasks; the Begin button is used to start the LED Display Mode; and the Exit button is used to exit the application. The left combo box includes 4 RadioButtons, corresponding to the on or off of the 4 LEDs; the right combo box includes 6 RadioButtons (corresponding to different flashing modes and flashing speeds) and 1 LCDNumber (used to display the flashing time interval). This program establishes many Signal-S1ot connections. Several important connections and functions are described below.

 


(1) connect(initPushButton.SIGNAL(clicked()), this.SLOT(initial()))
When the Initialize button is pressed, the LedForm dialog box receives this signal and executes the initial() function. The Linux operating system regards all devices as files, so the operation and control of the devices can be achieved through functions such as open() and ioctl(). In the initial() function, the open() function is called to open the LED device.

(2) connect(okPushButton, SIGNAL(clicked()), this, SLOT(modeSel()))

When the Begin button is pressed, the LedForm dialog box receives this signal and executes the modeSel() function. In the modeSel() function, the timer is started and another connection is created to display the LED in a loop. In the command line mode, the LED loop display requires an infinite loop and a keyboard interrupt to control the loop; in Qt or other visual languages, a timer is used to control the loop.

(3) The open() function

is declared in <fcntl.h>, which means opening a device file. If the opening is successful, 0 is returned; if it fails, -1 is returned.

(4) The function ioctl()

is declared in <sys/ioctl.h> to control the I/O port. For example:
Int fd = open("/dev/leds", 0);
ioctl(fd, 0, 3); // Turn off LED4

(5) The function select()

is declared in <sys/select.h>, which means how long it takes to access the device.


3 Program transplantation and operation
To make the program run in Qtopia of the development board, it must be compiled in the established QtE environment and the environment variables must be set. After the terminal enters the established QtE directory, the environment variables or running environment variables and scripts are set as follows:
export QTDIR=$PWD/qt
export QPEDlR=$PWD/qtopia
export TMAKEDIR=$PWD/tmake
export TMAKEPATH=$TMAKEDIR/lib/qws/linux-armg++
export PATH=$QTDIR/bin:$QPEDIR/bin:$TMAKEDIR/
bin:$PATH

One thing worth noting is that the project files created with the Qt Designer that comes with Linux are only suitable for qmake, and the QtE environment established by the author can only use tmake to generate makefiles, so it is necessary to modify the led.pro file to make it suitable for tmake, as follows:
TEMPLATE =app
CoNFIG +=qtopia warn_on release
SoURCES +=main.epp
INTERFACES =led. ui
TARGET = led

After the above work is done, you can compile. After successful compilation, an executable binary file led is generated. However, to run the program on the qtopia desktop on the development board, a desktop file led.desktop and a customized icon led.png are required. The desktop file is as follows:
[Desktop Entry]
Comment=a LED Control Program
Exee=led
Icon=led
Type=Application
Name=LED Control

Then, copy led to the /opt/qtopia/bin directory under SBC-2410X, copy led.png to the /opt/qtopia/pics directory, and copy led.desktop to the /0pt/qtopia/apps/Applications directory. Finally, use ehmod a+X led to change the permission of the file led, restart the system, and you can see the icon led.png displayed on the qtopia desktop. Click this icon to run the program.


4 Partial source code and comments
Since the source code is relatively long, it will not be listed in full here. Only the important parts of the code and comments are given for the reader's reference.

(1) Initialization of the program

int fd: //LED device file handle
int type=1; //Default mode is counter
double period=0.2; //Default time interval
QTimer*t=new QTimer(Q″timer″); //Create timer
void LedForm::initial(){
fd=open(″/dev/leds″,0); //Open LED device
//Some other initialization statements-
>stop(); //Close timer
~

(2) Setting of LED display mode

void LedForm::push-leds(void){
static unsigned step;
unsigned led—bitmap;
inti;
switch(type){
case 0: //Mode 0: Marqueeif
(step>=14){step=0;}
if(step<7){led_bitmap=1<<step;}
else{led_bitmap=1<<(14一step);}
break;
case 1: //Method 1: counter
if (step>255) {step=0;)
Ied_bitmap=step!
break;
case 2: //Method 2: stop
led_bitmap=0:
break;
step+ten;
for (i=0; i<8; l++) {
ioctl(fd, led_bitmap&1, i);
led_bitmap>>=1;
}
}

(3) Reading LED device and calling LED display program

void LedForm::ledDisplay() {
fd_set rds;
struct timeval step;
FD_ZERO(&rds); step.
tv_sec=period;
step. tv_usec=(pefiod—step.W_sec)*1000000L;
select(fd,&rds,NULL,NULL,&step);
push_leds();
}

(4) Implementation of loop display
void LedForm::modeSel(){
t-->start(O); //Start the timer and immediately send out Signal-timeout()
connect(t,SIGNAL(timeout()), this.SLOT(ledDisplay()));
}


Conclusion
With the rapid development of the communications industry, mobile handheld devices will become the mainstream of people's work, study and life. Using Qt to design the GUI of mobile handheld devices has a unique advantage. At present, Qt is used in hundreds of software development projects around the world. In China, the development of Qt also has the potential to start a prairie fire. This article uses a basic applet to demonstrate to readers how to use Qt to develop applications and how to establish the connection between Qt and ARM. I hope it will help readers learn ARM and Qt.

This post is from MCU
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list