mirror of https://github.com/stella-emu/stella.git
Ha, found a way to detect analog vs digital axis input
This commit is contained in:
parent
2f9bb04eb8
commit
1a706ab2f1
|
@ -569,28 +569,14 @@ bool PhysicalJoystickHandler::addJoyMapping(Event::Type event, EventMode mode, i
|
||||||
// but analog events only affect one of the axis.
|
// but analog events only affect one of the axis.
|
||||||
if(Event::isAnalog(event))
|
if(Event::isAnalog(event))
|
||||||
{
|
{
|
||||||
// Turn off the digital event(s) for this axis, because we cannot have both
|
|
||||||
if(j->joyMap.get(evMode, button, axis, JoyDir::NEG) != Event::NoType)
|
|
||||||
j->joyMap.erase(evMode, button, axis, JoyDir::NEG);
|
|
||||||
if(j->joyMap.get(evMode, button, axis, JoyDir::POS) != Event::NoType)
|
|
||||||
j->joyMap.erase(evMode, button, axis, JoyDir::POS);
|
|
||||||
j->joyMap.add(event, evMode, button, axis, JoyDir::ANALOG);
|
j->joyMap.add(event, evMode, button, axis, JoyDir::ANALOG);
|
||||||
// update running emulation mapping too
|
// update running emulation mapping too
|
||||||
if(j->joyMap.get(EventMode::kEmulationMode, button, axis, JoyDir::NEG) != Event::NoType)
|
|
||||||
j->joyMap.erase(EventMode::kEmulationMode, button, axis, JoyDir::NEG);
|
|
||||||
if(j->joyMap.get(EventMode::kEmulationMode, button, axis, JoyDir::POS) != Event::NoType)
|
|
||||||
j->joyMap.erase(EventMode::kEmulationMode, button, axis, JoyDir::POS);
|
|
||||||
j->joyMap.add(event, EventMode::kEmulationMode, button, axis, JoyDir::ANALOG);
|
j->joyMap.add(event, EventMode::kEmulationMode, button, axis, JoyDir::ANALOG);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Otherwise, turn off the analog event(s) for this axis, because we cannot have both
|
|
||||||
if (j->joyMap.get(evMode, button, axis, JoyDir::ANALOG) != Event::NoType)
|
|
||||||
j->joyMap.erase(evMode, button, axis, JoyDir::ANALOG);
|
|
||||||
j->joyMap.add(event, evMode, button, axis, adir);
|
j->joyMap.add(event, evMode, button, axis, adir);
|
||||||
// update running emulation mapping too
|
// update running emulation mapping too
|
||||||
if(j->joyMap.get(EventMode::kEmulationMode, button, axis, JoyDir::ANALOG) != Event::NoType)
|
|
||||||
j->joyMap.erase(EventMode::kEmulationMode, button, axis, JoyDir::ANALOG);
|
|
||||||
j->joyMap.add(event, EventMode::kEmulationMode, button, axis, adir);
|
j->joyMap.add(event, EventMode::kEmulationMode, button, axis, adir);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -628,15 +614,16 @@ void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value)
|
||||||
if(myHandler.state() == EventHandlerState::EMULATION)
|
if(myHandler.state() == EventHandlerState::EMULATION)
|
||||||
{
|
{
|
||||||
// Check for analog events, which are handled differently
|
// Check for analog events, which are handled differently
|
||||||
|
// A value change lower than ~90% indicates analog input
|
||||||
|
if(abs(j->axisLastValue[axis] - value) < 30000)
|
||||||
|
{
|
||||||
Event::Type eventAxisAnalog = j->joyMap.get(EventMode::kEmulationMode, button, JoyAxis(axis), JoyDir::ANALOG);
|
Event::Type eventAxisAnalog = j->joyMap.get(EventMode::kEmulationMode, button, JoyAxis(axis), JoyDir::ANALOG);
|
||||||
|
|
||||||
if (eventAxisAnalog != Event::NoType)
|
|
||||||
{
|
|
||||||
myHandler.handleEvent(eventAxisAnalog, value);
|
myHandler.handleEvent(eventAxisAnalog, value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Otherwise, we know the event is digital
|
// Otherwise, we assume the event is digital
|
||||||
// Every axis event has two associated values, negative and positive
|
// Every axis event has two associated values, negative and positive
|
||||||
Event::Type eventAxisNeg = j->joyMap.get(EventMode::kEmulationMode, button, JoyAxis(axis), JoyDir::NEG);
|
Event::Type eventAxisNeg = j->joyMap.get(EventMode::kEmulationMode, button, JoyAxis(axis), JoyDir::NEG);
|
||||||
Event::Type eventAxisPos = j->joyMap.get(EventMode::kEmulationMode, button, JoyAxis(axis), JoyDir::POS);
|
Event::Type eventAxisPos = j->joyMap.get(EventMode::kEmulationMode, button, JoyAxis(axis), JoyDir::POS);
|
||||||
|
@ -660,8 +647,8 @@ void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value)
|
||||||
myHandler.handleEvent(eventAxisPos, false);
|
myHandler.handleEvent(eventAxisPos, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
j->axisLastValue[axis] = value;
|
|
||||||
}
|
}
|
||||||
|
j->axisLastValue[axis] = value;
|
||||||
}
|
}
|
||||||
else if(myHandler.hasOverlay())
|
else if(myHandler.hasOverlay())
|
||||||
{
|
{
|
||||||
|
@ -827,8 +814,8 @@ PhysicalJoystickHandler::EventMappingArray PhysicalJoystickHandler::DefaultRight
|
||||||
PhysicalJoystickHandler::EventMappingArray PhysicalJoystickHandler::DefaultLeftPaddlesMapping = {
|
PhysicalJoystickHandler::EventMappingArray PhysicalJoystickHandler::DefaultLeftPaddlesMapping = {
|
||||||
{Event::PaddleZeroAnalog, JOY_CTRL_NONE, JoyAxis::X, JoyDir::ANALOG},
|
{Event::PaddleZeroAnalog, JOY_CTRL_NONE, JoyAxis::X, JoyDir::ANALOG},
|
||||||
// Current code does NOT allow digital and anlog events on the same axis at the same time
|
// Current code does NOT allow digital and anlog events on the same axis at the same time
|
||||||
//{Event::PaddleZeroDecrease, JOY_CTRL_NONE, JoyAxis::X, JoyDir::POS},
|
{Event::PaddleZeroDecrease, JOY_CTRL_NONE, JoyAxis::X, JoyDir::POS},
|
||||||
//{Event::PaddleZeroIncrease, JOY_CTRL_NONE, JoyAxis::X, JoyDir::NEG},
|
{Event::PaddleZeroIncrease, JOY_CTRL_NONE, JoyAxis::X, JoyDir::NEG},
|
||||||
{Event::PaddleZeroFire, 0},
|
{Event::PaddleZeroFire, 0},
|
||||||
{Event::PaddleOneAnalog, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::ANALOG},
|
{Event::PaddleOneAnalog, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::ANALOG},
|
||||||
// Current code does NOT allow digital and anlog events on the same axis at the same
|
// Current code does NOT allow digital and anlog events on the same axis at the same
|
||||||
|
|
Loading…
Reference in New Issue