added ui tweaks + fix for accepting wrong laptimes

This commit is contained in:
2017-12-26 20:26:30 +01:00
parent 8fea1a1108
commit 2a1a082a30
13 changed files with 443 additions and 149 deletions

View File

@@ -137,6 +137,8 @@ usb_dev_handle * HardwareSetup::usbOpenDevice(int vendor, char * vendorName,
void HardwareSetup::run() { void HardwareSetup::run() {
int testmode = 0;
int nBytes = 0; int nBytes = 0;
// char buffer[256]; // char buffer[256];
struct TransStruct buffer[6]; struct TransStruct buffer[6];
@@ -149,62 +151,108 @@ void HardwareSetup::run() {
// printf("usbtext.exe off\n"); // printf("usbtext.exe off\n");
// exit(1); // exit(1);
// } // }
while (!this->handle) { if (!testmode) {
this->handle = usbOpenDevice(0x16C0, "test01", 0x05DC, "USBExample"); while (!this->handle) {
this->handle =
usbOpenDevice(0x16C0, "test01", 0x05DC, "USBExample");
if (this->handle == NULL) { if (this->handle == NULL) {
fprintf(stderr, "Could not find USB device!\n"); fprintf(stderr, "Could not find USB device!\n");
}
sleep(1);
} }
sleep(1);
} }
int index; int index;
while (!this->stop) { while (!this->stop) {
usleep(100000); // 100ms
// while(1){ // test mode
nBytes = usb_control_msg(
this->handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
USB_DATA_OUT, 0, 0, (char *)buffer, sizeof(buffer), 5000);
for (int i = 0; i < 6; i++) { if (testmode) {
if (buffer[i].update != 0) { while (1) {
switch (buffer[i].id) { int validTimes = 1;
case 0: if (validTimes) {
cout << "Shell Zeit 1: " << (int)buffer[i].time << endl; Shell(1100, 1);
emit Shell((int)buffer[i].time, 1); sleep(1);
break; Shell(1200, 2);
case 1: sleep(1);
cout << "Dea Zeit 1: " << (int)buffer[i].time << endl; Shell(1300, 3);
emit Dea((int)buffer[i].time, 1); sleep(1);
break; Dea(1100, 1);
case 2: sleep(1);
cout << "Shell Zeit 2: " << (int)buffer[i].time << endl; Dea(1200, 2);
emit Shell((int)buffer[i].time, 2); sleep(1);
break; Dea(1300, 3);
case 3: // this->stop = 0;
cout << "Dea Zeit 2: " << (int)buffer[i].time << endl; sleep(1);
emit Dea((int)buffer[i].time, 2); }
break; else {
case 4: // invalid times
cout << "Shell Zeit 2: " << (int)buffer[i].time << endl; Shell(30, 1);
emit Shell((int)buffer[i].time, 3); sleep(1);
break; Shell(700, 2);
case 5: sleep(1);
cout << "Dea Zeit 3: " << (int)buffer[i].time << endl; Shell(700, 3);
emit Dea((int)buffer[i].time, 3); sleep(1);
break; Dea(700, 1);
sleep(1);
Dea(700, 2);
sleep(1);
Dea(700, 3);
// this->stop = 0;
sleep(1);
} }
} }
} }
if (buffer[0].update != 0) { else {
cout << "Got " << nBytes << " bytes: " << (int)buffer[2].time // normal mode -> no testmode
<< ", " << (int)buffer[2].id << endl; usleep(100000); // 100ms
}
//}
if (nBytes < 0) // while(1){
fprintf(stderr, "USB error: %sn", usb_strerror()); nBytes = usb_control_msg(
this->handle,
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
USB_DATA_OUT, 0, 0, (char *)buffer, sizeof(buffer), 5000);
for (int i = 0; i < 6; i++) {
if (buffer[i].update != 0) {
switch (buffer[i].id) {
case 0:
cout << "Shell Zeit 1: " << (int)buffer[i].time << endl;
emit Shell((int)buffer[i].time, 1);
break;
case 1:
cout << "Dea Zeit 1: " << (int)buffer[i].time << endl;
emit Dea((int)buffer[i].time, 1);
break;
case 2:
cout << "Shell Zeit 2: " << (int)buffer[i].time << endl;
emit Shell((int)buffer[i].time, 2);
break;
case 3:
cout << "Dea Zeit 2: " << (int)buffer[i].time << endl;
emit Dea((int)buffer[i].time, 2);
break;
case 4:
cout << "Shell Zeit 2: " << (int)buffer[i].time << endl;
emit Shell((int)buffer[i].time, 3);
break;
case 5:
cout << "Dea Zeit 3: " << (int)buffer[i].time << endl;
emit Dea((int)buffer[i].time, 3);
break;
}
}
}
if (buffer[0].update != 0) {
cout << "Got " << nBytes << " bytes: " << (int)buffer[2].time
<< ", " << (int)buffer[2].id << endl;
}
//}
if (nBytes < 0)
fprintf(stderr, "USB error: %sn", usb_strerror());
}
} }
} }

View File

@@ -1,6 +1,11 @@
#include "qvectorhelper.h" #include "qvectorhelper.h"
#include <qvector.h> #include <qvector.h>
int QVectorHelper::minSec1;
int QVectorHelper::minSec2;
int QVectorHelper::minSec3;
int QVectorHelper::minTrackTime;
QVectorHelper::QVectorHelper() { QVectorHelper::QVectorHelper() {
} }
@@ -13,12 +18,13 @@ int QVectorHelper::getCurTime(const QVector<int> x) {
} }
} }
int QVectorHelper::getMinSec1(const QVector<QVector<int>> x) { int QVectorHelper::getMinSec1(const QVector<QVector<int>> x) {
int min; int min = 9999;
if (x.size() > 0) { if (x.size() > 0) {
if (x.at(0).size() >= 3) { if (x.at(0).size() >= 3) {
min = getCurTime(x.at(0)); if (x.at(0).at(0) >= minSec1) {
min = x.at(0).at(0);
}
} }
else { else {
return 9999; return 9999;
@@ -29,9 +35,11 @@ int QVectorHelper::getMinSec1(const QVector<QVector<int>> x) {
} }
for (int i = 1; i < x.size(); i++) { for (int i = 1; i < x.size(); i++) {
if(x.at(i).size() >= 1){ if (x.at(i).size() >= 1) {
if (x.at(i).at(0) < min) { if (x.at(i).at(0) < min) {
min = x.at(i).at(0); if (x.at(i).at(0) >= minSec1) {
min = x.at(i).at(0);
}
} }
} }
} }
@@ -41,7 +49,9 @@ int QVectorHelper::getMinSec2(const QVector<QVector<int>> x) {
int min; int min;
if (x.size() > 0) { if (x.size() > 0) {
if (x.at(0).size() >= 3) { if (x.at(0).size() >= 3) {
min = getCurTime(x.at(1)); if (x.at(0).at(1) >= minSec2) {
min = x.at(0).at(1);
}
} }
else { else {
return 9999; return 9999;
@@ -54,7 +64,9 @@ int QVectorHelper::getMinSec2(const QVector<QVector<int>> x) {
for (int i = 1; i < x.size(); i++) { for (int i = 1; i < x.size(); i++) {
if (x.at(0).size() >= 2) { if (x.at(0).size() >= 2) {
if (x.at(i).at(1) < min) { if (x.at(i).at(1) < min) {
min = x.at(i).at(1); if (x.at(0).at(1) >= minSec2) {
min = x.at(i).at(1);
}
} }
} }
} }
@@ -64,7 +76,9 @@ int QVectorHelper::getMinSec3(const QVector<QVector<int>> x) {
int min; int min;
if (x.size() > 0) { if (x.size() > 0) {
if (x.at(0).size() >= 3) { if (x.at(0).size() >= 3) {
min = getCurTime(x.at(2)); if (x.at(0).at(2) >= minSec3) {
min = x.at(0).at(2);
}
} }
else { else {
return 9999; return 9999;
@@ -75,9 +89,11 @@ int QVectorHelper::getMinSec3(const QVector<QVector<int>> x) {
} }
for (int i = 1; i < x.size(); i++) { for (int i = 1; i < x.size(); i++) {
if(x.at(i).size() >= 3){ if (x.at(i).size() >= 3) {
if (x.at(i).at(2) < min) { if (x.at(i).at(2) < min) {
min = x.at(i).at(2); if (x.at(0).at(2) >= minSec3) {
min = x.at(i).at(2);
}
} }
} }
} }
@@ -88,7 +104,9 @@ int QVectorHelper::getMin(const QVector<QVector<int>> x) {
int min; int min;
if (x.size() > 0) { if (x.size() > 0) {
if (x.at(0).size() >= 3) { if (x.at(0).size() >= 3) {
min = getCurTime(x.at(0)); if (getCurTime(x.at(0)) >= minTrackTime) {
min = getCurTime(x.at(0));
}
} }
else { else {
return 9999; return 9999;
@@ -99,7 +117,9 @@ int QVectorHelper::getMin(const QVector<QVector<int>> x) {
} }
for (int i = 1; i < x.size(); i++) { for (int i = 1; i < x.size(); i++) {
if (getCurTime(x.at(i)) < min) { if (getCurTime(x.at(i)) < min) {
min = getCurTime(x.at(i)); if (getCurTime(x.at(0)) >= minTrackTime) {
min = getCurTime(x.at(i));
}
} }
} }
return min; return min;

View File

@@ -10,6 +10,10 @@ class QVectorHelper {
static int getMinSec1(const QVector<QVector<int>> x); static int getMinSec1(const QVector<QVector<int>> x);
static int getMinSec2(const QVector<QVector<int>> x); static int getMinSec2(const QVector<QVector<int>> x);
static int getMinSec3(const QVector<QVector<int>> x); static int getMinSec3(const QVector<QVector<int>> x);
static int minSec1;
static int minSec2;
static int minSec3;
static int minTrackTime;
}; };
#endif // QVECTORHELPER_H #endif // QVECTORHELPER_H

View File

@@ -31,7 +31,7 @@ QVariant TimeModel::headerData(int section, Qt::Orientation orientation,
return QString("Gerade"); return QString("Gerade");
case 2: case 2:
return QString("Kruven"); return QString("Kurven");
case 3: case 3:
return QString("Runde"); return QString("Runde");
@@ -71,7 +71,10 @@ QColor TimeModel::getColor(const QVector<QVector<int>> data, const int col,
// lap time // lap time
if (data.at(row).at(0) < this->minimumTimes.at(0) || if (data.at(row).at(0) < this->minimumTimes.at(0) ||
data.at(row).at(1) < this->minimumTimes.at(1) || data.at(row).at(1) < this->minimumTimes.at(1) ||
data.at(row).at(2) < this->minimumTimes.at(2)) { data.at(row).at(2) < this->minimumTimes.at(2) ||
data.at(row).at(0) + data.at(row).at(1) +
data.at(row).at(2) <
this->minimumTimes.at(3)) {
return QColor(Qt::red); return QColor(Qt::red);
} }
} }

View File

@@ -5,33 +5,42 @@
#include <qcolor.h> #include <qcolor.h>
#include <qvector.h> #include <qvector.h>
class TimeModel : public QAbstractTableModel class TimeModel : public QAbstractTableModel {
{
Q_OBJECT Q_OBJECT
public: public:
explicit TimeModel(QVector<QVector<int>> timeData, QVector<int> minimumTimes, QObject *parent = nullptr); explicit TimeModel(QVector<QVector<int>> timeData,
explicit TimeModel(QVector<QVector<int>> timeData, QVector<int> minimumTimes, QVector<int> topTime, QObject *parent = nullptr); QVector<int> minimumTimes, QObject * parent = nullptr);
explicit TimeModel(QVector<QVector<int>> timeData,
QVector<int> minimumTimes, QVector<int> topTime,
QObject * parent = nullptr);
// Header: // Header:
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;
// Basic functionality: // Basic functionality:
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex & parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex & parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex & index,
int role = Qt::DisplayRole) const override;
// Add data: // Add data:
bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; bool insertRows(int row, int count,
bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override; const QModelIndex & parent = QModelIndex()) override;
bool insertColumns(int column, int count,
const QModelIndex & parent = QModelIndex()) override;
private: private:
int getMin(const QVector<int> x) const; int getMin(const QVector<int> x) const;
QColor getColor(const QVector<QVector<int>> data, const int col, const int row) const; // row and col starts counting at 0 QColor getColor(const QVector<QVector<int>> data, const int col,
const int row) const; // row and col starts counting at 0
QVector<QVector<int>> timeData; QVector<QVector<int>> timeData;
QVector<int> topTime; QVector<int> topTime;
// 4 entries: min sec1, min sec2, min sec3, min for whole time
QVector<int> minimumTimes; QVector<int> minimumTimes;
}; };

View File

@@ -129,18 +129,9 @@ void Training::shellSlot(int time, int sector) {
timeModelShell = new TimeModel(VecShell, minSecTime, this); timeModelShell = new TimeModel(VecShell, minSecTime, this);
this->ui->lWShellTime->setModel(timeModelShell); this->ui->lWShellTime->setModel(timeModelShell);
this->ui->lbridgeShellTop->setText(QString::number( this->ui->lBridgeShellTop->setText(QString::number(
(double)QVectorHelper::getMinSec1(VecShell) / 1000)); (double)QVectorHelper::getMinSec1(VecShell) / 1000));
theoreticalMinShell = 9999;
theoreticalMinShell = QVectorHelper::getMinSec1(VecShell) +
QVectorHelper::getMinSec2(VecShell) +
QVectorHelper::getMinSec3(VecShell);
deltaShell =
QVectorHelper::getMin(VecShell) - theoreticalMinShell;
this->ui->lDeltaTopTimeShell->setText(
QString::number((double)deltaShell / 1000));
break; break;
case 2: case 2:
if (VecShell.size() > 0) { if (VecShell.size() > 0) {
@@ -154,7 +145,7 @@ void Training::shellSlot(int time, int sector) {
} }
} }
this->ui->lbridgeShellTop->setText(QString::number( this->ui->lStraightShellTop->setText(QString::number(
(double)QVectorHelper::getMinSec2(VecShell) / 1000)); (double)QVectorHelper::getMinSec2(VecShell) / 1000));
break; break;
case 3: case 3:
@@ -185,9 +176,16 @@ void Training::shellSlot(int time, int sector) {
1000)); 1000));
} }
this->ui->lbridgeShellTop->setText(QString::number( this->ui->lCurvesShellTop->setText(QString::number(
(double)QVectorHelper::getMinSec3(VecShell) / 1000)); (double)QVectorHelper::getMinSec3(VecShell) / 1000));
theoreticalMinShell = 9999;
theoreticalMinShell = QVectorHelper::getMinSec1(VecShell) +
QVectorHelper::getMinSec2(VecShell) +
QVectorHelper::getMinSec3(VecShell);
deltaShell =
QVectorHelper::getMin(VecShell) - theoreticalMinShell;
this->ui->lDeltaTopTimeShell->setText(
QString::number((double)deltaShell / 1000));
break; break;
} }
ui->lWShellTime->scrollToBottom(); ui->lWShellTime->scrollToBottom();
@@ -220,7 +218,8 @@ void Training::deaSlot(int time, int sector) {
// cout << "Dea Sektor 1" << endl; // cout << "Dea Sektor 1" << endl;
timeModelDea = new TimeModel(VecDea, minSecTime, this); timeModelDea = new TimeModel(VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea); this->ui->lWDeaTime->setModel(timeModelDea);
this->ui->lBridgeDeaTop->setText(QString::number(
(double)QVectorHelper::getMinSec1(VecDea) / 1000));
break; break;
case 2: case 2:
if (VecDea.size() > 0) { if (VecDea.size() > 0) {
@@ -234,6 +233,8 @@ void Training::deaSlot(int time, int sector) {
else { else {
// VecDea[VecDea.size()-1].append(9999); // VecDea[VecDea.size()-1].append(9999);
} }
this->ui->lStraightDeaTop->setText(QString::number(
(double)QVectorHelper::getMinSec2(VecDea) / 1000));
} }
break; break;
case 3: case 3:
@@ -265,6 +266,17 @@ void Training::deaSlot(int time, int sector) {
ui->lCurRoundDea->setText(QString::number( ui->lCurRoundDea->setText(QString::number(
(double)QVectorHelper::getCurTime(VecDea.last()) / (double)QVectorHelper::getCurTime(VecDea.last()) /
1000)); 1000));
this->ui->lCurvesDeaTop->setText(QString::number(
(double)QVectorHelper::getMinSec3(VecDea) / 1000));
theoreticalMinDea = 9999;
theoreticalMinDea = QVectorHelper::getMinSec1(VecDea) +
QVectorHelper::getMinSec2(VecDea) +
QVectorHelper::getMinSec3(VecDea);
deltaDea =
QVectorHelper::getMin(VecDea) - theoreticalMinDea;
this->ui->lDeltaTopTimeDea->setText(
QString::number((double)deltaDea / 1000));
} }
break; break;
} }

View File

@@ -44,6 +44,9 @@ class Training : public QMainWindow {
int theoreticalMinShell; int theoreticalMinShell;
int deltaShell; int deltaShell;
int theoreticalMinDea;
int deltaDea;
// timeModel // timeModel
TimeModel * timeModelDea; TimeModel * timeModelDea;
TimeModel * timeModelShell; TimeModel * timeModelShell;

View File

@@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>907</width> <width>1136</width>
<height>600</height> <height>600</height>
</rect> </rect>
</property> </property>
@@ -101,7 +101,7 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_14"> <layout class="QVBoxLayout" name="verticalLayout_14">
<item> <item>
<widget class="QLabel" name="lbridgeShellTop"> <widget class="QLabel" name="lBridgeShellTop">
<property name="text"> <property name="text">
<string>∞</string> <string>∞</string>
</property> </property>
@@ -279,7 +279,7 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_19"> <layout class="QVBoxLayout" name="verticalLayout_19">
<item> <item>
<widget class="QLabel" name="label"> <widget class="QLabel" name="lBridgeDeaTop">
<property name="text"> <property name="text">
<string>∞</string> <string>∞</string>
</property> </property>
@@ -389,8 +389,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>907</width> <width>1136</width>
<height>25</height> <height>22</height>
</rect> </rect>
</property> </property>
</widget> </widget>

View File

@@ -35,12 +35,20 @@ WindowRace::WindowRace(DataBase * db, QWidget * parent)
this->minimumTime = res[0][0].toInt(); this->minimumTime = res[0][0].toInt();
// fill minSecTimes vector // fill minSecTimes vector
statement = "select minsec1, minsec2, minsec3 from renndauer order by id " statement = "select minsec1, minsec2, minsec3, mindestRundenDauer from "
"renndauer order by id "
"DESC limit 1"; "DESC limit 1";
res = db->getData(statement, 3); cout << statement << endl;
res = db->getData(statement, 4);
this->minSecTime.append(res[0][0].toInt()); this->minSecTime.append(res[0][0].toInt());
this->minSecTime.append(res[0][1].toInt()); this->minSecTime.append(res[0][1].toInt());
this->minSecTime.append(res[0][2].toInt()); this->minSecTime.append(res[0][2].toInt());
this->minSecTime.append(res[0][3].toInt());
QVectorHelper::minSec1 = this->minSecTime.at(0);
QVectorHelper::minSec2 = this->minSecTime.at(1);
QVectorHelper::minSec3 = this->minSecTime.at(2);
QVectorHelper::minTrackTime = this->minSecTime.at(3);
firstTimeDea = true; firstTimeDea = true;
firstTimeShell = true; firstTimeShell = true;
@@ -368,6 +376,9 @@ void WindowRace::shellSlot(int time, int sector) {
new TimeModel(VecShell, minSecTime, test, this); new TimeModel(VecShell, minSecTime, test, this);
// this->ui->lWShellTime->setModel(this->timeModelShell); // this->ui->lWShellTime->setModel(this->timeModelShell);
ui->lWShellTime->setModel(this->timeModelShell); ui->lWShellTime->setModel(this->timeModelShell);
this->ui->lBridgeShell->setText(QString::number(
(double)QVectorHelper::getMinSec1(VecShell) / 1000));
break; break;
case 2: case 2:
@@ -385,6 +396,8 @@ void WindowRace::shellSlot(int time, int sector) {
// timeModelShell = new // timeModelShell = new
// TimeModel(VecShell, this); // TimeModel(VecShell, this);
this->ui->lWShellTime->setModel(timeModelShell); this->ui->lWShellTime->setModel(timeModelShell);
this->ui->lStraightShell->setText(QString::number(
(double)QVectorHelper::getMinSec2(VecShell) / 1000));
} }
break; break;
case 3: case 3:
@@ -414,17 +427,34 @@ void WindowRace::shellSlot(int time, int sector) {
// timeModelShell = new // timeModelShell = new
// TimeModel(VecShell, this); // TimeModel(VecShell, this);
this->ui->lWShellTime->setModel(timeModelShell); this->ui->lWShellTime->setModel(timeModelShell);
int zeit = QVectorHelper::getMin(VecShell);
QString statement =
"insert into Zeiten (id_rennen, id_fahrer, "
"id_auto, id_bahn, zeit) values (" +
QString::number(this->renn_id) + ", " +
QString::number(this->shellDriverId) + ", " +
QString::number(this->shellCarId) + ", 1, " +
QString::number(zeit) + ")";
cout << statement.toStdString() << endl;
// this->db->setData(statement.toStdString()); this->ui->lCurvesShell->setText(QString::number(
(double)QVectorHelper::getMinSec3(VecShell) /
1000));
theoreticalMinShell = 9999;
theoreticalMinShell =
QVectorHelper::getMinSec1(VecShell) +
QVectorHelper::getMinSec2(VecShell) +
QVectorHelper::getMinSec3(VecShell);
deltaShell = QVectorHelper::getMin(VecShell) -
theoreticalMinShell;
this->ui->lDeltaShellTop->setText(
QString::number((double)deltaShell / 1000));
if (VecShell.size() > 0) {
int zeit =
QVectorHelper::getCurTime(VecShell.last());
QString statement =
"insert into Zeiten (id_rennen, id_fahrer, "
"id_auto, id_bahn, zeit) values (" +
QString::number(this->renn_id) + ", " +
QString::number(this->shellDriverId) + ", " +
QString::number(this->shellCarId) + ", 1, " +
QString::number(zeit) + ")";
// cout << statement.toStdString() << endl;
this->db->setData(statement.toStdString());
}
} }
} }
@@ -456,6 +486,9 @@ void WindowRace::deaSlot(int time, int sector) {
timeModelDea = new TimeModel(VecDea, minSecTime, this); timeModelDea = new TimeModel(VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea); this->ui->lWDeaTime->setModel(timeModelDea);
this->ui->lBridgeDea->setText(QString::number(
(double)QVectorHelper::getMinSec1(VecDea) / 1000));
break; break;
case 2: case 2:
if (VecDea.size() > 0) { if (VecDea.size() > 0) {
@@ -464,6 +497,8 @@ void WindowRace::deaSlot(int time, int sector) {
VecDea[VecDea.size() - 1].push_back(time); VecDea[VecDea.size() - 1].push_back(time);
timeModelDea = new TimeModel(VecDea, minSecTime, this); timeModelDea = new TimeModel(VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea); this->ui->lWDeaTime->setModel(timeModelDea);
this->ui->lStraightDea->setText(QString::number(
(double)QVectorHelper::getMinSec2(VecDea) / 1000));
} }
else { else {
// VecDea[VecDea.size()-1].append(9999); // VecDea[VecDea.size()-1].append(9999);
@@ -500,17 +535,29 @@ void WindowRace::deaSlot(int time, int sector) {
(double)QVectorHelper::getCurTime(VecDea.last()) / (double)QVectorHelper::getCurTime(VecDea.last()) /
1000)); 1000));
} }
int zeit = QVectorHelper::getMin(VecDea);
QString statement = "insert into Zeiten (id_rennen, id_fahrer, "
"id_auto, id_bahn, zeit) values (" +
QString::number(this->renn_id) + ", " +
QString::number(this->deaDriverId) + ", " +
QString::number(this->deaCarId) + ", 2, " +
QString::number(zeit) + ")";
cout << statement.toStdString() << endl;
// this->db->setData(statement.toStdString());
ui->lWDeaTime->scrollToBottom();
this->ui->lCurvesDea->setText(QString::number(
(double)QVectorHelper::getMinSec3(VecDea) / 1000));
theoreticalMinDea = 9999;
theoreticalMinDea = QVectorHelper::getMinSec1(VecDea) +
QVectorHelper::getMinSec2(VecDea) +
QVectorHelper::getMinSec3(VecDea);
deltaDea = QVectorHelper::getMin(VecDea) - theoreticalMinDea;
this->ui->lDeltaDeaTop->setText(
QString::number((double)deltaDea / 1000));
if (VecDea.size() > 0) {
int zeit = QVectorHelper::getCurTime(VecDea.last());
QString statement =
"insert into Zeiten (id_rennen, id_fahrer, "
"id_auto, id_bahn, zeit) values (" +
QString::number(this->renn_id) + ", " +
QString::number(this->deaDriverId) + ", " +
QString::number(this->deaCarId) + ", 2, " +
QString::number(zeit) + ")";
// cout << statement.toStdString() << endl;
this->db->setData(statement.toStdString());
ui->lWDeaTime->scrollToBottom();
}
break; break;
} }
} }

View File

@@ -1,17 +1,17 @@
#ifndef WINDOWRACE_H #ifndef WINDOWRACE_H
#define WINDOWRACE_H #define WINDOWRACE_H
#include <QMainWindow>
#include "hardwaresetup.h"
#include "counter.h"
#include <vector>
#include "countdown.h"
#include <string>
#include "ampel.h" #include "ampel.h"
#include "countdown.h"
#include "counter.h"
#include "database.h" #include "database.h"
#include "windowrennliste.h" #include "hardwaresetup.h"
#include <QMessageBox>
#include "timemodel.h" #include "timemodel.h"
#include "windowrennliste.h"
#include <QMainWindow>
#include <QMessageBox>
#include <string>
#include <vector>
using std::string; using std::string;
@@ -19,52 +19,58 @@ namespace Ui {
class WindowRace; class WindowRace;
} }
class WindowRace : public QMainWindow class WindowRace : public QMainWindow {
{
Q_OBJECT Q_OBJECT
public: public:
explicit WindowRace(DataBase *db, QWidget *parent = 0); explicit WindowRace(DataBase * db, QWidget * parent = 0);
~WindowRace(); ~WindowRace();
void setWindowRennliste(WindowRennliste *ptrInstance); void setWindowRennliste(WindowRennliste * ptrInstance);
void setDriverAndCar(vector<QString> vec); void setDriverAndCar(vector<QString> vec);
void setDriverAndCarId(vector<QString> vec); void setDriverAndCarId(vector<QString> vec);
private: private:
int shellDriverId; int shellDriverId;
int deaDriverId; int deaDriverId;
int deaCarId; int deaCarId;
int shellCarId; int shellCarId;
void closeEvent(QCloseEvent *event); void closeEvent(QCloseEvent * event);
bool started; bool started;
Countdown *countdown; Countdown * countdown;
HardwareSetup *Hardware; HardwareSetup * Hardware;
Ui::WindowRace *ui; Ui::WindowRace * ui;
Counter counterShell; Counter counterShell;
Counter counterDea; Counter counterDea;
bool firstTimeShell; bool firstTimeShell;
bool firstTimeDea; bool firstTimeDea;
QVector<QVector<int>> VecShell; QVector<QVector<int>> VecShell;
QVector<QVector<int>> VecDea; QVector<QVector<int>> VecDea;
TimeModel *timeModelShell; TimeModel * timeModelShell;
TimeModel *timeModelDea; TimeModel * timeModelDea;
long getMinimum(std::vector<long> a); long getMinimum(std::vector<long> a);
QString timeWrapper(long zahl); QString timeWrapper(long zahl);
long countdownValue; //in sec long countdownValue; // in sec
Ampel *startAmpelThread; Ampel * startAmpelThread;
int ampelCounter; int ampelCounter;
bool paused; bool paused;
DataBase *db; DataBase * db;
bool finished; bool finished;
WindowRennliste *wRennliste; WindowRennliste * wRennliste;
bool wRennlisteSeted; bool wRennlisteSeted;
int fahrzeit; int fahrzeit;
int renn_id; int renn_id;
int minimumTime; int minimumTime;
QVector<int> minSecTime; QVector<int> minSecTime;
public slots: // sector top times
int theoreticalMinShell;
int deltaShell;
int theoreticalMinDea;
int deltaDea;
public slots:
void stopClicked(); void stopClicked();
void prepareNextRace(); void prepareNextRace();
void breakCounter(); void breakCounter();

View File

@@ -47,7 +47,7 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_12"> <layout class="QVBoxLayout" name="verticalLayout_12">
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0"> <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0">
<item> <item>
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
<property name="font"> <property name="font">
@@ -100,6 +100,74 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_14">
<item>
<widget class="QGroupBox" name="groupBox_8">
<property name="title">
<string>Brücke</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_19">
<item>
<widget class="QLabel" name="lBridgeShell">
<property name="text">
<string>∞</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_7">
<property name="title">
<string>Gerade</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_20">
<item>
<widget class="QLabel" name="lStraightShell">
<property name="text">
<string>∞</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_6">
<property name="title">
<string>Kurven</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_21">
<item>
<widget class="QLabel" name="lCurvesShell">
<property name="text">
<string>∞</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>Delta Topzeit</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_22">
<item>
<widget class="QLabel" name="lDeltaShellTop">
<property name="text">
<string>∞</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</item> </item>
<item> <item>
@@ -581,6 +649,74 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_15">
<item>
<widget class="QGroupBox" name="groupBox_12">
<property name="title">
<string>Brücke</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_23">
<item>
<widget class="QLabel" name="lBridgeDea">
<property name="text">
<string>∞</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_11">
<property name="title">
<string>Gerade</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_24">
<item>
<widget class="QLabel" name="lStraightDea">
<property name="text">
<string>∞</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_10">
<property name="title">
<string>Kurven</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_25">
<item>
<widget class="QLabel" name="lCurvesDea">
<property name="text">
<string>∞</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_9">
<property name="title">
<string>Delta Topzeit</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_26">
<item>
<widget class="QLabel" name="lDeltaDeaTop">
<property name="text">
<string>∞</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</item> </item>
<item> <item>
@@ -640,7 +776,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>840</width> <width>840</width>
<height>25</height> <height>22</height>
</rect> </rect>
</property> </property>
</widget> </widget>

View File

@@ -27,12 +27,15 @@ WindowsSettings::WindowsSettings(DataBase * db, QWidget * parent)
SLOT(SaveDauerAndExitSlot())); SLOT(SaveDauerAndExitSlot()));
// update minimal lap time on changeing minimal sector time // update minimal lap time on changeing minimal sector time
QObject::connect(this->ui->lEMinTimeSec1, SIGNAL(textChanged(QString)), // QObject::connect(this->ui->lEMinTimeSec1,
this, SLOT(repaintMinLapTime())); // SIGNAL(textChanged(QString)),
QObject::connect(this->ui->lEMinTimeSec2, SIGNAL(textChanged(QString)), // this, SLOT(repaintMinLapTime()));
this, SLOT(repaintMinLapTime())); // QObject::connect(this->ui->lEMinTimeSec2,
QObject::connect(this->ui->lEMinTimeSec3, SIGNAL(textChanged(QString)), // SIGNAL(textChanged(QString)),
this, SLOT(repaintMinLapTime())); // this, SLOT(repaintMinLapTime()));
// QObject::connect(this->ui->lEMinTimeSec3,
// SIGNAL(textChanged(QString)),
// this, SLOT(repaintMinLapTime()));
this->db = db; this->db = db;
@@ -70,8 +73,11 @@ WindowsSettings::WindowsSettings(DataBase * db, QWidget * parent)
this->ui->lEMinTimeSec1->setText(res[0][2]); this->ui->lEMinTimeSec1->setText(res[0][2]);
this->ui->lEMinTimeSec2->setText(res[0][3]); this->ui->lEMinTimeSec2->setText(res[0][3]);
this->ui->lEMinTimeSec3->setText(res[0][4]); this->ui->lEMinTimeSec3->setText(res[0][4]);
int minLapTime = res[0][2].toInt() + res[0][3].toInt() + res[0][4].toInt();
this->ui->lEMinRundenzeit->setText(QString::number(minLapTime)); // changed -> not reasonable
// int minLapTime = res[0][2].toInt() + res[0][3].toInt() +
// res[0][4].toInt();
this->ui->lEMinRundenzeit->setText(res[0][1]);
statement = statement =
"SELECT id, minimumroundtime FROM rennen order by id DESC limit 1"; "SELECT id, minimumroundtime FROM rennen order by id DESC limit 1";

View File

@@ -50,7 +50,7 @@
<item> <item>
<widget class="QLineEdit" name="lEMinRundenzeit"> <widget class="QLineEdit" name="lEMinRundenzeit">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
@@ -391,7 +391,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>800</width> <width>800</width>
<height>25</height> <height>22</height>
</rect> </rect>
</property> </property>
</widget> </widget>