remove some debugging output

refactored controller mapping loading
This commit is contained in:
Thomas Jentzsch 2019-08-14 09:47:34 +02:00
parent f7c70e46f5
commit a36e01ac71
6 changed files with 31 additions and 36 deletions

View File

@ -665,7 +665,6 @@ void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value)
if (value != j->axisLastValue[axis]) if (value != j->axisLastValue[axis])
{ {
#ifdef GUI_SUPPORT #ifdef GUI_SUPPORT
cerr << "axis event" << endl;
myHandler.overlay().handleJoyAxisEvent(stick, axis, value, button); myHandler.overlay().handleJoyAxisEvent(stick, axis, value, button);
#endif #endif
j->axisLastValue[axis] = value; j->axisLastValue[axis] = value;

View File

@ -67,11 +67,11 @@ void PhysicalJoystick::initialize(int index, const string& desc,
axisLastValue[a] = 0; axisLastValue[a] = 0;
// Erase the mappings // Erase the mappings
eraseMap(kMenuMode);
eraseMap(kJoystickMode); eraseMap(kJoystickMode);
eraseMap(kPaddlesMode); eraseMap(kPaddlesMode);
eraseMap(kKeypadMode); eraseMap(kKeypadMode);
eraseMap(kMenuMode); eraseMap(kCommonMode);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -96,24 +96,33 @@ string PhysicalJoystick::getMap() const
bool PhysicalJoystick::setMap(const string& mapString) bool PhysicalJoystick::setMap(const string& mapString)
{ {
istringstream buf(mapString); istringstream buf(mapString);
StringList mappings;
string map; string map;
int i = 0;
// Skip joystick name
getline(buf, map, MODE_DELIM);
while (getline(buf, map, MODE_DELIM)) while (getline(buf, map, MODE_DELIM))
{ {
// remove leading "<mode>|" string int mode;
map.erase(0, 2);
mappings.push_back(map);
}
// Error checking
if(mappings.size() != 1 + 5)
return false;
joyMap.loadMapping(mappings[1], kMenuMode); // Get event mode
joyMap.loadMapping(mappings[2], kJoystickMode); std::replace(map.begin(), map.end(), '|', ' ');
joyMap.loadMapping(mappings[3], kPaddlesMode); istringstream modeBuf(map);
joyMap.loadMapping(mappings[4], kKeypadMode); modeBuf >> mode;
joyMap.loadMapping(mappings[5], kCommonMode);
// Remove leading "<mode>|" string
map.erase(0, 2);
joyMap.loadMapping(map, EventMode(mode));
i++;
}
// Brief error checking
if(i != 5)
{
cerr << "ERROR: Invalid controller mappings found" << endl;
return false;
}
return true; return true;
} }
@ -146,7 +155,7 @@ void PhysicalJoystick::getValues(const string& list, IntArray& map) const
string PhysicalJoystick::about() const string PhysicalJoystick::about() const
{ {
ostringstream buf; ostringstream buf;
buf << " with: " << numAxes << " axes, " << numButtons << " buttons, " buf << "'" << name << "' with: " << numAxes << " axes, " << numButtons << " buttons, "
<< numHats << " hats"; << numHats << " hats";
return buf.str(); return buf.str();

View File

@ -56,6 +56,7 @@ class PhysicalJoystick
int axes, int buttons, int hats, int balls); int axes, int buttons, int hats, int balls);
private: private:
// TODO: these are not required anymore, delete or keep for future usage?
enum JoyType { enum JoyType {
JT_NONE = 0, JT_NONE = 0,
JT_REGULAR = 1, JT_REGULAR = 1,

View File

@ -54,7 +54,6 @@ enum class JoyDir {
ANALOG = 2 ANALOG = 2
}; };
enum class JoyHat { enum class JoyHat {
UP = 0, // make sure these are set correctly, UP = 0, // make sure these are set correctly,
DOWN = 1, // since they'll be used as array indices DOWN = 1, // since they'll be used as array indices
@ -79,17 +78,15 @@ static const int NUM_JOY_HAT_DIRS = 4;
// TODO - make this 'enum class' somehow // TODO - make this 'enum class' somehow
enum EventMode { enum EventMode {
kEmulationMode = 0, // make sure these are set correctly, kEmulationMode, // active mapping used for emulation
kMenuMode = 1, // since they'll be used as array indices kMenuMode, // mapping used for dialogs
kNumModes = 2, kJoystickMode, // 4 extra modes for mapping controller keys separately for emulation mode
kJoystickMode = kNumModes, // 5 extra modes for mapping controller keys separately
kPaddlesMode, kPaddlesMode,
kKeypadMode, kKeypadMode,
kCompuMateMode, kCompuMateMode, // cannot be remapped
kCommonMode kCommonMode // mapping common between controllers
}; };
namespace GUI namespace GUI
{ {
#ifdef RETRON77 #ifdef RETRON77

View File

@ -327,13 +327,11 @@ void DialogContainer::handleJoyAxisEvent(int stick, int axis, int value, int but
// Only stop firing events if it's the current stick // Only stop firing events if it's the current stick
if(myCurrentAxisDown.stick == stick && value == 0) if(myCurrentAxisDown.stick == stick && value == 0)
{ {
cerr << "handleJoyAxisEvent 0" << endl;
myCurrentAxisDown.stick = myCurrentAxisDown.axis = -1; myCurrentAxisDown.stick = myCurrentAxisDown.axis = -1;
myAxisRepeatTime = 0; myAxisRepeatTime = 0;
} }
else if(value != 0 && myAxisRepeatTime < myTime) // never repeat the 'off' event; prevent pending repeats after enabling repeat again else if(value != 0 && myAxisRepeatTime < myTime) // never repeat the 'off' event; prevent pending repeats after enabling repeat again
{ {
cerr << "handleJoyAxisEvent repeat" << endl;
// Now account for repeated axis events (press and hold) // Now account for repeated axis events (press and hold)
myCurrentAxisDown.stick = stick; myCurrentAxisDown.stick = stick;
myCurrentAxisDown.axis = axis; myCurrentAxisDown.axis = axis;

View File

@ -153,7 +153,6 @@ void EventMappingWidget::setDefaults()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventMappingWidget::startRemapping() void EventMappingWidget::startRemapping()
{ {
cerr << "startRemapping" << endl;
if(myActionSelected < 0 || myRemapStatus) if(myActionSelected < 0 || myRemapStatus)
return; return;
@ -217,7 +216,6 @@ void EventMappingWidget::stopRemapping()
{ {
// Turn off remap mode // Turn off remap mode
myRemapStatus = false; myRemapStatus = false;
cerr << "stopRemapping " << myRemapStatus << endl;
// Reset all previous events for determining correct axis/hat values // Reset all previous events for determining correct axis/hat values
myLastStick = -1; myLastStick = -1;
@ -311,11 +309,9 @@ bool EventMappingWidget::handleKeyUp(StellaKey key, StellaMod mod)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventMappingWidget::handleJoyDown(int stick, int button, bool longPress) void EventMappingWidget::handleJoyDown(int stick, int button, bool longPress)
{ {
cerr << "handleJoyDown" << endl;
// Remap joystick buttons in remap mode // Remap joystick buttons in remap mode
if(myRemapStatus && myActionSelected >= 0) if(myRemapStatus && myActionSelected >= 0)
{ {
cerr << "remap button start " << myRemapStatus << endl;
myLastStick = stick; myLastStick = stick;
myLastButton = button; myLastButton = button;
} }
@ -324,7 +320,6 @@ void EventMappingWidget::handleJoyDown(int stick, int button, bool longPress)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventMappingWidget::handleJoyUp(int stick, int button) void EventMappingWidget::handleJoyUp(int stick, int button)
{ {
cerr << "handleJoyUp" << endl;
// Remap joystick buttons in remap mode // Remap joystick buttons in remap mode
if (myRemapStatus && myActionSelected >= 0) if (myRemapStatus && myActionSelected >= 0)
{ {
@ -333,7 +328,6 @@ void EventMappingWidget::handleJoyUp(int stick, int button)
EventHandler& eh = instance().eventHandler(); EventHandler& eh = instance().eventHandler();
Event::Type event = eh.eventAtIndex(myActionSelected, myEventMode); Event::Type event = eh.eventAtIndex(myActionSelected, myEventMode);
cerr << "remap button stop" << endl;
// map either button/hat, solo button or button/axis combinations // map either button/hat, solo button or button/axis combinations
if(myLastHat != -1) if(myLastHat != -1)
{ {
@ -350,7 +344,6 @@ void EventMappingWidget::handleJoyUp(int stick, int button)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventMappingWidget::handleJoyAxis(int stick, int axis, int value, int button) void EventMappingWidget::handleJoyAxis(int stick, int axis, int value, int button)
{ {
cerr << "handleJoyAxis:" << axis << ", " << value << ", (" << stick << ", " << myLastStick << "), (" << axis << ", " << myLastAxis << ")" << endl;
// Remap joystick axes in remap mode // Remap joystick axes in remap mode
// There are two phases to detection: // There are two phases to detection:
// First, detect an axis 'on' event // First, detect an axis 'on' event
@ -360,7 +353,6 @@ void EventMappingWidget::handleJoyAxis(int stick, int axis, int value, int butto
// Detect the first axis event that represents 'on' // Detect the first axis event that represents 'on'
if((myLastStick == -1 || myLastStick == stick) && myLastAxis == -1 && value != 0) if((myLastStick == -1 || myLastStick == stick) && myLastAxis == -1 && value != 0)
{ {
cerr << "remap axis start" << endl;
myLastStick = stick; myLastStick = stick;
myLastAxis = axis; myLastAxis = axis;
myLastValue = value; myLastValue = value;
@ -372,7 +364,6 @@ void EventMappingWidget::handleJoyAxis(int stick, int axis, int value, int butto
EventHandler& eh = instance().eventHandler(); EventHandler& eh = instance().eventHandler();
Event::Type event = eh.eventAtIndex(myActionSelected, myEventMode); Event::Type event = eh.eventAtIndex(myActionSelected, myEventMode);
cerr << "remap axis stop" << endl;
if (eh.addJoyMapping(event, myEventMode, stick, myLastButton, JoyAxis(axis), myLastValue)) if (eh.addJoyMapping(event, myEventMode, stick, myLastButton, JoyAxis(axis), myLastValue))
stopRemapping(); stopRemapping();
} }