WdkHidDeviceHandle.h
Go to the documentation of this file.
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 
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 Device
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  virtual std::string getDeviceName() const override;
62 
63  virtual bool getDeviceIds(int* vendorId, int* productId) const override;
64 
65  virtual bool hasTranslationAndRotationAxes() const override;
66 
67  virtual bool updateStates(AxisStates* axisStates, ButtonStates* buttonStates, bool* updated) override;
68 
69  virtual 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 Device
118 }; // namespace SurgSim
119 
120 #endif // SURGSIM_DEVICES_MULTIAXIS_WIN32_WDKHIDDEVICEHANDLE_H
Definition: DriveElementFromInputBehavior.cpp:27
Access to an input/HID device using the HID API from the Windows Driver Kit.
Definition: WdkHidDeviceHandle.h:43
WdkHidDeviceHandle & operator=(const WdkHidDeviceHandle &other)
WdkHidDeviceHandle(std::shared_ptr< SurgSim::Framework::Logger > &&logger)
Constructor.
Definition: WdkHidDeviceHandle.cpp:91
virtual bool updateStates(AxisStates *axisStates, ButtonStates *buttonStates, bool *updated) override
Updates the axis and states from the device input, if any.
Definition: WdkHidDeviceHandle.cpp:429
bool startAsynchronousRead()
Starts an asynchronous read from the device.
Definition: WdkHidDeviceHandle.cpp:315
virtual void prepareForShutdown() override
Prepares the handle for sampling thread shutdown.
Definition: WdkHidDeviceHandle.cpp:496
~WdkHidDeviceHandle()
Destructor.
Definition: WdkHidDeviceHandle.cpp:96
void cancelAsynchronousRead()
Cancels an asynchronous read from the device.
Definition: WdkHidDeviceHandle.cpp:385
virtual std::string getDeviceName() const override
Gets the name returned by the operating system for this device.
Definition: WdkHidDeviceHandle.cpp:212
std::array< int, MAX_NUM_AXES > AxisStates
Type used to store axis states.
Definition: SystemInputDeviceHandle.h:39
std::unique_ptr< State > m_state
Definition: WdkHidDeviceHandle.h:113
virtual bool hasTranslationAndRotationAxes() const override
Queries if this device has 3 translation and 3 rotation axes.
Definition: WdkHidDeviceHandle.cpp:284
bool finishAsynchronousRead(size_t *numBytesRead)
Checks if an asynchronous read from the device has completed.
Definition: WdkHidDeviceHandle.cpp:350
An object that can be used to control logging parameters, such as verbosity and log output destinatio...
Definition: Logger.h:51
void decodeStateUpdates(const unsigned char *rawData, size_t rawDataSize, AxisStates *axisStates, ButtonStates *buttonStates, bool *updated)
Decode the raw state update data received from the device.
Definition: WdkHidDeviceHandle.cpp:513
std::array< bool, MAX_NUM_BUTTONS > ButtonStates
Type used to store button states.
Definition: SystemInputDeviceHandle.h:41
static std::vector< std::string > enumeratePaths(SurgSim::Framework::Logger *logger)
Enumerates input devices.
Definition: WdkHidDeviceHandle.cpp:100
A wrapper for system-dependent access to an input/HID device.
Definition: SystemInputDeviceHandle.h:30
static std::unique_ptr< WdkHidDeviceHandle > open(const std::string &path, std::shared_ptr< SurgSim::Framework::Logger > logger)
Opens the given path and creates an access wrapper for the device.
Definition: WdkHidDeviceHandle.cpp:184
bool getCapabilities(struct _HIDP_CAPS *capabilities) const
Gets the device capabilities.
Definition: WdkHidDeviceHandle.cpp:260
virtual bool getDeviceIds(int *vendorId, int *productId) const override
Gets the device identifiers.
Definition: WdkHidDeviceHandle.cpp:242
Definition: WdkHidDeviceHandle.cpp:61