diff --git a/RennbahnZeitmessung.pro b/RennbahnZeitmessung.pro index e496fa7..8ec8c2e 100644 --- a/RennbahnZeitmessung.pro +++ b/RennbahnZeitmessung.pro @@ -8,6 +8,7 @@ QT += core gui QT += sql QT += core + greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = RennbahnZeitmessung @@ -24,7 +25,8 @@ SOURCES += main.cpp\ ampel.cpp \ database.cpp \ windowrennliste.cpp \ - training.cpp + training.cpp \ + timemodel.cpp HEADERS += \ mainwindow.h \ @@ -36,7 +38,8 @@ HEADERS += \ ampel.h \ database.h \ windowrennliste.h \ - training.h + training.h \ + timemodel.h FORMS += mainwindow.ui \ windowrace.ui \ @@ -46,5 +49,8 @@ FORMS += mainwindow.ui \ OTHER_FILES += +INCLUDEPATH += /home/jpaehr/Dokumente/libusb/libusb +LIBS += -L "/usr/lib" -lusb + RESOURCES += \ resource.qrc diff --git a/RennbahnZeitmessung.pro.user b/RennbahnZeitmessung.pro.user index ea55ed7..3d47973 100644 --- a/RennbahnZeitmessung.pro.user +++ b/RennbahnZeitmessung.pro.user @@ -1,7 +1,11 @@ - + + + EnvironmentId + {15687edb-7104-42fa-a53c-7d0294bb7338} + ProjectExplorer.Project.ActiveTarget 0 @@ -29,10 +33,14 @@ false 4 false + 80 + true true 1 true + false 0 + true true 0 8 @@ -53,22 +61,23 @@ Desktop Desktop - {afd67bb0-e1fe-490f-9c05-717bc9979c59} + {e7c8e272-6c95-4fb7-9b69-d295b2ca02f0} 0 0 0 - /home/jpaehr/Dokumente/C/build-RennbahnZeitmessung-Desktop-Debug + /home/jpaehr/Dokumente/build-RennbahnZeitmessung-Desktop-Debug true qmake QtProjectManager.QMakeBuildStep - false - true + true false + false + false true @@ -117,7 +126,7 @@ true - /home/jpaehr/Dokumente/C/build-RennbahnZeitmessung-Desktop-Release + /home/jpaehr/Dokumente/build-RennbahnZeitmessung-Desktop-Release true @@ -125,9 +134,10 @@ QtProjectManager.QMakeBuildStep false - true false + false + false true @@ -175,7 +185,67 @@ 0 true - 2 + + /home/jpaehr/Dokumente/build-RennbahnZeitmessung-Desktop-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 0 @@ -191,6 +261,11 @@ 1 + false + false + 1000 + + true false false @@ -229,15 +304,16 @@ RennbahnZeitmessung - Qt4ProjectManager.Qt4RunConfiguration:/home/jpaehr/Dokumente/C/RennbahnZeitmessung/RennbahnZeitmessung.pro + Qt4ProjectManager.Qt4RunConfiguration:/home/jpaehr/Dokumente/rennbahnc/RennbahnZeitmessung.pro + true RennbahnZeitmessung.pro false - false + /home/jpaehr/Dokumente/build-RennbahnZeitmessung-Desktop-Debug 3768 - true - false + false + true false false true @@ -250,11 +326,11 @@ 1 - ProjectExplorer.Project.Updater.EnvironmentId - {5a3b068d-48fb-4b9d-beda-5a5c38651d77} + ProjectExplorer.Project.Updater.FileVersion + 18 - ProjectExplorer.Project.Updater.FileVersion - 15 + Version + 18 diff --git a/hardwaresetup.cpp b/hardwaresetup.cpp index a462535..d9c15b5 100644 --- a/hardwaresetup.cpp +++ b/hardwaresetup.cpp @@ -2,19 +2,28 @@ #include #include "sys/io.h" #include +#include +#include +#include +#include -//#define BASEPORT 0xe050 /* lp1 */ -//#define BASEPORT 0x378 -#define BASEPORT 0xd000 +#define USB_LED_ON 1 +#define USB_LED_OFF 0 +#define USB_DATA_OUT 2 + +using namespace std; +// not needed anymore -> usb +// #define BASEPORT 0xe050 /* lp1 */ +// #define BASEPORT 0x378 +// #define BASEPORT 0xd000 HardwareSetup::HardwareSetup() { - if (ioperm(BASEPORT, 3, 1)) { - //perror("ioperm"); - } - shellBefore = false; - deaBefore = false; +// if (ioperm(BASEPORT, 3, 1)) { +// //perror("ioperm"); +// } this->stop = 0; + this->handle = NULL; } void HardwareSetup::setStop(){ this->stop = 1; @@ -25,21 +34,192 @@ HardwareSetup::~HardwareSetup(){ //perror("ioperm"); }*/ std::cout << "Hardware beendet" << std::endl; - + this->stop = 1; + if(this->handle){ + usb_close(this->handle); + } + this->handle = NULL; } + +/* Used to get descriptor strings for device identification */ +int HardwareSetup::usbGetDescriptorString(usb_dev_handle *dev, int index, int langid, + char *buf, int buflen) { + char buffer[256]; + int rval, i; + + // make standard request GET_DESCRIPTOR, type string and given index + // (e.g. dev->iProduct) + rval = usb_control_msg(dev, + USB_TYPE_STANDARD | USB_RECIP_DEVICE | USB_ENDPOINT_IN, + USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) + index, langid, + buffer, sizeof(buffer), 1000); + + if(rval < 0) // error + return rval; + + // rval should be bytes read, but buffer[0] contains the actual response size + if((unsigned char)buffer[0] < rval) + rval = (unsigned char)buffer[0]; // string is shorter than bytes read + + if(buffer[1] != USB_DT_STRING) // second byte is the data type + return 0; // invalid return type + + // we're dealing with UTF-16LE here so actual chars is half of rval, + // and index 0 doesn't count + rval /= 2; + + /* lossy conversion to ISO Latin1 */ + for(i = 1; i < rval && i < buflen; i++) { + if(buffer[2 * i + 1] == 0) + buf[i-1] = buffer[2 * i]; + else + buf[i-1] = '?'; /* outside of ISO Latin1 range */ + } + buf[i-1] = 0; + + return i-1; +} + + + +usb_dev_handle * HardwareSetup::usbOpenDevice(int vendor, char *vendorName, + int product, char *productName) { + struct usb_bus *bus; + struct usb_device *dev; + char devVendor[256], devProduct[256]; + + usb_dev_handle * handle = NULL; + + usb_init(); + usb_find_busses(); + usb_find_devices(); + + for(bus=usb_get_busses(); bus; bus=bus->next) { + for(dev=bus->devices; dev; dev=dev->next) { + if(dev->descriptor.idVendor != vendor || + dev->descriptor.idProduct != product) + continue; + + /* we need to open the device in order to query strings */ + if(!(handle = usb_open(dev))) { + fprintf(stderr, "Warning: cannot open USB device: %sn", + usb_strerror()); + continue; + } + + /* get vendor name */ + if(usbGetDescriptorString(handle, dev->descriptor.iManufacturer, + 0x0409, devVendor, sizeof(devVendor)) < 0) { + fprintf(stderr, + "Warning: cannot query manufacturer for device: %sn", + usb_strerror()); + usb_close(handle); + continue; + } + + /* get product name */ + if(usbGetDescriptorString(handle, dev->descriptor.iProduct, + 0x0409, devProduct, sizeof(devVendor)) < 0) { + fprintf(stderr, + "Warning: cannot query product for device: %sn", + usb_strerror()); + usb_close(handle); + continue; + } + + if(strcmp(devVendor, vendorName) == 0 && + strcmp(devProduct, productName) == 0) + return handle; + else + usb_close(handle); + } + } + return NULL; +} + + void HardwareSetup::run(){ + + int nBytes = 0; + //char buffer[256]; + struct TransStruct buffer[6]; + //struct TransStruct *buffer = buffer1; + //cout << "thread started" << endl; + +// if(argc < 2) { +// printf("Usage:\n"); +// printf("usbtext.exe on\n"); +// printf("usbtext.exe off\n"); +// exit(1); +// } + while(!this->handle){ + this->handle = usbOpenDevice(0x16C0, "test01", 0x05DC, "USBExample"); + + if(this->handle == NULL) { + fprintf(stderr, "Could not find USB device!\n"); + } + sleep(1); + } + + + int index; while(!this->stop){ + usleep(100000); // 100ms - usleep(500); + 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); - if(getDea()){ + for(int i = 0; i < 6; i++){ + if(buffer[i].update != 0){ + switch(buffer[i].id){ + case 0: + emit Shell((int)buffer[i].time, 1); + break; + case 1: + emit Dea((int)buffer[i].time, 1); + break; + case 2: + emit Shell((int)buffer[i].time, 2); + break; + case 3: + cout << "Time: vor emit" << (int)buffer[i].time << endl; + emit Dea((int)buffer[i].time, 2); + break; + case 4: + cout << "emit shell" << endl; + emit Shell((int)buffer[i].time, 3); + break; + case 5: + 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(!deaBefore){ +// 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(); + //emit Dea(5); } else{ index += 1; @@ -52,10 +232,11 @@ void HardwareSetup::run(){ deaBefore = false; } - if(getShell()){ +// if(getShell()){ + if(1){ if(!shellBefore){ shellBefore = true; - emit Shell(); + //emit Shell(); } } else{ @@ -67,23 +248,23 @@ void HardwareSetup::run(){ bool HardwareSetup::getShell(){ - int zahl[8] = {0}; +// int zahl[8] = {0}; - if(findBit(zahl, inb(BASEPORT + 1))[7] == 1){ +// if(findBit(zahl, inb(BASEPORT + 1))[7] == 1){ - return true; - } +// return true; +// } return false; } bool HardwareSetup::getDea(){ - int zahl[8] = {0}; +// int zahl[8] = {0}; - if(findBit(zahl, inb(BASEPORT + 1))[6] == 0 ){ - return true; - } +// if(findBit(zahl, inb(BASEPORT + 1))[6] == 0 ){ +// return true; +// } return false; } diff --git a/hardwaresetup.h b/hardwaresetup.h index 8e091ef..f3a384b 100644 --- a/hardwaresetup.h +++ b/hardwaresetup.h @@ -2,6 +2,17 @@ #define HARDWARESETUP_H #include +#include +#include +#include +#include +#include + +struct TransStruct{ + uint16_t time; + uint8_t id; + uint8_t update; +}; class HardwareSetup : public QThread { @@ -11,18 +22,21 @@ protected: private: bool shellBefore; bool deaBefore; + usb_dev_handle *handle; bool getShell(); bool getDea(); int* findBit(int *array, int zahl); bool stop; + int usbGetDescriptorString(usb_dev_handle *dev, int index, int langid, char *buf, int buflen); + usb_dev_handle *usbOpenDevice(int vendor, char *vendorName, int product, char *productName); public: void setStop(); ~HardwareSetup(); HardwareSetup(); signals: - void Shell(); - void Dea(); + void Shell(int, int); + void Dea(int, int); }; #endif // HARDWARESETUP_H diff --git a/timemodel.cpp b/timemodel.cpp new file mode 100644 index 0000000..ecb2c4b --- /dev/null +++ b/timemodel.cpp @@ -0,0 +1,125 @@ +#include "timemodel.h" +#include +#include +#include + + +TimeModel::TimeModel(QVector> timeData, QObject *parent) + : QAbstractTableModel(parent) +{ + this->timeData = timeData; +} + +QVariant TimeModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role != Qt::DisplayRole) + return QVariant(); + + if (orientation == Qt::Horizontal) { + switch (section) { + case 0: + return QString("Sektor 1"); + + case 1: + return QString("Sektor 2"); + + case 2: + return QString("Sektor 3"); + + case 3: + return QString("Runde"); + default: + return QVariant(); + } + } + return QVariant(); +} + +int TimeModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + + return this->timeData.size(); +} + +int TimeModel::columnCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + return 4; +} + +QColor TimeModel::getColor(const QVector> data, const int col, const int row) const{ + if(row == 0){ + return QColor(Qt::gray); + } + else if(data.size() > row){ // check for enough rows + if(data.at(row).size() > col){ // check for enough cols + QVector compare; + for(int i = 0; i <= row; i++){ + compare.append(data.at(i).at(col)); + } + if(data.at(row).at(col) == getMin(compare)){ + return QColor(Qt::green); + } + else{ + return QColor(Qt::gray); + } + } + else{ + return QColor(Qt::white); + } + } + else{ + return QColor(Qt::white); + } +} + +int TimeModel::getMin(const QVector x) const{ + int min; + if(x.size() > 0){ + min = x.at(0); + } + for(int i = 1; i < x.size(); i++){ + if(x.at(i) < min){ + min = x.at(i); + } + } + return min; +} + +QVariant TimeModel::data(const QModelIndex &index, int role) const +{ + //std::cout << "data called" << std::endl; + if (!index.isValid()) + return QVariant(); + + if(role == Qt::DisplayRole){ + if(timeData.at(index.row()).size() > index.column()){ + return QString::number((double)timeData.at(index.row()).at(index.column())/1000); + } + else{ + return QString("∞"); + } + } + else if(role == Qt::BackgroundColorRole){ + return getColor(timeData, index.column(), index.row()); + } + return QVariant(); +} + +bool TimeModel::insertRows(int row, int count, const QModelIndex &parent) +{ + std::cout << "insert triggert" << std::endl; + beginInsertRows(parent, row, row + count - 1); + // FIXME: Implement me! + endInsertRows(); +} + +bool TimeModel::insertColumns(int column, int count, const QModelIndex &parent) +{ + beginInsertColumns(parent, column, column + count - 1); + // FIXME: Implement me! + endInsertColumns(); +} diff --git a/timemodel.h b/timemodel.h new file mode 100644 index 0000000..cedf1e0 --- /dev/null +++ b/timemodel.h @@ -0,0 +1,35 @@ +#ifndef TIMEMODEL_H +#define TIMEMODEL_H + +#include +#include +#include + +class TimeModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + explicit TimeModel(QVector> timeData, QObject *parent = nullptr); + + // Header: + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + + // Basic functionality: + int rowCount(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; + + // Add data: + bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; + bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override; + +private: + int getMin(const QVector x) const; + + QColor getColor(const QVector> data, const int col, const int row) const; // row and col starts counting at 0 + QVector> timeData; +}; + +#endif // TIMEMODEL_H diff --git a/training.cpp b/training.cpp index 15cccb2..524e0c3 100644 --- a/training.cpp +++ b/training.cpp @@ -6,6 +6,8 @@ #include #include #include "unistd.h" +#include +#include "timemodel.h" using std::vector; using std::string; @@ -31,8 +33,12 @@ Training::Training(QWidget *parent, DataBase *db) : this->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(this->ui->pBNextRace, SIGNAL(clicked()), this, SLOT(prepareNextRace())); //QObject::connect(this->ui->pBStop, SIGNAL(clicked()), this, SLOT(stopClicked())); @@ -52,7 +58,9 @@ Training::Training(QWidget *parent, DataBase *db) : void Training::ResetShell(){ this->VecShell.clear(); - this->ui->lWShellTime->clear(); + // this->ui->lWShellTime->clear(); + timeModelShell = new TimeModel(VecShell, this); + this->ui->lWShellTime->setModel(timeModelShell); this->ui->lBestZeitShell->setText("∞"); this->ui->lCurRoundTimeShell->setText("∞"); @@ -61,7 +69,9 @@ void Training::ResetShell(){ void Training::ResetDea(){ this->VecDea.clear(); - this->ui->lWDeaTime->clear(); + //this->ui->lWDeaTime->clear(); + timeModelDea = new TimeModel(VecDea, this); + this->ui->lWDeaTime->setModel(timeModelDea); this->ui->lBestZeitDea->setText("∞"); @@ -71,8 +81,8 @@ void Training::ResetDea(){ void Training::Reset(){ this->VecShell.clear(); this->VecDea.clear(); - this->ui->lWDeaTime->clear(); - this->ui->lWShellTime->clear(); + // this->ui->lWDeaTime->clear(); + // this->ui->lWShellTime->clear(); this->ui->lBestZeitDea->setText("∞"); this->ui->lBestZeitShell->setText("∞"); @@ -85,8 +95,8 @@ void Training::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("∞"); @@ -96,34 +106,75 @@ void Training::prepareNextRace(){ this->finished = false; this->paused = false; - this->started = false; + this->started = true; } -void Training::shellSlot(){ +void Training::shellSlot(int time, int sector){ + cout << "Shell slot" << endl; + // slot is called when a sector is finished + // time is given in ms + // counting of sector beginns at 1 + if(started && !paused && !this->finished){ if(firstTimeShell){ firstTimeShell = false; - 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); - } - if(zeit < this->minimumTime){ - item->setBackgroundColor(Qt::red); - this->firstTimeShell = true; - } - item->setText(QString::number((double)zeit/1000)); - ui->lWShellTime->addItem(item); + switch(sector){ + case 1: + VecShell.push_back(QVector()); + VecShell.last().push_back(time); - ui->lWShellTime->scrollToBottom(); - if(getMinimum(VecShell) > 0){ - ui->lBestZeitShell->setText(QString::number((double)getMinimum(VecShell)/1000)); + timeModelShell = new TimeModel(VecShell, this); + this->ui->lWShellTime->setModel(timeModelShell); + + break; + case 2: + if(VecShell.size() > 0){ + if(VecShell.last().size() == 1){ + cout << time << sector << endl; + VecShell.last().push_back(time); + timeModelShell = new TimeModel(VecShell, this); + this->ui->lWShellTime->setModel(timeModelShell); + } + else{ + + } + } + break; + case 3: + if(VecShell.size() > 0){ + //cout << "Time sec 3: " << time << endl; + if(VecShell.last().size() == 2){ +// cout << time << sector << endl; + VecShell.last().push_back(time); + + // add sum to vector + VecShell.last().push_back(getCurTime(VecShell.last())); + + + + timeModelShell = new TimeModel(VecShell, this); + this->ui->lWShellTime->setModel(timeModelShell); + + + } + + + + // best time on widget + + if(getCurTime(VecShell.last()) <= getMin(VecShell)){ + ui->lBestZeitShell->setText(QString::number((double)getMin(VecShell)/1000)); + } + ui->lCurRoundTimeShell->setText(QString::number((double)getCurTime(VecShell.last())/1000)); + } + + break; } - ui->lCurRoundTimeShell->setText(QString::number((double)zeit/1000)); + ui->lWShellTime->scrollToBottom(); + ui->lWShellTime->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + } } } @@ -131,67 +182,106 @@ void Training::closeEvent(QCloseEvent *event){ } -void Training::deaSlot(){ +void Training::deaSlot(int time, int sector){ + // slot is called when a sector is finished + // time is given in ms + // counting of sector beginns at 1 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); - } - item->setText(QString::number((double)zeit/1000)); - ui->lWDeaTime->addItem(item); - ui->lWDeaTime->scrollToBottom(); + switch(sector){ + case 1: + VecDea.push_back(QVector()); + VecDea.last().push_back(time); + cout << "Dea Sektor 1" << endl; + timeModelDea = new TimeModel(VecDea, this); + this->ui->lWDeaTime->setModel(timeModelDea); - ui->lBestZeitDea->setText(QString::number((double)getMinimum(VecDea)/1000)); - ui->lCurRoundDea->setText(QString::number((double)zeit/1000)); - */ - // - long zeit = counterDea.getTime(); - VecDea.push_back(zeit); - QListWidgetItem *item = new QListWidgetItem; - if(getMinimum(VecDea) == zeit && VecDea.size() > 1){ - item->setBackgroundColor(Qt::green); - } - if(zeit < this->minimumTime){ - item->setBackgroundColor(Qt::red); - this->firstTimeDea = true; - } - item->setText(QString::number((double)zeit/1000)); - ui->lWDeaTime->addItem(item); + 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[VecDea.size()-1].push_back(time); - ui->lWDeaTime->scrollToBottom(); - if(getMinimum(VecDea) > 0){ - ui->lBestZeitDea->setText(QString::number((double)getMinimum(VecDea)/1000)); + // add sum to vector + VecDea[VecDea.size()-1].push_back(getCurTime(VecDea.last())); + + + + timeModelDea = new TimeModel(VecDea, this); + this->ui->lWDeaTime->setModel(timeModelDea); + + + } + + + + // best time on widget + cout << "cur time: " << getCurTime(VecDea.last()) << endl; + cout << "min time: " << getMin(VecDea) << endl; + if(getCurTime(VecDea.last()) <= getMin(VecDea)){ + ui->lBestZeitDea->setText(QString::number((double)getMin(VecDea)/1000)); + } + ui->lCurRoundDea->setText(QString::number((double)getCurTime(VecDea.last())/1000)); + } + + break; } - ui->lCurRoundDea->setText(QString::number((double)zeit/1000)); + ui->lWDeaTime->scrollToBottom(); + ui->lWDeaTime->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + } } } -long Training::getMinimum(std::vector a){ - long minimum = -1; - for(unsigned int i = 0; i < a.size(); i++){ - if(minimum < 0){ - if(a[i] >= this->minimumTime){ - minimum = a[i]; - } +int Training::getCurTime(const QVector x) const { + if(x.size() >= 3){ + return x.at(0)+ x.at(1) + x.at(2); + } + else{ + return 9999; + } +} + + +int Training::getMin(const QVector> x) const{ + int min; + if(x.size() > 0){ + if(x.at(0).size() >= 3){ + min = getCurTime(x.at(0)); } else{ - if(a[i] < minimum && a[i] >= this->minimumTime){ - minimum = a[i]; - } + return 9999; } - } - return minimum; + else{ + return 9999; + } + for(int i = 1; i < x.size(); i++){ + if(getCurTime(x.at(i)) < min){ + min = getCurTime(x.at(i)); + } + } + return min; } + Training::~Training() { this->Hardware->setStop(); diff --git a/training.h b/training.h index 283fff5..857c594 100644 --- a/training.h +++ b/training.h @@ -6,6 +6,7 @@ #include "counter.h" #include #include "database.h" +#include "timemodel.h" namespace Ui { class Training; @@ -29,9 +30,13 @@ private: HardwareSetup *Hardware; bool firstTimeShell; bool firstTimeDea; - std::vector VecShell; - std::vector VecDea; + QVector> VecShell; + QVector> VecDea; long getMinimum(std::vector a); + int getCurTime(const QVector x) const; + int getMin(const QVector> x) const; + + bool paused; bool finished; Counter counterShell; @@ -40,12 +45,16 @@ private: long minTimeOneRound; int minimumTime; + // timeModel + TimeModel *timeModelDea; + TimeModel *timeModelShell; + public slots: void ResetShell(); void ResetDea(); void Reset(); - void deaSlot(); - void shellSlot(); + void deaSlot(int time, int sector); + void shellSlot(int time, int sector); }; diff --git a/training.ui b/training.ui index 9f898be..4b4358b 100644 --- a/training.ui +++ b/training.ui @@ -16,14 +16,14 @@ - + - 300 + 16777215 16777215 @@ -93,10 +93,10 @@ - + - 300 + 16777215 16777215 @@ -131,7 +131,7 @@ - 300 + 16777215 16777215 @@ -143,7 +143,7 @@ Dea - + @@ -201,10 +201,10 @@ - + - 300 + 16777215 16777215 @@ -250,7 +250,7 @@ 0 0 800 - 20 + 25 diff --git a/windowrace.cpp b/windowrace.cpp index 69d1262..2db16ac 100644 --- a/windowrace.cpp +++ b/windowrace.cpp @@ -49,6 +49,7 @@ 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(ui->pBStart, SIGNAL(clicked()), this, SLOT(go()));