added ui tweaks + fix for accepting wrong laptimes

This commit is contained in:
2017-12-26 20:26:30 +01:00
parent 8fea1a1108
commit 2a1a082a30
13 changed files with 443 additions and 149 deletions

View File

@@ -137,6 +137,8 @@ usb_dev_handle * HardwareSetup::usbOpenDevice(int vendor, char * vendorName,
void HardwareSetup::run() {
int testmode = 0;
int nBytes = 0;
// char buffer[256];
struct TransStruct buffer[6];
@@ -149,62 +151,108 @@ void HardwareSetup::run() {
// printf("usbtext.exe off\n");
// exit(1);
// }
while (!this->handle) {
this->handle = usbOpenDevice(0x16C0, "test01", 0x05DC, "USBExample");
if (!testmode) {
while (!this->handle) {
this->handle =
usbOpenDevice(0x16C0, "test01", 0x05DC, "USBExample");
if (this->handle == NULL) {
fprintf(stderr, "Could not find USB device!\n");
if (this->handle == NULL) {
fprintf(stderr, "Could not find USB device!\n");
}
sleep(1);
}
sleep(1);
}
int index;
while (!this->stop) {
usleep(100000); // 100ms
// 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);
// test mode
for (int i = 0; i < 6; i++) {
if (buffer[i].update != 0) {
switch (buffer[i].id) {
case 0:
cout << "Shell Zeit 1: " << (int)buffer[i].time << endl;
emit Shell((int)buffer[i].time, 1);
break;
case 1:
cout << "Dea Zeit 1: " << (int)buffer[i].time << endl;
emit Dea((int)buffer[i].time, 1);
break;
case 2:
cout << "Shell Zeit 2: " << (int)buffer[i].time << endl;
emit Shell((int)buffer[i].time, 2);
break;
case 3:
cout << "Dea Zeit 2: " << (int)buffer[i].time << endl;
emit Dea((int)buffer[i].time, 2);
break;
case 4:
cout << "Shell Zeit 2: " << (int)buffer[i].time << endl;
emit Shell((int)buffer[i].time, 3);
break;
case 5:
cout << "Dea Zeit 3: " << (int)buffer[i].time << endl;
emit Dea((int)buffer[i].time, 3);
break;
if (testmode) {
while (1) {
int validTimes = 1;
if (validTimes) {
Shell(1100, 1);
sleep(1);
Shell(1200, 2);
sleep(1);
Shell(1300, 3);
sleep(1);
Dea(1100, 1);
sleep(1);
Dea(1200, 2);
sleep(1);
Dea(1300, 3);
// this->stop = 0;
sleep(1);
}
else {
// invalid times
Shell(30, 1);
sleep(1);
Shell(700, 2);
sleep(1);
Shell(700, 3);
sleep(1);
Dea(700, 1);
sleep(1);
Dea(700, 2);
sleep(1);
Dea(700, 3);
// this->stop = 0;
sleep(1);
}
}
}
if (buffer[0].update != 0) {
cout << "Got " << nBytes << " bytes: " << (int)buffer[2].time
<< ", " << (int)buffer[2].id << endl;
}
//}
else {
// normal mode -> no testmode
usleep(100000); // 100ms
if (nBytes < 0)
fprintf(stderr, "USB error: %sn", usb_strerror());
// 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);
for (int i = 0; i < 6; i++) {
if (buffer[i].update != 0) {
switch (buffer[i].id) {
case 0:
cout << "Shell Zeit 1: " << (int)buffer[i].time << endl;
emit Shell((int)buffer[i].time, 1);
break;
case 1:
cout << "Dea Zeit 1: " << (int)buffer[i].time << endl;
emit Dea((int)buffer[i].time, 1);
break;
case 2:
cout << "Shell Zeit 2: " << (int)buffer[i].time << endl;
emit Shell((int)buffer[i].time, 2);
break;
case 3:
cout << "Dea Zeit 2: " << (int)buffer[i].time << endl;
emit Dea((int)buffer[i].time, 2);
break;
case 4:
cout << "Shell Zeit 2: " << (int)buffer[i].time << endl;
emit Shell((int)buffer[i].time, 3);
break;
case 5:
cout << "Dea Zeit 3: " << (int)buffer[i].time << endl;
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 (nBytes < 0)
fprintf(stderr, "USB error: %sn", usb_strerror());
}
}
}