changed more pointers to smart points

This commit is contained in:
2018-12-28 17:22:40 +01:00
parent 5229f5eec3
commit c2dc4b72a5
5 changed files with 37 additions and 22 deletions

View File

@@ -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<int>(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 {

View File

@@ -56,9 +56,10 @@ MainWindow::~MainWindow() {
}
void MainWindow::WindowTraining() {
// this->interfaceTraining = new Training(this, this->db);
this->interfaceTraining = std::make_shared<Training>(this, this->db);
this->interfaceTraining->show();
{
this->interfaceTraining = std::make_shared<Training>(this, this->db);
this->interfaceTraining->show();
}
}
void MainWindow::NewWindowSettings() {

View File

@@ -21,7 +21,7 @@ int QVectorHelper::getCurTime(const QVector<int> x) {
int QVectorHelper::getMinSec1(const QVector<QVector<int>> 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<QVector<int>> 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<QVector<int>> 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<QVector<int>> 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);

View File

@@ -3,6 +3,7 @@
#include "timemodel.h"
#include "ui_training.h"
#include "unistd.h"
#include <QCloseEvent>
#include <QListWidgetItem>
#include <QObject>
#include <QShortcut>
@@ -49,13 +50,15 @@ Training::Training(QWidget * parent, std::shared_ptr<DataBase> 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<QShortcut>(QKeySequence("Ctrl+Q"), this);
shellReset = std::make_shared<QShortcut>(QKeySequence("Ctrl+s"), this);
deaReset = std::make_shared<QShortcut>(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<DataBase> 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) {

View File

@@ -5,6 +5,7 @@
#include "hardwaresetup.h"
#include "timemodel.h"
#include <QMainWindow>
#include <QShortcut>
#include <memory>
#include <string>
#include <vector>
@@ -53,6 +54,11 @@ class Training : public QMainWindow {
TimeModel * timeModelShell;
QVector<int> minSecTime;
// shortcuts
std::shared_ptr<QShortcut> shellReset;
std::shared_ptr<QShortcut> shortcut;
std::shared_ptr<QShortcut> deaReset;
public slots:
void ResetShell();
void ResetDea();