From c2dc4b72a5485c9e61dd3608a5ec5dcb718ba81f Mon Sep 17 00:00:00 2001 From: Johannes Paehr Date: Fri, 28 Dec 2018 17:22:40 +0100 Subject: [PATCH] changed more pointers to smart points --- hardwaresetup.cpp | 17 +++++++++++------ mainwindow.cpp | 7 ++++--- qvectorhelper.cpp | 8 ++++---- training.cpp | 21 ++++++++++++--------- training.h | 6 ++++++ 5 files changed, 37 insertions(+), 22 deletions(-) diff --git a/hardwaresetup.cpp b/hardwaresetup.cpp index f9dfcf2..151261a 100644 --- a/hardwaresetup.cpp +++ b/hardwaresetup.cpp @@ -313,6 +313,7 @@ void HardwareSetup::run() { } // end HARDWARE_VERSION 2 else if (HARDWARE_VERSION == 3) { + uint8_t dummy[sizeof(struct TransCheck)] = {0}; fd = open(PORT_PATH, O_RDONLY); while (this->fd < 0) { @@ -360,8 +361,8 @@ void HardwareSetup::run() { usleep(50000); // 150ms - for (int i = 0; i < 6; i++) { - if (received->begin == '#' && received->end == '!') { + if (received->begin == '#' && received->end == '!') { + for (int i = 0; i < 6; i++) { cout << "i: " << i << " time: " << static_cast(received->data[i].time) << " update: " @@ -412,12 +413,16 @@ void HardwareSetup::run() { break; } } - } // dataframe ok - else { - // dataframe not ok - tcflush(fd, TCIFLUSH); } + } // dataframe ok + else { + // dataframe not ok + tcflush(fd, TCIFLUSH); } + + // overwrite received data to prevent same data gets read one more + // time; dummy data is array of zeros + memcpy(received.get(), dummy, sizeof(struct TransCheck)); } } else { diff --git a/mainwindow.cpp b/mainwindow.cpp index 939f6a0..6874948 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -56,9 +56,10 @@ MainWindow::~MainWindow() { } void MainWindow::WindowTraining() { - // this->interfaceTraining = new Training(this, this->db); - this->interfaceTraining = std::make_shared(this, this->db); - this->interfaceTraining->show(); + { + this->interfaceTraining = std::make_shared(this, this->db); + this->interfaceTraining->show(); + } } void MainWindow::NewWindowSettings() { diff --git a/qvectorhelper.cpp b/qvectorhelper.cpp index 85b2cde..43076f6 100644 --- a/qvectorhelper.cpp +++ b/qvectorhelper.cpp @@ -21,7 +21,7 @@ int QVectorHelper::getCurTime(const QVector x) { int QVectorHelper::getMinSec1(const QVector> x) { int min = 9999; if (x.size() > 0) { - if (x.at(0).size() >= 3) { + if (x.at(0).size() >= 4) { if (x.at(0).at(0) >= minSec1) { min = x.at(0).at(0); } @@ -35,7 +35,7 @@ int QVectorHelper::getMinSec1(const QVector> x) { } for (int i = 1; i < x.size(); i++) { - if (x.at(i).size() >= 1) { + if (x.at(i).size() >= 3) { // entire lap if (x.at(i).at(0) < min) { if (x.at(i).at(0) >= minSec1) { min = x.at(i).at(0); @@ -62,7 +62,7 @@ int QVectorHelper::getMinSec2(const QVector> x) { } for (int i = 1; i < x.size(); i++) { - if (x.at(0).size() >= 2) { + if (x.at(0).size() >= 3) { // entire lap if (x.at(i).at(1) < min) { if (x.at(0).at(1) >= minSec2) { min = x.at(i).at(1); @@ -89,7 +89,7 @@ int QVectorHelper::getMinSec3(const QVector> x) { } for (int i = 1; i < x.size(); i++) { - if (x.at(i).size() >= 3) { + if (x.at(i).size() >= 3) { // entire lap if (x.at(i).at(2) < min) { if (x.at(0).at(2) >= minSec3) { min = x.at(i).at(2); diff --git a/training.cpp b/training.cpp index 1b7ad1b..5f2d062 100644 --- a/training.cpp +++ b/training.cpp @@ -3,6 +3,7 @@ #include "timemodel.h" #include "ui_training.h" #include "unistd.h" +#include #include #include #include @@ -49,13 +50,15 @@ Training::Training(QWidget * parent, std::shared_ptr db) // SLOT(prepareNextRace())); QObject::connect(this->ui->pBStop, // SIGNAL(clicked()), this, SLOT(stopClicked())); - QShortcut * shortcut = new QShortcut(QKeySequence("Ctrl+Q"), this); - QShortcut * shellReset = new QShortcut(QKeySequence("Ctrl+s"), this); - QShortcut * deaReset = new QShortcut(QKeySequence("Ctrl+d"), this); + shortcut = std::make_shared(QKeySequence("Ctrl+Q"), this); + shellReset = std::make_shared(QKeySequence("Ctrl+s"), this); + deaReset = std::make_shared(QKeySequence("Ctrl+d"), this); - QObject::connect(shortcut, SIGNAL(activated()), this, SLOT(close())); - QObject::connect(shellReset, SIGNAL(activated()), this, SLOT(ResetShell())); - QObject::connect(deaReset, SIGNAL(activated()), this, SLOT(ResetDea())); + QObject::connect(shortcut.get(), SIGNAL(activated()), this, SLOT(close())); + QObject::connect(shellReset.get(), SIGNAL(activated()), this, + SLOT(ResetShell())); + QObject::connect(deaReset.get(), SIGNAL(activated()), this, + SLOT(ResetDea())); QObject::connect(this->ui->pBReset, SIGNAL(clicked()), this, SLOT(Reset())); QObject::connect(this->ui->pBResetDea, SIGNAL(clicked()), this, @@ -86,7 +89,7 @@ Training::Training(QWidget * parent, std::shared_ptr db) } } void Training::ResetShell() { - + cout << "reset shell" << endl; this->VecShell.clear(); // this->ui->lWShellTime->clear(); @@ -104,6 +107,7 @@ void Training::ResetShell() { this->ui->lShellLaps->setText("0"); } void Training::ResetDea() { + cout << "reset dea" << endl; this->VecDea.clear(); // this->ui->lWDeaTime->clear(); @@ -255,8 +259,7 @@ void Training::shellSlot(int time, int sector) { } void Training::closeEvent(QCloseEvent * event) { Hardware->setStop(); - this->close(); - Q_UNUSED(event); + event->accept(); } void Training::deaSlot(int time, int sector) { diff --git a/training.h b/training.h index fba2e3a..a85a817 100644 --- a/training.h +++ b/training.h @@ -5,6 +5,7 @@ #include "hardwaresetup.h" #include "timemodel.h" #include +#include #include #include #include @@ -53,6 +54,11 @@ class Training : public QMainWindow { TimeModel * timeModelShell; QVector minSecTime; + // shortcuts + std::shared_ptr shellReset; + std::shared_ptr shortcut; + std::shared_ptr deaReset; + public slots: void ResetShell(); void ResetDea();