ApolloInput Nova 0.2.0
Standalone virtual gamepad library
Loading...
Searching...
No Matches
gamepad.hpp
Go to the documentation of this file.
1
5#pragma once
6
7#include <cstdint>
8#include <string>
9#include <vector>
10
11namespace apollo::input {
12
29
45
55 bool has_touchpad = false;
56 bool has_motion = false;
57 bool has_paddles = false;
58 bool has_share = false;
59 std::uint8_t misc_buttons = 0;
60 };
61
91
98 constexpr std::uint32_t button_bit(Button button) {
99 return std::uint32_t {1} << static_cast<std::uint32_t>(button);
100 }
101
106 std::uint32_t buttons = 0;
107 std::uint8_t left_trigger = 0;
108 std::uint8_t right_trigger = 0;
109 std::int16_t left_x = 0;
110 std::int16_t left_y = 0;
111 std::int16_t right_x = 0;
112 std::int16_t right_y = 0;
113
120 bool pressed(Button button) const {
121 return (buttons & button_bit(button)) != 0;
122 }
123
130 void set(Button button, bool pressed) {
131 if (pressed) {
132 buttons |= button_bit(button);
133 } else {
134 buttons &= ~button_bit(button);
135 }
136 }
137
141 void clear() {
142 *this = {};
143 }
144 };
145
150 bool active = false;
151 std::uint16_t x = 0;
152 std::uint16_t y = 0;
153 };
154
158 struct ImuSample {
159 float gyro_x = 0.0F;
160 float gyro_y = 0.0F;
161 float gyro_z = 0.0F;
162 float accel_x = 0.0F;
163 float accel_y = 0.0F;
164 float accel_z = 0.0F;
165 std::uint64_t timestamp_us = 0;
166 };
167
172 bool rumble = false;
173 bool leds = false;
174 bool imu = false;
175 bool touchpad = false;
176 bool adaptive_triggers = false;
177 bool raw_keyboard = false;
178 bool raw_mouse = false;
179 bool trigger_rumble = false;
180 bool player_leds = false;
181 bool battery = false;
182 bool paddles = false;
183 std::uint8_t misc_buttons = 0;
184 };
185
190 std::uint16_t vendor_id = 0;
191 std::uint16_t product_id = 0;
192 std::uint16_t version = 0;
193 };
194
199 std::uint8_t stick_percent = 3;
200 std::uint8_t trigger_percent = 2;
201 };
202
212 void sanitize_gamepad_state(GamepadState &state, const AnalogDeadzone &deadzone = {});
213
222
229 const char *to_string(Profile profile);
230
241 bool profile_from_string(const std::string &name, Profile &profile);
242
249 const char *to_string(ControllerFamily family);
250
258 bool controller_family_from_string(const std::string &name, ControllerFamily &family);
259
271
282
294
305 std::vector<Profile> profile_compatibility_chain(Profile profile);
306
307} // namespace apollo::input
Profile recommended_profile(const ControllerDescription &controller)
Pick the most capable virtual profile for a client controller.
Definition gamepad.cpp:306
ControllerFamily
Physical controller family reported by a streaming client.
Definition gamepad.hpp:37
@ playstation
DualShock 3/4, DualSense, or another PlayStation-style pad.
Definition gamepad.hpp:40
@ xbox
Xbox 360, Xbox One, Xbox Series, or Xbox Elite controller.
Definition gamepad.hpp:39
@ steam
Valve Steam Controller.
Definition gamepad.hpp:42
@ nintendo
Switch Pro Controller, Joy-Con, or another Nintendo-style pad.
Definition gamepad.hpp:41
@ unknown
No reliable family information.
Definition gamepad.hpp:38
Capabilities profile_capabilities(Profile profile)
Features a profile can expose when the backend supports them.
Definition gamepad.cpp:201
bool profile_from_string(const std::string &name, Profile &profile)
Parse a profile from its short name or a compatible alias.
Definition gamepad.cpp:172
Profile
Virtual controller profile exposed by a backend.
Definition gamepad.hpp:16
@ steam_controller
Valve Steam Controller layout.
Definition gamepad.hpp:25
@ dualsense_edge
DualSense Edge with rear paddles and extra function buttons.
Definition gamepad.hpp:23
@ xbox_elite
Xbox Elite Series 2 with rear paddles and Share.
Definition gamepad.hpp:20
@ steam_deck
Valve Steam Deck built-in controls.
Definition gamepad.hpp:26
const char * to_string(BackendKind kind)
Convert a backend kind to a stable short name.
Definition backend.cpp:61
void sanitize_gamepad_state(GamepadState &state, const AnalogDeadzone &deadzone={})
Remove stick drift, trigger resting noise, and center jitter.
Definition gamepad.cpp:484
constexpr std::uint32_t button_bit(Button button)
Bit mask for one digital button.
Definition gamepad.hpp:98
Button
Digital gamepad buttons shared by all backends.
Definition gamepad.hpp:65
@ misc2
Second miscellaneous button, when a controller exposes one.
Definition gamepad.hpp:89
ProfileIdentity profile_identity(Profile profile)
USB identity associated with a profile.
Definition gamepad.cpp:277
bool controller_family_from_string(const std::string &name, ControllerFamily &family)
Parse a controller family from its short name or alias.
Definition gamepad.cpp:191
std::vector< Profile > profile_compatibility_chain(Profile profile)
Return a profile followed by progressively simpler alternatives.
Definition gamepad.cpp:337
Host-side analog filtering used to remove drift and resting noise.
Definition gamepad.hpp:198
std::uint8_t stick_percent
Radial stick deadzone percentage (0-30).
Definition gamepad.hpp:199
std::uint8_t trigger_percent
Trigger deadzone percentage (0-30).
Definition gamepad.hpp:200
Features a backend can expose for a profile.
Definition gamepad.hpp:171
bool touchpad
Touchpad input.
Definition gamepad.hpp:175
bool player_leds
Player indicator LEDs.
Definition gamepad.hpp:180
bool paddles
Rear paddle or grip buttons.
Definition gamepad.hpp:182
std::uint8_t misc_buttons
Number of Share, Capture, or misc buttons (0-2).
Definition gamepad.hpp:183
bool trigger_rumble
Independent left/right trigger rumble.
Definition gamepad.hpp:179
bool leds
LED or lightbar feedback.
Definition gamepad.hpp:173
bool raw_keyboard
Raw Input-visible keyboard.
Definition gamepad.hpp:177
bool rumble
Main rumble feedback.
Definition gamepad.hpp:172
bool adaptive_triggers
Adaptive trigger feedback.
Definition gamepad.hpp:176
bool imu
Gyroscope and accelerometer.
Definition gamepad.hpp:174
bool raw_mouse
Raw Input-visible mouse.
Definition gamepad.hpp:178
bool battery
Battery state reported by the client.
Definition gamepad.hpp:181
Capabilities reported by a client controller.
Definition gamepad.hpp:53
bool has_share
Reports a Share, Capture, or misc button.
Definition gamepad.hpp:58
bool has_touchpad
Reports touchpad contacts.
Definition gamepad.hpp:55
std::uint8_t misc_buttons
Number of extra misc/share buttons reported by the client.
Definition gamepad.hpp:59
bool has_paddles
Reports rear paddle or grip buttons.
Definition gamepad.hpp:57
bool has_motion
Reports accelerometer or gyroscope samples.
Definition gamepad.hpp:56
ControllerFamily family
Client-reported controller family.
Definition gamepad.hpp:54
Description of a created virtual device.
Definition gamepad.hpp:217
Profile profile
Active profile.
Definition gamepad.hpp:218
Capabilities capabilities
Features exposed by the backend.
Definition gamepad.hpp:219
std::string name
Device name shown by the operating system.
Definition gamepad.hpp:220
One complete gamepad input report.
Definition gamepad.hpp:105
void set(Button button, bool pressed)
Set or clear a button bit.
Definition gamepad.hpp:130
std::uint32_t buttons
Bit mask of Button values.
Definition gamepad.hpp:106
void clear()
Reset all buttons, triggers, and sticks.
Definition gamepad.hpp:141
std::int16_t right_x
-32768 to 32767.
Definition gamepad.hpp:111
std::uint8_t left_trigger
0-255.
Definition gamepad.hpp:107
std::uint8_t right_trigger
0-255.
Definition gamepad.hpp:108
std::int16_t left_x
-32768 to 32767.
Definition gamepad.hpp:109
bool pressed(Button button) const
Check whether a button is pressed.
Definition gamepad.hpp:120
std::int16_t left_y
-32768 to 32767.
Definition gamepad.hpp:110
std::int16_t right_y
-32768 to 32767.
Definition gamepad.hpp:112
Optional inertial measurement unit sample.
Definition gamepad.hpp:158
float gyro_y
Radians per second.
Definition gamepad.hpp:160
std::uint64_t timestamp_us
Host timestamp in microseconds.
Definition gamepad.hpp:165
float accel_y
Meters per second squared.
Definition gamepad.hpp:163
float accel_z
Meters per second squared.
Definition gamepad.hpp:164
float gyro_z
Radians per second.
Definition gamepad.hpp:161
float accel_x
Meters per second squared.
Definition gamepad.hpp:162
float gyro_x
Radians per second.
Definition gamepad.hpp:159
USB identity used by backends that create HID-style devices.
Definition gamepad.hpp:189
std::uint16_t version
Device version.
Definition gamepad.hpp:192
std::uint16_t product_id
USB product ID.
Definition gamepad.hpp:191
std::uint16_t vendor_id
USB vendor ID.
Definition gamepad.hpp:190
Optional touchpad report.
Definition gamepad.hpp:149
std::uint16_t x
Touch X coordinate.
Definition gamepad.hpp:151
bool active
Whether a finger is touching the pad.
Definition gamepad.hpp:150
std::uint16_t y
Touch Y coordinate.
Definition gamepad.hpp:152