- 积分
- 3
贡献25
飞刀2 FD
注册时间2019-1-9
在线时间0 小时
扫一扫,手机访问本帖
|
#include <QtGui>
#include <QtCore>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
#include "good.h"
#define LED_OPEN 0
#define LED_CLOSE 1
int fd;
void led2_on()
{
fd = open("/dev/leds", 0);
if (fd < 0)
{
perror("open device leds error");
exit(1);
}
ioctl(fd,LED_OPEN,1);//led2 close
close(fd);
}
void led2_off()
{
fd = open("/dev/leds", 0);
if (fd < 0)
{
perror("open device leds error");
exit(1);
}
ioctl(fd,LED_CLOSE,1);//led2 close
close(fd);
}
void led3_on()
{
fd = open("/dev/leds", 0);
if (fd < 0)
{
perror("open device leds error");
exit(1);
}
ioctl(fd,LED_OPEN,2);//led3 open
close(fd);
}
void led3_off()
{
fd = open("/dev/leds", 0);
if (fd < 0)
{
perror("open device leds error");
exit(1);
}
ioctl(fd,LED_CLOSE,2);//led3 close
close(fd);
}
void led4_on()
{
fd = open("/dev/leds", 0);
if (fd < 0)
{
perror("open device leds error");
exit(1);
}
ioctl(fd,LED_OPEN,3);//led4 open
close(fd);
}
void led4_off()
{
fd = open("/dev/leds", 0);
if (fd < 0)
{
perror("open device leds error");
exit(1);
}
ioctl(fd,LED_CLOSE,3);//led4 close
close(fd);
}
QProcess *pro_1=new QProcess;
Maindialog::Maindialog(QWidget *parent):QDialog(parent)
{
label_madplay=new QLabel(tr("Madplay:"));
label_time0=new QLabel(tr("Time0:"));
label_led2=new QLabel(tr("LED2:"));
label_led3=new QLabel(tr("LED3:"));
label_led4=new QLabel(tr("LED4:"));
btn_madplay=new QPushButton(tr("open"));
btn_madplay->setEnabled(true);
btn_madplay_off=new QPushButton(tr("close"));
btn_madplay_off->setEnabled(true);
btn_time0=new QPushButton(tr("open"));
btn_time0->setEnabled(false);
check_led2=new QCheckBox(tr("led2_status"));
check_led2->setEnabled(true);
check_led3=new QCheckBox(tr("led3_status"));
check_led3->setEnabled(true);
check_led4=new QCheckBox(tr("led4_status"));
check_led4->setEnabled(true);
//slots
connect(btn_madplay,SIGNAL(clicked()),this,SLOT(madplay()));
connect(btn_madplay_off,SIGNAL(clicked()),this,SLOT(madplay_off()));
connect(btn_time0,SIGNAL(clicked()),this,SLOT(time0()));
connect(check_led2,SIGNAL(clicked()),this,SLOT(led2()));
connect(check_led3,SIGNAL(clicked()),this,SLOT(led3()));
connect(check_led4,SIGNAL(clicked()),this,SLOT(led4()));
//
QHBoxLayout *layout_madplay=new QHBoxLayout;
layout_madplay->addWidget(label_madplay);
layout_madplay->addWidget(btn_madplay);
layout_madplay->addWidget(btn_madplay_off);
QHBoxLayout *layout_time0=new QHBoxLayout;
layout_time0->addWidget(label_time0);
layout_time0->addWidget(btn_time0);
QHBoxLayout *layout_led2=new QHBoxLayout;
layout_led2->addWidget(label_led2);
layout_led2->addWidget(check_led2);
QHBoxLayout *layout_led3=new QHBoxLayout;
layout_led3->addWidget(label_led3);
layout_led3->addWidget(check_led3);
QHBoxLayout *layout_led4=new QHBoxLayout;
layout_led4->addWidget(label_led4);
layout_led4->addWidget(check_led4);
QVBoxLayout *layout_main=new QVBoxLayout;
layout_main->addLayout(layout_madplay);
layout_main->addLayout(layout_time0);
layout_main->addLayout(layout_led2);
layout_main->addLayout(layout_led3);
layout_main->addLayout(layout_led4);
setLayout(layout_main);
setWindowTitle(tr("API"));
setFixedHeight(sizeHint().height());
}
void Maindialog::madplay()
{
pro_1->start("/opt/madplay_run");//直接运行脚本
}
void Maindialog::madplay_off()
{
pro_1->write(QByteArray("q"));
//pro_1->terminate();
pro_1->kill();
}
void Maindialog::time0()
{
QProcess *pro_8=new QProcess;
pro_8->start("/opt/time0_run");
}
void Maindialog::led2()
{
if(check_led2->isChecked())//选中了
{
led2_on();
/*
QProcess *pro_2=new QProcess;
pro_2->start("/opt/led2_on");
*/
}
else
{
led2_off();
/*
QProcess *pro_3=new QProcess;
pro_3->start("/opt/led2_off");
*/
}
}
void Maindialog::led3()
{
if(check_led3->isChecked())//选中了
{
led3_on();
/*
QProcess *pro_4=new QProcess;
pro_4->start("/opt/led3_on");
*/
}
else
{
led3_off();
/*
QProcess *pro_5=new QProcess;
pro_5->start("/opt/led3_off");
*/
}
}
void Maindialog::led4()
{
if(check_led4->isChecked())//选中了
{
led4_on();
/*
QProcess *pro_6=new QProcess;
pro_6->start("opt/led4_on");
*/
}
else
{
led4_off();
/*
QProcess *pro_7=new QProcess;
pro_7->start("/opt/led4_off");
*/
}
}
|
|