fixes for usb-support

This commit is contained in:
2017-12-25 08:12:10 +01:00
parent 3b66192591
commit 95b3471f49
19 changed files with 1196 additions and 3580 deletions

24
.clang-format Normal file
View File

@@ -0,0 +1,24 @@
---
# We'll use defaults from the LLVM style, but with 4 columns indentation.
BasedOnStyle: LLVM
IndentWidth: 4
---
Language: Cpp
# Force pointers to the type for C++.
DerivePointerAlignment: false
PointerAlignment: Middle
AlignTrailingComments: true
BreakBeforeBraces: Custom
BraceWrapping:
BeforeElse: true
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: InlineOnly
---
Language: JavaScript
# Use 100 columns for JS.
ColumnLimit: 100
---
Language: Proto
# Don't format .proto files.
DisableFormat: true
...

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*.o
moc_*

3021
Makefile

File diff suppressed because it is too large Load Diff

View File

@@ -51,8 +51,11 @@ FORMS += mainwindow.ui \
OTHER_FILES += OTHER_FILES +=
INCLUDEPATH += /home/jpaehr/Dokumente/libusb/libusb #INCLUDEPATH += /home/johannes/Dokumente/libusb/libusb
LIBS += -L "/usr/lib" -lusb LIBS += -L "/usr/lib" -lusb
RESOURCES += \ RESOURCES += \
resource.qrc resource.qrc
DISTFILES += \
.clang-format

View File

@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.4.0, 2017-09-12T15:10:06. --> <!-- Written by QtCreator 4.3.1, 2017-12-24T15:47:52. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
<value type="QByteArray">{15687edb-7104-42fa-a53c-7d0294bb7338}</value> <value type="QByteArray">{fa7f3dc3-5b46-4468-a19f-ea195cf466a8}</value>
</data> </data>
<data> <data>
<variable>ProjectExplorer.Project.ActiveTarget</variable> <variable>ProjectExplorer.Project.ActiveTarget</variable>
@@ -54,79 +54,21 @@
</data> </data>
<data> <data>
<variable>ProjectExplorer.Project.PluginSettings</variable> <variable>ProjectExplorer.Project.PluginSettings</variable>
<valuemap type="QVariantMap"/> <valuemap type="QVariantMap">
<valuelist type="QVariantList" key="ClangStaticAnalyzer.SuppressedDiagnostics"/>
</valuemap>
</data> </data>
<data> <data>
<variable>ProjectExplorer.Project.Target.0</variable> <variable>ProjectExplorer.Project.Target.0</variable>
<valuemap type="QVariantMap"> <valuemap type="QVariantMap">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Qt 5.9.1 in PATH (qt5)</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Qt 5.9.1 in PATH (qt5)</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{e7c8e272-6c95-4fb7-9b69-d295b2ca02f0}</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{48e51839-112c-4842-badf-f2eb9bcf81cb}</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value> <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value> <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value> <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/jpaehr/Dokumente/build-RennbahnZeitmessung-Desktop-Debug</value> <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/johannes/Dokumente/build-RennbahnZeitmessung-Qt_5_9_1_in_PATH_qt5-Release</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.SeparateDebugInfo">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.UseQtQuickCompiler">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments">
<value type="QString">-w</value>
<value type="QString">-r</value>
</valuelist>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments">
<value type="QString">-w</value>
<value type="QString">-r</value>
</valuelist>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/jpaehr/Dokumente/build-RennbahnZeitmessung-Desktop-Release</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
@@ -172,7 +114,7 @@
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value> <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value> <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Bereinigen</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap> </valuemap>
@@ -185,8 +127,8 @@
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value> <value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value> <value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
</valuemap> </valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/jpaehr/Dokumente/build-RennbahnZeitmessung-Desktop-Profile</value> <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/johannes/Dokumente/build-RennbahnZeitmessung-Qt_5_9_1_in_PATH_qt5-Debug</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
@@ -196,7 +138,7 @@
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">true</value> <value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value> <value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value> <value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.SeparateDebugInfo">true</value> <value type="bool" key="QtProjectManager.QMakeBuildStep.SeparateDebugInfo">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.UseQtQuickCompiler">false</value> <value type="bool" key="QtProjectManager.QMakeBuildStep.UseQtQuickCompiler">false</value>
</valuemap> </valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
@@ -232,29 +174,29 @@
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value> <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value> <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Bereinigen</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value> <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value> <value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/> <valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Profile</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value> <value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value> <value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">3</value> <value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">2</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value> <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deployment</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value> <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy locally</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Lokales Deployment</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap> </valuemap>
@@ -304,13 +246,13 @@
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">RennbahnZeitmessung</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">RennbahnZeitmessung</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/jpaehr/Dokumente/rennbahnc/RennbahnZeitmessung.pro</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/johannes/Dokumente/rennbahnc/RennbahnZeitmessung.pro</value>
<value type="bool" key="QmakeProjectManager.QmakeRunConfiguration.UseLibrarySearchPath">true</value> <value type="bool" key="QmakeProjectManager.QmakeRunConfiguration.UseLibrarySearchPath">true</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">RennbahnZeitmessung.pro</value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">RennbahnZeitmessung.pro</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value> <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default">/home/jpaehr/Dokumente/build-RennbahnZeitmessung-Desktop-Debug</value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default">/home/johannes/Dokumente/build-RennbahnZeitmessung-Qt_5_9_1_in_PATH_qt5-Release</value>
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value> <value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value> <value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value> <value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>

View File

@@ -1,8 +1,7 @@
#include "ampel.h" #include "ampel.h"
#include <unistd.h> #include <unistd.h>
Ampel::Ampel() Ampel::Ampel() {
{
this->running = 1; this->running = 1;
} }
void Ampel::setStop() { void Ampel::setStop() {
@@ -22,4 +21,3 @@ void Ampel::run(){
emit ampelUpdate(); emit ampelUpdate();
} }
} }

View File

@@ -1,7 +1,6 @@
#include "countdown.h" #include "countdown.h"
#include "unistd.h" #include "unistd.h"
Countdown::Countdown() Countdown::Countdown() {
{
this->running = 1; this->running = 1;
} }
void Countdown::setStop() { void Countdown::setStop() {

View File

@@ -1,11 +1,9 @@
#include "counter.h" #include "counter.h"
#include <sys/time.h>
#include <iostream>
#include <cstddef> #include <cstddef>
#include <iostream>
#include <sys/time.h>
Counter::Counter() Counter::Counter() {
{
} }
void Counter::start() { void Counter::start() {
@@ -14,8 +12,8 @@ void Counter::start(){
long Counter::getTime() { long Counter::getTime() {
gettimeofday(&endTime, NULL); gettimeofday(&endTime, NULL);
long back = (endTime.tv_usec-startTime.tv_usec)/1000+(endTime.tv_sec-startTime.tv_sec)*1000; long back = (endTime.tv_usec - startTime.tv_usec) / 1000 +
(endTime.tv_sec - startTime.tv_sec) * 1000;
this->start(); this->start();
return back; return back;
} }

View File

@@ -1,13 +1,12 @@
#include "database.h" #include "database.h"
#include <iostream>
#include <cstring>
#include <QVariant> #include <QVariant>
#include <cstring>
#include <iostream>
using std::vector; using std::vector;
DataBase::DataBase() DataBase::DataBase() {
{
this->db = new QSqlDatabase(); this->db = new QSqlDatabase();
*this->db = QSqlDatabase::addDatabase("QSQLITE"); *this->db = QSqlDatabase::addDatabase("QSQLITE");
this->db->setDatabaseName("Renndatenbank.sqlite"); this->db->setDatabaseName("Renndatenbank.sqlite");

View File

@@ -1,10 +1,10 @@
#include "hardwaresetup.h" #include "hardwaresetup.h"
#include <unistd.h>
#include "sys/io.h" #include "sys/io.h"
#include <iostream> #include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <usb.h> #include <usb.h>
#define USB_LED_ON 1 #define USB_LED_ON 1
@@ -17,8 +17,7 @@ using namespace std;
// #define BASEPORT 0x378 // #define BASEPORT 0x378
// #define BASEPORT 0xd000 // #define BASEPORT 0xd000
HardwareSetup::HardwareSetup() HardwareSetup::HardwareSetup() {
{
// if (ioperm(BASEPORT, 3, 1)) { // if (ioperm(BASEPORT, 3, 1)) {
// //perror("ioperm"); // //perror("ioperm");
// } // }
@@ -39,27 +38,26 @@ HardwareSetup::~HardwareSetup(){
usb_close(this->handle); usb_close(this->handle);
} }
this->handle = NULL; this->handle = NULL;
} }
/* Used to get descriptor strings for device identification */ /* Used to get descriptor strings for device identification */
int HardwareSetup::usbGetDescriptorString(usb_dev_handle *dev, int index, int langid, int HardwareSetup::usbGetDescriptorString(usb_dev_handle * dev, int index,
char *buf, int buflen) { int langid, char * buf, int buflen) {
char buffer[256]; char buffer[256];
int rval, i; int rval, i;
// make standard request GET_DESCRIPTOR, type string and given index // make standard request GET_DESCRIPTOR, type string and given index
// (e.g. dev->iProduct) // (e.g. dev->iProduct)
rval = usb_control_msg(dev, rval = usb_control_msg(
USB_TYPE_STANDARD | USB_RECIP_DEVICE | USB_ENDPOINT_IN, dev, USB_TYPE_STANDARD | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) + index, langid, USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) + index, langid, buffer,
buffer, sizeof(buffer), 1000); sizeof(buffer), 1000);
if (rval < 0) // error if (rval < 0) // error
return rval; return rval;
// rval should be bytes read, but buffer[0] contains the actual response size // rval should be bytes read, but buffer[0] contains the actual response
// size
if ((unsigned char)buffer[0] < rval) if ((unsigned char)buffer[0] < rval)
rval = (unsigned char)buffer[0]; // string is shorter than bytes read rval = (unsigned char)buffer[0]; // string is shorter than bytes read
@@ -82,8 +80,6 @@ int HardwareSetup::usbGetDescriptorString(usb_dev_handle *dev, int index, int la
return i - 1; return i - 1;
} }
usb_dev_handle * HardwareSetup::usbOpenDevice(int vendor, char * vendorName, usb_dev_handle * HardwareSetup::usbOpenDevice(int vendor, char * vendorName,
int product, char * productName) { int product, char * productName) {
struct usb_bus * bus; struct usb_bus * bus;
@@ -111,7 +107,8 @@ usb_dev_handle * HardwareSetup::usbOpenDevice(int vendor, char *vendorName,
/* get vendor name */ /* get vendor name */
if (usbGetDescriptorString(handle, dev->descriptor.iManufacturer, if (usbGetDescriptorString(handle, dev->descriptor.iManufacturer,
0x0409, devVendor, sizeof(devVendor)) < 0) { 0x0409, devVendor,
sizeof(devVendor)) < 0) {
fprintf(stderr, fprintf(stderr,
"Warning: cannot query manufacturer for device: %sn", "Warning: cannot query manufacturer for device: %sn",
usb_strerror()); usb_strerror());
@@ -120,10 +117,9 @@ usb_dev_handle * HardwareSetup::usbOpenDevice(int vendor, char *vendorName,
} }
/* get product name */ /* get product name */
if(usbGetDescriptorString(handle, dev->descriptor.iProduct, if (usbGetDescriptorString(handle, dev->descriptor.iProduct, 0x0409,
0x0409, devProduct, sizeof(devVendor)) < 0) { devProduct, sizeof(devVendor)) < 0) {
fprintf(stderr, fprintf(stderr, "Warning: cannot query product for device: %sn",
"Warning: cannot query product for device: %sn",
usb_strerror()); usb_strerror());
usb_close(handle); usb_close(handle);
continue; continue;
@@ -139,12 +135,11 @@ usb_dev_handle * HardwareSetup::usbOpenDevice(int vendor, char *vendorName,
return NULL; return NULL;
} }
void HardwareSetup::run() { void HardwareSetup::run() {
int nBytes = 0; int nBytes = 0;
// char buffer[256]; // char buffer[256];
struct TransStruct buffer[2]; struct TransStruct buffer[6];
// struct TransStruct *buffer = buffer1; // struct TransStruct *buffer = buffer1;
// cout << "thread started" << endl; // cout << "thread started" << endl;
@@ -163,18 +158,16 @@ void HardwareSetup::run(){
sleep(1); sleep(1);
} }
int index; int index;
while (!this->stop) { while (!this->stop) {
usleep(100000); // 100ms usleep(100000); // 100ms
// while(1){ // while(1){
nBytes = usb_control_msg(this->handle, nBytes = usb_control_msg(
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, this->handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
USB_DATA_OUT, 0, 0, (char *)buffer, sizeof(buffer), 5000); USB_DATA_OUT, 0, 0, (char *)buffer, sizeof(buffer), 5000);
for(int i = 0; i < 2; i++){ for (int i = 0; i < 6; i++) {
if (buffer[i].update != 0) { if (buffer[i].update != 0) {
switch (buffer[i].id) { switch (buffer[i].id) {
case 0: case 0:
@@ -205,28 +198,25 @@ void HardwareSetup::run(){
} }
} }
if (buffer[0].update != 0) { if (buffer[0].update != 0) {
cout << "Got " << nBytes << " bytes: " << (int)buffer[2].time << ", " << (int)buffer[2].id << endl; cout << "Got " << nBytes << " bytes: " << (int)buffer[2].time
<< ", " << (int)buffer[2].id << endl;
} }
//} //}
if (nBytes < 0) if (nBytes < 0)
fprintf(stderr, "USB error: %sn", usb_strerror()); fprintf(stderr, "USB error: %sn", usb_strerror());
} }
} }
bool HardwareSetup::getShell() { 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; return false;
} }
bool HardwareSetup::getDea() { bool HardwareSetup::getDea() {

View File

@@ -1,8 +1,7 @@
#include "mainwindow.h" #include "mainwindow.h"
#include <QApplication> #include <QApplication>
int main(int argc, char *argv[]) int main(int argc, char * argv[]) {
{
QApplication a(argc, argv); QApplication a(argc, argv);
MainWindow w; MainWindow w;
w.show(); w.show();

View File

@@ -1,22 +1,20 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "database.h"
#include "hardwaresetup.h"
#include "training.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include "unistd.h"
#include "windowrace.h"
#include "windowrennliste2.h"
#include "windowssettings.h"
#include <QObject> #include <QObject>
#include <QShortcut> #include <QShortcut>
#include "windowssettings.h"
#include <iostream> #include <iostream>
#include "hardwaresetup.h"
#include "windowrace.h"
#include "database.h"
#include <vector> #include <vector>
#include "windowrennliste2.h"
#include "training.h"
#include "unistd.h"
using std::vector; using std::vector;
MainWindow::MainWindow(QWidget *parent) : MainWindow::MainWindow(QWidget * parent)
QMainWindow(parent), : QMainWindow(parent), ui(new Ui::MainWindow) {
ui(new Ui::MainWindow)
{
ui->setupUi(this); ui->setupUi(this);
this->interfaceTraining = NULL; this->interfaceTraining = NULL;
@@ -27,34 +25,32 @@ MainWindow::MainWindow(QWidget *parent) :
// test = new HardwareSetup; // test = new HardwareSetup;
// this->test->start(); // this->test->start();
QObject::connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(NewWindowSettings())); QObject::connect(ui->pushButton, SIGNAL(clicked()), this,
SLOT(NewWindowSettings()));
QObject::connect(ui->pBRennen, SIGNAL(clicked()), this, SLOT(WindowRennen())); QObject::connect(ui->pBRennen, SIGNAL(clicked()), this,
QObject::connect(this->ui->pBTraining, SIGNAL(clicked()), this, SLOT(WindowTraining())); SLOT(WindowRennen()));
QObject::connect(this->ui->pBTraining, SIGNAL(clicked()), this,
SLOT(WindowTraining()));
QShortcut * startTraining = new QShortcut(QKeySequence("Ctrl+t"), this); QShortcut * startTraining = new QShortcut(QKeySequence("Ctrl+t"), this);
QShortcut * startRennen = new QShortcut(QKeySequence("Ctrl+r"), this); QShortcut * startRennen = new QShortcut(QKeySequence("Ctrl+r"), this);
QObject::connect(startTraining, SIGNAL(activated()), this, SLOT(WindowTraining())); QObject::connect(startTraining, SIGNAL(activated()), this,
QObject::connect(startRennen, SIGNAL(activated()), this, SLOT(WindowRennen())); SLOT(WindowTraining()));
QObject::connect(startRennen, SIGNAL(activated()), this,
SLOT(WindowRennen()));
this->db = new DataBase; this->db = new DataBase;
vector<vector<QString>> daten = db->getData("select * from Fahrer", 2); vector<vector<QString>> daten = db->getData("select * from Fahrer", 2);
} }
void MainWindow::closeEvent(QCloseEvent * event) { void MainWindow::closeEvent(QCloseEvent * event) {
} }
MainWindow::~MainWindow() MainWindow::~MainWindow() {
{
delete this->db; delete this->db;
delete ui; delete ui;
} }
void MainWindow::WindowTraining() { void MainWindow::WindowTraining() {

View File

@@ -1,9 +1,7 @@
#include "qvectorhelper.h" #include "qvectorhelper.h"
#include <qvector.h> #include <qvector.h>
QVectorHelper::QVectorHelper() QVectorHelper::QVectorHelper() {
{
} }
int QVectorHelper::getCurTime(const QVector<int> x) { int QVectorHelper::getCurTime(const QVector<int> x) {

View File

@@ -1,25 +1,24 @@
#include "timemodel.h" #include "timemodel.h"
#include<qvector.h>
#include <iostream> #include <iostream>
#include <qcolor.h> #include <qcolor.h>
#include <qvector.h>
TimeModel::TimeModel(QVector<QVector<int>> timeData, QVector<int> minimumTimes,
TimeModel::TimeModel(QVector<QVector<int>> timeData, QVector<int> minimumTimes, QObject *parent) QObject * parent)
: QAbstractTableModel(parent) : QAbstractTableModel(parent) {
{
this->timeData = timeData; this->timeData = timeData;
this->minimumTimes = minimumTimes; this->minimumTimes = minimumTimes;
} }
TimeModel::TimeModel(QVector<QVector<int>> timeData, QVector<int> minimumTimes, QVector<int> topTime, QObject *parent) TimeModel::TimeModel(QVector<QVector<int>> timeData, QVector<int> minimumTimes,
: QAbstractTableModel(parent) QVector<int> topTime, QObject * parent)
{ : QAbstractTableModel(parent) {
this->topTime = topTime; this->topTime = topTime;
this->timeData = timeData; this->timeData = timeData;
this->minimumTimes = minimumTimes; this->minimumTimes = minimumTimes;
} }
QVariant TimeModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant TimeModel::headerData(int section, Qt::Orientation orientation,
{ int role) const {
if (role != Qt::DisplayRole) if (role != Qt::DisplayRole)
return QVariant(); return QVariant();
@@ -43,22 +42,21 @@ QVariant TimeModel::headerData(int section, Qt::Orientation orientation, int rol
return QVariant(); return QVariant();
} }
int TimeModel::rowCount(const QModelIndex &parent) const int TimeModel::rowCount(const QModelIndex & parent) const {
{
if (parent.isValid()) if (parent.isValid())
return 0; return 0;
return this->timeData.size(); return this->timeData.size();
} }
int TimeModel::columnCount(const QModelIndex &parent) const int TimeModel::columnCount(const QModelIndex & parent) const {
{
if (parent.isValid()) if (parent.isValid())
return 0; return 0;
return 4; return 4;
} }
QColor TimeModel::getColor(const QVector<QVector<int>> data, const int col, const int row) const{ QColor TimeModel::getColor(const QVector<QVector<int>> data, const int col,
const int row) const {
if (row == 0) { if (row == 0) {
return QColor(Qt::gray); return QColor(Qt::gray);
} }
@@ -71,9 +69,9 @@ QColor TimeModel::getColor(const QVector<QVector<int>> data, const int col, cons
} }
else { else {
// 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)) {
return QColor(Qt::red); return QColor(Qt::red);
} }
} }
@@ -84,11 +82,15 @@ QColor TimeModel::getColor(const QVector<QVector<int>> data, const int col, cons
compare.append(data.at(i).at(col)); compare.append(data.at(i).at(col));
} }
} }
if(data.at(row).at(col) == getMin(compare)){ // at least personal best time if (data.at(row).at(col) ==
getMin(compare)) { // at least personal best time
if (col < 3) { // sector time if (col < 3) { // sector time
// std::cout << this->topTime.size() << std::endl; // std::cout << this->topTime.size() <<
if(this->topTime.size() > col){ // absolute top time exists // std::endl;
// std::cout << "local besttime" << std::endl; if (this->topTime.size() >
col) { // absolute top time exists
// std::cout << "local besttime"
// << std::endl;
if (this->topTime.at(col) >= data.at(row).at(col)) { if (this->topTime.at(col) >= data.at(row).at(col)) {
return QColor(Qt::magenta); return QColor(Qt::magenta);
} }
@@ -96,7 +98,9 @@ QColor TimeModel::getColor(const QVector<QVector<int>> data, const int col, cons
} }
else { // lap time else { // lap time
if (this->topTime.size() == 3) { if (this->topTime.size() == 3) {
if(this->topTime.at(0) + this->topTime.at(1) + this->topTime.at(2) >= data.at(row).at(col)){ if (this->topTime.at(0) + this->topTime.at(1) +
this->topTime.at(2) >=
data.at(row).at(col)) {
return QColor(Qt::magenta); return QColor(Qt::magenta);
} }
} }
@@ -129,15 +133,15 @@ int TimeModel::getMin(const QVector<int> x) const{
return min; return min;
} }
QVariant TimeModel::data(const QModelIndex &index, int role) const QVariant TimeModel::data(const QModelIndex & index, int role) const {
{
// std::cout << "data called" << std::endl; // std::cout << "data called" << std::endl;
if (!index.isValid()) if (!index.isValid())
return QVariant(); return QVariant();
if (role == Qt::DisplayRole) { if (role == Qt::DisplayRole) {
if (timeData.at(index.row()).size() > index.column()) { if (timeData.at(index.row()).size() > index.column()) {
return QString::number((double)timeData.at(index.row()).at(index.column())/1000); return QString::number(
(double)timeData.at(index.row()).at(index.column()) / 1000);
} }
else { else {
return QString(""); return QString("");
@@ -149,17 +153,18 @@ QVariant TimeModel::data(const QModelIndex &index, int role) const
return QVariant(); return QVariant();
} }
bool TimeModel::insertRows(int row, int count, const QModelIndex &parent) bool TimeModel::insertRows(int row, int count, const QModelIndex & parent) {
{
// std::cout << "insert triggert" << std::endl; // std::cout << "insert triggert" << std::endl;
beginInsertRows(parent, row, row + count - 1); beginInsertRows(parent, row, row + count - 1);
// FIXME: Implement me! // FIXME: Implement me!
endInsertRows(); endInsertRows();
return true;
} }
bool TimeModel::insertColumns(int column, int count, const QModelIndex &parent) bool TimeModel::insertColumns(int column, int count,
{ const QModelIndex & parent) {
beginInsertColumns(parent, column, column + count - 1); beginInsertColumns(parent, column, column + count - 1);
// FIXME: Implement me! // FIXME: Implement me!
endInsertColumns(); endInsertColumns();
return true;
} }

View File

@@ -1,27 +1,26 @@
#include "training.h" #include "training.h"
#include "qvectorhelper.h"
#include "timemodel.h"
#include "ui_training.h" #include "ui_training.h"
#include <QObject>
#include <string>
#include <sstream>
#include <iostream>
#include <QShortcut>
#include "unistd.h" #include "unistd.h"
#include <QListWidgetItem> #include <QListWidgetItem>
#include "timemodel.h" #include <QObject>
#include "qvectorhelper.h" #include <QShortcut>
#include <iostream>
#include <sstream>
#include <string>
using std::vector;
using std::string;
using std::cout; using std::cout;
using std::endl; using std::endl;
using std::string;
using std::vector;
Training::Training(QWidget *parent, DataBase *db) : Training::Training(QWidget * parent, DataBase * db)
QMainWindow(parent), : QMainWindow(parent), ui(new Ui::Training) {
ui(new Ui::Training)
{
ui->setupUi(this); ui->setupUi(this);
this->db = db; 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->minimumTime = this->db->getData(statement, 1)[0][0].toInt();
this->finished = false; this->finished = false;
@@ -35,13 +34,13 @@ Training::Training(QWidget *parent, DataBase *db) :
this->Hardware = new HardwareSetup; this->Hardware = new HardwareSetup;
Hardware->start(); Hardware->start();
QObject::connect(Hardware, SIGNAL(Dea(int, int)), this,
SLOT(deaSlot(int, int)));
QObject::connect(Hardware, SIGNAL(Shell(int, int)), this,
QObject::connect(Hardware, SIGNAL(Dea(int, int)), this, SLOT(deaSlot(int, int))); SLOT(shellSlot(int, int)));
QObject::connect(Hardware, SIGNAL(Shell(int, int)), this, SLOT(shellSlot(int, int))); // QObject::connect(this->ui->pBNextRace, SIGNAL(clicked()), this,
//QObject::connect(this->ui->pBNextRace, SIGNAL(clicked()), this, SLOT(prepareNextRace())); // SLOT(prepareNextRace())); QObject::connect(this->ui->pBStop,
//QObject::connect(this->ui->pBStop, SIGNAL(clicked()), this, SLOT(stopClicked())); // SIGNAL(clicked()), this, SLOT(stopClicked()));
QShortcut * shortcut = new QShortcut(QKeySequence("Ctrl+Q"), this); QShortcut * shortcut = new QShortcut(QKeySequence("Ctrl+Q"), this);
QShortcut * shellReset = new QShortcut(QKeySequence("Ctrl+s"), this); QShortcut * shellReset = new QShortcut(QKeySequence("Ctrl+s"), this);
@@ -52,17 +51,19 @@ Training::Training(QWidget *parent, DataBase *db) :
QObject::connect(deaReset, SIGNAL(activated()), this, SLOT(ResetDea())); QObject::connect(deaReset, SIGNAL(activated()), this, SLOT(ResetDea()));
QObject::connect(this->ui->pBReset, SIGNAL(clicked()), this, SLOT(Reset())); QObject::connect(this->ui->pBReset, SIGNAL(clicked()), this, SLOT(Reset()));
QObject::connect(this->ui->pBResetDea, SIGNAL(clicked()), this, SLOT(ResetDea())); QObject::connect(this->ui->pBResetDea, SIGNAL(clicked()), this,
QObject::connect(this->ui->pBResetShell, SIGNAL(clicked()), this, SLOT(ResetShell())); SLOT(ResetDea()));
QObject::connect(this->ui->pBResetShell, SIGNAL(clicked()), this,
SLOT(ResetShell()));
// fill minSecTimes vector // fill minSecTimes vector
statement = "select minsec1, minsec2, minsec3 from renndauer order by id DESC limit 1"; statement = "select minsec1, minsec2, minsec3 from renndauer order by id "
"DESC limit 1";
vector<vector<QString>> res; vector<vector<QString>> res;
res = db->getData(statement, 3); res = db->getData(statement, 3);
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());
} }
void Training::ResetShell() { void Training::ResetShell() {
this->VecShell.clear(); this->VecShell.clear();
@@ -132,9 +133,11 @@ void Training::shellSlot(int time, int sector){
case 2: case 2:
if (VecShell.size() > 0) { if (VecShell.size() > 0) {
if (VecShell.last().size() == 1) { if (VecShell.last().size() == 1) {
// cout << time << sector << endl; // cout << time << sector <<
// endl;
VecShell.last().push_back(time); VecShell.last().push_back(time);
timeModelShell = new TimeModel(VecShell, minSecTime, this); timeModelShell =
new TimeModel(VecShell, minSecTime, this);
this->ui->lWShellTime->setModel(timeModelShell); this->ui->lWShellTime->setModel(timeModelShell);
} }
} }
@@ -143,28 +146,35 @@ void Training::shellSlot(int time, int sector){
if (VecShell.size() > 0) { if (VecShell.size() > 0) {
// cout << "Time sec 3: " << time << endl; // cout << "Time sec 3: " << time << endl;
if (VecShell.last().size() == 2) { if (VecShell.last().size() == 2) {
// cout << time << sector << endl; // cout << time << sector <<
// endl;
VecShell.last().push_back(time); VecShell.last().push_back(time);
// add sum to vector // add sum to vector
VecShell.last().push_back(QVectorHelper::getCurTime(VecShell.last())); VecShell.last().push_back(
QVectorHelper::getCurTime(VecShell.last()));
timeModelShell = new TimeModel(VecShell, minSecTime, this); timeModelShell =
new TimeModel(VecShell, minSecTime, this);
this->ui->lWShellTime->setModel(timeModelShell); this->ui->lWShellTime->setModel(timeModelShell);
} }
// best time on widget // best time on widget
if(QVectorHelper::getCurTime(VecShell.last()) <= QVectorHelper::getMin(VecShell)){ if (QVectorHelper::getCurTime(VecShell.last()) <=
ui->lBestZeitShell->setText(QString::number((double)QVectorHelper::getMin(VecShell)/1000)); QVectorHelper::getMin(VecShell)) {
ui->lBestZeitShell->setText(QString::number(
(double)QVectorHelper::getMin(VecShell) / 1000));
} }
ui->lCurRoundTimeShell->setText(QString::number((double)QVectorHelper::getCurTime(VecShell.last())/1000)); ui->lCurRoundTimeShell->setText(QString::number(
(double)QVectorHelper::getCurTime(VecShell.last()) /
1000));
} }
break; break;
} }
ui->lWShellTime->scrollToBottom(); ui->lWShellTime->scrollToBottom();
ui->lWShellTime->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); ui->lWShellTime->horizontalHeader()->setSectionResizeMode(
QHeaderView::Stretch);
} }
} }
} }
@@ -180,7 +190,6 @@ void Training::deaSlot(int time, int sector){
cout << "received Deatime: " << time << sector << endl; cout << "received Deatime: " << time << sector << endl;
if (started && !paused && !this->finished) { if (started && !paused && !this->finished) {
if (firstTimeDea) { if (firstTimeDea) {
firstTimeDea = false; firstTimeDea = false;
@@ -198,7 +207,8 @@ void Training::deaSlot(int time, int sector){
case 2: case 2:
if (VecDea.size() > 0) { if (VecDea.size() > 0) {
if (VecDea.last().size() == 1) { if (VecDea.last().size() == 1) {
// cout << time << sector << endl; // cout << time << sector <<
// endl;
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);
@@ -212,33 +222,42 @@ void Training::deaSlot(int time, int sector){
if (VecDea.size() > 0) { if (VecDea.size() > 0) {
// cout << "Time sec 3: " << time << endl; // cout << "Time sec 3: " << time << endl;
if (VecDea.last().size() == 2) { if (VecDea.last().size() == 2) {
// cout << time << sector << endl; // cout << time << sector <<
// endl;
VecDea.last().push_back(time); VecDea.last().push_back(time);
// add sum to vector // add sum to vector
VecDea.last().push_back(QVectorHelper::getCurTime(VecDea.last())); VecDea.last().push_back(
QVectorHelper::getCurTime(VecDea.last()));
timeModelDea = new TimeModel(VecDea, minSecTime, this); timeModelDea = new TimeModel(VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea); this->ui->lWDeaTime->setModel(timeModelDea);
} }
// best time on widget // best time on widget
// cout << "cur time: " << QVectorHelper::getCurTime(VecDea.last()) << endl; // cout << "cur time: " <<
// cout << "min time: " << QVectorHelper::getMin(VecDea) << endl; // QVectorHelper::getCurTime(VecDea.last())
if(QVectorHelper::getCurTime(VecDea.last()) <= QVectorHelper::getMin(VecDea)){ // << endl; cout << "min time: " <<
ui->lBestZeitDea->setText(QString::number((double)QVectorHelper::getMin(VecDea)/1000)); // 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)); ui->lCurRoundDea->setText(QString::number(
(double)QVectorHelper::getCurTime(VecDea.last()) /
1000));
} }
break; break;
} }
ui->lWDeaTime->scrollToBottom(); ui->lWDeaTime->scrollToBottom();
ui->lWDeaTime->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); ui->lWDeaTime->horizontalHeader()->setSectionResizeMode(
QHeaderView::Stretch);
} }
} }
} }
Training::~Training() Training::~Training() {
{
cout << "destr Training" << endl; cout << "destr Training" << endl;
this->Hardware->setStop(); this->Hardware->setStop();
usleep(1000000); usleep(1000000);

View File

@@ -1,24 +1,22 @@
#include "windowrace.h" #include "windowrace.h"
#include "ui_windowrace.h"
#include <QObject>
#include <string>
#include <QShortcut>
#include <sstream>
#include <iostream>
#include "unistd.h"
#include <QKeySequence>
#include "qvectorhelper.h" #include "qvectorhelper.h"
#include "timemodel.h" #include "timemodel.h"
#include "ui_windowrace.h"
#include "unistd.h"
#include <QKeySequence>
#include <QObject>
#include <QShortcut>
#include <iostream>
#include <sstream>
#include <string>
using std::vector;
using std::string;
using std::cout; using std::cout;
using std::endl; using std::endl;
using std::string;
using std::vector;
WindowRace::WindowRace(DataBase *db, QWidget *parent) : WindowRace::WindowRace(DataBase * db, QWidget * parent)
QMainWindow(parent), : QMainWindow(parent), ui(new Ui::WindowRace) {
ui(new Ui::WindowRace)
{
ui->setupUi(this); ui->setupUi(this);
this->ui->pBNextRace->setEnabled(false); this->ui->pBNextRace->setEnabled(false);
this->finished = false; this->finished = false;
@@ -31,18 +29,19 @@ WindowRace::WindowRace(DataBase *db, QWidget *parent) :
res = db->getData("select dauer from renndauer", 1); res = db->getData("select dauer from renndauer", 1);
this->fahrzeit = res[0][0].toInt(); this->fahrzeit = res[0][0].toInt();
string statement = "select minimumroundtime from rennen order by id DESC limit 1"; string statement =
"select minimumroundtime from rennen order by id DESC limit 1";
res = db->getData(statement, 1); res = db->getData(statement, 1);
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 DESC limit 1"; statement = "select minsec1, minsec2, minsec3 from renndauer order by id "
"DESC limit 1";
res = db->getData(statement, 3); res = db->getData(statement, 3);
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());
firstTimeDea = true; firstTimeDea = true;
firstTimeShell = true; firstTimeShell = true;
started = false; started = false;
@@ -59,16 +58,23 @@ WindowRace::WindowRace(DataBase *db, QWidget *parent) :
Hardware = new HardwareSetup; Hardware = new HardwareSetup;
Hardware->start(); Hardware->start();
QObject::connect(Hardware, SIGNAL(Dea(int, int)), this, SLOT(deaSlot(int, int))); QObject::connect(Hardware, SIGNAL(Dea(int, int)), this,
QObject::connect(Hardware, SIGNAL(Shell(int, int)), this, SLOT(shellSlot(int, int))); 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(ui->pBStart, SIGNAL(clicked()), this, SLOT(go()));
QObject::connect(countdown, SIGNAL(CountdownUpdate()), this, SLOT(countdownUpdate())); QObject::connect(countdown, SIGNAL(CountdownUpdate()), this,
QObject::connect(startAmpelThread, SIGNAL(ampelUpdate()), this, SLOT(ampelSlot())); SLOT(countdownUpdate()));
QObject::connect(startAmpelThread, SIGNAL(ampelUpdate()), this, SLOT(laufcheck())); QObject::connect(startAmpelThread, SIGNAL(ampelUpdate()), this,
QObject::connect(ui->pBBreak, SIGNAL(clicked()), this, SLOT(breakCounter())); SLOT(ampelSlot()));
QObject::connect(this->ui->pBNextRace, SIGNAL(clicked()), this, SLOT(prepareNextRace())); QObject::connect(startAmpelThread, SIGNAL(ampelUpdate()), this,
QObject::connect(this->ui->pBStop, SIGNAL(clicked()), this, SLOT(stopClicked())); SLOT(laufcheck()));
QObject::connect(ui->pBBreak, SIGNAL(clicked()), this,
SLOT(breakCounter()));
QObject::connect(this->ui->pBNextRace, SIGNAL(clicked()), this,
SLOT(prepareNextRace()));
QObject::connect(this->ui->pBStop, SIGNAL(clicked()), this,
SLOT(stopClicked()));
ui->lCountdown->setText(timeWrapper(countdownValue)); ui->lCountdown->setText(timeWrapper(countdownValue));
@@ -94,28 +100,33 @@ WindowRace::WindowRace(DataBase *db, QWidget *parent) :
ui->hW11->setVisible(true); ui->hW11->setVisible(true);
ui->hW21->setVisible(true); ui->hW21->setVisible(true);
vector<vector<QString>> fahrer, autos, rennid, tableData; vector<vector<QString>> fahrer, autos, rennid, tableData;
statement = "select id_rennen from aktrennen group by id_rennen order by id_rennen DESC limit 1"; statement = "select id_rennen from aktrennen group by id_rennen order by "
"id_rennen DESC limit 1";
rennid = this->db->getData(statement, 1); rennid = this->db->getData(statement, 1);
this->renn_id = rennid[0][0].toInt(); this->renn_id = rennid[0][0].toInt();
statement = "select fahrershellid, autoshellid, fahrerdeaid, autodeaid from aktrennen where id_rennen like "+rennid[0][0].toStdString()+" limit 1"; statement = "select fahrershellid, autoshellid, fahrerdeaid, autodeaid "
"from aktrennen where id_rennen like " +
rennid[0][0].toStdString() + " limit 1";
tableData = db->getData2(statement, 4); tableData = db->getData2(statement, 4);
statement = "select name from fahrer where id like " +
statement = "select name from fahrer where id like " + tableData[0][0].toStdString(); tableData[0][0].toStdString();
fahrer = this->db->getData2(statement, 1); fahrer = this->db->getData2(statement, 1);
statement = "select name from AutoKonfiguration where id_auto like " + tableData[0][1].toStdString()+" order by seit DESC"; statement = "select name from AutoKonfiguration where id_auto like " +
tableData[0][1].toStdString() + " order by seit DESC";
autos = this->db->getData2(statement, 1); autos = this->db->getData2(statement, 1);
this->ui->gbShell->setTitle("Shell, " + fahrer[0][0] + ", " + autos[0][0]); this->ui->gbShell->setTitle("Shell, " + fahrer[0][0] + ", " + autos[0][0]);
statement = "select name from fahrer where id like " + tableData[0][2].toStdString(); statement = "select name from fahrer where id like " +
tableData[0][2].toStdString();
fahrer = this->db->getData2(statement, 1); fahrer = this->db->getData2(statement, 1);
statement = "select name from AutoKonfiguration where id_auto like " + tableData[0][3].toStdString()+" order by seit DESC"; statement = "select name from AutoKonfiguration where id_auto like " +
tableData[0][3].toStdString() + " order by seit DESC";
autos = this->db->getData2(statement, 1); autos = this->db->getData2(statement, 1);
this->ui->gbDea->setTitle("Dea, " + fahrer[0][0] + ", " + autos[0][0]); this->ui->gbDea->setTitle("Dea, " + fahrer[0][0] + ", " + autos[0][0]);
@@ -137,7 +148,6 @@ WindowRace::WindowRace(DataBase *db, QWidget *parent) :
QObject::connect(keyReturn, SIGNAL(activated()), this, SLOT(ReturnPress())); QObject::connect(keyReturn, SIGNAL(activated()), this, SLOT(ReturnPress()));
// QObject::connect(shortcut, SIGNAL(activated()), this, SLOT(close())); // QObject::connect(shortcut, SIGNAL(activated()), this, SLOT(close()));
} }
void WindowRace::ReturnPress() { void WindowRace::ReturnPress() {
@@ -229,21 +239,20 @@ void WindowRace::setDriverAndCar(vector<QString> vec){
} }
void WindowRace::stopClicked() { void WindowRace::stopClicked() {
this->prepareNextRace(); this->prepareNextRace();
} }
void WindowRace::setWindowRennliste(WindowRennliste * ptrInstance) { void WindowRace::setWindowRennliste(WindowRennliste * ptrInstance) {
this->wRennliste = ptrInstance; this->wRennliste = ptrInstance;
this->wRennlisteSeted = true; this->wRennlisteSeted = true;
QObject::connect(this->ui->pBNextRace, SIGNAL(clicked()), this->wRennliste, SLOT(changeSelection())); QObject::connect(this->ui->pBNextRace, SIGNAL(clicked()), this->wRennliste,
SLOT(changeSelection()));
} }
void WindowRace::setDriverAndCarId(vector<QString> vec) { void WindowRace::setDriverAndCarId(vector<QString> vec) {
this->shellDriverId = vec[0].toInt(); this->shellDriverId = vec[0].toInt();
this->shellCarId = vec[1].toInt(); this->shellCarId = vec[1].toInt();
this->deaDriverId = vec[2].toInt(); this->deaDriverId = vec[2].toInt();
this->deaCarId = vec[3].toInt(); this->deaCarId = vec[3].toInt();
} }
void WindowRace::closeEvent(QCloseEvent * event) { void WindowRace::closeEvent(QCloseEvent * event) {
countdown->setStop(); countdown->setStop();
@@ -279,7 +288,6 @@ void WindowRace::breakCounter(){
ui->pBBreak->setText("Pause"); ui->pBBreak->setText("Pause");
paused = false; paused = false;
} }
} }
void WindowRace::laufcheck() { void WindowRace::laufcheck() {
@@ -306,12 +314,14 @@ void WindowRace::countdownUpdate(){
countdownValue -= 1; countdownValue -= 1;
if (countdownValue <= 15) { if (countdownValue <= 15) {
this->ui->lCountdown->setStyleSheet("QLabel { color: red; }"); this->ui->lCountdown->setStyleSheet("QLabel { color: red; }");
this->ui->pbTime->setStyleSheet( "QProgressBar::chunk { background-color: orange; }"); this->ui->pbTime->setStyleSheet(
"QProgressBar::chunk { background-color: orange; }");
// this->ui->pbTime-> // this->ui->pbTime->
} }
if (countdownValue <= -1) { if (countdownValue <= -1) {
this->finished = true; this->finished = true;
this->wRennliste->setBesttime(QVectorHelper::getMin(VecShell),QVectorHelper::getMin(this->VecDea)); this->wRennliste->setBesttime(QVectorHelper::getMin(VecShell),
QVectorHelper::getMin(this->VecDea));
this->ui->pBNextRace->setEnabled(true); this->ui->pBNextRace->setEnabled(true);
} }
else { else {
@@ -321,9 +331,7 @@ void WindowRace::countdownUpdate(){
} }
} }
WindowRace::~WindowRace() {
WindowRace::~WindowRace()
{
this->startAmpelThread->setStop(); this->startAmpelThread->setStop();
this->countdown->setStop(); this->countdown->setStop();
this->Hardware->setStop(); this->Hardware->setStop();
@@ -356,7 +364,8 @@ void WindowRace::shellSlot(int time, int sector){
test.append(1); test.append(1);
test.append(2); test.append(2);
test.append(3); test.append(3);
this->timeModelShell = new TimeModel(VecShell, minSecTime, test, this); this->timeModelShell =
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);
break; break;
@@ -371,8 +380,10 @@ void WindowRace::shellSlot(int time, int sector){
test.append(1); test.append(1);
test.append(2); test.append(2);
test.append(3); test.append(3);
this->timeModelShell = new TimeModel(VecShell, minSecTime, test, this); this->timeModelShell =
// timeModelShell = new TimeModel(VecShell, this); new TimeModel(VecShell, minSecTime, test, this);
// timeModelShell = new
// TimeModel(VecShell, this);
this->ui->lWShellTime->setModel(timeModelShell); this->ui->lWShellTime->setModel(timeModelShell);
} }
break; break;
@@ -380,44 +391,54 @@ void WindowRace::shellSlot(int time, int sector){
if (VecShell.size() > 0) { if (VecShell.size() > 0) {
if (VecShell.last().size() == 2) { if (VecShell.last().size() == 2) {
VecShell.last().append(time); VecShell.last().append(time);
VecShell.last().append(QVectorHelper::getCurTime(VecShell.last())); VecShell.last().append(
QVectorHelper::getCurTime(VecShell.last()));
if(QVectorHelper::getCurTime(VecShell.last()) <= QVectorHelper::getMin(VecShell)){ if (QVectorHelper::getCurTime(VecShell.last()) <=
ui->lBestZeitShell->setText(QString::number((double)QVectorHelper::getMin(VecShell)/1000)); QVectorHelper::getMin(VecShell)) {
ui->lBestZeitShell->setText(QString::number(
(double)QVectorHelper::getMin(VecShell) /
1000));
} }
ui->lCurRoundTimeShell->setText(QString::number((double)QVectorHelper::getCurTime(VecShell.last())/1000)); ui->lCurRoundTimeShell->setText(QString::number(
(double)QVectorHelper::getCurTime(VecShell.last()) /
1000));
// update tableview // update tableview
test.append(1); test.append(1);
test.append(2); test.append(2);
test.append(3); test.append(3);
this->timeModelShell = new TimeModel(VecShell, minSecTime, test, this); this->timeModelShell =
// timeModelShell = new TimeModel(VecShell, this); new TimeModel(VecShell, minSecTime, test, this);
// timeModelShell = new
// TimeModel(VecShell, this);
this->ui->lWShellTime->setModel(timeModelShell); this->ui->lWShellTime->setModel(timeModelShell);
int zeit = QVectorHelper::getMin(VecShell); 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 statement =
", "+QString::number(this->shellDriverId)+", "+QString::number(this->shellCarId)+", 1, "+QString::number(zeit)+")"; "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; cout << statement.toStdString() << endl;
// this->db->setData(statement.toStdString()); // this->db->setData(statement.toStdString());
} }
} }
break; break;
} }
if (sector == 3) { if (sector == 3) {
} }
ui->lWShellTime->scrollToBottom(); ui->lWShellTime->scrollToBottom();
} }
} }
ui->lWShellTime->scrollToBottom(); ui->lWShellTime->scrollToBottom();
ui->lWShellTime->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); ui->lWShellTime->horizontalHeader()->setSectionResizeMode(
QHeaderView::Stretch);
} }
void WindowRace::deaSlot(int time, int sector) { void WindowRace::deaSlot(int time, int sector) {
if (started && !paused && !this->finished) { if (started && !paused && !this->finished) {
@@ -453,33 +474,39 @@ void WindowRace::deaSlot(int time, int sector){
if (VecDea.size() > 0) { if (VecDea.size() > 0) {
// cout << "Time sec 3: " << time << endl; // cout << "Time sec 3: " << time << endl;
if (VecDea.last().size() == 2) { if (VecDea.last().size() == 2) {
// cout << time << sector << endl; // cout << time << sector <<
// endl;
VecDea.last().push_back(time); VecDea.last().push_back(time);
// add sum to vector // add sum to vector
VecDea.last().push_back(QVectorHelper::getCurTime(VecDea.last())); VecDea.last().push_back(
QVectorHelper::getCurTime(VecDea.last()));
timeModelDea = new TimeModel(VecDea, minSecTime, this); timeModelDea = new TimeModel(VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea); this->ui->lWDeaTime->setModel(timeModelDea);
} }
// best time on widget // best time on widget
cout << "cur time: " << QVectorHelper::getCurTime(VecDea.last()) << endl; cout << "cur time: "
cout << "min time: " << QVectorHelper::getMin(VecDea) << endl; << QVectorHelper::getCurTime(VecDea.last()) << endl;
if(QVectorHelper::getCurTime(VecDea.last()) <= QVectorHelper::getMin(VecDea)){ cout << "min time: " << QVectorHelper::getMin(VecDea)
ui->lBestZeitDea->setText(QString::number((double)QVectorHelper::getMin(VecDea)/1000)); << 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)); ui->lCurRoundDea->setText(QString::number(
(double)QVectorHelper::getCurTime(VecDea.last()) /
1000));
} }
int zeit = QVectorHelper::getMin(VecDea); 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 statement = "insert into Zeiten (id_rennen, id_fahrer, "
", "+QString::number(this->deaDriverId)+", "+QString::number(this->deaCarId)+", 2, "+QString::number(zeit)+")"; "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; cout << statement.toStdString() << endl;
// this->db->setData(statement.toStdString()); // this->db->setData(statement.toStdString());
ui->lWDeaTime->scrollToBottom(); ui->lWDeaTime->scrollToBottom();
@@ -489,7 +516,8 @@ void WindowRace::deaSlot(int time, int sector){
} }
} }
ui->lWDeaTime->scrollToBottom(); ui->lWDeaTime->scrollToBottom();
ui->lWDeaTime->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); ui->lWDeaTime->horizontalHeader()->setSectionResizeMode(
QHeaderView::Stretch);
} }
long WindowRace::getMinimum(std::vector<long> a) { long WindowRace::getMinimum(std::vector<long> a) {
@@ -505,7 +533,6 @@ long WindowRace::getMinimum(std::vector<long> a){
minimum = a[i]; minimum = a[i];
} }
} }
} }
return minimum; return minimum;
} }

View File

@@ -1,17 +1,15 @@
#include "windowrennliste.h" #include "windowrennliste.h"
#include "ui_windowrennliste.h" #include "ui_windowrennliste.h"
#include <QColor>
#include <QBrush>
#include <iostream>
#include <QDebug>
#include "windowrace.h" #include "windowrace.h"
using std::vector; #include <QBrush>
#include <QColor>
#include <QDebug>
#include <iostream>
using std::string; using std::string;
using std::vector;
WindowRennliste::WindowRennliste(DataBase *db, QWidget *parent) : WindowRennliste::WindowRennliste(DataBase * db, QWidget * parent)
QMainWindow(parent), : QMainWindow(parent), ui(new Ui::WindowRennliste) {
ui(new Ui::WindowRennliste)
{
ui->setupUi(this); ui->setupUi(this);
this->windowClose = false; this->windowClose = false;
@@ -21,48 +19,64 @@ WindowRennliste::WindowRennliste(DataBase *db, QWidget *parent) :
this->ui->tWRennliste->setSelectionBehavior(QAbstractItemView::SelectRows); this->ui->tWRennliste->setSelectionBehavior(QAbstractItemView::SelectRows);
this->ui->tWRennliste->setSelectionMode(QAbstractItemView::SingleSelection); this->ui->tWRennliste->setSelectionMode(QAbstractItemView::SingleSelection);
QObject::connect(this->ui->tWRennliste, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(listClick(const QModelIndex&))); QObject::connect(this->ui->tWRennliste,
SIGNAL(doubleClicked(const QModelIndex &)), this,
SLOT(listClick(const QModelIndex &)));
this->db = db; this->db = db;
string statement; string statement;
vector<vector<QString>> fahrer, autos, rennid; vector<vector<QString>> fahrer, autos, rennid;
statement = "select id_rennen from aktrennen group by id_rennen order by id_rennen DESC limit 1"; statement = "select id_rennen from aktrennen group by id_rennen order by "
"id_rennen DESC limit 1";
rennid = this->db->getData(statement, 1); rennid = this->db->getData(statement, 1);
statement = "select fahrershellid, autoshellid, fahrerdeaid, autodeaid from aktrennen where id_rennen like "+rennid[0][0].toStdString(); statement = "select fahrershellid, autoshellid, fahrerdeaid, autodeaid "
"from aktrennen where id_rennen like " +
rennid[0][0].toStdString();
this->tableData = db->getData(statement, 4); this->tableData = db->getData(statement, 4);
this->ui->tWRennliste->setRowCount(this->tableData.size()); this->ui->tWRennliste->setRowCount(this->tableData.size());
this->ui->tWRennliste->setColumnCount(6); this->ui->tWRennliste->setColumnCount(6);
QStringList header; QStringList header;
header<< "Fahrer" << "Auto"<< "Zeit"<< "Fahrer"<< "Auto"<< "Zeit"; header << "Fahrer"
<< "Auto"
<< "Zeit"
<< "Fahrer"
<< "Auto"
<< "Zeit";
this->ui->tWRennliste->setHorizontalHeaderLabels(header); this->ui->tWRennliste->setHorizontalHeaderLabels(header);
for (int i = 0; i < this->ui->tWRennliste->horizontalHeader()->count();
for(int i = 0; i < this->ui->tWRennliste->horizontalHeader()->count();i++){ i++) {
this->ui->tWRennliste->horizontalHeader()->setSectionResizeMode(i, QHeaderView::Stretch); this->ui->tWRennliste->horizontalHeader()->setSectionResizeMode(
i, QHeaderView::Stretch);
} }
for (unsigned int i = 0; i < tableData.size(); i++) { for (unsigned int i = 0; i < tableData.size(); i++) {
statement = "select name from fahrer where id like " + tableData[i][0].toStdString(); statement = "select name from fahrer where id like " +
tableData[i][0].toStdString();
fahrer = this->db->getData(statement, 1); fahrer = this->db->getData(statement, 1);
this->ui->tWRennliste->setItem(i, 0, new QTableWidgetItem(fahrer[0][0])); this->ui->tWRennliste->setItem(i, 0,
new QTableWidgetItem(fahrer[0][0]));
this->ui->tWRennliste->item(i, 0)->setFlags(Qt::ItemIsEnabled); this->ui->tWRennliste->item(i, 0)->setFlags(Qt::ItemIsEnabled);
statement = "select name from AutoKonfiguration where id_auto like " + tableData[i][1].toStdString()+" order by seit DESC"; statement = "select name from AutoKonfiguration where id_auto like " +
tableData[i][1].toStdString() + " order by seit DESC";
autos = this->db->getData(statement, 1); autos = this->db->getData(statement, 1);
this->ui->tWRennliste->setItem(i, 1, new QTableWidgetItem(autos[0][0])); this->ui->tWRennliste->setItem(i, 1, new QTableWidgetItem(autos[0][0]));
this->ui->tWRennliste->item(i, 1)->setFlags(Qt::ItemIsEnabled); this->ui->tWRennliste->item(i, 1)->setFlags(Qt::ItemIsEnabled);
this->ui->tWRennliste->setItem(i, 2, new QTableWidgetItem()); this->ui->tWRennliste->setItem(i, 2, new QTableWidgetItem());
statement = "select name from fahrer where id like " + tableData[i][2].toStdString(); statement = "select name from fahrer where id like " +
tableData[i][2].toStdString();
fahrer = this->db->getData(statement, 1); fahrer = this->db->getData(statement, 1);
this->ui->tWRennliste->setItem(i, 3, new QTableWidgetItem(fahrer[0][0])); this->ui->tWRennliste->setItem(i, 3,
new QTableWidgetItem(fahrer[0][0]));
this->ui->tWRennliste->item(i, 3)->setFlags(Qt::ItemIsEnabled); this->ui->tWRennliste->item(i, 3)->setFlags(Qt::ItemIsEnabled);
statement = "select name from AutoKonfiguration where id_auto like " + tableData[i][3].toStdString()+" order by seit DESC"; statement = "select name from AutoKonfiguration where id_auto like " +
tableData[i][3].toStdString() + " order by seit DESC";
autos = this->db->getData(statement, 1); autos = this->db->getData(statement, 1);
this->ui->tWRennliste->setItem(i, 4, new QTableWidgetItem(autos[0][0])); this->ui->tWRennliste->setItem(i, 4, new QTableWidgetItem(autos[0][0]));
this->ui->tWRennliste->item(i, 4)->setFlags(Qt::ItemIsEnabled); this->ui->tWRennliste->item(i, 4)->setFlags(Qt::ItemIsEnabled);
@@ -78,10 +92,14 @@ void WindowRennliste::setWindowRace(WindowRace *instance){
} }
vector<QString> WindowRennliste::getDriverAndCarSettings() { vector<QString> WindowRennliste::getDriverAndCarSettings() {
vector<QString> vec; vector<QString> vec;
vec.push_back(this->ui->tWRennliste->item(this->selectedRow+1, 0)->text()); vec.push_back(
vec.push_back(this->ui->tWRennliste->item(this->selectedRow+1, 1)->text()); this->ui->tWRennliste->item(this->selectedRow + 1, 0)->text());
vec.push_back(this->ui->tWRennliste->item(this->selectedRow+1, 3)->text()); vec.push_back(
vec.push_back(this->ui->tWRennliste->item(this->selectedRow+1, 4)->text()); this->ui->tWRennliste->item(this->selectedRow + 1, 1)->text());
vec.push_back(
this->ui->tWRennliste->item(this->selectedRow + 1, 3)->text());
vec.push_back(
this->ui->tWRennliste->item(this->selectedRow + 1, 4)->text());
return vec; return vec;
} }
vector<QString> WindowRennliste::getDriverAndCarId() { vector<QString> WindowRennliste::getDriverAndCarId() {
@@ -90,8 +108,10 @@ vector<QString> WindowRennliste::getDriverAndCarId(){
} }
void WindowRennliste::setBesttime(int shell, int dea) { void WindowRennliste::setBesttime(int shell, int dea) {
this->ui->tWRennliste->item(this->selectedRow, 2)->setText(QString::number(shell/1000.0)); this->ui->tWRennliste->item(this->selectedRow, 2)
this->ui->tWRennliste->item(this->selectedRow, 5)->setText(QString::number(dea/1000.0)); ->setText(QString::number(shell / 1000.0));
this->ui->tWRennliste->item(this->selectedRow, 5)
->setText(QString::number(dea / 1000.0));
// std::cout << this->selectedRow << std::endl; // std::cout << this->selectedRow << std::endl;
} }
@@ -112,7 +132,6 @@ void WindowRennliste::listClick(const QModelIndex & index){
this->instanceWindowRace->prepareNextRace(); this->instanceWindowRace->prepareNextRace();
this->setSelection(index.row()); this->setSelection(index.row());
this->sendIds(); this->sendIds();
} }
void WindowRennliste::closeEvent(QCloseEvent * event) { void WindowRennliste::closeEvent(QCloseEvent * event) {
if (!this->windowClose) { if (!this->windowClose) {
@@ -122,7 +141,6 @@ void WindowRennliste::closeEvent(QCloseEvent *event){
else { else {
event->accept(); event->accept();
} }
} }
void WindowRennliste::schliessen() { void WindowRennliste::schliessen() {
this->windowClose = true; this->windowClose = true;
@@ -132,7 +150,8 @@ void WindowRennliste::schliessen(){
void WindowRennliste::setSelection(int row) { void WindowRennliste::setSelection(int row) {
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
this->ui->tWRennliste->item(this->selectedRow, i)->setBackground(Qt::yellow); this->ui->tWRennliste->item(this->selectedRow, i)
->setBackground(Qt::yellow);
} }
this->selectedRow = row; this->selectedRow = row;
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
@@ -145,7 +164,6 @@ void WindowRennliste::setSelection(int row){
vec.push_back(this->ui->tWRennliste->item(this->selectedRow, 3)->text()); vec.push_back(this->ui->tWRennliste->item(this->selectedRow, 3)->text());
vec.push_back(this->ui->tWRennliste->item(this->selectedRow, 4)->text()); vec.push_back(this->ui->tWRennliste->item(this->selectedRow, 4)->text());
this->instanceWindowRace->setDriverAndCar(vec); this->instanceWindowRace->setDriverAndCar(vec);
} }
void WindowRennliste::sendIds() { void WindowRennliste::sendIds() {
this->instanceWindowRace->setDriverAndCarId(this->getDriverAndCarId()); this->instanceWindowRace->setDriverAndCarId(this->getDriverAndCarId());
@@ -154,23 +172,27 @@ void WindowRennliste::sendIds(){
void WindowRennliste::changeSelection() { void WindowRennliste::changeSelection() {
if (this->selectedRow + 1 < this->tableData.size()) { if (this->selectedRow + 1 < this->tableData.size()) {
for (unsigned int i = 0; i < 6; i++) { for (unsigned int i = 0; i < 6; i++) {
this->ui->tWRennliste->item(this->selectedRow, i)->setBackground(Qt::gray); this->ui->tWRennliste->item(this->selectedRow, i)
this->ui->tWRennliste->item(this->selectedRow+1, i)->setBackground(Qt::green); ->setBackground(Qt::gray);
this->ui->tWRennliste->item(this->selectedRow + 1, i)
->setBackground(Qt::green);
} }
this->selectedRow += 1; this->selectedRow += 1;
this->sendIds(); this->sendIds();
vector<QString> vec; vector<QString> vec;
vec.push_back(this->ui->tWRennliste->item(this->selectedRow, 0)->text()); vec.push_back(
vec.push_back(this->ui->tWRennliste->item(this->selectedRow, 1)->text()); this->ui->tWRennliste->item(this->selectedRow, 0)->text());
vec.push_back(this->ui->tWRennliste->item(this->selectedRow, 3)->text()); vec.push_back(
vec.push_back(this->ui->tWRennliste->item(this->selectedRow, 4)->text()); this->ui->tWRennliste->item(this->selectedRow, 1)->text());
vec.push_back(
this->ui->tWRennliste->item(this->selectedRow, 3)->text());
vec.push_back(
this->ui->tWRennliste->item(this->selectedRow, 4)->text());
this->instanceWindowRace->setDriverAndCar(vec); this->instanceWindowRace->setDriverAndCar(vec);
} }
} }
WindowRennliste::~WindowRennliste() WindowRennliste::~WindowRennliste() {
{
delete ui; delete ui;
} }

View File

@@ -1,40 +1,44 @@
#include "windowssettings.h" #include "windowssettings.h"
#include "ui_windowssettings.h" #include "ui_windowssettings.h"
#include <iostream> #include <iostream>
#include <string>
#include <stdio.h> #include <stdio.h>
#include <string>
#include <time.h> #include <time.h>
#include <vector> #include <vector>
using std::vector;
using std::cout; using std::cout;
using std::endl; using std::endl;
using std::string; using std::string;
using std::vector;
WindowsSettings::WindowsSettings(DataBase *db, QWidget *parent) : WindowsSettings::WindowsSettings(DataBase * db, QWidget * parent)
QMainWindow(parent), : QMainWindow(parent), ui(new Ui::WindowsSettings) {
ui(new Ui::WindowsSettings)
{
ui->setupUi(this); ui->setupUi(this);
QObject::connect(ui->pBSpeichernStrecke, SIGNAL(clicked()), this, SLOT(StreckeSpeichernSlot())); QObject::connect(ui->pBSpeichernStrecke, SIGNAL(clicked()), this,
QObject::connect(ui->pBAbbrechenStrecke, SIGNAL(clicked()), this, SLOT(AbbrechenSlot())); SLOT(StreckeSpeichernSlot()));
QObject::connect(this->ui->pbAbbrechenDauer, SIGNAL(clicked()), this, SLOT(AbbrechenSlot())); QObject::connect(ui->pBAbbrechenStrecke, SIGNAL(clicked()), this,
QObject::connect(this->ui->pbSaveDauer, SIGNAL(clicked()), this, SLOT(SaveDauerSlot())); SLOT(AbbrechenSlot()));
QObject::connect(this->ui->pbSaveAndExitDauer, SIGNAL(clicked()), this, SLOT(SaveDauerAndExitSlot())); QObject::connect(this->ui->pbAbbrechenDauer, SIGNAL(clicked()), this,
SLOT(AbbrechenSlot()));
QObject::connect(this->ui->pbSaveDauer, SIGNAL(clicked()), this,
SLOT(SaveDauerSlot()));
QObject::connect(this->ui->pbSaveAndExitDauer, SIGNAL(clicked()), this,
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)), this, SLOT(repaintMinLapTime())); QObject::connect(this->ui->lEMinTimeSec1, SIGNAL(textChanged(QString)),
QObject::connect(this->ui->lEMinTimeSec2, SIGNAL(textChanged(QString)), this, SLOT(repaintMinLapTime())); this, SLOT(repaintMinLapTime()));
QObject::connect(this->ui->lEMinTimeSec3, SIGNAL(textChanged(QString)), this, SLOT(repaintMinLapTime())); QObject::connect(this->ui->lEMinTimeSec2, SIGNAL(textChanged(QString)),
this, SLOT(repaintMinLapTime()));
QObject::connect(this->ui->lEMinTimeSec3, SIGNAL(textChanged(QString)),
this, SLOT(repaintMinLapTime()));
this->db = db; this->db = db;
// Shell prepare // Shell prepare
string statement = "select geraden, kurven_aussen, " string statement =
"select geraden, kurven_aussen, "
"kurven_innen, steilkurve_innen, steilkurve_aussen, seit " "kurven_innen, steilkurve_innen, steilkurve_aussen, seit "
"from Strecke where id_bahn like 1 order by seit DESC limit 1"; "from Strecke where id_bahn like 1 order by seit DESC limit 1";
vector<vector<QString>> res; vector<vector<QString>> res;
@@ -51,7 +55,6 @@ WindowsSettings::WindowsSettings(DataBase *db, QWidget *parent) :
"kurven_innen, steilkurve_innen, steilkurve_aussen, seit " "kurven_innen, steilkurve_innen, steilkurve_aussen, seit "
"from Strecke where id_bahn like 2 order by seit DESC limit 1"; "from Strecke where id_bahn like 2 order by seit DESC limit 1";
res = db->getData(statement, 6); res = db->getData(statement, 6);
ui->lEDeaGeraden->setText(res[0][0]); ui->lEDeaGeraden->setText(res[0][0]);
ui->lEDeaKurvenAussen->setText(res[0][1]); ui->lEDeaKurvenAussen->setText(res[0][1]);
@@ -60,7 +63,8 @@ WindowsSettings::WindowsSettings(DataBase *db, QWidget *parent) :
ui->lEDeaSteilkurveAussen->setText(res[0][4]); ui->lEDeaSteilkurveAussen->setText(res[0][4]);
// duration prepare // duration prepare
statement = "select dauer, mindestrundendauer, minsec1, minsec2, minsec3 from renndauer"; statement = "select dauer, mindestrundendauer, minsec1, minsec2, minsec3 "
"from renndauer";
res = db->getData(statement, 5); res = db->getData(statement, 5);
this->ui->leRenndauer->setText(res[0][0]); this->ui->leRenndauer->setText(res[0][0]);
this->ui->lEMinTimeSec1->setText(res[0][2]); this->ui->lEMinTimeSec1->setText(res[0][2]);
@@ -69,11 +73,11 @@ WindowsSettings::WindowsSettings(DataBase *db, QWidget *parent) :
int minLapTime = res[0][2].toInt() + res[0][3].toInt() + res[0][4].toInt(); int minLapTime = res[0][2].toInt() + res[0][3].toInt() + res[0][4].toInt();
this->ui->lEMinRundenzeit->setText(QString::number(minLapTime)); this->ui->lEMinRundenzeit->setText(QString::number(minLapTime));
statement = "SELECT id, minimumroundtime FROM rennen order by id DESC limit 1"; statement =
"SELECT id, minimumroundtime FROM rennen order by id DESC limit 1";
res = this->db->getData(statement, 2); res = this->db->getData(statement, 2);
this->rennId = res[0][0].toInt(); this->rennId = res[0][0].toInt();
this->ui->lEMinRundenzeitAktRennen->setText(res[0][1]); this->ui->lEMinRundenzeitAktRennen->setText(res[0][1]);
} }
void WindowsSettings::repaintMinLapTime() { void WindowsSettings::repaintMinLapTime() {
int minlapTime = 0; int minlapTime = 0;
@@ -88,16 +92,20 @@ void WindowsSettings::AbbrechenSlot(){
delete this; delete this;
} }
void WindowsSettings::SaveDauerSlot() { void WindowsSettings::SaveDauerSlot() {
string statement = "update renndauer set " string statement =
"dauer="+this->ui->leRenndauer->text().toStdString()+", "+ "update renndauer set "
"mindestrundendauer="+this->ui->lEMinRundenzeit->text().toStdString()+", "+ "dauer=" +
this->ui->leRenndauer->text().toStdString() + ", " +
"mindestrundendauer=" +
this->ui->lEMinRundenzeit->text().toStdString() + ", " +
"minsec1=" + this->ui->lEMinTimeSec1->text().toStdString() + ", " + "minsec1=" + this->ui->lEMinTimeSec1->text().toStdString() + ", " +
"minsec2=" + this->ui->lEMinTimeSec2->text().toStdString() + ", " + "minsec2=" + this->ui->lEMinTimeSec2->text().toStdString() + ", " +
"minsec3=" + this->ui->lEMinTimeSec3->text().toStdString() + " " + "minsec3=" + this->ui->lEMinTimeSec3->text().toStdString() + " " +
" where id like 1"; " where id like 1";
cout << statement << endl; cout << statement << endl;
this->db->setData(statement); this->db->setData(statement);
statement = "update rennen set minimumroundtime="+this->ui->lEMinRundenzeitAktRennen->text().toStdString()+ statement = "update rennen set minimumroundtime=" +
this->ui->lEMinRundenzeitAktRennen->text().toStdString() +
" where id like " + QString::number(this->rennId).toStdString(); " where id like " + QString::number(this->rennId).toStdString();
this->db->setData(statement); this->db->setData(statement);
} }
@@ -106,17 +114,23 @@ void WindowsSettings::SaveDauerAndExitSlot(){
this->AbbrechenSlot(); this->AbbrechenSlot();
} }
void WindowsSettings::StreckeSpeichernSlot() { void WindowsSettings::StreckeSpeichernSlot() {
QString shellGeraden, shellKurvenAussen, shellKurvenInnen, shellSteilAussen, shellSteilInnen; QString shellGeraden, shellKurvenAussen, shellKurvenInnen, shellSteilAussen,
QString deaGeraden, deaKurvenAussen, deaKurvenInnen, deaSteilAussen, deaSteilInnen; shellSteilInnen;
QString deaGeraden, deaKurvenAussen, deaKurvenInnen, deaSteilAussen,
deaSteilInnen;
shellGeraden = ui->lEShellGeraden->text(); shellGeraden = ui->lEShellGeraden->text();
shellKurvenAussen = ui->lEShellKurvenAussen->text(); shellKurvenAussen = ui->lEShellKurvenAussen->text();
shellKurvenInnen = ui->lEShellKurvenInnen->text(); shellKurvenInnen = ui->lEShellKurvenInnen->text();
shellSteilAussen = ui->lEShellSteilkurveaussen->text(); shellSteilAussen = ui->lEShellSteilkurveaussen->text();
shellSteilInnen = ui->lEShellSteilkurveInnen->text(); shellSteilInnen = ui->lEShellSteilkurveInnen->text();
QString statement = QString("insert into strecke (geraden, kurven_aussen, kurven_innen, steilkurve_innen, steilkurve_aussen, seit, id_bahn)" QString statement = QString(
" values ("+shellGeraden+", "+shellKurvenAussen+", "+shellKurvenInnen+", "+shellSteilInnen+", "+shellSteilAussen+", '"+QString::fromStdString(currentDateTime())+"', 1)"); "insert into strecke (geraden, kurven_aussen, kurven_innen, "
"steilkurve_innen, steilkurve_aussen, seit, id_bahn)"
" values (" +
shellGeraden + ", " + shellKurvenAussen + ", " + shellKurvenInnen +
", " + shellSteilInnen + ", " + shellSteilAussen + ", '" +
QString::fromStdString(currentDateTime()) + "', 1)");
// cout << statement.toStdString() << endl; // cout << statement.toStdString() << endl;
db->setData(statement.toStdString()); db->setData(statement.toStdString());
@@ -125,14 +139,18 @@ void WindowsSettings::StreckeSpeichernSlot(){
deaKurvenInnen = ui->lEDeaKurvenInnen->text(); deaKurvenInnen = ui->lEDeaKurvenInnen->text();
deaSteilAussen = ui->lEDeaSteilkurveAussen->text(); deaSteilAussen = ui->lEDeaSteilkurveAussen->text();
deaSteilInnen = ui->lEDeaSteilkurveInnen->text(); deaSteilInnen = ui->lEDeaSteilkurveInnen->text();
statement = QString("insert into strecke (geraden, kurven_aussen, kurven_innen, steilkurve_innen, steilkurve_aussen, seit, id_bahn)" statement =
" values ("+deaGeraden+", "+deaKurvenAussen+", "+deaKurvenInnen+", "+deaSteilInnen+", "+deaSteilAussen+", '"+QString::fromStdString(currentDateTime())+"', 2)"); QString("insert into strecke (geraden, kurven_aussen, kurven_innen, "
"steilkurve_innen, steilkurve_aussen, seit, id_bahn)"
" values (" +
deaGeraden + ", " + deaKurvenAussen + ", " + deaKurvenInnen +
", " + deaSteilInnen + ", " + deaSteilAussen + ", '" +
QString::fromStdString(currentDateTime()) + "', 2)");
// cout << statement.toStdString() << endl; // cout << statement.toStdString() << endl;
db->setData(statement.toStdString()); db->setData(statement.toStdString());
} }
WindowsSettings::~WindowsSettings() WindowsSettings::~WindowsSettings() {
{
delete ui; delete ui;
std::cout << "Destruktor einstellungen" << std::endl; std::cout << "Destruktor einstellungen" << std::endl;
} }