mirror of https://github.com/EspoTek/Labrador.git
Iso working, but can't get libusb_handle_events() to run in another
thread.
This commit is contained in:
parent
ea47ae4133
commit
4509c31f55
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 4.1.0, 2016-10-20T17:15:11. -->
|
||||
<!-- Written by QtCreator 4.1.0, 2016-10-21T13:09:33. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -13,13 +13,25 @@ gahnooSlashLinuxUsbDriver::gahnooSlashLinuxUsbDriver(QWidget *parent) : genericU
|
|||
|
||||
unsigned char error = 1;
|
||||
while(error){
|
||||
QThread::msleep(32);
|
||||
error = usbInit(0x03eb, 0xa000);
|
||||
if(error)QThread::msleep(64);
|
||||
}
|
||||
setDeviceMode(deviceMode);
|
||||
newDig(digitalPinState);
|
||||
usbIsoInit();
|
||||
|
||||
|
||||
psuTimer = new QTimer();
|
||||
psuTimer->setTimerType(Qt::PreciseTimer);
|
||||
psuTimer->start(PSU_PERIOD);
|
||||
connect(psuTimer, SIGNAL(timeout()), this, SLOT(psuTick()));
|
||||
}
|
||||
|
||||
gahnooSlashLinuxUsbDriver::~gahnooSlashLinuxUsbDriver(void){
|
||||
qDebug() << "\n\ngahnooSlashLinuxUsbDriver destructor ran!";
|
||||
workerThread->quit();
|
||||
workerThread->wait();
|
||||
libusb_release_interface(handle, 0);
|
||||
libusb_exit(ctx);
|
||||
}
|
||||
|
||||
|
@ -27,11 +39,11 @@ unsigned char gahnooSlashLinuxUsbDriver::usbInit(unsigned long VIDin, unsigned l
|
|||
qDebug() << "Entering gahnooSlashLinuxUsbDriver::usbInit";
|
||||
|
||||
int error = libusb_init(&ctx);
|
||||
|
||||
if(error){
|
||||
qDebug() << "libusb_init FAILED";
|
||||
return error;
|
||||
}
|
||||
} else qDebug() << "Libusb context initialised";
|
||||
|
||||
libusb_set_debug(ctx, 3);
|
||||
|
||||
handle = libusb_open_device_with_vid_pid(ctx, VIDin, PIDin);
|
||||
|
@ -40,6 +52,18 @@ unsigned char gahnooSlashLinuxUsbDriver::usbInit(unsigned long VIDin, unsigned l
|
|||
return -1;
|
||||
}
|
||||
qDebug() << "Device found!!";
|
||||
|
||||
qDebug() << (libusb_kernel_driver_active(handle, 0) ? "KERNEL DRIVER ACTIVE" : "KERNEL DRIVER INACTIVE");
|
||||
if(libusb_kernel_driver_active(handle, 0)){
|
||||
libusb_detach_kernel_driver(handle, 0);
|
||||
}
|
||||
error = libusb_claim_interface(handle, 0);
|
||||
if(error){
|
||||
qDebug() << "libusb_claim_interface FAILED";
|
||||
qDebug() << "ERROR" << error << libusb_error_name(error);
|
||||
return error;
|
||||
} else qDebug() << "Interface claimed!";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -57,12 +81,13 @@ unsigned char gahnooSlashLinuxUsbDriver::usbIsoInit(void){
|
|||
|
||||
for(int n=0;n<NUM_FUTURE_CTX;n++){
|
||||
isoCtx[n] = libusb_alloc_transfer(ISO_PACKETS_PER_CTX);
|
||||
libusb_fill_iso_transfer(isoCtx[n], handle, pipeID, dataBuffer[n], ISO_PACKET_SIZE*ISO_PACKETS_PER_CTX, ISO_PACKETS_PER_CTX, NULL, NULL, 0);
|
||||
libusb_fill_iso_transfer(isoCtx[n], handle, pipeID, dataBuffer[n], ISO_PACKET_SIZE*ISO_PACKETS_PER_CTX, ISO_PACKETS_PER_CTX, isoCallback, (void*)n, 4000);
|
||||
libusb_set_iso_packet_lengths(isoCtx[n], ISO_PACKET_SIZE);
|
||||
error = libusb_submit_transfer(isoCtx[n]);
|
||||
if(error){
|
||||
qDebug() << "libusb_submit_transfer FAILED";
|
||||
qDebug() << "ERROR" << libusb_error_name(error);
|
||||
}
|
||||
} else qDebug() << "isoCtx submitted successfully!";
|
||||
}
|
||||
isoTimer = new QTimer();
|
||||
isoTimer->setTimerType(Qt::PreciseTimer);
|
||||
|
@ -71,10 +96,35 @@ unsigned char gahnooSlashLinuxUsbDriver::usbIsoInit(void){
|
|||
|
||||
qDebug() << "Setup successful!";
|
||||
|
||||
isoHandler = new worker();
|
||||
workerThread = new QThread();
|
||||
|
||||
isoHandler->ctx = ctx;
|
||||
isoHandler->moveToThread(workerThread);
|
||||
connect(workerThread, SIGNAL(started()), isoHandler, SLOT(handle()));
|
||||
//workerThread->start();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void gahnooSlashLinuxUsbDriver::isoTimerTick(void){
|
||||
timerCount++;
|
||||
|
||||
char subString[3] = "th";
|
||||
if(timerCount%10 == 1) strcpy(subString, "st");
|
||||
if(timerCount%10 == 2) strcpy(subString, "nd");
|
||||
if(timerCount%10 == 3) strcpy(subString, "rd");
|
||||
if((timerCount<20) && (timerCount > 10)) strcpy(subString, "th");
|
||||
|
||||
//qDebug("\n\nThis is the %d%s Tick!", timerCount, subString);
|
||||
return;
|
||||
|
||||
int n;
|
||||
for (n=0; n<NUM_FUTURE_CTX; n++){
|
||||
if(isoCtx[n]->status==LIBUSB_TRANSFER_COMPLETED){
|
||||
qDebug("Transfer %d is complete!!", n);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -82,3 +132,8 @@ char *gahnooSlashLinuxUsbDriver::isoRead(unsigned int *newLength){
|
|||
*(newLength) = 0;
|
||||
return (char*) NULL;
|
||||
}
|
||||
|
||||
static void LIBUSB_CALL isoCallback(struct libusb_transfer * transfer){
|
||||
qDebug() << "CALLBACK" << (long) transfer->user_data;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -2,10 +2,32 @@
|
|||
#define GAHNOOSLASHLINUXUSBDRIVER_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QThread>
|
||||
|
||||
#include "genericusbdriver.h"
|
||||
#include "libusb.h"
|
||||
|
||||
/*while(1){
|
||||
if(libusb_event_handling_ok(ctx)){
|
||||
libusb_handle_events(ctx);
|
||||
qDebug() << "HANDLED";
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
class worker : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
worker(){};
|
||||
~worker(){};
|
||||
libusb_context *ctx;
|
||||
public slots:
|
||||
void handle(){
|
||||
while(1);
|
||||
}
|
||||
};
|
||||
|
||||
class gahnooSlashLinuxUsbDriver : public genericUsbDriver
|
||||
{
|
||||
|
@ -18,7 +40,7 @@ public:
|
|||
private:
|
||||
//USB Vars
|
||||
libusb_context *ctx;
|
||||
libusb_device_handle *handle;
|
||||
libusb_device_handle *handle = NULL;
|
||||
unsigned char pipeID = 0x83;
|
||||
//USBIso Vars
|
||||
libusb_transfer *isoCtx[NUM_FUTURE_CTX];
|
||||
|
@ -26,11 +48,16 @@ private:
|
|||
QTimer *isoTimer;
|
||||
unsigned char currentWriteBuffer = 0;
|
||||
unsigned long timerCount = 0;
|
||||
worker *isoHandler;
|
||||
QThread *workerThread;
|
||||
//Generic Functions
|
||||
unsigned char usbInit(unsigned long VIDin, unsigned long PIDin);
|
||||
unsigned char usbIsoInit(void);
|
||||
signals:
|
||||
public slots:
|
||||
void isoTimerTick(void);
|
||||
};
|
||||
|
||||
static void LIBUSB_CALL isoCallback(struct libusb_transfer *transfer);
|
||||
|
||||
#endif // GAHNOOSLASHLINUXUSBDRIVER_H
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -18,6 +18,96 @@
|
|||
#endif
|
||||
|
||||
QT_BEGIN_MOC_NAMESPACE
|
||||
struct qt_meta_stringdata_worker_t {
|
||||
QByteArrayData data[3];
|
||||
char stringdata0[15];
|
||||
};
|
||||
#define QT_MOC_LITERAL(idx, ofs, len) \
|
||||
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
|
||||
qptrdiff(offsetof(qt_meta_stringdata_worker_t, stringdata0) + ofs \
|
||||
- idx * sizeof(QByteArrayData)) \
|
||||
)
|
||||
static const qt_meta_stringdata_worker_t qt_meta_stringdata_worker = {
|
||||
{
|
||||
QT_MOC_LITERAL(0, 0, 6), // "worker"
|
||||
QT_MOC_LITERAL(1, 7, 6), // "handle"
|
||||
QT_MOC_LITERAL(2, 14, 0) // ""
|
||||
|
||||
},
|
||||
"worker\0handle\0"
|
||||
};
|
||||
#undef QT_MOC_LITERAL
|
||||
|
||||
static const uint qt_meta_data_worker[] = {
|
||||
|
||||
// content:
|
||||
7, // revision
|
||||
0, // classname
|
||||
0, 0, // classinfo
|
||||
1, 14, // methods
|
||||
0, 0, // properties
|
||||
0, 0, // enums/sets
|
||||
0, 0, // constructors
|
||||
0, // flags
|
||||
0, // signalCount
|
||||
|
||||
// slots: name, argc, parameters, tag, flags
|
||||
1, 0, 19, 2, 0x0a /* Public */,
|
||||
|
||||
// slots: parameters
|
||||
QMetaType::Void,
|
||||
|
||||
0 // eod
|
||||
};
|
||||
|
||||
void worker::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
|
||||
{
|
||||
if (_c == QMetaObject::InvokeMetaMethod) {
|
||||
worker *_t = static_cast<worker *>(_o);
|
||||
Q_UNUSED(_t)
|
||||
switch (_id) {
|
||||
case 0: _t->handle(); break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
Q_UNUSED(_a);
|
||||
}
|
||||
|
||||
const QMetaObject worker::staticMetaObject = {
|
||||
{ &QObject::staticMetaObject, qt_meta_stringdata_worker.data,
|
||||
qt_meta_data_worker, qt_static_metacall, Q_NULLPTR, Q_NULLPTR}
|
||||
};
|
||||
|
||||
|
||||
const QMetaObject *worker::metaObject() const
|
||||
{
|
||||
return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
|
||||
}
|
||||
|
||||
void *worker::qt_metacast(const char *_clname)
|
||||
{
|
||||
if (!_clname) return Q_NULLPTR;
|
||||
if (!strcmp(_clname, qt_meta_stringdata_worker.stringdata0))
|
||||
return static_cast<void*>(const_cast< worker*>(this));
|
||||
return QObject::qt_metacast(_clname);
|
||||
}
|
||||
|
||||
int worker::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
|
||||
{
|
||||
_id = QObject::qt_metacall(_c, _id, _a);
|
||||
if (_id < 0)
|
||||
return _id;
|
||||
if (_c == QMetaObject::InvokeMetaMethod) {
|
||||
if (_id < 1)
|
||||
qt_static_metacall(this, _c, _id, _a);
|
||||
_id -= 1;
|
||||
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
|
||||
if (_id < 1)
|
||||
*reinterpret_cast<int*>(_a[0]) = -1;
|
||||
_id -= 1;
|
||||
}
|
||||
return _id;
|
||||
}
|
||||
struct qt_meta_stringdata_gahnooSlashLinuxUsbDriver_t {
|
||||
QByteArrayData data[3];
|
||||
char stringdata0[40];
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue