From cea522cee33f58e069bfab475fe9067ac1fdf0f4 Mon Sep 17 00:00:00 2001 From: jan Date: Mon, 23 Dec 2024 20:28:53 +0100 Subject: [PATCH] Mapped the left stick of a gamepad to be used as a DPad --- Cargo.lock | 2 +- Cargo.toml | 3 ++- src/utils.rs | 26 +++++++++++++++++++++----- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b481647..907e175 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1813,7 +1813,7 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "svc16" -version = "0.7.0" +version = "0.7.1" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index 744f1ac..f3fa109 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "svc16" -version = "0.7.0" +version = "0.7.1" edition = "2021" authors = ["Jan Neuendorf"] description = "An emulator for a simple virtual computer" @@ -18,4 +18,5 @@ winit-input-map = {version="0.4.1",optional=true} winit_input_helper = "0.16.0" [features] +default=[] gamepad = ["gilrs","winit-input-map"] diff --git a/src/utils.rs b/src/utils.rs index 7857c09..ec59669 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -8,7 +8,7 @@ use winit::{ }; use winit_input_helper::WinitInputHelper; #[cfg(feature = "gamepad")] -use winit_input_map::{input_map, GamepadButton, InputMap}; +use winit_input_map::{input_map, GamepadAxis, GamepadButton, InputCode, InputMap}; #[cfg(feature = "gamepad")] #[derive(Debug, std::hash::Hash, PartialEq, Eq, Clone, Copy)] @@ -30,10 +30,26 @@ pub fn build_gamepad_map() -> InputMap { (NesInput::B, GamepadButton::South), (NesInput::Select, GamepadButton::Select), (NesInput::Start, GamepadButton::Start), - (NesInput::Up, GamepadButton::DPadUp), - (NesInput::Down, GamepadButton::DPadDown), - (NesInput::Left, GamepadButton::DPadLeft), - (NesInput::Right, GamepadButton::DPadRight) + ( + NesInput::Up, + GamepadButton::DPadUp, + InputCode::gamepad_axis_pos(GamepadAxis::LeftStickY) + ), + ( + NesInput::Down, + GamepadButton::DPadDown, + InputCode::gamepad_axis_neg(GamepadAxis::LeftStickY) + ), + ( + NesInput::Left, + GamepadButton::DPadLeft, + InputCode::gamepad_axis_neg(GamepadAxis::LeftStickX) + ), + ( + NesInput::Right, + GamepadButton::DPadRight, + InputCode::gamepad_axis_pos(GamepadAxis::LeftStickX) + ) ) }