7#include <hidapi/hidapi.h>
11#include <condition_variable>
14#include <unordered_map>
17#include <hidapi/hidapi_darwin.h>
21#include <hidapi/hidapi_winapi.h>
28 typedef std::array<unsigned char, 13> DataPacketRaw;
29 typedef short unsigned int VendorId;
30 typedef short unsigned int ProductId;
31 struct SpaceMouseAction {
32 bool isButtonStateChanged =
false;
33 std::bitset<SMB_BUTTON_COUNT> buttons = 0;
34 Vector3f translate = { 0.0f, 0.0f, 0.0f };
35 Vector3f rotate = { 0.0f, 0.0f, 0.0f };
49 return activeMouseScrollZoom_;
53 void initListenerThread_();
54 void setButtonsMap_( VendorId vendorId, ProductId productId );
55 virtual void postFocus_(
bool focused )
override;
57 void processAction_(
const SpaceMouseAction& action );
58 float convertCoord_(
int coord_byte_low,
int coord_byte_high );
61 void updateActionWithInput_(
const DataPacketRaw& packet,
int packet_length, SpaceMouseAction& action );
63 bool findAndAttachDevice_(
bool verbose );
64 void printDevices_(
struct hid_device_info* cur_dev );
67 hid_device* device_ =
nullptr;
68 const std::vector<std::vector<SpaceMouseButtons>>* buttonsMapPtr_ =
nullptr;
69 std::bitset<SMB_BUTTON_COUNT> buttonsState_;
70 std::thread listenerThread_;
71 std::atomic_bool terminateListenerThread_{
false };
72 std::mutex syncThreadMutex_;
73 std::condition_variable cv_;
74 DataPacketRaw dataPacket_;
75 int packetLength_ = 0;
76 std::atomic_bool active_{
false };
77 bool activeMouseScrollZoom_ =
false;
80 const std::unordered_map<VendorId, std::vector<ProductId>> vendor2device_ = {
114 std::vector<std::vector<SpaceMouseButtons>> buttonMapCompact = {
128 std::vector<std::vector<SpaceMouseButtons>> buttonMapPro = {
138 std::vector<std::vector<SpaceMouseButtons>> buttonMapEnterprise = {
Definition MRSpaceMouseHandlerHidapi.h:27
MRVIEWER_API bool isMouseScrollZoomActive()
Definition MRSpaceMouseHandlerHidapi.h:47
MRVIEWER_API void activateMouseScrollZoom(bool activeMouseScrollZoom)
SpaceMouseHandlerHidapi()
bool initialize() override
initialize device
void handle() override
handle device state and call Viewer signals
~SpaceMouseHandlerHidapi() override
class to handle spacemouse
Definition MRSpaceMouseHandler.h:55
Definition MRCameraOrientationPlugin.h:8
@ SMB_SHIFT
Definition MRSpaceMouseHandler.h:18
@ SMB_ALT
Definition MRSpaceMouseHandler.h:20
@ SMB_FIT
Definition MRSpaceMouseHandler.h:37
@ SMB_RIGHT
Definition MRSpaceMouseHandler.h:39
@ SMB_MENU
Definition MRSpaceMouseHandler.h:13
@ SMB_ROLL_CW
Definition MRSpaceMouseHandler.h:41
@ SMB_NO
Definition MRSpaceMouseHandler.h:12
@ SMB_CUSTOM_1
Definition MRSpaceMouseHandler.h:24
@ SMB_CUSTOM_3
Definition MRSpaceMouseHandler.h:26
@ SMB_CUSTOM_2
Definition MRSpaceMouseHandler.h:25
@ SMB_FRONT
Definition MRSpaceMouseHandler.h:40
@ SMB_ESC
Definition MRSpaceMouseHandler.h:15
@ SMB_TOP
Definition MRSpaceMouseHandler.h:38
@ SMB_CUSTOM_4
Definition MRSpaceMouseHandler.h:27
@ SMB_LOCK_ROT
Definition MRSpaceMouseHandler.h:42
@ SMB_CTRL
Definition MRSpaceMouseHandler.h:19
class to subscribe on PostFocusSingal
Definition MRViewerEventsListener.h:370