1#ifndef SDL3PP_HIDAPI_H_
2#define SDL3PP_HIDAPI_H_
4#include <SDL3/SDL_hidapi.h>
5#include "SDL3pp_error.h"
6#include "SDL3pp_properties.h"
7#include "SDL3pp_stdinc.h"
68 constexpr explicit operator bool()
const {
return !!
value; }
85 SDL_HID_API_BUS_UNKNOWN;
150 : m_resource(resource)
185 unsigned short product_id,
186 const wchar_t* serial_number)
187 : m_resource(
CheckError(SDL_hid_open(vendor_id, product_id, serial_number)))
203 : m_resource(
CheckError(SDL_hid_open_path(path)))
213 std::swap(m_resource, other.m_resource);
229 m_resource =
nullptr;
237 constexpr explicit operator bool() const noexcept {
return !!m_resource; }
251#if SDL_VERSION_ATLEAST(3, 4, 0)
570 return SDL_hid_device_change_count();
600 unsigned short product_id)
602 return CheckError(SDL_hid_enumerate(vendor_id, product_id));
616 SDL_hid_free_enumeration(devs);
636 unsigned short product_id,
637 const wchar_t* serial_number)
639 return HidDevice(vendor_id, product_id, serial_number);
659#if SDL_VERSION_ATLEAST(3, 4, 0)
677 return CheckError(SDL_hid_get_properties(dev));
685namespace prop::Hidapi {
687constexpr auto LIBUSB_DEVICE_HANDLE_POINTER =
688 SDL_PROP_HIDAPI_LIBUSB_DEVICE_HANDLE_POINTER;
746 return SDL_hid_read_timeout(
828 return SDL_hid_send_feature_report(
858 return SDL_hid_get_feature_report(
888 return SDL_hid_get_input_report(
926 CheckErrorIfNot(SDL_hid_get_manufacturer_string(dev,
string, maxlen), 0);
970 CheckErrorIfNot(SDL_hid_get_serial_number_string(dev,
string, maxlen), 0);
994 CheckErrorIfNot(SDL_hid_get_indexed_string(dev, string_index,
string, maxlen),
1018 return CheckError(SDL_hid_get_device_info(dev));
1041 return SDL_hid_get_report_descriptor(
An opaque handle representing an open HID device.
Definition: SDL3pp_hidapi.h:132
constexpr auto operator<=>(const HidDevice &other) const noexcept=default
Comparison.
constexpr HidDeviceRaw release() noexcept
Retrieves underlying HidDeviceRaw and clear this.
Definition: SDL3pp_hidapi.h:226
HidDevice(StringParam path)
Open a HID device by its path name.
Definition: SDL3pp_hidapi.h:202
HidDevice(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)
Open a HID device using a Vendor ID (VID), Product ID (PID) and optionally a serial number.
Definition: SDL3pp_hidapi.h:184
constexpr HidDevice(const HidDeviceRaw resource) noexcept
Constructs from HidDeviceParam.
Definition: SDL3pp_hidapi.h:149
constexpr HidDeviceRaw get() const noexcept
Retrieves underlying HidDeviceRaw.
Definition: SDL3pp_hidapi.h:223
~HidDevice()
Destructor.
Definition: SDL3pp_hidapi.h:208
constexpr HidDevice(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition: SDL3pp_hidapi.h:137
constexpr HidDevice & operator=(HidDevice &&other) noexcept
Assignment operator.
Definition: SDL3pp_hidapi.h:211
constexpr HidDevice(HidDevice &&other) noexcept
Move constructor.
Definition: SDL3pp_hidapi.h:160
constexpr HidDevice(const HidDevice &other) noexcept=default
Copy constructor.
constexpr HidDevice & operator=(const HidDevice &other) noexcept=default
Assignment operator.
Source byte stream.
Definition: SDL3pp_strings.h:240
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition: SDL3pp_strings.h:304
constexpr const T * data_as() const
Retrieves contained data.
Definition: SDL3pp_strings.h:314
Helpers to use C++ strings parameters.
Definition: SDL3pp_strings.h:43
Target byte stream.
Definition: SDL3pp_strings.h:326
constexpr T * data_as() const
Retrieves contained data.
Definition: SDL3pp_strings.h:416
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition: SDL3pp_strings.h:409
constexpr void CheckErrorIfNot(T result, T validValue)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:244
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:197
int hid_get_feature_report(HidDeviceParam dev, TargetBytes data)
Get a feature report from a HID device.
Definition: SDL3pp_hidapi.h:856
void hid_close(HidDeviceRaw dev)
Close a HID device.
Definition: SDL3pp_hidapi.h:905
void get_manufacturer_string(wchar_t *string, size_t maxlen)
Get The Manufacturer String from a HID device.
Definition: SDL3pp_hidapi.h:929
PropertiesRef hid_get_properties()
Get the properties associated with an HidDevice.
Definition: SDL3pp_hidapi.h:680
SDL_hid_bus_type hid_bus_type
HID underlying bus types.
Definition: SDL3pp_hidapi.h:82
SDL_hid_device * HidDeviceRaw
Alias to raw representation for HidDevice.
Definition: SDL3pp_hidapi.h:45
hid_device_info * hid_get_device_info(HidDeviceParam dev)
Get the device info from a HID device.
Definition: SDL3pp_hidapi.h:1016
void set_nonblocking(bool nonblock)
Set the device handle to be non-blocking.
Definition: SDL3pp_hidapi.h:801
hid_device_info * hid_enumerate(unsigned short vendor_id, unsigned short product_id)
Enumerate the HID Devices.
Definition: SDL3pp_hidapi.h:599
int get_feature_report(TargetBytes data)
Get a feature report from a HID device.
Definition: SDL3pp_hidapi.h:862
int read(TargetBytes data)
Read an Input report from a HID device.
Definition: SDL3pp_hidapi.h:775
SDL_hid_device_info hid_device_info
Information about a connected HID device.
Definition: SDL3pp_hidapi.h:122
hid_device_info * get_device_info()
Get the device info from a HID device.
Definition: SDL3pp_hidapi.h:1021
constexpr hid_bus_type HID_API_BUS_I2C
I2C bus Specifications:
Definition: SDL3pp_hidapi.h:108
int hid_get_report_descriptor(HidDeviceParam dev, TargetBytes buf)
Get a report descriptor from a HID device.
Definition: SDL3pp_hidapi.h:1039
void hid_exit()
Finalize the HIDAPI library.
Definition: SDL3pp_hidapi.h:547
void get_product_string(wchar_t *string, size_t maxlen)
Get The Product String from a HID device.
Definition: SDL3pp_hidapi.h:951
int send_feature_report(SourceBytes data)
Send a Feature report to the device.
Definition: SDL3pp_hidapi.h:832
int hid_write(HidDeviceParam dev, SourceBytes data)
Write an Output report to a HID device.
Definition: SDL3pp_hidapi.h:716
int read_timeout(TargetBytes data, Milliseconds timeout)
Read an Input report from a HID device with timeout.
Definition: SDL3pp_hidapi.h:750
int hid_read(HidDeviceParam dev, TargetBytes data)
Read an Input report from a HID device.
Definition: SDL3pp_hidapi.h:770
int get_input_report(TargetBytes data)
Get an input report from a HID device.
Definition: SDL3pp_hidapi.h:892
void close()
Close a HID device.
Definition: SDL3pp_hidapi.h:910
PropertiesRef hid_get_properties(HidDeviceParam dev)
Get the properties associated with an HidDevice.
Definition: SDL3pp_hidapi.h:675
constexpr hid_bus_type HID_API_BUS_UNKNOWN
Unknown bus type.
Definition: SDL3pp_hidapi.h:84
Uint32 hid_device_change_count()
Check to see if devices may have been added or removed.
Definition: SDL3pp_hidapi.h:568
int hid_send_feature_report(HidDeviceParam dev, SourceBytes data)
Send a Feature report to the device.
Definition: SDL3pp_hidapi.h:826
HidDevice hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)
Open a HID device using a Vendor ID (VID), Product ID (PID) and optionally a serial number.
Definition: SDL3pp_hidapi.h:635
void get_indexed_string(int string_index, wchar_t *string, size_t maxlen)
Get a string from a HID device, based on its string index.
Definition: SDL3pp_hidapi.h:998
void hid_free_enumeration(hid_device_info *devs)
Free an enumeration linked list.
Definition: SDL3pp_hidapi.h:614
void hid_get_product_string(HidDeviceParam dev, wchar_t *string, size_t maxlen)
Get The Product String from a HID device.
Definition: SDL3pp_hidapi.h:944
void hid_ble_scan(bool active)
Start or stop a BLE scan on iOS and tvOS to pair Steam Controllers.
Definition: SDL3pp_hidapi.h:1057
void get_serial_number_string(wchar_t *string, size_t maxlen)
Get The Serial Number String from a HID device.
Definition: SDL3pp_hidapi.h:973
void hid_get_serial_number_string(HidDeviceParam dev, wchar_t *string, size_t maxlen)
Get The Serial Number String from a HID device.
Definition: SDL3pp_hidapi.h:966
int write(SourceBytes data)
Write an Output report to a HID device.
Definition: SDL3pp_hidapi.h:721
void hid_init()
Initialize the HIDAPI library.
Definition: SDL3pp_hidapi.h:533
int hid_read_timeout(HidDeviceParam dev, TargetBytes data, Milliseconds timeout)
Read an Input report from a HID device with timeout.
Definition: SDL3pp_hidapi.h:742
constexpr hid_bus_type HID_API_BUS_BLUETOOTH
Bluetooth or Bluetooth LE bus Specifications:
Definition: SDL3pp_hidapi.h:101
constexpr hid_bus_type HID_API_BUS_USB
USB bus Specifications:
Definition: SDL3pp_hidapi.h:92
constexpr hid_bus_type HID_API_BUS_SPI
SPI bus Specifications:
Definition: SDL3pp_hidapi.h:115
void hid_get_indexed_string(HidDeviceParam dev, int string_index, wchar_t *string, size_t maxlen)
Get a string from a HID device, based on its string index.
Definition: SDL3pp_hidapi.h:989
int hid_get_input_report(HidDeviceParam dev, TargetBytes data)
Get an input report from a HID device.
Definition: SDL3pp_hidapi.h:886
HidDevice hid_open_path(StringParam path)
Open a HID device by its path name.
Definition: SDL3pp_hidapi.h:654
int get_report_descriptor(TargetBytes buf)
Get a report descriptor from a HID device.
Definition: SDL3pp_hidapi.h:1045
void hid_get_manufacturer_string(HidDeviceParam dev, wchar_t *string, size_t maxlen)
Get The Manufacturer String from a HID device.
Definition: SDL3pp_hidapi.h:922
void hid_set_nonblocking(HidDeviceParam dev, bool nonblock)
Set the device handle to be non-blocking.
Definition: SDL3pp_hidapi.h:796
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:341
std::chrono::milliseconds Milliseconds
Duration in Miliseconds (Uint32).
Definition: SDL3pp_stdinc.h:386
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition: SDL3pp_stdinc.h:289
Main include header for the SDL3pp library.
Safely wrap HidDevice for non owning parameters.
Definition: SDL3pp_hidapi.h:52
constexpr HidDeviceParam(HidDeviceRaw value)
Constructs from HidDeviceRaw.
Definition: SDL3pp_hidapi.h:56
HidDeviceRaw value
parameter's HidDeviceRaw
Definition: SDL3pp_hidapi.h:53
constexpr auto operator<=>(const HidDeviceParam &other) const =default
Comparison.
constexpr HidDeviceParam(std::nullptr_t=nullptr)
Constructs null/invalid.
Definition: SDL3pp_hidapi.h:62
Semi-safe reference for HidDevice.
Definition: SDL3pp_hidapi.h:482
~HidDeviceRef()
Destructor.
Definition: SDL3pp_hidapi.h:513
constexpr HidDeviceRef(const HidDeviceRef &other) noexcept=default
Copy constructor.
HidDeviceRef(HidDeviceParam resource) noexcept
Constructs from HidDeviceParam.
Definition: SDL3pp_hidapi.h:492
HidDeviceRef(HidDeviceRaw resource) noexcept
Constructs from HidDeviceParam.
Definition: SDL3pp_hidapi.h:504
Semi-safe reference for Properties.
Definition: SDL3pp_properties.h:716