[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 "input_common/sdl_input/sdl_input.h"
|
||||||
|
|
||||||
|
#include "common/key_map.h"
|
||||||
|
|
||||||
namespace InputCommon {
|
namespace InputCommon {
|
||||||
|
|
||||||
SDLController::SDLController() {
|
SDLController::SDLController() {
|
||||||
|
@ -38,6 +40,13 @@ bool SDLController::Init() {
|
||||||
std::cout<<"What\n";
|
std::cout<<"What\n";
|
||||||
return false;
|
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() {}
|
void SDLController::DiscoverDevices() {}
|
||||||
|
@ -65,9 +74,6 @@ void SDLController::ProcessInput() {
|
||||||
//Use a unique id for joystick input
|
//Use a unique id for joystick input
|
||||||
int pad_id = 0;
|
int pad_id = 0;
|
||||||
int val = 0;
|
int val = 0;
|
||||||
|
|
||||||
//Pressed state, for joystick buttons only
|
|
||||||
bool pressed = false;
|
|
||||||
|
|
||||||
//Generate the id based on input from an event
|
//Generate the id based on input from an event
|
||||||
switch(input_event.type) {
|
switch(input_event.type) {
|
||||||
|
@ -75,14 +81,16 @@ void SDLController::ProcessInput() {
|
||||||
case SDL_JOYBUTTONDOWN:
|
case SDL_JOYBUTTONDOWN:
|
||||||
pad_id = 100;
|
pad_id = 100;
|
||||||
pad_id += input_event.jbutton.button;
|
pad_id += input_event.jbutton.button;
|
||||||
pressed = true;
|
|
||||||
|
controller.pad_state.hex |= KeyMap::GetPadKey({pad_id, joypad_id}).hex;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//Joystick button release events
|
//Joystick button release events
|
||||||
case SDL_JOYBUTTONUP:
|
case SDL_JOYBUTTONUP:
|
||||||
pad_id = 100;
|
pad_id = 100;
|
||||||
pad_id += input_event.jbutton.button;
|
pad_id += input_event.jbutton.button;
|
||||||
pressed = false;
|
|
||||||
|
controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id, joypad_id}).hex;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//Joystick axis motion events
|
//Joystick axis motion events
|
||||||
|
@ -94,7 +102,52 @@ void SDLController::ProcessInput() {
|
||||||
if(val > 0) {
|
if(val > 0) {
|
||||||
pad_id += 1;
|
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
|
}//namespace
|
||||||
|
|
|
@ -30,6 +30,9 @@ public:
|
||||||
///Processes input when polling
|
///Processes input when polling
|
||||||
void ProcessInput();
|
void ProcessInput();
|
||||||
|
|
||||||
|
///Sets up keymaps from input configuration
|
||||||
|
void SetupKeyMaps();
|
||||||
|
|
||||||
///SDL event used for polling
|
///SDL event used for polling
|
||||||
SDL_Event input_event;
|
SDL_Event input_event;
|
||||||
|
|
||||||
|
@ -38,6 +41,8 @@ private:
|
||||||
|
|
||||||
///Index of joystick, used for opening/closing a joystick
|
///Index of joystick, used for opening/closing a joystick
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
|
int joypad_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //namespace
|
} //namespace
|
||||||
|
|
Loading…
Reference in a new issue