[WIP] Hardcode values for joystick into keymap, implement buttons
This commit is contained in:
parent
0d6c90a1ea
commit
d1d04df937
2 changed files with 63 additions and 5 deletions
|
@ -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() {}
|
||||
|
@ -66,23 +75,22 @@ void SDLController::ProcessInput() {
|
|||
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) {
|
||||
//Joystick button press events
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue