opensurgsim
WdkHidDeviceHandle.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_DEVICES_MULTIAXIS_WIN32_WDKHIDDEVICEHANDLE_H
17 #define SURGSIM_DEVICES_MULTIAXIS_WIN32_WDKHIDDEVICEHANDLE_H
18 
19 #include <string>
20 #include <memory>
21 #include <array>
22 #include <vector>
23 
24 #include "SurgSim/Devices/MultiAxis/SystemInputDeviceHandle.h"
25 
26 
27 // The following structure is defined by the Windows HID API, but we don't want to include the whole thing here.
28 struct _HIDP_CAPS;
29 
30 
31 namespace SurgSim
32 {
33 namespace Framework
34 {
35 class Logger;
36 }; // namespace Framework
37 
38 namespace Devices
39 {
40 
44 {
45 public:
48 
52  static std::vector<std::string> enumeratePaths(SurgSim::Framework::Logger* logger);
53 
58  static std::unique_ptr<WdkHidDeviceHandle> open(const std::string& path,
59  std::shared_ptr<SurgSim::Framework::Logger> logger);
60 
61  std::string getDeviceName() const override;
62 
63  bool getDeviceIds(int* vendorId, int* productId) const override;
64 
65  bool hasTranslationAndRotationAxes() const override;
66 
67  bool updateStates(AxisStates* axisStates, ButtonStates* buttonStates, bool* updated) override;
68 
69  void prepareForShutdown() override;
70 
71 private:
75  explicit WdkHidDeviceHandle(std::shared_ptr<SurgSim::Framework::Logger>&& logger);
76 
77  // Prevent copy construction and copy assignment. (VS2012 does not support "= delete" yet.)
78  WdkHidDeviceHandle(const WdkHidDeviceHandle& other) /*= delete*/;
79  WdkHidDeviceHandle& operator=(const WdkHidDeviceHandle& other) /*= delete*/;
80 
84  bool getCapabilities(struct _HIDP_CAPS* capabilities) const;
85 
89  bool startAsynchronousRead();
90 
96  bool finishAsynchronousRead(size_t* numBytesRead);
97 
100  void cancelAsynchronousRead();
101 
109  void decodeStateUpdates(const unsigned char* rawData, size_t rawDataSize,
110  AxisStates* axisStates, ButtonStates* buttonStates, bool* updated);
111 
112 
113  struct State;
114  std::unique_ptr<State> m_state;
115 };
116 
117 }; // namespace Devices
118 }; // namespace SurgSim
119 
120 #endif // SURGSIM_DEVICES_MULTIAXIS_WIN32_WDKHIDDEVICEHANDLE_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
std::array< bool, MAX_NUM_BUTTONS > ButtonStates
Type used to store button states.
Definition: SystemInputDeviceHandle.h:41
An object that can be used to control logging parameters, such as verbosity and log output destinatio...
Definition: Logger.h:51
Definition: WdkHidDeviceHandle.cpp:61
A wrapper for system-dependent access to an input/HID device.
Definition: SystemInputDeviceHandle.h:30
Access to an input/HID device using the HID API from the Windows Driver Kit.
Definition: WdkHidDeviceHandle.h:43
std::array< int, MAX_NUM_AXES > AxisStates
Type used to store axis states.
Definition: SystemInputDeviceHandle.h:39