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( std::function<void(const std::string&)> deviceSignal ) override;
35 void handle() override;
36
37 // set state of zoom by mouse scroll (to fix scroll signal from SpaceMouse driver)
38 MRVIEWER_API void activateMouseScrollZoom( bool activeMouseScrollZoom );
39 // get state of zoom by mouse scroll
40 MRVIEWER_API bool isMouseScrollZoomActive()
41 {
42 return activeMouseScrollZoom_;
43 }
44
45private:
46 void initListenerThread_();
47 virtual void postFocus_( bool focused ) override;
48
49 void processAction_( const Action& action );
50
51 // update (rewrite its data) SpaceMouseAction if DataPacketRaw is not empty
52 void updateActionWithInput_( const DataPacketRaw& packet, int packet_length, Action& action );
53
54 bool findAndAttachDevice_( bool verbose );
55
56private:
57 std::function<void(const std::string&)> deviceSignal_;
58 hid_device* device_ = nullptr;
59 std::unique_ptr<Device> smDevice_;
60 size_t numMsg_ = 0;
61 std::thread listenerThread_;
62 std::atomic_bool terminateListenerThread_{ false };
63 std::mutex syncThreadMutex_; // which thread reads and handles SpaceMouse data
64 std::condition_variable cv_; // notify on thread change
65 DataPacketRaw dataPacket_; // packet from listener thread
66 int packetLength_ = 0;
67 std::atomic_bool active_{ false };
68 bool activeMouseScrollZoom_ = false;
69};
70
71}
72#endif
Definition MRSpaceMouseHandlerHidapi.h:29
void handle() override
handle device state and call Viewer signals
MRVIEWER_API bool isMouseScrollZoomActive()
Definition MRSpaceMouseHandlerHidapi.h:40
MRVIEWER_API void activateMouseScrollZoom(bool activeMouseScrollZoom)
bool initialize(std::function< void(const std::string &)> deviceSignal) override
base class for handler of spacemouse devices
Definition MRSpaceMouseHandler.h:12
Definition MRSpaceMouseController.h:7
std::array< unsigned char, 13 > DataPacketRaw
Definition MRSpaceMouseDevice.h:14
class to subscribe on PostFocusSingal
Definition MRViewerEventsListener.h:397
Definition MRSpaceMouseDevice.h:91