added usb-racemode, database needs to be reconfigured and colors in timemodel needs to be adapted
This commit is contained in:
@@ -26,7 +26,8 @@ SOURCES += main.cpp\
|
||||
database.cpp \
|
||||
windowrennliste.cpp \
|
||||
training.cpp \
|
||||
timemodel.cpp
|
||||
timemodel.cpp \
|
||||
qvectorhelper.cpp
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.h \
|
||||
@@ -39,7 +40,8 @@ HEADERS += \
|
||||
database.h \
|
||||
windowrennliste.h \
|
||||
training.h \
|
||||
timemodel.h
|
||||
timemodel.h \
|
||||
qvectorhelper.h
|
||||
|
||||
FORMS += mainwindow.ui \
|
||||
windowrace.ui \
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 4.3.1, 2017-09-07T16:51:17. -->
|
||||
<!-- Written by QtCreator 4.4.0, 2017-09-09T12:01:57. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
||||
@@ -169,7 +169,7 @@ void HardwareSetup::run(){
|
||||
while(!this->stop){
|
||||
usleep(100000); // 100ms
|
||||
|
||||
while(1){
|
||||
//while(1){
|
||||
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);
|
||||
@@ -203,46 +203,11 @@ void HardwareSetup::run(){
|
||||
// if(buffer[0].update != 0){
|
||||
// cout << "Got " << nBytes << " bytes: " << (int)buffer[2].time << ", " << (int)buffer[2].id << endl;
|
||||
// }
|
||||
|
||||
// if((int)buffer->update == 1){
|
||||
// //if((int) buffer->id)
|
||||
// emit Dea((int)buffer->time, 1);
|
||||
// }
|
||||
}
|
||||
//}
|
||||
|
||||
if(nBytes < 0)
|
||||
fprintf(stderr, "USB error: %sn", usb_strerror());
|
||||
|
||||
//if(getDea()){
|
||||
if(1){
|
||||
|
||||
// if(!deaBefore){
|
||||
if(1){
|
||||
index = 1;
|
||||
deaBefore = true;
|
||||
//emit Dea(5);
|
||||
}
|
||||
else{
|
||||
index += 1;
|
||||
//Debug
|
||||
//std::cout << index << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
deaBefore = false;
|
||||
}
|
||||
|
||||
// if(getShell()){
|
||||
if(1){
|
||||
if(!shellBefore){
|
||||
shellBefore = true;
|
||||
//emit Shell();
|
||||
}
|
||||
}
|
||||
else{
|
||||
shellBefore = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
37
qvectorhelper.cpp
Normal file
37
qvectorhelper.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "qvectorhelper.h"
|
||||
#include <qvector.h>
|
||||
|
||||
QVectorHelper::QVectorHelper()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int QVectorHelper::getCurTime(const QVector<int> x) {
|
||||
if(x.size() >= 3){
|
||||
return x.at(0)+ x.at(1) + x.at(2);
|
||||
}
|
||||
else{
|
||||
return 9999;
|
||||
}
|
||||
}
|
||||
|
||||
int QVectorHelper::getMin(const QVector<QVector<int>> x){
|
||||
int min;
|
||||
if(x.size() > 0){
|
||||
if(x.at(0).size() >= 3){
|
||||
min = getCurTime(x.at(0));
|
||||
}
|
||||
else{
|
||||
return 9999;
|
||||
}
|
||||
}
|
||||
else{
|
||||
return 9999;
|
||||
}
|
||||
for(int i = 1; i < x.size(); i++){
|
||||
if(getCurTime(x.at(i)) < min){
|
||||
min = getCurTime(x.at(i));
|
||||
}
|
||||
}
|
||||
return min;
|
||||
}
|
||||
13
qvectorhelper.h
Normal file
13
qvectorhelper.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef QVECTORHELPER_H
|
||||
#define QVECTORHELPER_H
|
||||
#include <qvector.h>
|
||||
|
||||
class QVectorHelper
|
||||
{
|
||||
public:
|
||||
QVectorHelper();
|
||||
static int getCurTime(const QVector<int> x);
|
||||
static int getMin(const QVector<QVector<int>> x);
|
||||
};
|
||||
|
||||
#endif // QVECTORHELPER_H
|
||||
@@ -58,7 +58,9 @@ QColor TimeModel::getColor(const QVector<QVector<int>> data, const int col, cons
|
||||
if(data.at(row).size() > col){ // check for enough cols
|
||||
QVector<int> compare;
|
||||
for(int i = 0; i <= row; i++){
|
||||
compare.append(data.at(i).at(col));
|
||||
if(data.at(i).size() > col){
|
||||
compare.append(data.at(i).at(col));
|
||||
}
|
||||
}
|
||||
if(data.at(row).at(col) == getMin(compare)){
|
||||
return QColor(Qt::green);
|
||||
|
||||
@@ -179,7 +179,8 @@ void Training::shellSlot(int time, int sector){
|
||||
}
|
||||
}
|
||||
void Training::closeEvent(QCloseEvent *event){
|
||||
|
||||
Hardware->setStop();
|
||||
delete this->Hardware;
|
||||
}
|
||||
|
||||
void Training::deaSlot(int time, int sector){
|
||||
@@ -218,10 +219,10 @@ void Training::deaSlot(int time, int sector){
|
||||
//cout << "Time sec 3: " << time << endl;
|
||||
if(VecDea.last().size() == 2){
|
||||
// cout << time << sector << endl;
|
||||
VecDea[VecDea.size()-1].push_back(time);
|
||||
VecDea.last().push_back(time);
|
||||
|
||||
// add sum to vector
|
||||
VecDea[VecDea.size()-1].push_back(getCurTime(VecDea.last()));
|
||||
VecDea.last().push_back(getCurTime(VecDea.last()));
|
||||
|
||||
|
||||
|
||||
|
||||
181
windowrace.cpp
181
windowrace.cpp
@@ -7,6 +7,8 @@
|
||||
#include <iostream>
|
||||
#include "unistd.h"
|
||||
#include <QKeySequence>
|
||||
#include "qvectorhelper.h"
|
||||
#include "timemodel.h"
|
||||
|
||||
using std::vector;
|
||||
using std::string;
|
||||
@@ -50,8 +52,8 @@ WindowRace::WindowRace(DataBase *db, QWidget *parent) :
|
||||
Hardware = new HardwareSetup;
|
||||
Hardware->start();
|
||||
|
||||
QObject::connect(Hardware, SIGNAL(Dea()), this, SLOT(deaSlot()));
|
||||
QObject::connect(Hardware, SIGNAL(Shell()), this, SLOT(shellSlot()));
|
||||
QObject::connect(Hardware, SIGNAL(Dea(int, int)), this, SLOT(deaSlot(int, int)));
|
||||
QObject::connect(Hardware, SIGNAL(Shell(int, int)), this, SLOT(shellSlot(int, int)));
|
||||
QObject::connect(ui->pBStart, SIGNAL(clicked()), this, SLOT(go()));
|
||||
QObject::connect(countdown, SIGNAL(CountdownUpdate()), this, SLOT(countdownUpdate()));
|
||||
QObject::connect(startAmpelThread, SIGNAL(ampelUpdate()), this, SLOT(ampelSlot()));
|
||||
@@ -156,8 +158,8 @@ void WindowRace::prepareNextRace(){
|
||||
this->firstTimeShell = true;
|
||||
this->firstTimeDea = true;
|
||||
|
||||
this->ui->lWShellTime->clear();
|
||||
this->ui->lWDeaTime->clear();
|
||||
// this->ui->lWShellTime->clear();
|
||||
// this->ui->lWDeaTime->clear();
|
||||
|
||||
this->ui->lBestZeitDea->setText("∞");
|
||||
this->ui->lBestZeitShell->setText("∞");
|
||||
@@ -167,6 +169,13 @@ void WindowRace::prepareNextRace(){
|
||||
this->VecShell.clear();
|
||||
this->VecDea.clear();
|
||||
|
||||
// clear tableview shell
|
||||
timeModelShell = new TimeModel(VecShell);
|
||||
ui->lWShellTime->setModel(timeModelShell);
|
||||
|
||||
// clear tableview dea
|
||||
timeModelDea = new TimeModel(VecDea);
|
||||
ui->lWDeaTime->setModel(timeModelDea);
|
||||
|
||||
this->finished = false;
|
||||
this->paused = false;
|
||||
@@ -230,6 +239,8 @@ void WindowRace::setDriverAndCarId(vector<QString> vec){
|
||||
|
||||
}
|
||||
void WindowRace::closeEvent(QCloseEvent *event){
|
||||
countdown->setStop();
|
||||
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText("Wirklich schliessen?");
|
||||
msgBox.setInformativeText("");
|
||||
@@ -292,7 +303,7 @@ void WindowRace::countdownUpdate(){
|
||||
}
|
||||
if(countdownValue <= -1){
|
||||
this->finished = true;
|
||||
this->wRennliste->setBesttime(getMinimum(this->VecShell),getMinimum(this->VecDea));
|
||||
this->wRennliste->setBesttime(QVectorHelper::getMin(VecShell),QVectorHelper::getMin(this->VecDea));
|
||||
this->ui->pBNextRace->setEnabled(true);
|
||||
}
|
||||
else{
|
||||
@@ -302,6 +313,7 @@ void WindowRace::countdownUpdate(){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
WindowRace::~WindowRace()
|
||||
{
|
||||
this->startAmpelThread->setStop();
|
||||
@@ -317,67 +329,144 @@ WindowRace::~WindowRace()
|
||||
|
||||
delete ui;
|
||||
}
|
||||
void WindowRace::shellSlot(){
|
||||
void WindowRace::shellSlot(int time, int sector){
|
||||
if(started && !paused && !this->finished){
|
||||
if(firstTimeShell){
|
||||
firstTimeShell = false;
|
||||
counterShell.start();
|
||||
// counterShell.start();
|
||||
}
|
||||
else{
|
||||
long zeit = counterShell.getTime();
|
||||
VecShell.push_back(zeit);
|
||||
QListWidgetItem *item = new QListWidgetItem;
|
||||
if(getMinimum(VecShell) == zeit && VecShell.size() > 1){
|
||||
item->setBackgroundColor(Qt::green);
|
||||
// long zeit = counterShell.getTime();
|
||||
switch(sector){
|
||||
case 1:
|
||||
VecShell.append(QVector<int>());
|
||||
VecShell.last().append(time);
|
||||
|
||||
// update tableview
|
||||
this->timeModelShell = new TimeModel(VecShell, this);
|
||||
// this->ui->lWShellTime->setModel(this->timeModelShell);
|
||||
ui->lWShellTime->setModel(this->timeModelShell);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if(VecShell.size() > 0){
|
||||
if(VecShell.last().size() == 1){
|
||||
VecShell.last().append(time);
|
||||
}
|
||||
// update tableview
|
||||
timeModelShell = new TimeModel(VecShell, this);
|
||||
this->ui->lWShellTime->setModel(timeModelShell);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if(VecShell.size() > 0){
|
||||
if(VecShell.last().size() == 2){
|
||||
VecShell.last().append(time);
|
||||
VecShell.last().append(QVectorHelper::getCurTime(VecShell.last()));
|
||||
|
||||
if(QVectorHelper::getCurTime(VecShell.last()) <= QVectorHelper::getMin(VecShell)){
|
||||
ui->lBestZeitShell->setText(QString::number((double)QVectorHelper::getMin(VecShell)/1000));
|
||||
}
|
||||
ui->lCurRoundTimeShell->setText(QString::number((double)QVectorHelper::getCurTime(VecShell.last())/1000));
|
||||
|
||||
// update tableview
|
||||
timeModelShell = new TimeModel(VecShell, this);
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
if(zeit < this->minimumTime){
|
||||
item->setBackgroundColor(Qt::red);
|
||||
this->firstTimeShell = true;
|
||||
if(sector == 3){
|
||||
}
|
||||
item->setText(QString::number((double)zeit/1000));
|
||||
ui->lWShellTime->addItem(item);
|
||||
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());
|
||||
|
||||
|
||||
ui->lWShellTime->scrollToBottom();
|
||||
if(getMinimum(VecShell) > 0){
|
||||
ui->lBestZeitShell->setText(QString::number((double)getMinimum(VecShell)/1000));
|
||||
}
|
||||
ui->lCurRoundTimeShell->setText(QString::number((double)zeit/1000));
|
||||
}
|
||||
}
|
||||
ui->lWShellTime->scrollToBottom();
|
||||
ui->lWShellTime->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
}
|
||||
void WindowRace::deaSlot(){
|
||||
void WindowRace::deaSlot(int time, int sector){
|
||||
if(started && !paused && !this->finished){
|
||||
if(firstTimeDea){
|
||||
firstTimeDea = false;
|
||||
counterDea.start();
|
||||
}
|
||||
else{
|
||||
long zeit = counterDea.getTime();
|
||||
VecDea.push_back(zeit);
|
||||
QListWidgetItem *item = new QListWidgetItem;
|
||||
if(getMinimum(VecDea) == zeit && VecDea.size() > 1){
|
||||
item->setBackgroundColor(Qt::green);
|
||||
|
||||
switch(sector){
|
||||
case 1:
|
||||
VecDea.push_back(QVector<int>());
|
||||
VecDea.last().push_back(time);
|
||||
cout << "Dea Sektor 1" << endl;
|
||||
timeModelDea = new TimeModel(VecDea, this);
|
||||
this->ui->lWDeaTime->setModel(timeModelDea);
|
||||
|
||||
break;
|
||||
case 2:
|
||||
if(VecDea.size() > 0){
|
||||
if(VecDea.last().size() == 1){
|
||||
cout << time << sector << endl;
|
||||
VecDea[VecDea.size()-1].push_back(time);
|
||||
timeModelDea = new TimeModel(VecDea, this);
|
||||
this->ui->lWDeaTime->setModel(timeModelDea);
|
||||
}
|
||||
else{
|
||||
//VecDea[VecDea.size()-1].append(9999);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if(VecDea.size() > 0){
|
||||
//cout << "Time sec 3: " << time << endl;
|
||||
if(VecDea.last().size() == 2){
|
||||
// cout << time << sector << endl;
|
||||
VecDea.last().push_back(time);
|
||||
|
||||
// add sum to vector
|
||||
VecDea.last().push_back(QVectorHelper::getCurTime(VecDea.last()));
|
||||
|
||||
|
||||
|
||||
timeModelDea = new TimeModel(VecDea, this);
|
||||
this->ui->lWDeaTime->setModel(timeModelDea);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// best time on widget
|
||||
cout << "cur time: " << QVectorHelper::getCurTime(VecDea.last()) << endl;
|
||||
cout << "min time: " << QVectorHelper::getMin(VecDea) << endl;
|
||||
if(QVectorHelper::getCurTime(VecDea.last()) <= QVectorHelper::getMin(VecDea)){
|
||||
ui->lBestZeitDea->setText(QString::number((double)QVectorHelper::getMin(VecDea)/1000));
|
||||
}
|
||||
ui->lCurRoundDea->setText(QString::number((double)QVectorHelper::getCurTime(VecDea.last())/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();
|
||||
|
||||
break;
|
||||
}
|
||||
if(zeit < this->minimumTime){
|
||||
item->setBackgroundColor(Qt::red);
|
||||
this->firstTimeDea = true;
|
||||
}
|
||||
item->setText(QString::number((double)zeit/1000));
|
||||
ui->lWDeaTime->addItem(item);
|
||||
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();
|
||||
if(getMinimum(VecDea) > 0){
|
||||
ui->lBestZeitDea->setText(QString::number((double)getMinimum(VecDea)/1000));
|
||||
}
|
||||
ui->lCurRoundDea->setText(QString::number((double)zeit/1000));
|
||||
}
|
||||
}
|
||||
ui->lWDeaTime->scrollToBottom();
|
||||
ui->lWDeaTime->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
}
|
||||
|
||||
long WindowRace::getMinimum(std::vector<long> a){
|
||||
|
||||
11
windowrace.h
11
windowrace.h
@@ -11,6 +11,7 @@
|
||||
#include "database.h"
|
||||
#include "windowrennliste.h"
|
||||
#include <QMessageBox>
|
||||
#include "timemodel.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
@@ -44,8 +45,10 @@ private:
|
||||
Counter counterDea;
|
||||
bool firstTimeShell;
|
||||
bool firstTimeDea;
|
||||
std::vector<long> VecShell;
|
||||
std::vector<long> VecDea;
|
||||
QVector<QVector<int>> VecShell;
|
||||
QVector<QVector<int>> VecDea;
|
||||
TimeModel *timeModelShell;
|
||||
TimeModel *timeModelDea;
|
||||
long getMinimum(std::vector<long> a);
|
||||
QString timeWrapper(long zahl);
|
||||
long countdownValue; //in sec
|
||||
@@ -68,8 +71,8 @@ public slots:
|
||||
void go();
|
||||
void ampelSlot();
|
||||
void laufcheck();
|
||||
void deaSlot();
|
||||
void shellSlot();
|
||||
void deaSlot(int, int);
|
||||
void shellSlot(int, int);
|
||||
void ReturnPress();
|
||||
};
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<widget class="QGroupBox" name="gbShell">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>300</width>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
@@ -103,10 +103,10 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="lWShellTime">
|
||||
<widget class="QTableView" name="lWShellTime">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>300</width>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
@@ -514,7 +514,7 @@
|
||||
<widget class="QGroupBox" name="gbDea">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>300</width>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
@@ -584,10 +584,10 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="lWDeaTime">
|
||||
<widget class="QTableView" name="lWDeaTime">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>300</width>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
@@ -640,7 +640,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>840</width>
|
||||
<height>20</height>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
|
||||
Reference in New Issue
Block a user