mini2440之--leds程序

如图所示,图中用到了PushButton,GroupBox,SpinBox,PixmapLabel,TextLabel组件


led.h

#ifndef MYHELLOFORM_H
#define MYHELLOFORM_H
#include "led_base.h"
#include <qpixmap.h>
 
class MyLEDForm : public LEDBaseForm
{ 
    Q_OBJECT
	
    public:
        MyLEDForm( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
	    virtual ~MyLEDForm();
	    //const QPixmap *eddy;
 
    private slots:
        void startSys();
	void stopSys();
	void OnLED();
	void OffLED();
	void blink1();
	void blink2();
};
 
#endif // MYHELLOFORM_H

led.cpp

#include "led.h"
#include <qlabel.h>
#include <qpushbutton.h>
#include <qspinbox.h>
 
#include <qtopia/qpeapplication.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <fcntl.h>
 
MyLEDForm::MyLEDForm( QWidget* parent, const char* name, WFlags fl)
	    :LEDBaseForm(parent, name, fl)
{
    connect(PushButton1,SIGNAL(clicked()),this,SLOT(stopSys()));
    connect(PushButton2,SIGNAL(clicked()),this,SLOT(startSys()));
    connect(PushButton3,SIGNAL(clicked()),this,SLOT(OnLED()));
    connect(PushButton4,SIGNAL(clicked()),this,SLOT(OffLED()));
    connect(PushButton5,SIGNAL(clicked()),this,SLOT(blink1()));
    connect(PushButton6,SIGNAL(clicked()),this,SLOT(blink2()));
}
 
MyLEDForm::~MyLEDForm()
{
    system("/etc/rc.d/init.d/leds start");
}
 
void MyLEDForm::stopSys()
{
    system("/etc/rc.d/init.d/leds stop");
    TextLabel1->setText("System Led is Stoped");
}
 
void MyLEDForm::startSys()
{
    system("/etc/rc.d/init.d/leds start");
    TextLabel1->setText("System Led is Started");
}void MyLEDForm::OnLED()
{
    int iData=SpinBox1->text().toFloat();
 
    int fd = ::open("/dev/leds", 0);
    ::ioctl(fd, 1, iData);
    ::close(fd); // 关闭设备
}
void MyLEDForm::OffLED()
{
    int iData=SpinBox1->text().toFloat();//取得SpinBox1上的数字
 
    int fd = ::open("/dev/leds", 0);
    ::ioctl(fd, 0, iData);
    ::close(fd); // 关闭设备
}
void MyLEDForm::blink1()
{
    volatile int k;
 
    int fd=::open("/dev/leds", 0);  // 打开设备
    for (k=0; k<4; k++)
    {
      ::ioctl(fd, 1, k);      
	usleep(500000);
      ::ioctl(fd, 0, k);
	usleep(500000);
    }
    ::close(fd); // 关闭设备
}
void MyLEDForm::blink2()
{
    // transfer codes from the demostration.
    // " :: "is added before each function.
    int fd = ::open("/dev/leds0", 0);
    if (fd < 0) {
	fd = ::open("/dev/leds", 0);
    }
    if (fd < 0) {
	::perror("open device leds");
	::exit(1);
    }
    for (int k=0; k<4; k++)
    {
      	::ioctl(fd, 0, 3-k);      
	usleep(500000);
      	::ioctl(fd, 1, 3-k);
	usleep(500000);
    }
    ::close(fd);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值