MeshLib C++ Docs
Loading...
Searching...
No Matches
MRSpaceMouseDevice.h
Go to the documentation of this file.
1#pragma once
2#include "MRMesh/MRVector3.h"
3#include <bitset>
4#include <array>
5#include <vector>
6#include <unordered_map>
7#include <string>
8
9namespace MR::SpaceMouse
10{
11
12using VendorId = short unsigned int;
13using ProductId = short unsigned int;
14using DataPacketRaw = std::array<unsigned char, 13>;
15
58
61const std::unordered_map<VendorId, std::vector<ProductId>> cVendor2Device = {
62 { VendorId( 0x046d ), { // Logitech (3Dconnexion was a subsidiary)
63 0xc603, // SpaceMouse plus XT
64 0xc605, // cadman
65 0xc606, // SpaceMouse classic
66 0xc621, // spaceball 5000
67 0xc623, // space traveller
68 0xc625, // space pilot
69 0xc626, // Full-size SpaceNavigator
70 0xc627, // space explorer
71 0xc628, // SpaceNavigator for notebooks
72 0xc629, // space pilot pro
73 0xc62b, // space mouse pro
74 0xc640 // nulooq
75 }},
76 { VendorId( 0x256f ), { // 3Dconnexion
77 0xc62e, // SpaceMouse wireless (USB cable)
78 0xc62f, // SpaceMouse wireless receiver
79 0xc631, // SpaceMouse pro wireless (USB cable)
80 0xc632, // SpaceMouse pro wireless receiver
81 0xc633, // SpaceMouse enterprise
82 0xc635, // SpaceMouse compact
83 0xc638, // SpaceMouse Pro Wireless Bluetooth Edition (USB cable)
84 0xc63a, // SpaceMouse Wireless BT
85 0xc652, // Universal receiver
86 0xc658 // Wireless (3DConnexion Universal Wireless Receiver in WIN32)
87 }}
88};
89
90
91struct Action {
92 bool btnStateChanged = false;
93 std::bitset<size_t( Buttons::SMB_BUTTON_COUNT )> buttons = 0;
94 Vector3f translate = { 0.0f, 0.0f, 0.0f };
95 Vector3f rotate = { 0.0f, 0.0f, 0.0f };
96};
97
99class Device
100{
101public:
104
107
109 bool valid() const;
110
112 void parseRawEvent( const DataPacketRaw& raw, int numBytes, Action& action ) const;
113
116 void processAction( const Action& action );
117private:
118 VendorId vId_{ 0 };
119 ProductId pId_{ 0 };
120 std::bitset<size_t( Buttons::SMB_BUTTON_COUNT )> buttonsState_;
121
122 const std::vector<std::vector<Buttons>>* buttonsMapPtr_ = nullptr;
123
124 /* | <--- packet values --->
125 * #byte | 1 2
126 * ------+--------------------------
127 * 0 | - -
128 * 1 | custom_1 custom_2
129 */
130 std::vector<std::vector<Buttons>> buttonMapCompact = {
131 { }, // 0th byte (unused)
133 };
134
135 /* | <--- packet values --->
136 * #byte | 1 2 4 8 16 32 64 126
137 * ------+------------------------------------------------------------------
138 * 1 | menu fit T R F
139 * 2 | rot 1 2 3 4
140 * 3 | esc alt
141 * 4 | shift ctrl lock
142 *
143 */
144 std::vector<std::vector<Buttons>> buttonMapPro = {
145 { }, // 0th byte (unused)
146 //1 2 4 8 16 32 64 128
151 };
152
153 // @TODO !!! NOT TESTED !!!
154 std::vector<std::vector<Buttons>> buttonMapEnterprise = {
155 { }, // 0th byte (unused)
157 };
158 /* @TODO !!! NOT TESTED !!!
159 static constexpr int mapButtonsEnterprise[31] = {
160 SMB_MENU, SMB_FIT,
161 SMB_TOP, SMB_RIGHT, SMB_FRONT, SMB_ROLL_CW, SMB_LOCK_ROT,
162 SMB_ISO1, SMB_BTN_V1, SMB_BTN_V2, SMB_BTN_V3,
163 SMB_CUSTOM_1, SMB_CUSTOM_2, SMB_CUSTOM_3, SMB_CUSTOM_4, SMB_CUSTOM_5, SMB_CUSTOM_6,
164 SMB_CUSTOM_7, SMB_CUSTOM_8, SMB_CUSTOM_9, SMB_CUSTOM_10, SMB_CUSTOM_11, SMB_CUSTOM_12,
165 SMB_ESC, SMB_ENTER, SMB_ALT, SMB_SHIFT, SMB_CTRL, SMB_TAB, SMB_SPACE, SMB_DELETE
166 };
167 */
168};
169}
This class holds information and state of single SpaceMouse device.
Definition MRSpaceMouseDevice.h:100
void parseRawEvent(const DataPacketRaw &raw, int numBytes, Action &action) const
Parses data from raw packet to unified action
bool valid() const
Check if this device is set and valid.
void updateDevice(VendorId vId, ProductId pId)
Updates internal data by device ids (does nothing if ids is same for current device)
void resetDevice()
Invalidates this device and its state.
void processAction(const Action &action)
Definition MRSpaceMouseController.h:7
short unsigned int ProductId
Definition MRSpaceMouseDevice.h:13
Buttons
enumeration all spacemouse buttons
Definition MRSpaceMouseDevice.h:18
short unsigned int VendorId
Definition MRSpaceMouseDevice.h:12
const std::unordered_map< VendorId, std::vector< ProductId > > cVendor2Device
Definition MRSpaceMouseDevice.h:61
std::array< unsigned char, 13 > DataPacketRaw
Definition MRSpaceMouseDevice.h:14
Definition MRSpaceMouseDevice.h:91
std::bitset< size_t(Buttons::SMB_BUTTON_COUNT)> buttons
Definition MRSpaceMouseDevice.h:93
Vector3f translate
Definition MRSpaceMouseDevice.h:94
Vector3f rotate
Definition MRSpaceMouseDevice.h:95
bool btnStateChanged
Definition MRSpaceMouseDevice.h:92