Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion rootfs/usr/share/inputplumber/schema/capability_map_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,36 @@
"type": "object",
"properties": {
"deadzone": {
"description": "A value from 0.0-1.0 of how far an axis should be pressed in a particular direction\nin order for it to be considered \"pressed\"",
"type": [
"number",
"null"
],
"format": "double"
},
"direction": {
"description": "Direction of the axis to translate. Can be one of [\"vertical\", \"horizontal\", \"left\",\n\"right\", \"up\", \"down\"].",
"type": [
"string",
"null"
]
},
"invert": {
"description": "Invert all values of this axis with the matching direction",
"type": [
"boolean",
"null"
]
},
"name": {
"type": "string"
},
"quadratic_scaling": {
"description": "Use quadratic scaling for more precise control with small stick movements",
"type": [
"boolean",
"null"
]
}
},
"required": [
Expand Down Expand Up @@ -1430,4 +1446,4 @@
]
}
}
}
}
8 changes: 8 additions & 0 deletions src/config/capability_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,20 @@ pub struct GamepadCapability {
#[serde(rename_all = "snake_case")]
pub struct AxisCapability {
pub name: String,
/// Direction of the axis to translate. Can be one of ["vertical", "horizontal", "left",
/// "right", "up", "down"].
#[serde(skip_serializing_if = "Option::is_none")]
pub direction: Option<String>,
/// A value from 0.0-1.0 of how far an axis should be pressed in a particular direction
/// in order for it to be considered "pressed"
#[serde(skip_serializing_if = "Option::is_none")]
pub deadzone: Option<f64>,
/// Use quadratic scaling for more precise control with small stick movements
#[serde(skip_serializing_if = "Option::is_none")]
pub quadratic_scaling: Option<bool>,
/// Invert all values of this axis with the matching direction
#[serde(skip_serializing_if = "Option::is_none")]
pub invert: Option<bool>,
}

#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema, PartialEq)]
Expand Down
35 changes: 24 additions & 11 deletions src/input/event/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,19 +253,32 @@ impl InputValue {
.and_then(|gamepad| gamepad.axis.as_ref())
.and_then(|axis| axis.quadratic_scaling)
.unwrap_or(false);
let use_inverse_value = target_config
.gamepad
.as_ref()
.and_then(|gamepad| gamepad.axis.as_ref())
.and_then(|axis| axis.invert)
.unwrap_or(false);

match use_scaling {
false => Ok(self.clone()),
true => match self {
InputValue::Vector2 { x, y } => {
let scaled_x = x.map(|v| v * v.abs());
let scaled_y = y.map(|v| v * v.abs());
Ok(InputValue::Vector2 { x: scaled_x, y: scaled_y })
},
_ => Ok(self.clone()),
},
match self {
InputValue::Vector2 { x, y } => {
let (mut value_x, mut value_y) = (*x, *y);
if use_inverse_value {
value_x = value_x.map(|v| -v);
value_y = value_y.map(|v| -v);
}
if use_scaling {
value_x = value_x.map(|v| v * v.abs());
value_y = value_y.map(|v| v * v.abs());
}
Ok(InputValue::Vector2 {
x: value_x,
y: value_y,
})
}
_ => Ok(self.clone()),
}
},
}
// Axis -> Trigger
Gamepad::Trigger(_) => Err(TranslationError::NotImplemented),
// Axis -> Accelerometer
Expand Down