diff --git a/src/input_common/sdl_input/sdl_input.cpp b/src/input_common/sdl_input/sdl_input.cpp index c47f6f859..3d5663ab5 100644 --- a/src/input_common/sdl_input/sdl_input.cpp +++ b/src/input_common/sdl_input/sdl_input.cpp @@ -43,10 +43,11 @@ bool SDLController::Init() { //If joystick successfully opened, load up keymap from input configuration //TODO - Make it NOT hardcoded - else { - joypad_id = KeyMap::NewDeviceId(); - SetupKeyMaps(); - } + joypad_id = KeyMap::NewDeviceId(); + SetupKeyMaps(); + + //TODO - Make it NOT hardcoded + SetDeadZone(8000); } void SDLController::DiscoverDevices() {} @@ -103,6 +104,20 @@ void SDLController::ProcessInput() { pad_id += 1; } + //If analog input is beyond dead zone, set it + if(CheckDeadZone(val)) { + controller.pad_state.hex |= KeyMap::GetPadKey({pad_id, joypad_id}).hex; + } else { + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id, joypad_id}).hex; + } + + //Release opposite axis + if(pad_id % 2 == 0) { + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+1, joypad_id}).hex; + } else { + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id-1, joypad_id}).hex; + } + break; //Joystick hat motion events @@ -208,4 +223,16 @@ void SDLController::SetupKeyMaps() { KeyMap::SetKeyMapping({203, joypad_id}, Service::HID::PAD_CIRCLE_DOWN); } +void SDLController::SetDeadZone(int range) { + dead_zone = range; +} + +bool SDLController::CheckDeadZone(int range) { + if((range < -dead_zone) || (range > dead_zone)) { + return true; + } else if((range > -dead_zone) && (range < dead_zone)) { + return false; + } +} + }//namespace diff --git a/src/input_common/sdl_input/sdl_input.h b/src/input_common/sdl_input/sdl_input.h index dafadb3ac..73ea627db 100644 --- a/src/input_common/sdl_input/sdl_input.h +++ b/src/input_common/sdl_input/sdl_input.h @@ -33,16 +33,25 @@ public: ///Sets up keymaps from input configuration void SetupKeyMaps(); - ///SDL event used for polling - SDL_Event input_event; + ///Sets analog deadzones + void SetDeadZone(int range); + + ///Checks if analog input is within the dead zone + bool CheckDeadZone(int range); private: SDL_Joystick* jpad; + ///SDL event used for polling + SDL_Event input_event; + ///Index of joystick, used for opening/closing a joystick int index; + ///Keymap id for this controller int joypad_id; + + int dead_zone; }; } //namespace