void UsbCom::run()
{
int r;
r = libusb_init(NULL);
send = false;
if (r < 0)
{
emit error("Failed to initialize USB!");
}
devh = libusb_open_device_with_vid_pid(NULL, idVENDOR, idPRODUCT);
if(!devh)
{
emit error("Could not locate device");
}
else
{
r = libusb_kernel_driver_active (devh, 0);
if (r != 0)
{
if(r==1)
{
r = libusb_detach_kernel_driver(devh, 0);
if (r > 0)
{
emit error
("some other random error:"+ QString::number(r
));
}
}
}
r = libusb_claim_interface(devh, 0);
if (r < 0)
{
emit error
("usb_claim_interface error"+ QString::number(r
));
}
int a = 0;
unsigned char irqbuf[64];
irq_transfer = libusb_alloc_transfer(0);
libusb_fill_interrupt_transfer(irq_transfer, devh, EP_INTR_IN, irqbuf,sizeof(irqbuf), ep_irq_in_cb, &a, 0);
r = libusb_submit_transfer(irq_transfer);
while(1)
{
wait.wait(mutex); //QMutex *mutex
if(send)
{
sendData();
}
if (a == 1)
{
emit dataRecieved(irqbuf);
a = 0;
}
r = libusb_handle_events(NULL);
}
}
libusb_close(devh);
}
void UsbCom::sendData()
{
int r,transf;
a.append((const char*)data);
r = libusb_interrupt_transfer(devh, EP_INTR_OUT, data, a.length(),&transf,1000);
if (r == 0)
{
emit error("Configuration sent");
}
send = false;
}
void ep_irq_in_cb(libusb_transfer *transfer)
{
if(transfer->status != LIBUSB_TRANSFER_COMPLETED)
{
fprintf(stderr, "uncompleted transter\n");
}
else
{
int *data = static_cast<int*>(transfer->user_data);
*data = 1;
}
if (libusb_submit_transfer(transfer) < 0)
{
fprintf(stderr,"could not resubmit irq \n");
//exit(1);
}
}
void UsbCom::run()
{
int r;
r = libusb_init(NULL);
send = false;
if (r < 0)
{
emit error("Failed to initialize USB!");
}
devh = libusb_open_device_with_vid_pid(NULL, idVENDOR, idPRODUCT);
if(!devh)
{
emit error("Could not locate device");
}
else
{
r = libusb_kernel_driver_active (devh, 0);
if (r != 0)
{
if(r==1)
{
r = libusb_detach_kernel_driver(devh, 0);
if (r > 0)
{
emit error("some other random error:"+ QString::number(r));
}
}
}
r = libusb_claim_interface(devh, 0);
if (r < 0)
{
emit error("usb_claim_interface error"+ QString::number(r));
}
int a = 0;
unsigned char irqbuf[64];
irq_transfer = libusb_alloc_transfer(0);
libusb_fill_interrupt_transfer(irq_transfer, devh, EP_INTR_IN, irqbuf,sizeof(irqbuf), ep_irq_in_cb, &a, 0);
r = libusb_submit_transfer(irq_transfer);
while(1)
{
wait.wait(mutex); //QMutex *mutex
if(send)
{
sendData();
}
if (a == 1)
{
emit dataRecieved(irqbuf);
a = 0;
}
r = libusb_handle_events(NULL);
}
}
libusb_close(devh);
}
void UsbCom::sendData()
{
int r,transf;
QString a;
a.append((const char*)data);
r = libusb_interrupt_transfer(devh, EP_INTR_OUT, data, a.length(),&transf,1000);
if (r == 0)
{
emit error("Configuration sent");
}
send = false;
}
void ep_irq_in_cb(libusb_transfer *transfer)
{
if(transfer->status != LIBUSB_TRANSFER_COMPLETED)
{
fprintf(stderr, "uncompleted transter\n");
}
else
{
int *data = static_cast<int*>(transfer->user_data);
*data = 1;
}
if (libusb_submit_transfer(transfer) < 0)
{
fprintf(stderr,"could not resubmit irq \n");
//exit(1);
}
}
To copy to clipboard, switch view to plain text mode
void Project::sendSettings()
{
unsigned char *b;
int r, transf;
if (ui->checkBox_RPM->isChecked())
{
sprintf((char*)b,"*1 %d %d %d",ui->spinBox_RPM->value(), ui->spinBox_KOPPEL->value(), ui->spinBox_over->value());
a.append((const char*)b);
usbcom->data = b;
usbcom->send = true;
}
else if (ui->checkBox_TEMP->isChecked())
{
sprintf((char*)b,"*0 %d %d", (char)ui->spinBox_TEMP->value(), (char)ui->spinBox_over->value());
a.append((const char*)b);
usbcom->data = b;
usbcom->send = true;
}
else
{
box.setText("Must at least check one option!");
box.exec();
}
usbcom->wait.wakeAll();
void Project::sendSettings()
{
QString a;
QMessageBox box;
unsigned char *b;
int r, transf;
if (ui->checkBox_RPM->isChecked())
{
sprintf((char*)b,"*1 %d %d %d",ui->spinBox_RPM->value(), ui->spinBox_KOPPEL->value(), ui->spinBox_over->value());
a.append((const char*)b);
usbcom->data = b;
usbcom->send = true;
}
else if (ui->checkBox_TEMP->isChecked())
{
sprintf((char*)b,"*0 %d %d", (char)ui->spinBox_TEMP->value(), (char)ui->spinBox_over->value());
a.append((const char*)b);
usbcom->data = b;
usbcom->send = true;
}
else
{
box.setText("Must at least check one option!");
box.exec();
}
usbcom->wait.wakeAll();
To copy to clipboard, switch view to plain text mode
Bookmarks