fixes for usb-support
This commit is contained in:
269
training.cpp
269
training.cpp
@@ -1,27 +1,26 @@
|
||||
#include "training.h"
|
||||
#include "qvectorhelper.h"
|
||||
#include "timemodel.h"
|
||||
#include "ui_training.h"
|
||||
#include <QObject>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <QShortcut>
|
||||
#include "unistd.h"
|
||||
#include <QListWidgetItem>
|
||||
#include "timemodel.h"
|
||||
#include "qvectorhelper.h"
|
||||
#include <QObject>
|
||||
#include <QShortcut>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
using std::vector;
|
||||
using std::string;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
Training::Training(QWidget *parent, DataBase *db) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::Training)
|
||||
{
|
||||
Training::Training(QWidget * parent, DataBase * db)
|
||||
: QMainWindow(parent), ui(new Ui::Training) {
|
||||
ui->setupUi(this);
|
||||
this->db = db;
|
||||
string statement = "select mindestrundendauer from renndauer where id like 1";
|
||||
string statement =
|
||||
"select mindestrundendauer from renndauer where id like 1";
|
||||
|
||||
this->minimumTime = this->db->getData(statement, 1)[0][0].toInt();
|
||||
this->finished = false;
|
||||
@@ -35,36 +34,38 @@ Training::Training(QWidget *parent, DataBase *db) :
|
||||
this->Hardware = new HardwareSetup;
|
||||
Hardware->start();
|
||||
|
||||
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()));
|
||||
|
||||
|
||||
|
||||
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()));
|
||||
|
||||
QShortcut *shortcut = new QShortcut(QKeySequence("Ctrl+Q"), this);
|
||||
QShortcut *shellReset = new QShortcut(QKeySequence("Ctrl+s"), this);
|
||||
QShortcut *deaReset = new QShortcut(QKeySequence("Ctrl+d"), this);
|
||||
QShortcut * shortcut = new QShortcut(QKeySequence("Ctrl+Q"), this);
|
||||
QShortcut * shellReset = new QShortcut(QKeySequence("Ctrl+s"), this);
|
||||
QShortcut * deaReset = new 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(this->ui->pBReset, SIGNAL(clicked()), this, SLOT(Reset()));
|
||||
QObject::connect(this->ui->pBResetDea, SIGNAL(clicked()), this, SLOT(ResetDea()));
|
||||
QObject::connect(this->ui->pBResetShell, SIGNAL(clicked()), this, SLOT(ResetShell()));
|
||||
QObject::connect(this->ui->pBResetDea, SIGNAL(clicked()), this,
|
||||
SLOT(ResetDea()));
|
||||
QObject::connect(this->ui->pBResetShell, SIGNAL(clicked()), this,
|
||||
SLOT(ResetShell()));
|
||||
|
||||
// fill minSecTimes vector
|
||||
statement = "select minsec1, minsec2, minsec3 from renndauer order by id DESC limit 1";
|
||||
vector< vector< QString > > res;
|
||||
statement = "select minsec1, minsec2, minsec3 from renndauer order by id "
|
||||
"DESC limit 1";
|
||||
vector<vector<QString>> res;
|
||||
res = db->getData(statement, 3);
|
||||
this->minSecTime.append(res[0][0].toInt());
|
||||
this->minSecTime.append(res[0][1].toInt());
|
||||
this->minSecTime.append(res[0][2].toInt());
|
||||
|
||||
}
|
||||
void Training::ResetShell(){
|
||||
void Training::ResetShell() {
|
||||
this->VecShell.clear();
|
||||
|
||||
// this->ui->lWShellTime->clear();
|
||||
@@ -75,10 +76,10 @@ void Training::ResetShell(){
|
||||
this->ui->lCurRoundTimeShell->setText("∞");
|
||||
this->firstTimeShell = true;
|
||||
}
|
||||
void Training::ResetDea(){
|
||||
void Training::ResetDea() {
|
||||
this->VecDea.clear();
|
||||
|
||||
//this->ui->lWDeaTime->clear();
|
||||
// this->ui->lWDeaTime->clear();
|
||||
timeModelDea = new TimeModel(VecDea, minSecTime, this);
|
||||
this->ui->lWDeaTime->setModel(timeModelDea);
|
||||
|
||||
@@ -87,11 +88,11 @@ void Training::ResetDea(){
|
||||
this->ui->lCurRoundDea->setText("∞");
|
||||
this->firstTimeDea = true;
|
||||
}
|
||||
void Training::Reset(){
|
||||
void Training::Reset() {
|
||||
this->ResetDea();
|
||||
this->ResetShell();
|
||||
}
|
||||
void Training::prepareNextRace(){
|
||||
void Training::prepareNextRace() {
|
||||
this->firstTimeShell = true;
|
||||
this->firstTimeDea = true;
|
||||
|
||||
@@ -108,137 +109,155 @@ void Training::prepareNextRace(){
|
||||
this->started = true;
|
||||
}
|
||||
|
||||
void Training::shellSlot(int time, int sector){
|
||||
void Training::shellSlot(int time, int sector) {
|
||||
// slot is called when a sector is finished
|
||||
// time is given in ms
|
||||
// counting of sector beginns at 1
|
||||
|
||||
cout << "received Shelltime: " << time << sector << endl;
|
||||
|
||||
if(started && !paused && !this->finished){
|
||||
if(firstTimeShell){
|
||||
if (started && !paused && !this->finished) {
|
||||
if (firstTimeShell) {
|
||||
firstTimeShell = false;
|
||||
}
|
||||
else{
|
||||
switch(sector){
|
||||
case 1:
|
||||
VecShell.push_back(QVector<int>());
|
||||
VecShell.last().push_back(time);
|
||||
else {
|
||||
switch (sector) {
|
||||
case 1:
|
||||
VecShell.push_back(QVector<int>());
|
||||
VecShell.last().push_back(time);
|
||||
|
||||
timeModelShell = new TimeModel(VecShell, minSecTime, this);
|
||||
this->ui->lWShellTime->setModel(timeModelShell);
|
||||
timeModelShell = new TimeModel(VecShell, minSecTime, 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, minSecTime, 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, minSecTime, this);
|
||||
this->ui->lWShellTime->setModel(timeModelShell);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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(QVectorHelper::getCurTime(VecShell.last()));
|
||||
// add sum to vector
|
||||
VecShell.last().push_back(
|
||||
QVectorHelper::getCurTime(VecShell.last()));
|
||||
|
||||
timeModelShell = new TimeModel(VecShell, minSecTime, this);
|
||||
this->ui->lWShellTime->setModel(timeModelShell);
|
||||
}
|
||||
// best time on widget
|
||||
|
||||
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));
|
||||
timeModelShell =
|
||||
new TimeModel(VecShell, minSecTime, this);
|
||||
this->ui->lWShellTime->setModel(timeModelShell);
|
||||
}
|
||||
// best time on widget
|
||||
|
||||
break;
|
||||
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));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
ui->lWShellTime->scrollToBottom();
|
||||
ui->lWShellTime->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
|
||||
ui->lWShellTime->horizontalHeader()->setSectionResizeMode(
|
||||
QHeaderView::Stretch);
|
||||
}
|
||||
}
|
||||
}
|
||||
void Training::closeEvent(QCloseEvent *event){
|
||||
void Training::closeEvent(QCloseEvent * event) {
|
||||
Hardware->setStop();
|
||||
//delete this->Hardware;
|
||||
// delete this->Hardware;
|
||||
}
|
||||
|
||||
void Training::deaSlot(int time, int sector){
|
||||
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
|
||||
|
||||
cout << "received Deatime: " << time << sector << endl;
|
||||
|
||||
|
||||
if(started && !paused && !this->finished){
|
||||
if(firstTimeDea){
|
||||
if (started && !paused && !this->finished) {
|
||||
if (firstTimeDea) {
|
||||
firstTimeDea = false;
|
||||
}
|
||||
else{
|
||||
switch(sector){
|
||||
case 1:
|
||||
VecDea.push_back(QVector<int>());
|
||||
VecDea.last().push_back(time);
|
||||
// cout << "Dea Sektor 1" << endl;
|
||||
timeModelDea = new TimeModel(VecDea, minSecTime, this);
|
||||
this->ui->lWDeaTime->setModel(timeModelDea);
|
||||
else {
|
||||
switch (sector) {
|
||||
case 1:
|
||||
VecDea.push_back(QVector<int>());
|
||||
VecDea.last().push_back(time);
|
||||
// cout << "Dea Sektor 1" << endl;
|
||||
timeModelDea = new TimeModel(VecDea, minSecTime, 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, minSecTime, this);
|
||||
this->ui->lWDeaTime->setModel(timeModelDea);
|
||||
}
|
||||
else{
|
||||
//VecDea[VecDea.size()-1].append(9999);
|
||||
}
|
||||
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, minSecTime, this);
|
||||
this->ui->lWDeaTime->setModel(timeModelDea);
|
||||
}
|
||||
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, minSecTime, 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));
|
||||
else {
|
||||
// VecDea[VecDea.size()-1].append(9999);
|
||||
}
|
||||
break;
|
||||
}
|
||||
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, minSecTime, 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));
|
||||
}
|
||||
break;
|
||||
}
|
||||
ui->lWDeaTime->scrollToBottom();
|
||||
ui->lWDeaTime->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
ui->lWDeaTime->horizontalHeader()->setSectionResizeMode(
|
||||
QHeaderView::Stretch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Training::~Training()
|
||||
{
|
||||
Training::~Training() {
|
||||
cout << "destr Training" << endl;
|
||||
this->Hardware->setStop();
|
||||
usleep(1000000);
|
||||
|
||||
Reference in New Issue
Block a user