libvirtualhid 16
Cross-platform C++ library for virtual HID devices.
report.hpp File Reference

Gamepad state normalization, report packing, and output parsing declarations. More...

#include <cstdint>
#include <vector>
#include <libvirtualhid/types.hpp>
Include dependency graph for report.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  lvh
 Public libvirtualhid API namespace.
 

Functions

float lvh::reports::clamp_axis (float value)
 Clamp a stick axis value to the normalized range.
 
float lvh::reports::clamp_trigger (float value)
 Clamp a trigger value to the normalized range.
 
std::uint8_t lvh::reports::hat_from_buttons (const ButtonSet &buttons)
 Convert directional pad buttons to a HID hat switch value.
 
std::int16_t lvh::reports::normalize_axis (float value)
 Convert a normalized axis value to a signed HID axis value.
 
GamepadState lvh::reports::normalize_state (const GamepadState &state)
 Normalize all scalar fields in a gamepad state.
 
std::uint8_t lvh::reports::normalize_trigger (float value)
 Convert a normalized trigger value to an unsigned HID trigger value.
 
std::vector< std::uint8_t > lvh::reports::pack_input_report (const DeviceProfile &profile, const GamepadState &state)
 Pack a gamepad state into the profile's common input report format.
 
GamepadOutput lvh::reports::parse_output_report (const DeviceProfile &profile, const std::vector< std::uint8_t > &report)
 Parse a backend output report into the profile-neutral output model.
 
std::vector< GamepadOutputlvh::reports::parse_output_reports (const DeviceProfile &profile, const std::vector< std::uint8_t > &report)
 Parse a backend output report into zero or more profile-neutral output events.
 

Detailed Description

Gamepad state normalization, report packing, and output parsing declarations.

Function Documentation

◆ clamp_axis()

float lvh::reports::clamp_axis ( float value)

Clamp a stick axis value to the normalized range.

Parameters
valueAxis value.
Returns
Clamped axis value in the inclusive range [-1.0, 1.0].

◆ clamp_trigger()

float lvh::reports::clamp_trigger ( float value)

Clamp a trigger value to the normalized range.

Parameters
valueTrigger value.
Returns
Clamped trigger value in the inclusive range [0.0, 1.0].

◆ hat_from_buttons()

std::uint8_t lvh::reports::hat_from_buttons ( const ButtonSet & buttons)

Convert directional pad buttons to a HID hat switch value.

Parameters
buttonsButton set containing directional pad state.
Returns
HID hat switch value, or 8 for neutral.

◆ normalize_axis()

std::int16_t lvh::reports::normalize_axis ( float value)

Convert a normalized axis value to a signed HID axis value.

Parameters
valueAxis value in the inclusive range [-1.0, 1.0].
Returns
Signed 16-bit HID axis value.

◆ normalize_state()

GamepadState lvh::reports::normalize_state ( const GamepadState & state)

Normalize all scalar fields in a gamepad state.

Parameters
stateGamepad state to normalize.
Returns
Normalized gamepad state.

◆ normalize_trigger()

std::uint8_t lvh::reports::normalize_trigger ( float value)

Convert a normalized trigger value to an unsigned HID trigger value.

Parameters
valueTrigger value in the inclusive range [0.0, 1.0].
Returns
Unsigned 8-bit HID trigger value.

◆ pack_input_report()

std::vector< std::uint8_t > lvh::reports::pack_input_report ( const DeviceProfile & profile,
const GamepadState & state )

Pack a gamepad state into the profile's common input report format.

Parameters
profileDevice profile used for report identity and size.
stateGamepad state to pack.
Returns
Packed input report bytes.

◆ parse_output_report()

GamepadOutput lvh::reports::parse_output_report ( const DeviceProfile & profile,
const std::vector< std::uint8_t > & report )

Parse a backend output report into the profile-neutral output model.

Parameters
profileDevice profile used for report identity and capabilities.
reportRaw HID output report bytes.
Returns
Parsed gamepad output. Unrecognized reports are returned as raw reports.

◆ parse_output_reports()

std::vector< GamepadOutput > lvh::reports::parse_output_reports ( const DeviceProfile & profile,
const std::vector< std::uint8_t > & report )

Parse a backend output report into zero or more profile-neutral output events.

Parameters
profileDevice profile used for report identity and capabilities.
reportRaw HID output report bytes.
Returns
Parsed gamepad outputs. Unrecognized reports are returned as one raw-report event.