实验室智能管理系统(2)——Arm+QT部分(二)

主界面
这里写图片描述

myzigbee.h

#ifndef MYZIGBEE_H
#define MYZIGBEE_H

#include <QDialog>
#include "posix_qextserialport.h"
#include <QTimer>
#include <QTime>
#include "safegate.h"
#include <QProgressDialog>


namespace Ui {
class Myzigbee;
}

class Myzigbee : public QDialog
{
    Q_OBJECT

public:
    explicit Myzigbee(QWidget *parent = 0);
    ~Myzigbee();

    Safegate *safegate;

    int temp_init;

private:
    Ui::Myzigbee *ui;

    QTime timeCurrect;
    QString time_currect;
    QTimer *timeTimer;
    QTimer *zigbeeReadTime;    
    QTimer *UIrefushTime;

    Posix_QextSerialPort *zigbeeSerialPort; 
    QByteArray zigbeeReadData;
    QByteArray zigbeeWriteData;

    void serialInit();
    QString temp,hum;
    unsigned char led1, led2, led3, fan, sunlight, smoke ,finger;

private slots:
    void on_btn_check_clicked();
    void on_btn_look_clicked();
    void on_btn_delet_clicked();
    void on_btn_add_clicked();
    //void on_toolButton_clicked();
    void on_btn_reboot_clicked();
    void on_btn_fan_close_clicked();
    void on_btn_fan_open_clicked();
    void on_toolButton_6_clicked();
    void on_btn_led3_open_clicked();
    void on_btn_led2_close_clicked();
    void on_btn_led2_open_clicked();
    void on_btn_led1_close_clicked();
    void on_btn_led1_open_clicked();
    void on_btn_close_clicked();
    void on_btn_home_clicked();
    void on_btn_system_clicked();
    void zigbeeReadSlots();      
    void timeRefreshSlots();
    void respond_to_wakeup();

    void on_btn_close_2_clicked();
};

#endif // MYZIGBEE_H

myzigbee.cpp

#include "myzigbee.h"
#include "ui_myzigbee.h"

Myzigbee::Myzigbee(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Myzigbee)
{
    ui->setupUi(this);
    ui->page_home->show();
    ui->page_system->hide();
    ui->page_close->hide();
    //ui->btn_home->setEnabled(false);
    //ui->btn_system->setEnabled(true);
    //ui->btn_close->setEnabled(true);
    temp_init = 0;

    safegate = new Safegate ;
    safegate->show();

    this->setMaximumSize(800,500);
    this->setMinimumSize(800,500);
    this->setWindowFlags(Qt::FramelessWindowHint);
    timeCurrect = QTime::currentTime();
    time_currect = timeCurrect.toString(" hh : mm : ss");

    timeTimer = new QTimer;
    timeTimer->start(1000);
    connect(timeTimer,SIGNAL(timeout()),this,SLOT(timeRefreshSlots()));

    serialInit();
    zigbeeReadTime = new QTimer(this);
    zigbeeReadTime->start(500);000ms
    connect(zigbeeReadTime,SIGNAL(timeout()),this,SLOT(zigbeeReadSlots()));

    connect(safegate,SIGNAL(ask_for_wakeup()),this,SLOT(respond_to_wakeup()));
}

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

void Myzigbee::respond_to_wakeup()
{
    QByteArray  denglu;
    denglu.append("200");
    zigbeeSerialPort->write(denglu);
    this->show();
    safegate->hide();

}

void Myzigbee::serialInit()
{
    zigbeeSerialPort = new Posix_QextSerialPort;
    zigbeeSerialPort->setPortName("/dev/ttySAC3");
    zigbeeSerialPort->setQueryMode(QextSerialBase::Polling);
    zigbeeSerialPort->open(QIODevice::ReadWrite);
    zigbeeSerialPort->setBaudRate(BAUD115200);
    zigbeeSerialPort->setDataBits(DATA_8); 
    zigbeeSerialPort->setParity(PAR_NONE);
    zigbeeSerialPort->setStopBits(STOP_1); 
    zigbeeSerialPort->setFlowControl(FLOW_OFF);
    zigbeeSerialPort->setTimeout(100); 
}


void Myzigbee::zigbeeReadSlots()
{
    zigbeeReadData = zigbeeSerialPort->readAll(); 

    /* F+D+[]+DATA+E
     * 0x00 temp
     * 0x01 hum
     */
     for(int i = 0; i < zigbeeReadData.length(); i++)
     {

         if(zigbeeReadData[i] == 'F' && zigbeeReadData[i+1] == 'D' && zigbeeReadData[i+4] == 'E')
         {
             switch (zigbeeReadData[i+2]) {
             case 0x01:
             {
                 temp = QString::number(zigbeeReadData[i+3],10);
                 ui->label_temp->setText(temp);
                 break;
             }
             case 0x02:
             {
                 hum = QString::number(zigbeeReadData[i+3],10);
                 ui->label_hum->setText(hum);
                 break;
             }
             case 0x03:
             {
                 sunlight = zigbeeReadData[i+3];
                 if(sunlight == 'A')
                 {
                     ui->label_light->setText("normal");
                 }
                 else
                 {
                     ui->label_light->setText("error");
                 }
                 break;
             }
             case 0x04:
             {
                 smoke = zigbeeReadData[i+3];
                 if(smoke == 'A')
                 {
                     ui->label_fire->setText("normal");
                 }
                 else
                 {
                     ui->label_fire->setText("error");
                 }
                 break;
             }
             case 0x05://LOGIN
             {
                 finger = zigbeeReadData[i+3];
                 if(finger == 'A')
                 {
                     safegate->delay();
                     safegate->hide();
                     this->show();
                 }
                 break;
             }
             case 0x06://yanzhen zhi wen
             {
                 finger = zigbeeReadData[i+3];
                 if(finger == 'A')
                 {
                     ui->tb->setText(tr("THE FINGER IS TRUE!"));
                 }
                 else
                 {
                     ui->tb->setText(tr("THE FINGER HAS NO RECORD!"));
                 }
                 break;
             }
             case 0x07: //add finger
             {
                 finger = zigbeeReadData[i+3];
                 if(finger == 'A')
                 {
                     ui->tb->setText(tr("Add success"));
                 }
                 else
                 {
                     ui->tb->setText(tr("Add Error"));
                 }
                 break;
             }
             case 0x08: //finger has had
             {
                 finger = zigbeeReadData[i+3];
                 if(finger == 'A')
                 {
                     ui->tb->setText(tr("The usr has log"));
                 }
                 else
                 {

                 }
                 break;
             }
             case 0x09: //clear finger
             {
                 finger = zigbeeReadData[i+3];
                 if(finger == 'A')
                 {
                     ui->tb->setText(tr("Clear finger success"));
                 }
                 else
                 {

                 }
                 break;
             }
             case 0x0A: //finger num
             {
                 finger = zigbeeReadData[i+3];
                 QString num = QString("Account num is : %1").arg(QString::number(finger, 10));
                 ui->tb->setText(num);
                 break;
             }
             default:
                 break;
             }
         }
     }
}

void Myzigbee::timeRefreshSlots()
{
//    timeCurrect = QTime::currentTime();
//    time_currect = timeCurrect.toString(" hh : mm : ss");
//    ui->label_time->setText(time_currect);
}

void Myzigbee::on_btn_home_clicked()
{
    ui->page_home->show();
    ui->page_system->hide();
    ui->page_close->hide();
    ui->btn_home->setEnabled(true);
    ui->btn_system->setEnabled(true);
    ui->btn_close->setEnabled(true);
}

void Myzigbee::on_btn_system_clicked()
{
    ui->page_system->show();
    ui->page_home->hide();
    ui->page_close->hide();
    ui->btn_system->setEnabled(true);
    ui->btn_home->setEnabled(true);
    ui->btn_close->setEnabled(true);
}

void Myzigbee::on_btn_close_clicked()
{
    ui->page_close->show();
    ui->page_home->hide();
    ui->page_system->hide();
    ui->btn_close->setEnabled(true);
    ui->btn_home->setEnabled(true);
    ui->btn_system->setEnabled(true);
}

void Myzigbee::on_btn_led1_open_clicked()
{
    QByteArray  led1_open;
    led1_open.append("100");
    zigbeeSerialPort->write(led1_open);
}

void Myzigbee::on_btn_led1_close_clicked()
{
    QByteArray  led1_close;
    led1_close.append("101");
    zigbeeSerialPort->write(led1_close);
}

void Myzigbee::on_btn_led2_open_clicked()
{
    QByteArray  led2_open;
    led2_open.append("102");
    zigbeeSerialPort->write(led2_open);
}

void Myzigbee::on_btn_led2_close_clicked()
{
    QByteArray  led2_close;
    led2_close.append("103");
    zigbeeSerialPort->write(led2_close);
}

void Myzigbee::on_btn_led3_open_clicked()
{
    QByteArray  led3_open;
    led3_open.append("104");
    zigbeeSerialPort->write(led3_open);
}

void Myzigbee::on_toolButton_6_clicked()
{
    QByteArray  led3_close;
    led3_close.append("105");
    zigbeeSerialPort->write(led3_close);
}

void Myzigbee::on_btn_fan_open_clicked()
{
    QByteArray  fan_open;
    fan_open.append("106");
    zigbeeSerialPort->write(fan_open);
}

void Myzigbee::on_btn_fan_close_clicked()
{
    QByteArray  fan_close;
    fan_close.append("107");
    zigbeeSerialPort->write(fan_close);
}

void Myzigbee::on_btn_add_clicked()
{
    QByteArray  btn_add;
    btn_add.append("201");
    zigbeeSerialPort->write(btn_add);
}

void Myzigbee::on_btn_delet_clicked()
{
    QByteArray  btn_delet;
    btn_delet.append("202");
    zigbeeSerialPort->write(btn_delet);
}

void Myzigbee::on_btn_look_clicked()
{
    QByteArray  btn_look;
    btn_look.append("203");
    zigbeeSerialPort->write(btn_look);
}

void Myzigbee::on_btn_check_clicked()
{
    QByteArray  btn_check;
    btn_check.append("204");
    zigbeeSerialPort->write(btn_check);
}


void Myzigbee::on_btn_reboot_clicked()
{
    QByteArray  btn_relog;
    btn_relog.append("205");
    zigbeeSerialPort->write(btn_relog);
    safegate->show();
    this->hide();
    ui->page_home->show();
    ui->page_system->hide();
    ui->page_close->hide();
}

void Myzigbee::on_btn_close_2_clicked()
{
    system("halt");
}

附上主程序

#include <QtGui/QApplication>
#include "myzigbee.h"
#include <QTextCodec>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
    QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
    //QApplication::setOverrideCursor(Qt::BlankCursor);
    Myzigbee w;
    w.hide();

    return a.exec();
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值