Preliminary analog input support

This commit is contained in:
Daniel Stuart Baxter 2015-05-29 10:34:07 -05:00
parent c736bc2572
commit 558422c2ac
2 changed files with 42 additions and 6 deletions

View File

@ -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

View File

@ -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