Skip to content
Open
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ Input controllers:
- Axis to button mapping?
- Rumble support
- Other 'fancy' settings (leds etc.)

## Known issues

- xwiimote not linked properly => try to compile with `XWIIMOTE_SYS_STATIC=1`
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
reorder_imports = true
22 changes: 14 additions & 8 deletions src/controller_abs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ fn test_normalization() {
}

// Values in axis are all u64, most likely controllers will have smaller sizes, so more easily convertible.
#[derive(Clone, Debug)]
pub struct Axis {
pub value: u64,
min: u64,
Expand Down Expand Up @@ -293,8 +294,14 @@ impl Default for Axis {

#[test]
fn test_axis() {
assert_eq!(Axis::new::<u8, _>(127, u8::MIN, u8::MAX).convert_into::<u8, _>(false), 127);
assert_eq!(Axis::new::<u8, _>(50, 0, 100).convert_into::<u8, _>(false), 127);
assert_eq!(
Axis::new::<u8, _>(127, u8::MIN, u8::MAX).convert_into::<u8, _>(false),
127
);
assert_eq!(
Axis::new::<u8, _>(50, 0, 100).convert_into::<u8, _>(false),
127
);
assert_eq!(Axis::new(0.0, -1.0, 1.0).convert_into::<u8, _>(false), 127);
}

Expand Down Expand Up @@ -357,7 +364,7 @@ impl JoystickState {
}

// Generic gamepad
#[derive(EnumIter, Hash, Eq, PartialEq, Clone)]
#[derive(EnumIter, Hash, Eq, PartialEq, Clone, Debug)]
pub enum GamepadButton {
North,
East,
Expand All @@ -376,7 +383,7 @@ pub enum GamepadButton {
DPadRight,
}

#[derive(EnumIter, PartialEq, Eq, Hash, Clone)]
#[derive(EnumIter, PartialEq, Eq, Hash, Clone, Debug)]
pub enum GamepadAxis {
LeftTrigger,
RightTrigger,
Expand Down Expand Up @@ -423,11 +430,12 @@ pub enum InputType {
}

// Mappings
#[derive(Clone)]
#[derive(Clone, Debug)]
pub enum OutputMapping {
Button(GamepadButton),
Axis(GamepadAxis),
}

pub struct ControllerMapping<T>
where
T: Clone,
Expand All @@ -438,8 +446,6 @@ where

pub trait ControllerInput {
type ControllerType;
fn to_gamepad<'a>(&'a mut self) -> &'a Gamepad;
fn discover_all() -> Vec<Self::ControllerType>;
fn to_gamepad(&mut self) -> &Gamepad;
fn prep_for_input_events(&mut self);
async fn get_next_inputs(&mut self) -> Result<bool, &'static str>;
}
Loading