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"
69 constexpr explicit operator bool()
const {
return !!
value; }
86 SDL_HID_API_BUS_UNKNOWN;
92 SDL_HID_API_BUS_BLUETOOTH;
130 : m_resource(resource)
163 unsigned short product_id,
164 const wchar_t* serial_number)
165 : m_resource(
CheckError(SDL_hid_open(vendor_id, product_id, serial_number)))
181 : m_resource(
CheckError(SDL_hid_open_path(path)))
191 std::swap(m_resource, other.m_resource);
202 m_resource =
nullptr;
210 constexpr bool operator==(std::nullptr_t _)
const {
return !m_resource; }
213 constexpr explicit operator bool()
const {
return !!m_resource; }
517 return SDL_hid_device_change_count();
547 unsigned short product_id)
549 return CheckError(SDL_hid_enumerate(vendor_id, product_id));
564 SDL_hid_free_enumeration(devs);
584 unsigned short product_id,
585 const wchar_t* serial_number)
587 return HidDevice(vendor_id, product_id, serial_number);
661 return SDL_hid_read_timeout(
745 return SDL_hid_send_feature_report(
775 return SDL_hid_get_feature_report(
805 return SDL_hid_get_input_report(
843 CheckErrorIfNot(SDL_hid_get_manufacturer_string(dev,
string, maxlen), 0);
887 CheckErrorIfNot(SDL_hid_get_serial_number_string(dev,
string, maxlen), 0);
911 CheckErrorIfNot(SDL_hid_get_indexed_string(dev, string_index,
string, maxlen),
935 return CheckError(SDL_hid_get_device_info(dev));
958 return SDL_hid_get_report_descriptor(
An opaque handle representing an open HID device.
Definition: SDL3pp_hidapi.h:115
constexpr HidDevice(const HidDeviceRaw resource)
Constructs from HidDeviceParam.
Definition: SDL3pp_hidapi.h:129
constexpr HidDevice(const HidDevice &other)=delete
Copy constructor.
constexpr HidDevice(HidDevice &&other)
Move constructor.
Definition: SDL3pp_hidapi.h:138
HidDevice(StringParam path)
Open a HID device by its path name.
Definition: SDL3pp_hidapi.h:180
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:162
constexpr bool operator==(std::nullptr_t _) const
Comparison.
Definition: SDL3pp_hidapi.h:210
constexpr HidDeviceRaw get() const
Retrieves underlying HidDeviceRaw.
Definition: SDL3pp_hidapi.h:196
constexpr HidDeviceRaw release()
Retrieves underlying HidDeviceRaw and clear this.
Definition: SDL3pp_hidapi.h:199
constexpr auto operator<=>(const HidDevice &other) const =default
Comparison.
~HidDevice()
Destructor.
Definition: SDL3pp_hidapi.h:186
HidDevice & operator=(HidDevice other)
Assignment operator.
Definition: SDL3pp_hidapi.h:189
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:245
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:198
int hid_get_feature_report(HidDeviceParam dev, TargetBytes data)
Get a feature report from a HID device.
Definition: SDL3pp_hidapi.h:773
void hid_close(HidDeviceRaw dev)
Close a HID device.
Definition: SDL3pp_hidapi.h:822
void get_manufacturer_string(wchar_t *string, size_t maxlen)
Get The Manufacturer String from a HID device.
Definition: SDL3pp_hidapi.h:846
SDL_hid_bus_type hid_bus_type
HID underlying bus types.
Definition: SDL3pp_hidapi.h:83
SDL_hid_device * HidDeviceRaw
Alias to raw representation for HidDevice.
Definition: SDL3pp_hidapi.h:46
hid_device_info * hid_get_device_info(HidDeviceParam dev)
Get the device info from a HID device.
Definition: SDL3pp_hidapi.h:933
void set_nonblocking(bool nonblock)
Set the device handle to be non-blocking.
Definition: SDL3pp_hidapi.h:717
hid_device_info * hid_enumerate(unsigned short vendor_id, unsigned short product_id)
Enumerate the HID Devices.
Definition: SDL3pp_hidapi.h:546
int get_feature_report(TargetBytes data)
Get a feature report from a HID device.
Definition: SDL3pp_hidapi.h:779
int read(TargetBytes data)
Read an Input report from a HID device.
Definition: SDL3pp_hidapi.h:691
SDL_hid_device_info hid_device_info
Information about a connected HID device.
Definition: SDL3pp_hidapi.h:105
hid_device_info * get_device_info()
Get the device info from a HID device.
Definition: SDL3pp_hidapi.h:938
constexpr hid_bus_type HID_API_BUS_I2C
[object Object]
Definition: SDL3pp_hidapi.h:94
int hid_get_report_descriptor(HidDeviceParam dev, TargetBytes buf)
Get a report descriptor from a HID device.
Definition: SDL3pp_hidapi.h:956
void hid_exit()
Finalize the HIDAPI library.
Definition: SDL3pp_hidapi.h:494
void get_product_string(wchar_t *string, size_t maxlen)
Get The Product String from a HID device.
Definition: SDL3pp_hidapi.h:868
int send_feature_report(SourceBytes data)
Send a Feature report to the device.
Definition: SDL3pp_hidapi.h:749
int hid_write(HidDeviceParam dev, SourceBytes data)
Write an Output report to a HID device.
Definition: SDL3pp_hidapi.h:631
int read_timeout(TargetBytes data, Milliseconds timeout)
Read an Input report from a HID device with timeout.
Definition: SDL3pp_hidapi.h:665
int hid_read(HidDeviceParam dev, TargetBytes data)
Read an Input report from a HID device.
Definition: SDL3pp_hidapi.h:686
int get_input_report(TargetBytes data)
Get an input report from a HID device.
Definition: SDL3pp_hidapi.h:809
void close()
Close a HID device.
Definition: SDL3pp_hidapi.h:827
constexpr hid_bus_type HID_API_BUS_UNKNOWN
Unknown bus type.
Definition: SDL3pp_hidapi.h:85
Uint32 hid_device_change_count()
Check to see if devices may have been added or removed.
Definition: SDL3pp_hidapi.h:515
int hid_send_feature_report(HidDeviceParam dev, SourceBytes data)
Send a Feature report to the device.
Definition: SDL3pp_hidapi.h:743
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:583
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:915
void hid_free_enumeration(hid_device_info *devs)
Free an enumeration linked list.
Definition: SDL3pp_hidapi.h:562
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:861
void hid_ble_scan(bool active)
Start or stop a BLE scan on iOS and tvOS to pair Steam Controllers.
Definition: SDL3pp_hidapi.h:974
void get_serial_number_string(wchar_t *string, size_t maxlen)
Get The Serial Number String from a HID device.
Definition: SDL3pp_hidapi.h:890
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:883
int write(SourceBytes data)
Write an Output report to a HID device.
Definition: SDL3pp_hidapi.h:636
void hid_init()
Initialize the HIDAPI library.
Definition: SDL3pp_hidapi.h:480
int hid_read_timeout(HidDeviceParam dev, TargetBytes data, Milliseconds timeout)
Read an Input report from a HID device with timeout.
Definition: SDL3pp_hidapi.h:657
constexpr hid_bus_type HID_API_BUS_BLUETOOTH
[object Object]
Definition: SDL3pp_hidapi.h:91
constexpr hid_bus_type HID_API_BUS_USB
[object Object]
Definition: SDL3pp_hidapi.h:88
constexpr hid_bus_type HID_API_BUS_SPI
[object Object]
Definition: SDL3pp_hidapi.h:97
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:906
int hid_get_input_report(HidDeviceParam dev, TargetBytes data)
Get an input report from a HID device.
Definition: SDL3pp_hidapi.h:803
HidDevice hid_open_path(StringParam path)
Open a HID device by its path name.
Definition: SDL3pp_hidapi.h:602
int get_report_descriptor(TargetBytes buf)
Get a report descriptor from a HID device.
Definition: SDL3pp_hidapi.h:962
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:839
void hid_set_nonblocking(HidDeviceParam dev, bool nonblock)
Set the device handle to be non-blocking.
Definition: SDL3pp_hidapi.h:712
std::chrono::milliseconds Milliseconds
Duration in Miliseconds (Uint32).
Definition: SDL3pp_stdinc.h:380
Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:325
Uint8 Uint8
An unsigned 8-bit integer type.
Definition: SDL3pp_stdinc.h:257
Main include header for the SDL3pp library.
Safely wrap HidDevice for non owning parameters.
Definition: SDL3pp_hidapi.h:53
constexpr HidDeviceParam(HidDeviceRaw value)
Constructs from HidDeviceRaw.
Definition: SDL3pp_hidapi.h:57
constexpr HidDeviceParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_hidapi.h:63
HidDeviceRaw value
parameter's HidDeviceRaw
Definition: SDL3pp_hidapi.h:54
constexpr auto operator<=>(const HidDeviceParam &other) const =default
Comparison.
Semi-safe reference for HidDevice.
Definition: SDL3pp_hidapi.h:440
HidDeviceRef(const HidDeviceRef &other)
Copy constructor.
Definition: SDL3pp_hidapi.h:454
~HidDeviceRef()
Destructor.
Definition: SDL3pp_hidapi.h:460
HidDeviceRef(HidDeviceParam resource)
Constructs from HidDeviceParam.
Definition: SDL3pp_hidapi.h:448