18 struct profile_name_t {
20 std::string_view name;
23 constexpr std::array PROFILE_NAMES {
37 struct profile_alias_t {
38 std::string_view alias;
42 constexpr std::array PROFILE_ALIASES {
85 struct family_name_t {
87 std::string_view name;
90 constexpr std::array FAMILY_NAMES {
99 struct family_alias_t {
100 std::string_view alias;
104 constexpr std::array FAMILY_ALIASES {
144 bool equals_ignore_case(std::string_view left, std::string_view right) {
145 return left.size() == right.size() && std::equal(left.begin(), left.end(), right.begin(), [](
char lhs,
char rhs) {
146 return std::tolower(static_cast<unsigned char>(lhs)) == std::tolower(static_cast<unsigned char>(rhs));
156 void append_unique(std::vector<Profile> &chain,
Profile profile) {
157 if (std::find(chain.begin(), chain.end(), profile) == chain.end()) {
158 chain.push_back(profile);
164 for (
const auto &entry : PROFILE_NAMES) {
165 if (entry.profile == profile) {
166 return entry.name.data();
173 for (
const auto &entry : PROFILE_ALIASES) {
174 if (equals_ignore_case(entry.alias, name)) {
175 profile = entry.profile;
183 for (
const auto &entry : FAMILY_NAMES) {
184 if (entry.family == family) {
185 return entry.name.data();
192 for (
const auto &entry : FAMILY_ALIASES) {
193 if (equals_ignore_case(entry.alias, name)) {
194 family = entry.family;
205 capabilities.
rumble =
true;
208 capabilities.
rumble =
true;
213 capabilities.
rumble =
true;
219 capabilities.
rumble =
true;
226 capabilities.
rumble =
true;
227 capabilities.
leds =
true;
228 capabilities.
imu =
true;
233 capabilities.
rumble =
true;
234 capabilities.
leds =
true;
235 capabilities.
imu =
true;
247 capabilities.
rumble =
true;
248 capabilities.
leds =
true;
250 capabilities.
imu =
true;
255 capabilities.
rumble =
true;
256 capabilities.
imu =
true;
262 capabilities.
rumble =
true;
263 capabilities.
imu =
true;
270 capabilities.
rumble =
true;
280 return {0x045E, 0x028E, 0x0114};
282 return {0x045E, 0x02EA, 0x0408};
284 return {0x045E, 0x0B12, 0x0500};
286 return {0x045E, 0x0B05, 0x0903};
288 return {0x054C, 0x05C4, 0x0100};
290 return {0x054C, 0x0CE6, 0x8111};
292 return {0x054C, 0x0DF2, 0x8111};
294 return {0x057E, 0x2009, 0x0210};
296 return {0x28DE, 0x1142, 0x0001};
298 return {0x28DE, 0x1205, 0x0001};
300 return {0x1209, 0x0001, 0x0001};
303 return {0x1209, 0x0001, 0x0001};
307 switch (controller.
family) {
338 std::vector<Profile> chain;
339 append_unique(chain, profile);
408 std::uint8_t clamp_deadzone(std::uint8_t percent) {
409 return std::min<std::uint8_t>(percent, 30);
418 float normalize_axis(std::int16_t value) {
419 return value < 0 ? static_cast<float>(value) / 32768.0F :
static_cast<float>(value) / 32767.0F;
428 std::int16_t denormalize_axis(
float value) {
429 const auto scaled = value < 0 ? value * 32768.0F : value * 32767.0F;
430 return static_cast<std::int16_t
>(std::clamp<std::int32_t>(
static_cast<std::int32_t
>(std::lround(scaled)), -32768, 32767));
441 std::pair<std::int16_t, std::int16_t> sanitize_stick(std::int16_t
x, std::int16_t
y, std::uint8_t percent) {
442 const auto deadzone =
static_cast<float>(clamp_deadzone(percent)) / 100.0F;
443 if (deadzone <= 0.0F) {
447 auto nx = normalize_axis(
x);
448 auto ny = normalize_axis(
y);
449 const auto magnitude = std::sqrt(nx * nx + ny * ny);
450 if (magnitude <= deadzone) {
454 const auto clamped_magnitude = std::min(magnitude, 1.0F);
455 const auto scaled_magnitude = (clamped_magnitude - deadzone) / (1.0F - deadzone);
456 const auto scale = scaled_magnitude / magnitude;
457 return {denormalize_axis(nx * scale), denormalize_axis(ny * scale)};
467 std::uint8_t sanitize_trigger(std::uint8_t value, std::uint8_t percent) {
468 const auto deadzone = clamp_deadzone(percent);
473 const auto threshold =
static_cast<int>(std::lround(255.0 * deadzone / 100.0));
474 if (value <= threshold) {
477 if (threshold >= 255) {
480 return static_cast<std::uint8_t
>(std::lround((value - threshold) * 255.0 / (255 - threshold)));
Portable gamepad state, profiles, and capability definitions.