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 ), {
63 0xc603,
64 0xc605,
65 0xc606,
66 0xc621,
67 0xc623,
68 0xc625,
69 0xc626,
70 0xc627,
71 0xc628,
72 0xc629,
73 0xc62b,
74 0xc640
75 }},
76 { VendorId( 0x256f ), {
77 0xc62e,
78 0xc62f,
79 0xc631,
80 0xc632,
81 0xc633,
82 0xc635,
83 0xc638,
84 0xc63a,
85 0xc652,
86 0xc658
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
130 std::vector<std::vector<Buttons>> buttonMapCompact = {
131 { },
133 };
134
144 std::vector<std::vector<Buttons>> buttonMapPro = {
145 { },
151 };
152
154 std::vector<std::vector<Buttons>> buttonMapEnterprise = {
155 { },
157 };
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
@ SMB_LOCK_ROT
roll clockwise
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