• 大小: 7KB
    文件类型: .gz
    金币: 1
    下载: 0 次
    发布日期: 2021-06-15
  • 语言: 其他
  • 标签: qt程序  

资源简介

里面有针对ok6410的led、蜂鸣器、ad的qt程序,很适合qt及arm初学者自己学

资源截图

代码片段和文件信息

#include “frmmain.h“
#include “ui_frmmain.h“
#include “unistd.h“
#include “stdlib.h“
#include “sys/types.h“
#include “sys/stat.h“
#include “sys/ioctl.h“
#include “fcntl.h“
#include “myARMLinuxHelper.h“

frmMain::frmMain(QWidget *parent) :
        QMainWindow(parent)
        ui(new Ui::frmMain)
{
    ui->setupUi(this);

    ::FormHelper::FormOnlyCloseButton(this);
    ::FormHelper::FormInCenter(this);

    //LED控制处理
    ::system(“kill -s STOP ‘pidof led-player‘“);
    ledHand=::open(“/dev/leds0“ O_RDONLY);

    if (ledHand<0)
    {
        ledHand=::open(“/dev/leds“ O_RDONLY);
    }    

    ledIndex=0;

    this->setWindowtitle(tr(“TE6410驱动演示“));
    myTimer=new QTimer(this);
    myTimer->setInterval(100);
    connect(myTimerSIGNAL(timeout())thisSLOT(DoLED()));

    //蜂鸣器控制处理
    beepHand=::open(“/dev/pwm“ O_RDONLY);
    ::ioctl(beepHand 0);

    beepValue=100;

    //AD采样
    adHand=::open(“/dev/adc“ O_RDONLY);

    timerAD=new QTimer(this);
    timerAD->setInterval(500);
    connect(timerADSIGNAL(timeout())thisSLOT(GetADValue()));


    //按键识别处理
    keyHand=::open(“/dev/input/event0“ O_RDONLY | O_NONBLOCK);

    key=new QSocketNotifier(keyHandQSocketNotifier::Readthis);
    connect(keySIGNAL(activated(int))thisSLOT(keyEvent()));

}

frmMain::~frmMain()
{
    delete ui;
}

void frmMain::closeEvent(QCloseEvent *)
{
    //关闭LED
    ::close(ledHand);

    //关闭蜂鸣器
    ::ioctl(beepHand0);
    ::close(beepHand);

    //关闭AD
    ::close(adHand);

    //关闭按键
    ::close(keyHand);
}

void frmMain::DoLED()
{
    ioctl(ledHand0ledIndex);
    ledIndex++;
    if (ledIndex>3){ledIndex=0;}
    ioctl(ledHand1ledIndex);    
}

void frmMain::on_btnLed0_clicked()
{
    if (ui->btnLed0->text()==tr(“LED0亮“))
    {
        ioctl(ledHand10);
        ui->btnLed0->setText(tr(“LED0灭“));
    }
    else
    {
        ioctl(ledHand00);
        ui->btnLed0->setText(tr(“LED0亮“));
    }
}

void frmMain::on_btnLed1_clicked()
{
    if (ui->btnLed1->text()==tr(“LED1亮“))
    {
        ioctl(ledHand11);
        ui->btnLed1->setText(tr(“LED1灭“));
    }
    else
    {
        ioctl(ledHand01);
        ui->btnLed1->setText(tr(“LED1亮“));
    }
}

void frmMain::on_btnLed2_clicked()
{
    if (ui->btnLed2->text()==tr(“LED2亮“))
    {
        ioctl(ledHand12);
        ui->btnLed2->setText(tr(“LED2灭“));
    }
    else
    {
        ioctl(ledHand02);
        ui->btnLed2->setText(tr(“LED2亮“));
    }
}

void frmMain::on_btnLed3_clicked()
{
    if (ui->btnLed3->text()==tr(“LED3亮“))
    {
        ioctl(ledHand13);
        ui->btnLed3->setText(tr(“LED3灭“));
    }
    else
    {
        ioctl(ledHand03);
        ui->btnLed3->setText(tr(“LED3亮“));
    }
}

void frmMain::on_btnStart_clicked()
{
    if (ui->btnStart->text()==tr(“开始“))
    {
        myTimer->start();
        ui->btnStart->setText(tr(“停止“));
    }
    else
    {
        myTimer->stop();
        ui->btnStart->setText(tr(“开始“));
    }
}

void frmMain::on_btnOpen_clicked()
{
    if (ui->btnOpen->text(

评论

共有 条评论