|
@@ -0,0 +1,132 @@
|
|
|
+#include "mainwindow.h"
|
|
|
+#include "ui_mainwindow.h"
|
|
|
+
|
|
|
+#include <iostream>
|
|
|
+#include "takeover.pb.h"
|
|
|
+
|
|
|
+MainWindow::MainWindow(QWidget *parent) :
|
|
|
+ QMainWindow(parent),
|
|
|
+ ui(new Ui::MainWindow)
|
|
|
+{
|
|
|
+ ui->setupUi(this);
|
|
|
+
|
|
|
+ ui->checkBox_minDec->setChecked(false);
|
|
|
+ ui->checkBox_speed->setChecked(false);
|
|
|
+ ui->horizontalSlider_Speed->setVisible(false);
|
|
|
+ ui->lineEdit_Speed->setVisible(false);
|
|
|
+ ui->horizontalSlider_minDec->setVisible(false);
|
|
|
+ ui->lineEdit_minDec->setVisible(false);
|
|
|
+
|
|
|
+ setWindowTitle("Take Over");
|
|
|
+
|
|
|
+ mpa = iv::modulecomm::RegisterSend("takeover",1000,1);
|
|
|
+
|
|
|
+ mpTimer = new QTimer;
|
|
|
+ mpTimer->setInterval(100);
|
|
|
+ connect(mpTimer,SIGNAL(timeout()),this,SLOT(onTimer()));
|
|
|
+ mpTimer->start();
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+MainWindow::~MainWindow()
|
|
|
+{
|
|
|
+ delete mpTimer;
|
|
|
+
|
|
|
+ iv::modulecomm::Unregister(mpa);
|
|
|
+
|
|
|
+ delete ui;
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::on_checkBox_speed_clicked()
|
|
|
+{
|
|
|
+ if(ui->checkBox_speed->isChecked())
|
|
|
+ {
|
|
|
+ ui->horizontalSlider_Speed->setVisible(true);
|
|
|
+ ui->horizontalSlider_Speed->setValue(15);
|
|
|
+ ui->lineEdit_Speed->setVisible(true);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ui->horizontalSlider_Speed->setVisible(false);
|
|
|
+ ui->lineEdit_Speed->setVisible(false);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::on_horizontalSlider_Speed_valueChanged(int value)
|
|
|
+{
|
|
|
+ ui->lineEdit_Speed->setText(QString::number(value));
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::on_checkBox_minDec_clicked()
|
|
|
+{
|
|
|
+ if(ui->checkBox_minDec->isChecked())
|
|
|
+ {
|
|
|
+ ui->horizontalSlider_minDec->setVisible(true);
|
|
|
+ ui->lineEdit_minDec->setVisible(true);
|
|
|
+ ui->horizontalSlider_minDec->setValue(15);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ui->horizontalSlider_minDec->setVisible(false);
|
|
|
+ ui->lineEdit_minDec->setVisible(false);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::on_horizontalSlider_minDec_valueChanged(int value)
|
|
|
+{
|
|
|
+ double fvalue = value * 0.1 - 1.0;
|
|
|
+ ui->lineEdit_minDec->setText(QString::number(fvalue,'f',1));
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::on_pushButton_5kmh_clicked()
|
|
|
+{
|
|
|
+ ui->horizontalSlider_Speed->setValue(5);
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::on_pushButton_15kmh_clicked()
|
|
|
+{
|
|
|
+ ui->horizontalSlider_Speed->setValue(15);
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::on_pushButton_m1ms2_clicked()
|
|
|
+{
|
|
|
+ ui->horizontalSlider_minDec->setValue(0);
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::on_pushButton_d5ms2_clicked()
|
|
|
+{
|
|
|
+ ui->horizontalSlider_minDec->setValue(15);
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::onTimer()
|
|
|
+{
|
|
|
+ iv::brain::takeover xtakeover;
|
|
|
+ xtakeover.set_btakeacc(false);
|
|
|
+ xtakeover.set_btakebrake(false);
|
|
|
+ xtakeover.set_btakespeed(false);
|
|
|
+ xtakeover.set_btakewheel(false);
|
|
|
+
|
|
|
+ if(ui->checkBox_minDec->isChecked())
|
|
|
+ {
|
|
|
+ double minDec = ui->lineEdit_minDec->text().toDouble();
|
|
|
+ xtakeover.set_mindecelerate(minDec);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ui->checkBox_speed->isChecked())
|
|
|
+ {
|
|
|
+ double fspeed = ui->lineEdit_Speed->text().toDouble();
|
|
|
+ xtakeover.set_fspeed(fspeed);
|
|
|
+ }
|
|
|
+
|
|
|
+ int nsize = xtakeover.ByteSize();
|
|
|
+ std::shared_ptr<char> pstr_ptr = std::shared_ptr<char>(new char[nsize]);
|
|
|
+ if(xtakeover.SerializeToArray(pstr_ptr.get(),nsize))
|
|
|
+ {
|
|
|
+ iv::modulecomm::ModuleSendMsg(mpa, pstr_ptr.get(),nsize);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cout<<" Serialize take over Fail."<<std::endl;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|