Skip to content

Commit 8b44648

Browse files
remove hidapi lib in favor of SDL_hidapi
1 parent 47c992c commit 8b44648

35 files changed

+15
-7634
lines changed

code/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ TARGET_LINK_LIBRARIES(code PUBLIC jansson)
7676

7777
target_link_libraries(code PUBLIC anl)
7878

79-
target_link_libraries(code PUBLIC hidapi::hidapi)
80-
8179
target_link_libraries(code PUBLIC imgui)
8280

8381
IF(FSO_BUILD_WITH_OPENXR)

code/io/spacemouse.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#include "spacemouse.h"
22

3-
#include <hidapi.h>
4-
53
using namespace io::spacemouse;
64

75
#pragma pack(push,1)
@@ -43,7 +41,7 @@ void SpaceMouse::poll() {
4341
case SpaceMouseDefinition::Protocol::CONNEXION_3D_OLD: {
4442
static connexion_3d_old_protocol data;
4543

46-
bytes_read = hid_read(m_deviceHandle, reinterpret_cast<unsigned char*>(&data), sizeof(connexion_3d_old_protocol));
44+
bytes_read = SDL_hid_read(m_deviceHandle, reinterpret_cast<unsigned char*>(&data), sizeof(connexion_3d_old_protocol));
4745
if (bytes_read <= 0)
4846
continue;
4947

@@ -69,7 +67,7 @@ void SpaceMouse::poll() {
6967
case SpaceMouseDefinition::Protocol::CONNEXION_3D_NEW: {
7068
static connexion_3d_new_protocol data;
7169

72-
bytes_read = hid_read(m_deviceHandle, reinterpret_cast<unsigned char*>(&data), sizeof(connexion_3d_new_protocol));
70+
bytes_read = SDL_hid_read(m_deviceHandle, reinterpret_cast<unsigned char*>(&data), sizeof(connexion_3d_new_protocol));
7371
if (bytes_read <= 0)
7472
continue;
7573

@@ -106,14 +104,15 @@ void SpaceMouse::pollMaybe() {
106104
}
107105
}
108106

109-
SpaceMouse::SpaceMouse(const SpaceMouseDefinition& definition, hid_device* deviceHandle, int pollingFrequency)
107+
SpaceMouse::SpaceMouse(const SpaceMouseDefinition& definition, SDL_hid_device* deviceHandle, int pollingFrequency)
110108
: m_definition(definition), m_pollingFrequency(pollingFrequency), m_deviceHandle(deviceHandle),
111109
m_current({ ZERO_VECTOR, ZERO_ANGLES }), m_keypresses(definition.buttons, false), m_lastPolled(UI_TIMESTAMP::never()) {
112-
hid_set_nonblocking(m_deviceHandle, 1);
110+
SDL_hid_set_nonblocking(m_deviceHandle, 1);
113111
}
114112

115113
SpaceMouse::~SpaceMouse() {
116-
hid_close(m_deviceHandle);
114+
SDL_hid_close(m_deviceHandle);
115+
SDL_hid_exit();
117116
}
118117

119118
const SpaceMouseMovement& SpaceMouse::getMovement() {
@@ -146,14 +145,14 @@ const static SCP_vector<SpaceMouseDefinition> knownSpaceMice {
146145
std::unique_ptr<SpaceMouse> SpaceMouse::searchSpaceMice(int pollingFrequency) {
147146
std::unique_ptr<SpaceMouse> mouse = nullptr;
148147

149-
hid_device_info* devices = hid_enumerate(0, 0);
148+
auto devices = SDL_hid_enumerate(0, 0);
150149

151-
for (const hid_device_info* head = devices; head != nullptr && mouse == nullptr; head = head->next) {
150+
for (auto head = devices; head != nullptr && mouse == nullptr; head = head->next) {
152151
for (const SpaceMouseDefinition& mouseDef : knownSpaceMice) {
153152
if (mouseDef.vendorID != head->vendor_id || mouseDef.productID != head->product_id)
154153
continue;
155154

156-
hid_device* device = hid_open_path(head->path);
155+
auto device = SDL_hid_open_path(head->path);
157156

158157
if (device != nullptr) {
159158
mouse = std::unique_ptr<SpaceMouse>(new SpaceMouse(mouseDef, device, pollingFrequency));
@@ -162,7 +161,7 @@ std::unique_ptr<SpaceMouse> SpaceMouse::searchSpaceMice(int pollingFrequency) {
162161
}
163162
}
164163

165-
hid_free_enumeration(devices);
164+
SDL_hid_free_enumeration(devices);
166165

167166
return mouse;
168167
}
@@ -176,4 +175,4 @@ void SpaceMouseMovement::handleNonlinearities(std::array<std::tuple<float, float
176175
HANDLE_NONLINEARITY(rotation.p, 3);
177176
HANDLE_NONLINEARITY(rotation.b, 4);
178177
HANDLE_NONLINEARITY(rotation.h, 5);
179-
}
178+
}

code/io/spacemouse.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
#pragma once
22

3-
#include "globalincs/vmallocator.h"
3+
#include "globalincs/pstypes.h"
44
#include "math/vecmat.h"
55
#include "io/timer.h"
66

7-
struct hid_device_;
8-
typedef hid_device_ hid_device;
9-
107
namespace io
118
{
129
namespace spacemouse {
@@ -27,14 +24,14 @@ namespace io
2724
const SpaceMouseDefinition& m_definition;
2825
const int m_pollingFrequency;
2926

30-
hid_device* m_deviceHandle;
27+
SDL_hid_device* m_deviceHandle;
3128
SpaceMouseMovement m_current;
3229
SCP_vector<bool> m_keypresses;
3330
UI_TIMESTAMP m_lastPolled;
3431

3532
void poll();
3633
void pollMaybe();
37-
SpaceMouse(const SpaceMouseDefinition& definition, hid_device* deviceHandle, int pollingFrequency = 10);
34+
SpaceMouse(const SpaceMouseDefinition& definition, SDL_hid_device* deviceHandle, int pollingFrequency = 10);
3835
public:
3936
~SpaceMouse();
4037

@@ -59,4 +56,4 @@ namespace io
5956
static std::unique_ptr<SpaceMouse> searchSpaceMice(int pollingFrequency = 10);
6057
};
6158
}
62-
}
59+
}

lib/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ add_subdirectory(accidental-noise)
5151

5252
ADD_SUBDIRECTORY(lz4)
5353

54-
set(HIDAPI_WITH_LIBUSB OFF)
55-
set(HIDAPI_WITH_HIDRAW ON)
56-
add_subdirectory(hidapi)
57-
5854
ADD_SUBDIRECTORY(imgui)
5955

6056
if(FSO_BUILD_WITH_OPENXR)

lib/hidapi/AUTHORS.txt

Lines changed: 0 additions & 18 deletions
This file was deleted.

lib/hidapi/CMakeLists.txt

Lines changed: 0 additions & 61 deletions
This file was deleted.

lib/hidapi/LICENSE-orig.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.

lib/hidapi/VERSION

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)