Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update hidapi to 0.15.0 #13

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions hid.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,22 @@ func (d *Device) SendFeatureReport(p []byte) (int, error) {
return int(res), nil
}

// SendOutputReport sends an output report with len(p) bytes to the Device.
// It returns the number of bytes written and an error, if any.
//
// The first byte must contain the report ID to send. Data will be sent over
// the control endpoint as a Set_Report transfer.
func (d *Device) SendOutputReport(p []byte) (int, error) {
data := (*C.uchar)(&p[0])
length := C.size_t(len(p))

res := C.hid_send_output_report(d.handle, data, length)
if res == -1 {
return int(res), wrapErr(d.Error())
}
return int(res), nil
}

// GetFeatureReport receives a feature report with len(p) bytes from the
// Device. It returns the number of bytes read and an error, if any.
//
Expand Down
38 changes: 22 additions & 16 deletions hid_darwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@

#include "hidapi_darwin.h"

/* As defined in AppKit.h, but we don't need the entire AppKit for a single constant. */
extern const double NSAppKitVersionNumber;

/* Barrier implementation because Mac OSX doesn't have pthread_barrier.
It also doesn't have clock_gettime(). So much for POSIX and SUSv2.
This implementation came from Brent Priddy and was posted on
Expand All @@ -57,15 +54,15 @@ static int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrie
{
(void) attr;

if(count == 0) {
if (count == 0) {
errno = EINVAL;
return -1;
}

if(pthread_mutex_init(&barrier->mutex, 0) < 0) {
if (pthread_mutex_init(&barrier->mutex, 0) < 0) {
return -1;
}
if(pthread_cond_init(&barrier->cond, 0) < 0) {
if (pthread_cond_init(&barrier->cond, 0) < 0) {
pthread_mutex_destroy(&barrier->mutex);
return -1;
}
Expand All @@ -86,16 +83,18 @@ static int pthread_barrier_wait(pthread_barrier_t *barrier)
{
pthread_mutex_lock(&barrier->mutex);
++(barrier->count);
if(barrier->count >= barrier->trip_count)
{
if (barrier->count >= barrier->trip_count) {
barrier->count = 0;
pthread_cond_broadcast(&barrier->cond);
pthread_mutex_unlock(&barrier->mutex);
pthread_cond_broadcast(&barrier->cond);
return 1;
}
else
{
pthread_cond_wait(&barrier->cond, &(barrier->mutex));
else {
do {
pthread_cond_wait(&barrier->cond, &(barrier->mutex));
}
while (barrier->count != 0);

pthread_mutex_unlock(&barrier->mutex);
return 0;
}
Expand Down Expand Up @@ -376,7 +375,7 @@ static int get_string_property(IOHIDDeviceRef device, CFStringRef prop, wchar_t

buf[0] = 0;

if (str) {
if (str && CFGetTypeID(str) == CFStringGetTypeID()) {
CFIndex str_len = CFStringGetLength(str);
CFRange range;
CFIndex used_buf_len;
Expand Down Expand Up @@ -466,7 +465,7 @@ int HID_API_EXPORT hid_init(void)
register_global_error(NULL);

if (!hid_mgr) {
is_macos_10_10_or_greater = (NSAppKitVersionNumber >= 1343); /* NSAppKitVersionNumber10_10 */
is_macos_10_10_or_greater = (kCFCoreFoundationVersionNumber >= 1151.16); /* kCFCoreFoundationVersionNumber10_10 */
hid_darwin_set_open_exclusive(1); /* Backward compatibility */
return init_hid_manager();
}
Expand Down Expand Up @@ -769,7 +768,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
}
cur_dev = tmp;

/* move the pointer to the tail of returnd list */
/* move the pointer to the tail of returned list */
while (cur_dev->next != NULL) {
cur_dev = cur_dev->next;
}
Expand Down Expand Up @@ -1188,7 +1187,9 @@ static int return_data(hid_device *dev, unsigned char *data, size_t length)
return buffer (data), and delete the liked list item. */
struct input_report *rpt = dev->input_reports;
size_t len = (length < rpt->len)? length: rpt->len;
memcpy(data, rpt->data, len);
if (data != NULL) {
memcpy(data, rpt->data, len);
}
dev->input_reports = rpt->next;
free(rpt->data);
free(rpt);
Expand Down Expand Up @@ -1340,6 +1341,11 @@ int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data,
return get_report(dev, kIOHIDReportTypeFeature, data, length);
}

int HID_API_EXPORT hid_send_output_report(hid_device *dev, const unsigned char *data, size_t length)
{
return set_report(dev, kIOHIDReportTypeOutput, data, length);
}

int HID_API_EXPORT HID_API_CALL hid_get_input_report(hid_device *dev, unsigned char *data, size_t length)
{
return get_report(dev, kIOHIDReportTypeInput, data, length);
Expand Down
Loading