Traing mode changed from parallel port to usb solution
This commit is contained in:
@@ -8,6 +8,7 @@ QT += core gui
|
||||
QT += sql
|
||||
QT += core
|
||||
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
TARGET = RennbahnZeitmessung
|
||||
@@ -24,7 +25,8 @@ SOURCES += main.cpp\
|
||||
ampel.cpp \
|
||||
database.cpp \
|
||||
windowrennliste.cpp \
|
||||
training.cpp
|
||||
training.cpp \
|
||||
timemodel.cpp
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.h \
|
||||
@@ -36,7 +38,8 @@ HEADERS += \
|
||||
ampel.h \
|
||||
database.h \
|
||||
windowrennliste.h \
|
||||
training.h
|
||||
training.h \
|
||||
timemodel.h
|
||||
|
||||
FORMS += mainwindow.ui \
|
||||
windowrace.ui \
|
||||
@@ -46,5 +49,8 @@ FORMS += mainwindow.ui \
|
||||
|
||||
OTHER_FILES +=
|
||||
|
||||
INCLUDEPATH += /home/jpaehr/Dokumente/libusb/libusb
|
||||
LIBS += -L "/usr/lib" -lusb
|
||||
|
||||
RESOURCES += \
|
||||
resource.qrc
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 3.0.1, 2014-12-22T19:22:12. -->
|
||||
<!-- Written by QtCreator 4.3.1, 2017-09-07T16:51:17. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
<value type="QByteArray">{15687edb-7104-42fa-a53c-7d0294bb7338}</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
||||
<value type="int">0</value>
|
||||
@@ -29,10 +33,14 @@
|
||||
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
|
||||
<value type="int" key="EditorConfiguration.IndentSize">4</value>
|
||||
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
|
||||
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
|
||||
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
|
||||
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
|
||||
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
|
||||
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
|
||||
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
|
||||
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
|
||||
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
|
||||
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
|
||||
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
|
||||
<value type="int" key="EditorConfiguration.TabSize">8</value>
|
||||
@@ -53,22 +61,23 @@
|
||||
<valuemap type="QVariantMap">
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{afd67bb0-e1fe-490f-9c05-717bc9979c59}</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{e7c8e272-6c95-4fb7-9b69-d295b2ca02f0}</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.ActiveRunConfiguration">0</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/jpaehr/Dokumente/C/build-RennbahnZeitmessung-Desktop-Debug</value>
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/jpaehr/Dokumente/build-RennbahnZeitmessung-Desktop-Debug</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">false</value>
|
||||
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</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>
|
||||
@@ -117,7 +126,7 @@
|
||||
<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/C/build-RennbahnZeitmessung-Desktop-Release</value>
|
||||
<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.BuildStepList.Step.0">
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
@@ -125,9 +134,10 @@
|
||||
<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">false</value>
|
||||
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">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>
|
||||
@@ -175,7 +185,67 @@
|
||||
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
|
||||
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">2</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2">
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/jpaehr/Dokumente/build-RennbahnZeitmessung-Desktop-Profile</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">true</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">Profile</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">0</value>
|
||||
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">3</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
|
||||
@@ -191,6 +261,11 @@
|
||||
<value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.PluginSettings"/>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
|
||||
<value type="bool" key="Analyzer.QmlProfiler.AggregateTraces">false</value>
|
||||
<value type="bool" key="Analyzer.QmlProfiler.FlushEnabled">false</value>
|
||||
<value type="uint" key="Analyzer.QmlProfiler.FlushInterval">1000</value>
|
||||
<value type="QString" key="Analyzer.QmlProfiler.LastTraceFile"></value>
|
||||
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
||||
<valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
|
||||
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
|
||||
@@ -229,15 +304,16 @@
|
||||
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">RennbahnZeitmessung</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/jpaehr/Dokumente/C/RennbahnZeitmessung/RennbahnZeitmessung.pro</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/jpaehr/Dokumente/rennbahnc/RennbahnZeitmessung.pro</value>
|
||||
<value type="bool" key="QmakeProjectManager.QmakeRunConfiguration.UseLibrarySearchPath">true</value>
|
||||
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></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.UseTerminal">false</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="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebugger">true</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||
<value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||
@@ -250,11 +326,11 @@
|
||||
<value type="int">1</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.Updater.EnvironmentId</variable>
|
||||
<value type="QByteArray">{5a3b068d-48fb-4b9d-beda-5a5c38651d77}</value>
|
||||
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
|
||||
<value type="int">18</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
|
||||
<value type="int">15</value>
|
||||
<variable>Version</variable>
|
||||
<value type="int">18</value>
|
||||
</data>
|
||||
</qtcreator>
|
||||
|
||||
@@ -2,19 +2,28 @@
|
||||
#include <unistd.h>
|
||||
#include "sys/io.h"
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <usb.h>
|
||||
|
||||
//#define BASEPORT 0xe050 /* lp1 */
|
||||
//#define BASEPORT 0x378
|
||||
#define BASEPORT 0xd000
|
||||
#define USB_LED_ON 1
|
||||
#define USB_LED_OFF 0
|
||||
#define USB_DATA_OUT 2
|
||||
|
||||
using namespace std;
|
||||
// not needed anymore -> usb
|
||||
// #define BASEPORT 0xe050 /* lp1 */
|
||||
// #define BASEPORT 0x378
|
||||
// #define BASEPORT 0xd000
|
||||
|
||||
HardwareSetup::HardwareSetup()
|
||||
{
|
||||
if (ioperm(BASEPORT, 3, 1)) {
|
||||
//perror("ioperm");
|
||||
}
|
||||
shellBefore = false;
|
||||
deaBefore = false;
|
||||
// if (ioperm(BASEPORT, 3, 1)) {
|
||||
// //perror("ioperm");
|
||||
// }
|
||||
this->stop = 0;
|
||||
this->handle = NULL;
|
||||
}
|
||||
void HardwareSetup::setStop(){
|
||||
this->stop = 1;
|
||||
@@ -25,21 +34,192 @@ HardwareSetup::~HardwareSetup(){
|
||||
//perror("ioperm");
|
||||
}*/
|
||||
std::cout << "Hardware beendet" << std::endl;
|
||||
|
||||
this->stop = 1;
|
||||
if(this->handle){
|
||||
usb_close(this->handle);
|
||||
}
|
||||
this->handle = NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Used to get descriptor strings for device identification */
|
||||
int HardwareSetup::usbGetDescriptorString(usb_dev_handle *dev, int index, int langid,
|
||||
char *buf, int buflen) {
|
||||
char buffer[256];
|
||||
int rval, i;
|
||||
|
||||
// make standard request GET_DESCRIPTOR, type string and given index
|
||||
// (e.g. dev->iProduct)
|
||||
rval = usb_control_msg(dev,
|
||||
USB_TYPE_STANDARD | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
|
||||
USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) + index, langid,
|
||||
buffer, sizeof(buffer), 1000);
|
||||
|
||||
if(rval < 0) // error
|
||||
return rval;
|
||||
|
||||
// rval should be bytes read, but buffer[0] contains the actual response size
|
||||
if((unsigned char)buffer[0] < rval)
|
||||
rval = (unsigned char)buffer[0]; // string is shorter than bytes read
|
||||
|
||||
if(buffer[1] != USB_DT_STRING) // second byte is the data type
|
||||
return 0; // invalid return type
|
||||
|
||||
// we're dealing with UTF-16LE here so actual chars is half of rval,
|
||||
// and index 0 doesn't count
|
||||
rval /= 2;
|
||||
|
||||
/* lossy conversion to ISO Latin1 */
|
||||
for(i = 1; i < rval && i < buflen; i++) {
|
||||
if(buffer[2 * i + 1] == 0)
|
||||
buf[i-1] = buffer[2 * i];
|
||||
else
|
||||
buf[i-1] = '?'; /* outside of ISO Latin1 range */
|
||||
}
|
||||
buf[i-1] = 0;
|
||||
|
||||
return i-1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
usb_dev_handle * HardwareSetup::usbOpenDevice(int vendor, char *vendorName,
|
||||
int product, char *productName) {
|
||||
struct usb_bus *bus;
|
||||
struct usb_device *dev;
|
||||
char devVendor[256], devProduct[256];
|
||||
|
||||
usb_dev_handle * handle = NULL;
|
||||
|
||||
usb_init();
|
||||
usb_find_busses();
|
||||
usb_find_devices();
|
||||
|
||||
for(bus=usb_get_busses(); bus; bus=bus->next) {
|
||||
for(dev=bus->devices; dev; dev=dev->next) {
|
||||
if(dev->descriptor.idVendor != vendor ||
|
||||
dev->descriptor.idProduct != product)
|
||||
continue;
|
||||
|
||||
/* we need to open the device in order to query strings */
|
||||
if(!(handle = usb_open(dev))) {
|
||||
fprintf(stderr, "Warning: cannot open USB device: %sn",
|
||||
usb_strerror());
|
||||
continue;
|
||||
}
|
||||
|
||||
/* get vendor name */
|
||||
if(usbGetDescriptorString(handle, dev->descriptor.iManufacturer,
|
||||
0x0409, devVendor, sizeof(devVendor)) < 0) {
|
||||
fprintf(stderr,
|
||||
"Warning: cannot query manufacturer for device: %sn",
|
||||
usb_strerror());
|
||||
usb_close(handle);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* get product name */
|
||||
if(usbGetDescriptorString(handle, dev->descriptor.iProduct,
|
||||
0x0409, devProduct, sizeof(devVendor)) < 0) {
|
||||
fprintf(stderr,
|
||||
"Warning: cannot query product for device: %sn",
|
||||
usb_strerror());
|
||||
usb_close(handle);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(strcmp(devVendor, vendorName) == 0 &&
|
||||
strcmp(devProduct, productName) == 0)
|
||||
return handle;
|
||||
else
|
||||
usb_close(handle);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void HardwareSetup::run(){
|
||||
|
||||
int nBytes = 0;
|
||||
//char buffer[256];
|
||||
struct TransStruct buffer[6];
|
||||
//struct TransStruct *buffer = buffer1;
|
||||
//cout << "thread started" << endl;
|
||||
|
||||
// if(argc < 2) {
|
||||
// printf("Usage:\n");
|
||||
// printf("usbtext.exe on\n");
|
||||
// printf("usbtext.exe off\n");
|
||||
// exit(1);
|
||||
// }
|
||||
while(!this->handle){
|
||||
this->handle = usbOpenDevice(0x16C0, "test01", 0x05DC, "USBExample");
|
||||
|
||||
if(this->handle == NULL) {
|
||||
fprintf(stderr, "Could not find USB device!\n");
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int index;
|
||||
while(!this->stop){
|
||||
usleep(100000); // 100ms
|
||||
|
||||
usleep(500);
|
||||
while(1){
|
||||
nBytes = usb_control_msg(this->handle,
|
||||
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
|
||||
USB_DATA_OUT, 0, 0, (char *)buffer, sizeof(buffer), 5000);
|
||||
|
||||
if(getDea()){
|
||||
for(int i = 0; i < 6; i++){
|
||||
if(buffer[i].update != 0){
|
||||
switch(buffer[i].id){
|
||||
case 0:
|
||||
emit Shell((int)buffer[i].time, 1);
|
||||
break;
|
||||
case 1:
|
||||
emit Dea((int)buffer[i].time, 1);
|
||||
break;
|
||||
case 2:
|
||||
emit Shell((int)buffer[i].time, 2);
|
||||
break;
|
||||
case 3:
|
||||
cout << "Time: vor emit" << (int)buffer[i].time << endl;
|
||||
emit Dea((int)buffer[i].time, 2);
|
||||
break;
|
||||
case 4:
|
||||
cout << "emit shell" << endl;
|
||||
emit Shell((int)buffer[i].time, 3);
|
||||
break;
|
||||
case 5:
|
||||
emit Dea((int)buffer[i].time, 3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// if(buffer[0].update != 0){
|
||||
// cout << "Got " << nBytes << " bytes: " << (int)buffer[2].time << ", " << (int)buffer[2].id << endl;
|
||||
// }
|
||||
|
||||
if(!deaBefore){
|
||||
// if((int)buffer->update == 1){
|
||||
// //if((int) buffer->id)
|
||||
// emit Dea((int)buffer->time, 1);
|
||||
// }
|
||||
}
|
||||
|
||||
if(nBytes < 0)
|
||||
fprintf(stderr, "USB error: %sn", usb_strerror());
|
||||
|
||||
//if(getDea()){
|
||||
if(1){
|
||||
|
||||
// if(!deaBefore){
|
||||
if(1){
|
||||
index = 1;
|
||||
deaBefore = true;
|
||||
emit Dea();
|
||||
//emit Dea(5);
|
||||
}
|
||||
else{
|
||||
index += 1;
|
||||
@@ -52,10 +232,11 @@ void HardwareSetup::run(){
|
||||
deaBefore = false;
|
||||
}
|
||||
|
||||
if(getShell()){
|
||||
// if(getShell()){
|
||||
if(1){
|
||||
if(!shellBefore){
|
||||
shellBefore = true;
|
||||
emit Shell();
|
||||
//emit Shell();
|
||||
}
|
||||
}
|
||||
else{
|
||||
@@ -67,23 +248,23 @@ void HardwareSetup::run(){
|
||||
|
||||
bool HardwareSetup::getShell(){
|
||||
|
||||
int zahl[8] = {0};
|
||||
// int zahl[8] = {0};
|
||||
|
||||
if(findBit(zahl, inb(BASEPORT + 1))[7] == 1){
|
||||
// if(findBit(zahl, inb(BASEPORT + 1))[7] == 1){
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
// return true;
|
||||
// }
|
||||
return false;
|
||||
|
||||
}
|
||||
bool HardwareSetup::getDea(){
|
||||
|
||||
int zahl[8] = {0};
|
||||
// int zahl[8] = {0};
|
||||
|
||||
if(findBit(zahl, inb(BASEPORT + 1))[6] == 0 ){
|
||||
return true;
|
||||
}
|
||||
// if(findBit(zahl, inb(BASEPORT + 1))[6] == 0 ){
|
||||
// return true;
|
||||
// }
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,17 @@
|
||||
#define HARDWARESETUP_H
|
||||
|
||||
#include <QtCore>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <usb.h>
|
||||
|
||||
struct TransStruct{
|
||||
uint16_t time;
|
||||
uint8_t id;
|
||||
uint8_t update;
|
||||
};
|
||||
|
||||
class HardwareSetup : public QThread
|
||||
{
|
||||
@@ -11,18 +22,21 @@ protected:
|
||||
private:
|
||||
bool shellBefore;
|
||||
bool deaBefore;
|
||||
usb_dev_handle *handle;
|
||||
|
||||
bool getShell();
|
||||
bool getDea();
|
||||
int* findBit(int *array, int zahl);
|
||||
bool stop;
|
||||
int usbGetDescriptorString(usb_dev_handle *dev, int index, int langid, char *buf, int buflen);
|
||||
usb_dev_handle *usbOpenDevice(int vendor, char *vendorName, int product, char *productName);
|
||||
public:
|
||||
void setStop();
|
||||
~HardwareSetup();
|
||||
HardwareSetup();
|
||||
signals:
|
||||
void Shell();
|
||||
void Dea();
|
||||
void Shell(int, int);
|
||||
void Dea(int, int);
|
||||
};
|
||||
|
||||
#endif // HARDWARESETUP_H
|
||||
|
||||
125
timemodel.cpp
Normal file
125
timemodel.cpp
Normal file
@@ -0,0 +1,125 @@
|
||||
#include "timemodel.h"
|
||||
#include<qvector.h>
|
||||
#include <iostream>
|
||||
#include <qcolor.h>
|
||||
|
||||
|
||||
TimeModel::TimeModel(QVector<QVector<int>> timeData, QObject *parent)
|
||||
: QAbstractTableModel(parent)
|
||||
{
|
||||
this->timeData = timeData;
|
||||
}
|
||||
|
||||
QVariant TimeModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
if (orientation == Qt::Horizontal) {
|
||||
switch (section) {
|
||||
case 0:
|
||||
return QString("Sektor 1");
|
||||
|
||||
case 1:
|
||||
return QString("Sektor 2");
|
||||
|
||||
case 2:
|
||||
return QString("Sektor 3");
|
||||
|
||||
case 3:
|
||||
return QString("Runde");
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
int TimeModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
|
||||
return this->timeData.size();
|
||||
}
|
||||
|
||||
int TimeModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
return 4;
|
||||
}
|
||||
|
||||
QColor TimeModel::getColor(const QVector<QVector<int>> data, const int col, const int row) const{
|
||||
if(row == 0){
|
||||
return QColor(Qt::gray);
|
||||
}
|
||||
else if(data.size() > row){ // check for enough rows
|
||||
if(data.at(row).size() > col){ // check for enough cols
|
||||
QVector<int> compare;
|
||||
for(int i = 0; i <= row; i++){
|
||||
compare.append(data.at(i).at(col));
|
||||
}
|
||||
if(data.at(row).at(col) == getMin(compare)){
|
||||
return QColor(Qt::green);
|
||||
}
|
||||
else{
|
||||
return QColor(Qt::gray);
|
||||
}
|
||||
}
|
||||
else{
|
||||
return QColor(Qt::white);
|
||||
}
|
||||
}
|
||||
else{
|
||||
return QColor(Qt::white);
|
||||
}
|
||||
}
|
||||
|
||||
int TimeModel::getMin(const QVector<int> x) const{
|
||||
int min;
|
||||
if(x.size() > 0){
|
||||
min = x.at(0);
|
||||
}
|
||||
for(int i = 1; i < x.size(); i++){
|
||||
if(x.at(i) < min){
|
||||
min = x.at(i);
|
||||
}
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
QVariant TimeModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
//std::cout << "data called" << std::endl;
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
if(role == Qt::DisplayRole){
|
||||
if(timeData.at(index.row()).size() > index.column()){
|
||||
return QString::number((double)timeData.at(index.row()).at(index.column())/1000);
|
||||
}
|
||||
else{
|
||||
return QString("∞");
|
||||
}
|
||||
}
|
||||
else if(role == Qt::BackgroundColorRole){
|
||||
return getColor(timeData, index.column(), index.row());
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
bool TimeModel::insertRows(int row, int count, const QModelIndex &parent)
|
||||
{
|
||||
std::cout << "insert triggert" << std::endl;
|
||||
beginInsertRows(parent, row, row + count - 1);
|
||||
// FIXME: Implement me!
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
bool TimeModel::insertColumns(int column, int count, const QModelIndex &parent)
|
||||
{
|
||||
beginInsertColumns(parent, column, column + count - 1);
|
||||
// FIXME: Implement me!
|
||||
endInsertColumns();
|
||||
}
|
||||
35
timemodel.h
Normal file
35
timemodel.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef TIMEMODEL_H
|
||||
#define TIMEMODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <qcolor.h>
|
||||
#include <qvector.h>
|
||||
|
||||
class TimeModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TimeModel(QVector<QVector<int>> timeData, QObject *parent = nullptr);
|
||||
|
||||
// Header:
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
|
||||
// Basic functionality:
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
// Add data:
|
||||
bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
|
||||
private:
|
||||
int getMin(const QVector<int> x) const;
|
||||
|
||||
QColor getColor(const QVector<QVector<int>> data, const int col, const int row) const; // row and col starts counting at 0
|
||||
QVector<QVector<int>> timeData;
|
||||
};
|
||||
|
||||
#endif // TIMEMODEL_H
|
||||
232
training.cpp
232
training.cpp
@@ -6,6 +6,8 @@
|
||||
#include <iostream>
|
||||
#include <QShortcut>
|
||||
#include "unistd.h"
|
||||
#include <QListWidgetItem>
|
||||
#include "timemodel.h"
|
||||
|
||||
using std::vector;
|
||||
using std::string;
|
||||
@@ -31,8 +33,12 @@ Training::Training(QWidget *parent, DataBase *db) :
|
||||
|
||||
this->Hardware = new HardwareSetup;
|
||||
Hardware->start();
|
||||
QObject::connect(Hardware, SIGNAL(Dea()), this, SLOT(deaSlot()));
|
||||
QObject::connect(Hardware, SIGNAL(Shell()), this, SLOT(shellSlot()));
|
||||
|
||||
|
||||
|
||||
|
||||
QObject::connect(Hardware, SIGNAL(Dea(int, int)), this, SLOT(deaSlot(int, int)));
|
||||
QObject::connect(Hardware, SIGNAL(Shell(int, int)), this, SLOT(shellSlot(int, int)));
|
||||
//QObject::connect(this->ui->pBNextRace, SIGNAL(clicked()), this, SLOT(prepareNextRace()));
|
||||
//QObject::connect(this->ui->pBStop, SIGNAL(clicked()), this, SLOT(stopClicked()));
|
||||
|
||||
@@ -52,7 +58,9 @@ Training::Training(QWidget *parent, DataBase *db) :
|
||||
void Training::ResetShell(){
|
||||
this->VecShell.clear();
|
||||
|
||||
this->ui->lWShellTime->clear();
|
||||
// this->ui->lWShellTime->clear();
|
||||
timeModelShell = new TimeModel(VecShell, this);
|
||||
this->ui->lWShellTime->setModel(timeModelShell);
|
||||
|
||||
this->ui->lBestZeitShell->setText("∞");
|
||||
this->ui->lCurRoundTimeShell->setText("∞");
|
||||
@@ -61,7 +69,9 @@ void Training::ResetShell(){
|
||||
void Training::ResetDea(){
|
||||
this->VecDea.clear();
|
||||
|
||||
this->ui->lWDeaTime->clear();
|
||||
//this->ui->lWDeaTime->clear();
|
||||
timeModelDea = new TimeModel(VecDea, this);
|
||||
this->ui->lWDeaTime->setModel(timeModelDea);
|
||||
|
||||
this->ui->lBestZeitDea->setText("∞");
|
||||
|
||||
@@ -71,8 +81,8 @@ void Training::ResetDea(){
|
||||
void Training::Reset(){
|
||||
this->VecShell.clear();
|
||||
this->VecDea.clear();
|
||||
this->ui->lWDeaTime->clear();
|
||||
this->ui->lWShellTime->clear();
|
||||
// this->ui->lWDeaTime->clear();
|
||||
// this->ui->lWShellTime->clear();
|
||||
|
||||
this->ui->lBestZeitDea->setText("∞");
|
||||
this->ui->lBestZeitShell->setText("∞");
|
||||
@@ -85,8 +95,8 @@ void Training::prepareNextRace(){
|
||||
this->firstTimeShell = true;
|
||||
this->firstTimeDea = true;
|
||||
|
||||
this->ui->lWShellTime->clear();
|
||||
this->ui->lWDeaTime->clear();
|
||||
// this->ui->lWShellTime->clear();
|
||||
// this->ui->lWDeaTime->clear();
|
||||
|
||||
this->ui->lBestZeitDea->setText("∞");
|
||||
this->ui->lBestZeitShell->setText("∞");
|
||||
@@ -96,34 +106,75 @@ void Training::prepareNextRace(){
|
||||
|
||||
this->finished = false;
|
||||
this->paused = false;
|
||||
this->started = false;
|
||||
this->started = true;
|
||||
}
|
||||
|
||||
void Training::shellSlot(){
|
||||
void Training::shellSlot(int time, int sector){
|
||||
cout << "Shell slot" << endl;
|
||||
// slot is called when a sector is finished
|
||||
// time is given in ms
|
||||
// counting of sector beginns at 1
|
||||
|
||||
if(started && !paused && !this->finished){
|
||||
if(firstTimeShell){
|
||||
firstTimeShell = false;
|
||||
counterShell.start();
|
||||
}
|
||||
else{
|
||||
long zeit = counterShell.getTime();
|
||||
VecShell.push_back(zeit);
|
||||
QListWidgetItem *item = new QListWidgetItem;
|
||||
if(getMinimum(VecShell) == zeit && VecShell.size() > 1){
|
||||
item->setBackgroundColor(Qt::green);
|
||||
}
|
||||
if(zeit < this->minimumTime){
|
||||
item->setBackgroundColor(Qt::red);
|
||||
this->firstTimeShell = true;
|
||||
}
|
||||
item->setText(QString::number((double)zeit/1000));
|
||||
ui->lWShellTime->addItem(item);
|
||||
switch(sector){
|
||||
case 1:
|
||||
VecShell.push_back(QVector<int>());
|
||||
VecShell.last().push_back(time);
|
||||
|
||||
ui->lWShellTime->scrollToBottom();
|
||||
if(getMinimum(VecShell) > 0){
|
||||
ui->lBestZeitShell->setText(QString::number((double)getMinimum(VecShell)/1000));
|
||||
timeModelShell = new TimeModel(VecShell, this);
|
||||
this->ui->lWShellTime->setModel(timeModelShell);
|
||||
|
||||
break;
|
||||
case 2:
|
||||
if(VecShell.size() > 0){
|
||||
if(VecShell.last().size() == 1){
|
||||
cout << time << sector << endl;
|
||||
VecShell.last().push_back(time);
|
||||
timeModelShell = new TimeModel(VecShell, this);
|
||||
this->ui->lWShellTime->setModel(timeModelShell);
|
||||
}
|
||||
else{
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if(VecShell.size() > 0){
|
||||
//cout << "Time sec 3: " << time << endl;
|
||||
if(VecShell.last().size() == 2){
|
||||
// cout << time << sector << endl;
|
||||
VecShell.last().push_back(time);
|
||||
|
||||
// add sum to vector
|
||||
VecShell.last().push_back(getCurTime(VecShell.last()));
|
||||
|
||||
|
||||
|
||||
timeModelShell = new TimeModel(VecShell, this);
|
||||
this->ui->lWShellTime->setModel(timeModelShell);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// best time on widget
|
||||
|
||||
if(getCurTime(VecShell.last()) <= getMin(VecShell)){
|
||||
ui->lBestZeitShell->setText(QString::number((double)getMin(VecShell)/1000));
|
||||
}
|
||||
ui->lCurRoundTimeShell->setText(QString::number((double)getCurTime(VecShell.last())/1000));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
ui->lCurRoundTimeShell->setText(QString::number((double)zeit/1000));
|
||||
ui->lWShellTime->scrollToBottom();
|
||||
ui->lWShellTime->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,67 +182,106 @@ void Training::closeEvent(QCloseEvent *event){
|
||||
|
||||
}
|
||||
|
||||
void Training::deaSlot(){
|
||||
void Training::deaSlot(int time, int sector){
|
||||
// slot is called when a sector is finished
|
||||
// time is given in ms
|
||||
// counting of sector beginns at 1
|
||||
if(started && !paused && !this->finished){
|
||||
if(firstTimeDea){
|
||||
firstTimeDea = false;
|
||||
counterDea.start();
|
||||
}
|
||||
else{
|
||||
/*
|
||||
long zeit = counterDea.getTime();
|
||||
VecDea.push_back(zeit);
|
||||
QListWidgetItem *item = new QListWidgetItem;
|
||||
if(getMinimum(VecDea) == zeit && VecDea.size() > 1){
|
||||
item->setBackgroundColor(Qt::green);
|
||||
}
|
||||
item->setText(QString::number((double)zeit/1000));
|
||||
ui->lWDeaTime->addItem(item);
|
||||
ui->lWDeaTime->scrollToBottom();
|
||||
switch(sector){
|
||||
case 1:
|
||||
VecDea.push_back(QVector<int>());
|
||||
VecDea.last().push_back(time);
|
||||
cout << "Dea Sektor 1" << endl;
|
||||
timeModelDea = new TimeModel(VecDea, this);
|
||||
this->ui->lWDeaTime->setModel(timeModelDea);
|
||||
|
||||
ui->lBestZeitDea->setText(QString::number((double)getMinimum(VecDea)/1000));
|
||||
ui->lCurRoundDea->setText(QString::number((double)zeit/1000));
|
||||
*/
|
||||
//
|
||||
long zeit = counterDea.getTime();
|
||||
VecDea.push_back(zeit);
|
||||
QListWidgetItem *item = new QListWidgetItem;
|
||||
if(getMinimum(VecDea) == zeit && VecDea.size() > 1){
|
||||
item->setBackgroundColor(Qt::green);
|
||||
}
|
||||
if(zeit < this->minimumTime){
|
||||
item->setBackgroundColor(Qt::red);
|
||||
this->firstTimeDea = true;
|
||||
}
|
||||
item->setText(QString::number((double)zeit/1000));
|
||||
ui->lWDeaTime->addItem(item);
|
||||
break;
|
||||
case 2:
|
||||
if(VecDea.size() > 0){
|
||||
if(VecDea.last().size() == 1){
|
||||
cout << time << sector << endl;
|
||||
VecDea[VecDea.size()-1].push_back(time);
|
||||
timeModelDea = new TimeModel(VecDea, this);
|
||||
this->ui->lWDeaTime->setModel(timeModelDea);
|
||||
}
|
||||
else{
|
||||
//VecDea[VecDea.size()-1].append(9999);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if(VecDea.size() > 0){
|
||||
//cout << "Time sec 3: " << time << endl;
|
||||
if(VecDea.last().size() == 2){
|
||||
// cout << time << sector << endl;
|
||||
VecDea[VecDea.size()-1].push_back(time);
|
||||
|
||||
ui->lWDeaTime->scrollToBottom();
|
||||
if(getMinimum(VecDea) > 0){
|
||||
ui->lBestZeitDea->setText(QString::number((double)getMinimum(VecDea)/1000));
|
||||
// add sum to vector
|
||||
VecDea[VecDea.size()-1].push_back(getCurTime(VecDea.last()));
|
||||
|
||||
|
||||
|
||||
timeModelDea = new TimeModel(VecDea, this);
|
||||
this->ui->lWDeaTime->setModel(timeModelDea);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// best time on widget
|
||||
cout << "cur time: " << getCurTime(VecDea.last()) << endl;
|
||||
cout << "min time: " << getMin(VecDea) << endl;
|
||||
if(getCurTime(VecDea.last()) <= getMin(VecDea)){
|
||||
ui->lBestZeitDea->setText(QString::number((double)getMin(VecDea)/1000));
|
||||
}
|
||||
ui->lCurRoundDea->setText(QString::number((double)getCurTime(VecDea.last())/1000));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
ui->lCurRoundDea->setText(QString::number((double)zeit/1000));
|
||||
ui->lWDeaTime->scrollToBottom();
|
||||
ui->lWDeaTime->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
long Training::getMinimum(std::vector<long> a){
|
||||
long minimum = -1;
|
||||
for(unsigned int i = 0; i < a.size(); i++){
|
||||
if(minimum < 0){
|
||||
if(a[i] >= this->minimumTime){
|
||||
minimum = a[i];
|
||||
}
|
||||
int Training::getCurTime(const QVector<int> x) const {
|
||||
if(x.size() >= 3){
|
||||
return x.at(0)+ x.at(1) + x.at(2);
|
||||
}
|
||||
else{
|
||||
return 9999;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int Training::getMin(const QVector<QVector<int>> x) const{
|
||||
int min;
|
||||
if(x.size() > 0){
|
||||
if(x.at(0).size() >= 3){
|
||||
min = getCurTime(x.at(0));
|
||||
}
|
||||
else{
|
||||
if(a[i] < minimum && a[i] >= this->minimumTime){
|
||||
minimum = a[i];
|
||||
}
|
||||
return 9999;
|
||||
}
|
||||
|
||||
}
|
||||
return minimum;
|
||||
else{
|
||||
return 9999;
|
||||
}
|
||||
for(int i = 1; i < x.size(); i++){
|
||||
if(getCurTime(x.at(i)) < min){
|
||||
min = getCurTime(x.at(i));
|
||||
}
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
Training::~Training()
|
||||
{
|
||||
this->Hardware->setStop();
|
||||
|
||||
17
training.h
17
training.h
@@ -6,6 +6,7 @@
|
||||
#include "counter.h"
|
||||
#include <QMainWindow>
|
||||
#include "database.h"
|
||||
#include "timemodel.h"
|
||||
|
||||
namespace Ui {
|
||||
class Training;
|
||||
@@ -29,9 +30,13 @@ private:
|
||||
HardwareSetup *Hardware;
|
||||
bool firstTimeShell;
|
||||
bool firstTimeDea;
|
||||
std::vector<long> VecShell;
|
||||
std::vector<long> VecDea;
|
||||
QVector<QVector<int>> VecShell;
|
||||
QVector<QVector<int>> VecDea;
|
||||
long getMinimum(std::vector<long> a);
|
||||
int getCurTime(const QVector<int> x) const;
|
||||
int getMin(const QVector<QVector<int>> x) const;
|
||||
|
||||
|
||||
bool paused;
|
||||
bool finished;
|
||||
Counter counterShell;
|
||||
@@ -40,12 +45,16 @@ private:
|
||||
long minTimeOneRound;
|
||||
int minimumTime;
|
||||
|
||||
// timeModel
|
||||
TimeModel *timeModelDea;
|
||||
TimeModel *timeModelShell;
|
||||
|
||||
public slots:
|
||||
void ResetShell();
|
||||
void ResetDea();
|
||||
void Reset();
|
||||
void deaSlot();
|
||||
void shellSlot();
|
||||
void deaSlot(int time, int sector);
|
||||
void shellSlot(int time, int sector);
|
||||
|
||||
};
|
||||
|
||||
|
||||
18
training.ui
18
training.ui
@@ -16,14 +16,14 @@
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_18">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="1,0,1">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="gbShell">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>300</width>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
@@ -93,10 +93,10 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="lWShellTime">
|
||||
<widget class="QTableView" name="lWShellTime">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>300</width>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
@@ -131,7 +131,7 @@
|
||||
<widget class="QGroupBox" name="gbDea">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>300</width>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
@@ -143,7 +143,7 @@
|
||||
<property name="title">
|
||||
<string>Dea</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_13">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_13" stretch="0,0">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
@@ -201,10 +201,10 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="lWDeaTime">
|
||||
<widget class="QTableView" name="lWDeaTime">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>300</width>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
@@ -250,7 +250,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>20</height>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
|
||||
@@ -49,6 +49,7 @@ WindowRace::WindowRace(DataBase *db, QWidget *parent) :
|
||||
|
||||
Hardware = new HardwareSetup;
|
||||
Hardware->start();
|
||||
|
||||
QObject::connect(Hardware, SIGNAL(Dea()), this, SLOT(deaSlot()));
|
||||
QObject::connect(Hardware, SIGNAL(Shell()), this, SLOT(shellSlot()));
|
||||
QObject::connect(ui->pBStart, SIGNAL(clicked()), this, SLOT(go()));
|
||||
|
||||
Reference in New Issue
Block a user