#include "mainwindow.h"#include <QMessageBox>#include <QString>#include <QDesktopWidget>#include <QScreen>#include <QMetaEnum>//#include <unistd.h>#include <errno.h>#include "ui_mainwindow.h"#include <QPixmap>#include "dialog_settings.h"#include "packet.h"#include <qdebug.h>MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ num_time=0; num_temp=0; flag_but_on=0; packet_one= {254, 232, 0, 0, 0, 0, 0, 0, 0}; QPixmap myPixmap_on( "C:/Users/leono/Desktop/reactor2/if_Circle_Green_34211.png" ); QPixmap myPixmap_of( "C:/Users/leono/Desktop/reactor2/icon/if_Circle_Grey_34212.png" ); QPixmap myPixmap_red( "C:/Users/leono/Desktop/reactor2/icon/if_Circle_Red_34214.png" ); ui->setupUi(this); info = new Dialog_Settings(this);//Создаем окно с настройками Com порта, info->setVisible(false);// но не отображаем. ui->lcdNumber_3->display("00:00"); ui->lcdNumber_4->display("00:00"); ui->label_4->setPixmap(myPixmap_red); ui->label_3->setPixmap(myPixmap_of); ui->spinBox->setMaximum(250); ui->spinBox_2->setMaximum(500); connect(ui->action_Com,SIGNAL(triggered(bool)),this,SLOT(settings_menu())); connect(ui->action_3,SIGNAL(triggered(bool)),this,SLOT(close())); connect(ui->pushButton_3,SIGNAL(clicked()),this,SLOT(nasos_on())); connect(ui->pushButton_4,SIGNAL(clicked()),this,SLOT(nasos_of())); connect(ui->pushButton_5,SIGNAL(clicked(bool)),this,SLOT(on_Button_clicked())); connect(this,SIGNAL(on()),this,SLOT(vizvat_taimer())); connect(this,SIGNAL(off()),this,SLOT(taimer_stop())); connect(ui->pushButton_2,SIGNAL(clicked(bool)),this,SLOT(disp_lcd_time())); connect(ui->pushButton,SIGNAL(clicked(bool)),this,SLOT(disp_lcd_temp())); connect(info, SIGNAL(duble_send_signal(QByteArray)), this, SLOT(save_str(QByteArray))); connect(this,SIGNAL(sendArray(QByteArray)),info,SIGNAL(writeData(QByteArray))); connect(this,SIGNAL(pomp_off(packet_big)),this,SLOT(put_in_array(packet_big))); connect(this,SIGNAL(pomp_on(packet_big)),this,SLOT(put_in_array(packet_big)));}MainWindow::~MainWindow(){ delete ui; qDebug("del");}void MainWindow::nasos_on(){ QPixmap myPixmap_on( "C:/Users/leono/Desktop/reactor2/if_Circle_Green_34211.png" ); QPixmap myPixmap_of( "C:/Users/leono/Desktop/reactor2/icon/if_Circle_Grey_34212.png" ); ui->label_3->setPixmap(myPixmap_on); ui->label_4->setPixmap(myPixmap_of); packet_one.on_of_pomp=1; packet_one.test_pask(); emit pomp_on(packet_one); qDebug("idx1");}void MainWindow::nasos_of(){ QPixmap myPixmap_of( "C:/Users/leono/Desktop/reactor2/icon/if_Circle_Grey_34212.png" ); QPixmap myPixmap_red( "C:/Users/leono/Desktop/reactor2/icon/if_Circle_Red_34214.png" ); ui->label_4->setPixmap(myPixmap_red); ui->label_3->setPixmap(myPixmap_of); packet_one.on_of_pomp=0; packet_one.test_pask(); emit pomp_off(packet_one); qDebug("idx2");}void MainWindow::settings_menu(){ info->setVisible(true);}void MainWindow::disp_lcd_time(){ num_time=ui->spinBox_2->value(); ui->lcdNumber_4->display(QTime::fromMSecsSinceStartOfDay(num_time*60000).toString("hh:mm"));}void MainWindow::disp_lcd_temp(){ num_temp=ui->spinBox->value(); ui->lcdNumber->display(num_temp);}void MainWindow::vizvat_taimer(){ timer = new QTimer(this); updater = new QTimer(this); updater->setSingleShot(false); connect(updater,SIGNAL(timeout()), this, SLOT(disp_lcd_temp_timer())); timer->setSingleShot(true); connect(timer, &QTimer::timeout, timer, &QObject::deleteLater); connect(timer, &QTimer::timeout, updater, &QObject::deleteLater); updater->start(1000); timer->start(num_time*60000);}void MainWindow::disp_lcd_temp_timer(){ QString text = QTime::fromMSecsSinceStartOfDay(timer->interval() - timer->remainingTime()).toString("hh:mm"); if (((((timer->interval() - timer->remainingTime())/1000)) % 2) != 0) text[2] = ' '; ui->lcdNumber_3->display(text);}void MainWindow::on_Button_clicked(){ if(flag_but_on==0) { flag_but_on=1; qDebug("flag_but_on_1"); ui->pushButton_5->setText("СТОП"); emit on(); } else if(flag_but_on==1) { flag_but_on=0; qDebug("flag_but_off_2"); ui->pushButton_5->setText("ПУСК"); emit off(); }}void MainWindow::taimer_stop(){ qDebug("stop"); updater->stop();}void MainWindow::save_str(QByteArray data){ packet_big tmp; unsigned char* masstmp = (unsigned char* )&tmp; for(unsigned int i=0; i<sizeof(tmp); i++) { masstmp[i]=(unsigned char)data[i]; } if(!tmp.test_pask()) { packet_one=tmp; qDebug()<<" ONE byte: "<<packet_one.start_byte_one<<"\n"<<"TWO byte: " << packet_one.start_byte_two <<"\n"<<"TEMP byte: "<< packet_one.temp_pomp<<"\n"<<"ON-OF byte: "<<packet_one.on_of_pomp<<"\n"<<"CRC8 byte: "<<packet_one.CRC8<<"\n"; } ui->lcdNumber_5->display(packet_one.temp_pomp); if(packet_one.on_of_pomp==0) { QPixmap myPixmap_on( "C:/Users/leono/Desktop/reactor2/if_Circle_Green_34211.png" ); QPixmap myPixmap_of( "C:/Users/leono/Desktop/reactor2/icon/if_Circle_Grey_34212.png" ); QPixmap myPixmap_red( "C:/Users/leono/Desktop/reactor2/icon/if_Circle_Red_34214.png" ); ui->label_4->setPixmap(myPixmap_red); ui->label_3->setPixmap(myPixmap_of); } else if(packet_one.on_of_pomp==1) { QPixmap myPixmap_on( "C:/Users/leono/Desktop/reactor2/if_Circle_Green_34211.png" ); QPixmap myPixmap_of( "C:/Users/leono/Desktop/reactor2/icon/if_Circle_Grey_34212.png" ); ui->label_3->setPixmap(myPixmap_on); ui->label_4->setPixmap(myPixmap_of); }}void MainWindow::put_in_array(packet_big data){ QByteArray tmp; unsigned char* masstmp = (unsigned char* )&data; qDebug()<<" QQQQQQQQQQQQQQQQQQQQQ "<<packet_one.on_of_pomp; for(unsigned int i=0; i<sizeof(data); i++) { tmp[i]=masstmp[i]; } emit sendArray(tmp);}
DEFINES += _USING_V110_SDK71_