MeshLib C++ Docs
Loading...
Searching...
No Matches
MRSpaceMouseHandlerHidapi.h
Go to the documentation of this file.
1#pragma once
2#ifndef __EMSCRIPTEN__
6#include "MRMesh/MRVector.h"
7
8#include <hidapi/hidapi.h>
9
10#include <atomic>
11#include <bitset>
12#include <condition_variable>
13#include <mutex>
14#include <thread>
15#include <unordered_map>
16
17#ifdef __APPLE__
18#include <hidapi/hidapi_darwin.h>
19#endif
20#ifdef _WIN32
21#include "MRPch/MRWinapi.h"
22#include <hidapi/hidapi_winapi.h>
23#endif
24
25namespace MR::SpaceMouse
26{
27
28class MRVIEWER_CLASS HandlerHidapi : public Handler, public PostFocusListener
29{
30public:
32 ~HandlerHidapi() override;
33
34 bool initialize() override;
35 void handle() override;
36
38 MRVIEWER_API bool hasValidDeviceConnected() const;
39
40private:
41 void initListenerThread_();
42 virtual void postFocus_( bool focused ) override;
43
44 void processAction_( const Action& action );
45
46 bool findAndAttachDevice_( bool verbose );
47
48private:
49 hid_device* device_ = nullptr;
50
51 class AtomicDevice
52 {
53 public:
54 void resetDevice( VendorId vId = 0, ProductId pId = 0 );
55
57 void parseRaw( const DataPacketRaw& packet, int packet_length, Action& action ) const;
58
59 void process( const Action& action );
60 bool valid() const;
61 private:
62 mutable std::mutex mutex_;
63 std::unique_ptr<Device> device_;
64 } smDevice_;
65
66 size_t numMsg_ = 0;
67 std::thread listenerThread_;
68 std::atomic_bool terminateListenerThread_{ false };
69 std::mutex syncThreadMutex_;
70 std::condition_variable cv_;
71 DataPacketRaw dataPacket_;
72 int packetLength_ = 0;
73 std::atomic_bool active_{ false };
74};
75
76}
77#endif
Definition MRSpaceMouseHandlerHidapi.h:29
void handle() override
handle device state and call Viewer signals
MRVIEWER_API bool hasValidDeviceConnected() const
returns true if this handler has connected device
bool initialize() override
initialize device
base class for handler of spacemouse devices
Definition MRSpaceMouseHandler.h:12
Definition MRSpaceMouseController.h:7
short unsigned int ProductId
Definition MRSpaceMouseDevice.h:13
short unsigned int VendorId
Definition MRSpaceMouseDevice.h:12
std::array< unsigned char, 13 > DataPacketRaw
Definition MRSpaceMouseDevice.h:14
class to subscribe on PostFocusSingal
Definition MRViewerEventsListener.h:400
Definition MRSpaceMouseDevice.h:91