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;
147 : m_resource(resource)
180 unsigned short product_id,
181 const wchar_t* serial_number)
182 : m_resource(
CheckError(SDL_hid_open(vendor_id, product_id, serial_number)))
198 : m_resource(
CheckError(SDL_hid_open_path(path)))
208 std::swap(m_resource, other.m_resource);
219 m_resource =
nullptr;
227 constexpr bool operator==(std::nullptr_t _)
const {
return !m_resource; }
230 constexpr explicit operator bool()
const {
return !!m_resource; }
533 return SDL_hid_device_change_count();
563 unsigned short product_id)
565 return CheckError(SDL_hid_enumerate(vendor_id, product_id));
579 SDL_hid_free_enumeration(devs);
599 unsigned short product_id,
600 const wchar_t* serial_number)
602 return HidDevice(vendor_id, product_id, serial_number);
674 return SDL_hid_read_timeout(
756 return SDL_hid_send_feature_report(
786 return SDL_hid_get_feature_report(
816 return SDL_hid_get_input_report(
854 CheckErrorIfNot(SDL_hid_get_manufacturer_string(dev,
string, maxlen), 0);
898 CheckErrorIfNot(SDL_hid_get_serial_number_string(dev,
string, maxlen), 0);
922 CheckErrorIfNot(SDL_hid_get_indexed_string(dev, string_index,
string, maxlen),
946 return CheckError(SDL_hid_get_device_info(dev));
969 return SDL_hid_get_report_descriptor(
An opaque handle representing an open HID device.
Definition: SDL3pp_hidapi.h:132
constexpr HidDevice(const HidDeviceRaw resource)
Constructs from HidDeviceParam.
Definition: SDL3pp_hidapi.h:146
constexpr HidDevice(const HidDevice &other)=delete
Copy constructor.
constexpr HidDevice(HidDevice &&other)
Move constructor.
Definition: SDL3pp_hidapi.h:155
HidDevice(StringParam path)
Open a HID device by its path name.
Definition: SDL3pp_hidapi.h:197
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:179
constexpr bool operator==(std::nullptr_t _) const
Comparison.
Definition: SDL3pp_hidapi.h:227
constexpr HidDeviceRaw get() const
Retrieves underlying HidDeviceRaw.
Definition: SDL3pp_hidapi.h:213
constexpr HidDeviceRaw release()
Retrieves underlying HidDeviceRaw and clear this.
Definition: SDL3pp_hidapi.h:216
constexpr auto operator<=>(const HidDevice &other) const =default
Comparison.
~HidDevice()
Destructor.
Definition: SDL3pp_hidapi.h:203
HidDevice & operator=(HidDevice other)
Assignment operator.
Definition: SDL3pp_hidapi.h:206
constexpr HidDevice()=default
Default ctor.
Source byte stream.
Definition: SDL3pp_strings.h:239
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition: SDL3pp_strings.h:303
constexpr const T * data_as() const
Retrieves contained data.
Definition: SDL3pp_strings.h:313
Helpers to use C++ strings parameters.
Definition: SDL3pp_strings.h:43
Target byte stream.
Definition: SDL3pp_strings.h:325
constexpr T * data_as() const
Retrieves contained data.
Definition: SDL3pp_strings.h:415
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition: SDL3pp_strings.h:408
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:784
void hid_close(HidDeviceRaw dev)
Close a HID device.
Definition: SDL3pp_hidapi.h:833
void get_manufacturer_string(wchar_t *string, size_t maxlen)
Get The Manufacturer String from a HID device.
Definition: SDL3pp_hidapi.h:857
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:944
void set_nonblocking(bool nonblock)
Set the device handle to be non-blocking.
Definition: SDL3pp_hidapi.h:729
hid_device_info * hid_enumerate(unsigned short vendor_id, unsigned short product_id)
Enumerate the HID Devices.
Definition: SDL3pp_hidapi.h:562
int get_feature_report(TargetBytes data)
Get a feature report from a HID device.
Definition: SDL3pp_hidapi.h:790
int read(TargetBytes data)
Read an Input report from a HID device.
Definition: SDL3pp_hidapi.h:703
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:949
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:967
void hid_exit()
Finalize the HIDAPI library.
Definition: SDL3pp_hidapi.h:510
void get_product_string(wchar_t *string, size_t maxlen)
Get The Product String from a HID device.
Definition: SDL3pp_hidapi.h:879
int send_feature_report(SourceBytes data)
Send a Feature report to the device.
Definition: SDL3pp_hidapi.h:760
int hid_write(HidDeviceParam dev, SourceBytes data)
Write an Output report to a HID device.
Definition: SDL3pp_hidapi.h:644
int read_timeout(TargetBytes data, Milliseconds timeout)
Read an Input report from a HID device with timeout.
Definition: SDL3pp_hidapi.h:678
int hid_read(HidDeviceParam dev, TargetBytes data)
Read an Input report from a HID device.
Definition: SDL3pp_hidapi.h:698
int get_input_report(TargetBytes data)
Get an input report from a HID device.
Definition: SDL3pp_hidapi.h:820
void close()
Close a HID device.
Definition: SDL3pp_hidapi.h:838
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:531
int hid_send_feature_report(HidDeviceParam dev, SourceBytes data)
Send a Feature report to the device.
Definition: SDL3pp_hidapi.h:754
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:598
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:926
void hid_free_enumeration(hid_device_info *devs)
Free an enumeration linked list.
Definition: SDL3pp_hidapi.h:577
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:872
void hid_ble_scan(bool active)
Start or stop a BLE scan on iOS and tvOS to pair Steam Controllers.
Definition: SDL3pp_hidapi.h:985
void get_serial_number_string(wchar_t *string, size_t maxlen)
Get The Serial Number String from a HID device.
Definition: SDL3pp_hidapi.h:901
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:894
int write(SourceBytes data)
Write an Output report to a HID device.
Definition: SDL3pp_hidapi.h:649
void hid_init()
Initialize the HIDAPI library.
Definition: SDL3pp_hidapi.h:496
int hid_read_timeout(HidDeviceParam dev, TargetBytes data, Milliseconds timeout)
Read an Input report from a HID device with timeout.
Definition: SDL3pp_hidapi.h:670
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:917
int hid_get_input_report(HidDeviceParam dev, TargetBytes data)
Get an input report from a HID device.
Definition: SDL3pp_hidapi.h:814
HidDevice hid_open_path(StringParam path)
Open a HID device by its path name.
Definition: SDL3pp_hidapi.h:617
int get_report_descriptor(TargetBytes buf)
Get a report descriptor from a HID device.
Definition: SDL3pp_hidapi.h:973
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:850
void hid_set_nonblocking(HidDeviceParam dev, bool nonblock)
Set the device handle to be non-blocking.
Definition: SDL3pp_hidapi.h:724
::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
constexpr HidDeviceParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_hidapi.h:62
HidDeviceRaw value
parameter's HidDeviceRaw
Definition: SDL3pp_hidapi.h:53
constexpr auto operator<=>(const HidDeviceParam &other) const =default
Comparison.
Semi-safe reference for HidDevice.
Definition: SDL3pp_hidapi.h:456
HidDeviceRef(const HidDeviceRef &other)
Copy constructor.
Definition: SDL3pp_hidapi.h:470
~HidDeviceRef()
Destructor.
Definition: SDL3pp_hidapi.h:476
HidDeviceRef(HidDeviceParam resource)
Constructs from HidDeviceParam.
Definition: SDL3pp_hidapi.h:464