From d1d04df937428687011a28b43629adc4ae509f53 Mon Sep 17 00:00:00 2001 From: Daniel Stuart Baxter Date: Thu, 28 May 2015 02:37:43 -0500 Subject: [PATCH] [WIP] Hardcode values for joystick into keymap, implement buttons --- src/input_common/sdl_input/sdl_input.cpp | 63 ++++++++++++++++++++++-- src/input_common/sdl_input/sdl_input.h | 5 ++ 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/src/input_common/sdl_input/sdl_input.cpp b/src/input_common/sdl_input/sdl_input.cpp index ad7d9a38e..6958aa473 100644 --- a/src/input_common/sdl_input/sdl_input.cpp +++ b/src/input_common/sdl_input/sdl_input.cpp @@ -4,6 +4,8 @@ #include "input_common/sdl_input/sdl_input.h" +#include "common/key_map.h" + namespace InputCommon { SDLController::SDLController() { @@ -38,6 +40,13 @@ bool SDLController::Init() { std::cout<<"What\n"; return false; } + + //If joystick successfully opened, load up keymap from input configuration + //TODO - Make it NOT hardcoded + else { + joypad_id = KeyMap::NewDeviceId(); + SetupKeyMaps(); + } } void SDLController::DiscoverDevices() {} @@ -65,9 +74,6 @@ void SDLController::ProcessInput() { //Use a unique id for joystick input int pad_id = 0; int val = 0; - - //Pressed state, for joystick buttons only - bool pressed = false; //Generate the id based on input from an event switch(input_event.type) { @@ -75,14 +81,16 @@ void SDLController::ProcessInput() { case SDL_JOYBUTTONDOWN: pad_id = 100; pad_id += input_event.jbutton.button; - pressed = true; + + controller.pad_state.hex |= KeyMap::GetPadKey({pad_id, joypad_id}).hex; break; //Joystick button release events case SDL_JOYBUTTONUP: pad_id = 100; pad_id += input_event.jbutton.button; - pressed = false; + + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id, joypad_id}).hex; break; //Joystick axis motion events @@ -94,7 +102,52 @@ void SDLController::ProcessInput() { if(val > 0) { pad_id += 1; } + + break; + + //Joystick hat motion events + case SDL_JOYHATMOTION: + pad_id = 300; + pad_id += input_event.jhat.hat * 4; + + switch(input_event.jhat.value) { + case SDL_HAT_LEFT: break; + case SDL_HAT_RIGHT: pad_id += 1; break; + case SDL_HAT_UP: pad_id += 2; break; + case SDL_HAT_DOWN: pad_id += 3; break; + } + + break; } } +void SDLController::SetupKeyMaps() { + KeyMap::SetKeyMapping({100, joypad_id}, Service::HID::PAD_A); + KeyMap::SetKeyMapping({101, joypad_id}, Service::HID::PAD_B); + KeyMap::SetKeyMapping({102, joypad_id}, Service::HID::PAD_X); + KeyMap::SetKeyMapping({103, joypad_id}, Service::HID::PAD_Y); + KeyMap::SetKeyMapping({104, joypad_id}, Service::HID::PAD_R); + KeyMap::SetKeyMapping({105, joypad_id}, Service::HID::PAD_L); + KeyMap::SetKeyMapping({0, joypad_id}, Service::HID::PAD_ZL); + KeyMap::SetKeyMapping({0, joypad_id}, Service::HID::PAD_ZR); + + KeyMap::SetKeyMapping({107, joypad_id}, Service::HID::PAD_START); + KeyMap::SetKeyMapping({106, joypad_id}, Service::HID::PAD_SELECT); + + KeyMap::SetKeyMapping({300, joypad_id}, Service::HID::PAD_LEFT); + KeyMap::SetKeyMapping({301, joypad_id}, Service::HID::PAD_RIGHT); + KeyMap::SetKeyMapping({302, joypad_id}, Service::HID::PAD_UP); + KeyMap::SetKeyMapping({303, joypad_id}, Service::HID::PAD_DOWN); + + KeyMap::SetKeyMapping({0, joypad_id}, Service::HID::PAD_C_LEFT); + KeyMap::SetKeyMapping({0, joypad_id}, Service::HID::PAD_C_RIGHT); + KeyMap::SetKeyMapping({0, joypad_id}, Service::HID::PAD_C_UP); + KeyMap::SetKeyMapping({0, joypad_id}, Service::HID::PAD_C_DOWN); + + KeyMap::SetKeyMapping({200, joypad_id}, Service::HID::PAD_CIRCLE_LEFT); + KeyMap::SetKeyMapping({201, joypad_id}, Service::HID::PAD_CIRCLE_RIGHT); + KeyMap::SetKeyMapping({202, joypad_id}, Service::HID::PAD_CIRCLE_UP); + KeyMap::SetKeyMapping({203, joypad_id}, Service::HID::PAD_CIRCLE_DOWN); +} + }//namespace diff --git a/src/input_common/sdl_input/sdl_input.h b/src/input_common/sdl_input/sdl_input.h index 065308383..dafadb3ac 100644 --- a/src/input_common/sdl_input/sdl_input.h +++ b/src/input_common/sdl_input/sdl_input.h @@ -30,6 +30,9 @@ public: ///Processes input when polling void ProcessInput(); + ///Sets up keymaps from input configuration + void SetupKeyMaps(); + ///SDL event used for polling SDL_Event input_event; @@ -38,6 +41,8 @@ private: ///Index of joystick, used for opening/closing a joystick int index; + + int joypad_id; }; } //namespace