WdkHidDeviceHandle.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_DEVICES_MULTIAXIS_WIN32_WDKHIDDEVICEHANDLE_H
#define SURGSIM_DEVICES_MULTIAXIS_WIN32_WDKHIDDEVICEHANDLE_H
#include <string>
#include <memory>
#include <array>
#include <vector>
#include "SurgSim/Devices/MultiAxis/SystemInputDeviceHandle.h"
// The following structure is defined by the Windows HID API, but we don't want to include the whole thing here.
struct _HIDP_CAPS;
namespace SurgSim
{
namespace Framework
{
class Logger;
}; // namespace Framework
namespace Devices
{
class WdkHidDeviceHandle : public SystemInputDeviceHandle
{
public:
~WdkHidDeviceHandle();
static std::vector<std::string> enumeratePaths(SurgSim::Framework::Logger* logger);
static std::unique_ptr<WdkHidDeviceHandle> open(const std::string& path,
std::shared_ptr<SurgSim::Framework::Logger> logger);
std::string getDeviceName() const override;
bool getDeviceIds(int* vendorId, int* productId) const override;
bool hasTranslationAndRotationAxes() const override;
bool updateStates(AxisStates* axisStates, ButtonStates* buttonStates, bool* updated) override;
void prepareForShutdown() override;
private:
explicit WdkHidDeviceHandle(std::shared_ptr<SurgSim::Framework::Logger>&& logger);
// Prevent copy construction and copy assignment. (VS2012 does not support "= delete" yet.)
WdkHidDeviceHandle(const WdkHidDeviceHandle& other) /*= delete*/;
WdkHidDeviceHandle& operator=(const WdkHidDeviceHandle& other) /*= delete*/;
bool getCapabilities(struct _HIDP_CAPS* capabilities) const;
bool startAsynchronousRead();
bool finishAsynchronousRead(size_t* numBytesRead);
void cancelAsynchronousRead();
void decodeStateUpdates(const unsigned char* rawData, size_t rawDataSize,
AxisStates* axisStates, ButtonStates* buttonStates, bool* updated);
struct State;
std::unique_ptr<State> m_state;
};
}; // namespace Devices
}; // namespace SurgSim
#endif // SURGSIM_DEVICES_MULTIAXIS_WIN32_WDKHIDDEVICEHANDLE_H
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Devices::SystemInputDeviceHandle::ButtonStates
std::array< bool, MAX_NUM_BUTTONS > ButtonStates
Type used to store button states.
Definition: SystemInputDeviceHandle.h:41
SurgSim::Framework::Logger
An object that can be used to control logging parameters, such as verbosity and log output destinatio...
Definition: Logger.h:51
SurgSim::Devices::WdkHidDeviceHandle::State
Definition: WdkHidDeviceHandle.cpp:61
SurgSim::Devices::SystemInputDeviceHandle
A wrapper for system-dependent access to an input/HID device.
Definition: SystemInputDeviceHandle.h:30
SurgSim::Devices::WdkHidDeviceHandle::m_state
std::unique_ptr< State > m_state
Definition: WdkHidDeviceHandle.h:113
SystemInputDeviceHandle.h
SurgSim::Devices::WdkHidDeviceHandle
Access to an input/HID device using the HID API from the Windows Driver Kit.
Definition: WdkHidDeviceHandle.h:43
SurgSim::Devices::SystemInputDeviceHandle::AxisStates
std::array< int, MAX_NUM_AXES > AxisStates
Type used to store axis states.
Definition: SystemInputDeviceHandle.h:39