mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
Attempt to make USB faster on Mac. Breaks the Firmware upload system!!!
This commit is contained in:
parent
c06c08e831
commit
de8478718c
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
#if defined( Q_OS_MAC)
|
#if defined( Q_OS_MAC)
|
||||||
|
|
||||||
|
#include <QTimer>
|
||||||
// todo:
|
// todo:
|
||||||
|
|
||||||
#elif defined(Q_OS_UNIX)
|
#elif defined(Q_OS_UNIX)
|
||||||
@ -104,10 +105,16 @@ public:
|
|||||||
void mytest(int num);
|
void mytest(int num);
|
||||||
signals:
|
signals:
|
||||||
void deviceUnplugged(int);//just to make pips changes compile
|
void deviceUnplugged(int);//just to make pips changes compile
|
||||||
|
#if defined( Q_OS_MAC)
|
||||||
|
public slots:
|
||||||
|
void timeout_callback();
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#if defined( Q_OS_MAC)
|
#if defined( Q_OS_MAC)
|
||||||
|
|
||||||
// todo:
|
int timeout_occurred;
|
||||||
|
QTimer m_timer;
|
||||||
|
|
||||||
#elif defined(Q_OS_UNIX)
|
#elif defined(Q_OS_UNIX)
|
||||||
//#elif defined(Q_OS_LINUX)
|
//#elif defined(Q_OS_LINUX)
|
||||||
|
@ -44,6 +44,17 @@
|
|||||||
#include <IOKit/hid/IOHIDLib.h>
|
#include <IOKit/hid/IOHIDLib.h>
|
||||||
#include <CoreFoundation/CFString.h>
|
#include <CoreFoundation/CFString.h>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QThread>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
class delay : public QThread
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void msleep(unsigned long msecs)
|
||||||
|
{
|
||||||
|
QThread::msleep(msecs);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
#define BUFFER_SIZE 64
|
#define BUFFER_SIZE 64
|
||||||
|
|
||||||
@ -75,7 +86,6 @@ static void free_all_hid(void);
|
|||||||
static void hid_close(hid_t *);
|
static void hid_close(hid_t *);
|
||||||
static void attach_callback(void *, IOReturn, void *, IOHIDDeviceRef);
|
static void attach_callback(void *, IOReturn, void *, IOHIDDeviceRef);
|
||||||
static void detach_callback(void *, IOReturn, void *hid_mgr, IOHIDDeviceRef dev);
|
static void detach_callback(void *, IOReturn, void *hid_mgr, IOHIDDeviceRef dev);
|
||||||
static void timeout_callback(CFRunLoopTimerRef, void *);
|
|
||||||
static void input_callback(void *, IOReturn, void *, IOHIDReportType, uint32_t, uint8_t *, CFIndex);
|
static void input_callback(void *, IOReturn, void *, IOHIDReportType, uint32_t, uint8_t *, CFIndex);
|
||||||
static void output_callback(hid_t *context, IOReturn ret, void *sender, IOHIDReportType type, uint32_t id, uint8_t *data, CFIndex len);
|
static void output_callback(hid_t *context, IOReturn ret, void *sender, IOHIDReportType type, uint32_t id, uint8_t *data, CFIndex len);
|
||||||
|
|
||||||
@ -109,6 +119,8 @@ int pjrc_rawhid::open(int max, int vid, int pid, int usage_page, int usage)
|
|||||||
hid_t *p;
|
hid_t *p;
|
||||||
int count=0;
|
int count=0;
|
||||||
|
|
||||||
|
connect(&m_timer, SIGNAL(timeout()), this, SLOT(timeout_callback()));
|
||||||
|
|
||||||
if (first_hid) free_all_hid();
|
if (first_hid) free_all_hid();
|
||||||
//printf("pjrc_rawhid_open, max=%d\n", max);
|
//printf("pjrc_rawhid_open, max=%d\n", max);
|
||||||
if (max < 1) return 0;
|
if (max < 1) return 0;
|
||||||
@ -185,9 +197,7 @@ int pjrc_rawhid::receive(int num, void *buf, int len, int timeout)
|
|||||||
{
|
{
|
||||||
hid_t *hid;
|
hid_t *hid;
|
||||||
buffer_t *b;
|
buffer_t *b;
|
||||||
CFRunLoopTimerRef timer=NULL;
|
int ret=0;
|
||||||
CFRunLoopTimerContext context;
|
|
||||||
int ret=0, timeout_occurred=0;
|
|
||||||
|
|
||||||
if (len < 1) return 0;
|
if (len < 1) return 0;
|
||||||
hid = get_hid(num);
|
hid = get_hid(num);
|
||||||
@ -197,21 +207,28 @@ int pjrc_rawhid::receive(int num, void *buf, int len, int timeout)
|
|||||||
memcpy(buf, b->buf, len);
|
memcpy(buf, b->buf, len);
|
||||||
hid->first_buffer = b->next;
|
hid->first_buffer = b->next;
|
||||||
free(b);
|
free(b);
|
||||||
|
//printf("packet already, returning before loop");
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
memset(&context, 0, sizeof(context));
|
|
||||||
context.info = &timeout_occurred;
|
// This does not work while in a "while" loop!! Come on...
|
||||||
timer = CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent() +
|
// BEWARE: this area is broken.
|
||||||
(double)timeout / 1000.0, 0, 0, 0, timeout_callback, &context);
|
// We need a way (probably thread?) to wait for USB data
|
||||||
CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopDefaultMode);
|
// while also accepting a timeout.
|
||||||
while (1) {
|
timeout_occurred = 1;
|
||||||
|
m_timer.start(timeout);
|
||||||
|
while (true) {
|
||||||
|
// CFRunLoopRun does not work properly with Qt's event loop...
|
||||||
CFRunLoopRun();
|
CFRunLoopRun();
|
||||||
|
printf(".");
|
||||||
|
delay::msleep(20);
|
||||||
if ((b = hid->first_buffer) != NULL) {
|
if ((b = hid->first_buffer) != NULL) {
|
||||||
if (len > b->len) len = b->len;
|
if (len > b->len) len = b->len;
|
||||||
memcpy(buf, b->buf, len);
|
memcpy(buf, b->buf, len);
|
||||||
hid->first_buffer = b->next;
|
hid->first_buffer = b->next;
|
||||||
free(b);
|
free(b);
|
||||||
ret = len;
|
ret = len;
|
||||||
|
// printf("got packet, exit waiting loop with %i bytes",ret);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!hid->open) {
|
if (!hid->open) {
|
||||||
@ -219,10 +236,12 @@ int pjrc_rawhid::receive(int num, void *buf, int len, int timeout)
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (timeout_occurred) break;
|
if (timeout_occurred) {
|
||||||
|
qDebug("Timeout while waiting for packet");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
CFRunLoopTimerInvalidate(timer);
|
m_timer.stop();
|
||||||
CFRelease(timer);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,10 +354,11 @@ static void input_callback(void *context, IOReturn ret, void *sender, IOHIDRepor
|
|||||||
buffer_t *n;
|
buffer_t *n;
|
||||||
hid_t *hid;
|
hid_t *hid;
|
||||||
|
|
||||||
printf("input_callback, report id: %i buf: %x %x, len: %d\n", id, data[0], data[1], len);
|
//printf("input_callback, ret: %i - report id: %i buf: %x %x, len: %d\n", ret, id, data[0], data[1], len);
|
||||||
if (ret != kIOReturnSuccess || len < 1) return;
|
if (ret != kIOReturnSuccess || len < 1) return;
|
||||||
hid = (hid_t*)context;
|
hid = (hid_t*)context;
|
||||||
if (!hid || hid->ref != sender) return;
|
if (!hid || hid->ref != sender) return;
|
||||||
|
printf("Processing packet");
|
||||||
n = (buffer_t *)malloc(sizeof(buffer_t));
|
n = (buffer_t *)malloc(sizeof(buffer_t));
|
||||||
if (!n) return;
|
if (!n) return;
|
||||||
if (len > BUFFER_SIZE) len = BUFFER_SIZE;
|
if (len > BUFFER_SIZE) len = BUFFER_SIZE;
|
||||||
@ -355,11 +375,10 @@ static void input_callback(void *context, IOReturn ret, void *sender, IOHIDRepor
|
|||||||
CFRunLoopStop(CFRunLoopGetCurrent());
|
CFRunLoopStop(CFRunLoopGetCurrent());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void timeout_callback(CFRunLoopTimerRef timer, void *info)
|
void pjrc_rawhid::timeout_callback()
|
||||||
{
|
{
|
||||||
printf("timeout_callback\n");
|
qDebug("[pjrc_rawhid_mac] timeout_callback");
|
||||||
*(int *)info = 1;
|
timeout_occurred = 1;
|
||||||
CFRunLoopStop(CFRunLoopGetCurrent());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_hid(hid_t *h)
|
static void add_hid(hid_t *h)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user