11#include " spacemouse.h"
22
3- #include < hidapi.h>
4-
53using 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
115113SpaceMouse::~SpaceMouse () {
116- hid_close (m_deviceHandle);
114+ SDL_hid_close (m_deviceHandle);
115+ SDL_hid_exit ();
117116}
118117
119118const SpaceMouseMovement& SpaceMouse::getMovement () {
@@ -146,14 +145,14 @@ const static SCP_vector<SpaceMouseDefinition> knownSpaceMice {
146145std::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+ }
0 commit comments