Skip to content

Commit 240ad8f

Browse files
authored
Merge pull request #1 from ltjax/do_not_expose_hid_api
Do not expose hid api
2 parents 9af7e3a + 0efc069 commit 240ad8f

File tree

9 files changed

+124
-201
lines changed

9 files changed

+124
-201
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ conan remote add ltjax https://api.bintray.com/conan/ltjax/conan
2222

2323
Then you can add the dependency via
2424
```
25-
steam_controller/1.0@ltjax/stable
25+
steam_controller/1.1@ltjax/stable
2626
```
2727

2828
# How to use

conanfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class SteamControllerConan(ConanFile):
55
name = "steam_controller"
6-
version = "1.0"
6+
version = "1.1"
77
license = "MIT"
88
author = "Marius Elvert [email protected]"
99
url = "https://github.com/ltjax/steam_controller"

externals/hidapi/hid_common.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include "hidapi.h"
4+
5+
HID_API_NAMESPACE_BEGIN
6+
7+
void HID_API_EXPORT hid_free_enumeration(struct hid_device_info* devs)
8+
{
9+
struct hid_device_info* d = devs;
10+
while (d) {
11+
struct hid_device_info* next = d->next;
12+
free(d->path);
13+
free(d->serial_number);
14+
free(d->manufacturer_string);
15+
free(d->product_string);
16+
free(d);
17+
d = next;
18+
}
19+
}
20+
21+
hid_device* hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t* serial_number)
22+
{
23+
struct hid_device_info* devs, * cur_dev;
24+
const char* path_to_open = NULL;
25+
hid_device* handle = NULL;
26+
27+
devs = hid_enumerate(vendor_id, product_id);
28+
cur_dev = devs;
29+
while (cur_dev) {
30+
if (cur_dev->vendor_id == vendor_id &&
31+
cur_dev->product_id == product_id) {
32+
if (serial_number) {
33+
if (wcscmp(serial_number, cur_dev->serial_number) == 0) {
34+
path_to_open = cur_dev->path;
35+
break;
36+
}
37+
}
38+
else {
39+
path_to_open = cur_dev->path;
40+
break;
41+
}
42+
}
43+
cur_dev = cur_dev->next;
44+
}
45+
46+
if (path_to_open) {
47+
/* Open the device */
48+
handle = hid_open_path(path_to_open);
49+
}
50+
51+
hid_free_enumeration(devs);
52+
53+
return handle;
54+
}
55+
56+
HID_API_NAMESPACE_END

externals/hidapi/include/hidapi/hidapi.h

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,17 @@
2929

3030
#include <wchar.h>
3131

32-
#ifdef _WIN32
32+
#ifdef APPLE
33+
#include <IOKit/hid/IOHIDManager.h>
34+
#include <IOKit/hid/IOHIDKeys.h>
35+
#include <CoreFoundation/CoreFoundation.h>
36+
#endif
37+
38+
#ifdef WIN32
39+
#include <windows.h>
40+
#endif
41+
42+
#ifdef WIN32
3343
#define HID_API_EXPORT __declspec(dllexport)
3444
#define HID_API_CALL
3545
#else
@@ -39,9 +49,15 @@
3949

4050
#define HID_API_EXPORT_CALL HID_API_EXPORT HID_API_CALL /**< API export and call macro*/
4151

42-
#ifdef __cplusplus
43-
extern "C" {
52+
#ifndef HID_API_NAMESPACE_BEGIN
53+
#error HID_API_NAMESPACE_BEGIN not defined
4454
#endif
55+
56+
#ifndef HID_API_NAMESPACE_END
57+
#error HID_API_NAMESPACE_END not defined
58+
#endif
59+
60+
HID_API_NAMESPACE_BEGIN
4561
struct hid_device_;
4662
typedef struct hid_device_ hid_device; /**< opaque hidapi structure */
4763
typedef void* hid_handle_t;
@@ -421,22 +437,14 @@ extern "C" {
421437

422438

423439
#ifdef APPLE
424-
425-
#include <IOKit/hid/IOHIDManager.h>
426-
#include <IOKit/hid/IOHIDKeys.h>
427-
#include <CoreFoundation/CoreFoundation.h>
428-
429440
int HID_API_EXPORT HID_API_CALL hid_dump_element_info(hid_device *dev);
430441
IOHIDDeviceRef HID_API_EXPORT HID_API_CALL get_device_handle( hid_device *dev );
431442
#endif
432443
#ifdef WIN32
433-
#include <windows.h>
434444
HANDLE HID_API_EXPORT HID_API_CALL get_device_handle(hid_device *dev);
435445
#endif
436446

437-
#ifdef __cplusplus
438-
}
439-
#endif
447+
HID_API_NAMESPACE_END
440448

441449
#endif
442450

externals/hidapi/linux/hid.c renamed to externals/hidapi/linux/hid.cpp

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545

4646
#include "hidapi.h"
4747

48+
HID_API_NAMESPACE_BEGIN
49+
4850
/* Definitions from linux/hidraw.h. Since these are new, some distros
4951
may not have header files which contain them. */
5052
#ifndef HIDIOCSFEATURE
@@ -103,7 +105,7 @@ static __u32 detect_kernel_version(void)
103105

104106
static hid_device *new_hid_device(void)
105107
{
106-
hid_device *dev = calloc(1, sizeof(hid_device));
108+
hid_device *dev = reinterpret_cast<hid_device*>(calloc(1, sizeof(hid_device)));
107109
dev->device_handle = -1;
108110
dev->blocking = 1;
109111
dev->uses_numbered_reports = 0;
@@ -122,7 +124,7 @@ static wchar_t *utf8_to_wchar_t(const char *utf8)
122124
if ((size_t) -1 == wlen) {
123125
return wcsdup(L"");
124126
}
125-
ret = calloc(wlen+1, sizeof(wchar_t));
127+
ret = reinterpret_cast<wchar_t*>(calloc(wlen+1, sizeof(wchar_t)));
126128
mbstowcs(ret, utf8, wlen+1);
127129
ret[wlen] = 0x0000;
128130
}
@@ -461,7 +463,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
461463
struct hid_device_info *tmp;
462464

463465
/* VID/PID match. Create the record. */
464-
tmp = malloc(sizeof(struct hid_device_info));
466+
tmp = reinterpret_cast<hid_device_info*>(malloc(sizeof(struct hid_device_info)));
465467
if (cur_dev) {
466468
cur_dev->next = tmp;
467469
}
@@ -568,55 +570,6 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
568570
return root;
569571
}
570572

571-
void HID_API_EXPORT hid_free_enumeration(struct hid_device_info *devs)
572-
{
573-
struct hid_device_info *d = devs;
574-
while (d) {
575-
struct hid_device_info *next = d->next;
576-
free(d->path);
577-
free(d->serial_number);
578-
free(d->manufacturer_string);
579-
free(d->product_string);
580-
free(d);
581-
d = next;
582-
}
583-
}
584-
585-
hid_device * hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)
586-
{
587-
struct hid_device_info *devs, *cur_dev;
588-
const char *path_to_open = NULL;
589-
hid_device *handle = NULL;
590-
591-
devs = hid_enumerate(vendor_id, product_id);
592-
cur_dev = devs;
593-
while (cur_dev) {
594-
if (cur_dev->vendor_id == vendor_id &&
595-
cur_dev->product_id == product_id) {
596-
if (serial_number) {
597-
if (wcscmp(serial_number, cur_dev->serial_number) == 0) {
598-
path_to_open = cur_dev->path;
599-
break;
600-
}
601-
}
602-
else {
603-
path_to_open = cur_dev->path;
604-
break;
605-
}
606-
}
607-
cur_dev = cur_dev->next;
608-
}
609-
610-
if (path_to_open) {
611-
/* Open the device */
612-
handle = hid_open_path(path_to_open);
613-
}
614-
615-
hid_free_enumeration(devs);
616-
617-
return handle;
618-
}
619-
620573
hid_device * HID_API_EXPORT hid_open_path(const char *path)
621574
{
622575
hid_device *dev = NULL;
@@ -795,3 +748,5 @@ HID_API_EXPORT const wchar_t * HID_API_CALL hid_error(hid_device *dev)
795748
{
796749
return NULL;
797750
}
751+
752+
HID_API_NAMESPACE_END

0 commit comments

Comments
 (0)