Added --debug switch.

You no longer need a keyboard to save input configuration; that was stupid anyway. You should be able to set up ES without a keyboard now!
This commit is contained in:
Aloshi 2012-12-20 12:29:05 -06:00
parent af36932f30
commit d0cea1b8e7
6 changed files with 74 additions and 6 deletions

View file

@ -83,6 +83,7 @@ You can use `--help` to view a list of command-line options. Briefly outlined he
--ignore-gamelist - do not parse any gamelist.xml files.
--draw-framerate - draw the framerate.
--no-exit - do not display 'exit' in the ES menu.
--debug - print additional output to the console, primarily about input.
```
Writing an es_systems.cfg

View file

@ -1,3 +1,7 @@
December 20, 2012
-Added --debug command-line option. Useful if you're having input config problems.
-Changed things so you can finish configuring without a keyboard. You should no longer need a keyboard to set up ES; SSH access should be sufficient.
December 14, 2012
-Added %BASENAME% tag for launch commands. Useful for AdvMAME.

View file

@ -4,6 +4,8 @@
#include <fstream>
#include <sstream>
extern bool DEBUG; //defined in main.cpp
std::vector<GuiComponent*> InputManager::inputVector;
SDL_Event* InputManager::lastEvent = NULL;
@ -196,6 +198,9 @@ void InputManager::processEvent(SDL_Event* event)
void InputManager::loadConfig()
{
if(DEBUG)
std::cout << "Loading input config...\n";
//clear any old config
joystickButtonMap.clear();
joystickAxisPosMap.clear();
@ -263,18 +268,35 @@ void InputManager::loadConfig()
{
if(!joystickName.empty())
{
if(DEBUG)
std::cout << " attempting to open joystick of name \"" << joystickName << "\"\n";
bool found = false;
for(int i = 0; i < SDL_NumJoysticks(); i++)
{
if(strcmp(SDL_JoystickName(i), joystickName.c_str()) == 0)
{
std::cout << "opening joystick " << joystickName << "\n";
if(DEBUG)
std::cout << " found, opening joystick " << joystickName << "\n";
SDL_JoystickOpen(i);
found = true;
break;
}
}
if(DEBUG && !found)
std::cout << " could not find named joystick! You could try manually removing the joystick name entry in the input config file.\n";
}else{
if(DEBUG)
std::cout << " opening first joystick\n";
SDL_JoystickOpen(0); //if we don't have a specific joystick in mind, take the first
}
}else{
if(DEBUG)
std::cout << " no joysticks detected by SDL_NumJoysticks(), input loaded but no joystick opened\n";
}
}

View file

@ -3,7 +3,8 @@
#include <iostream>
#include <fstream>
std::string GuiInputConfig::sConfigPath = "./input.cfg";
extern bool DEBUG; //defined in main.cpp
std::string GuiInputConfig::sInputs[] = { "UNKNOWN", "UP", "DOWN", "LEFT", "RIGHT", "BUTTON1 (Accept)", "BUTTON2 (Back)", "START (Menu)", "SELECT (Jump-to-letter)", "PAGE UP", "PAGE DOWN" }; //must be same order as InputManager::InputButton enum; only add to the end to preserve backwards compatibility
int GuiInputConfig::sInputCount = 11;
@ -51,7 +52,7 @@ void GuiInputConfig::onRender()
Renderer::drawCenteredText("Remember - you'll need to set up your emulator separately!", 0, Renderer::getScreenHeight() - height, 0x000000FF, font);
if(mDone)
Renderer::drawCenteredText("All done! Press a keyboard key to save.", 0, height * 5, 0x00BB00FF, font);
Renderer::drawCenteredText("All done! Press a key or button to save.", 0, height * 5, 0x00BB00FF, font);
else
Renderer::drawCenteredText("Please press the axis/button for " + sInputs[mInputNum], 0, height * 5, 0x00C000FF, font);
}
@ -60,13 +61,19 @@ void GuiInputConfig::onInput(InputManager::InputButton button, bool keyDown)
{
if(mDone)
{
if(InputManager::lastEvent->type == SDL_KEYUP)
if(InputManager::lastEvent->type == SDL_KEYUP || InputManager::lastEvent->type == SDL_JOYBUTTONDOWN)
{
if(DEBUG)
std::cout << " finishing configuration...\n";
writeConfig();
if(mJoystick)
SDL_JoystickClose(mJoystick);
if(DEBUG)
std::cout << "Config complete. Closed joystick, loading input then opening GuiGameList.\n";
InputManager::loadConfig();
delete this;
GuiGameList::create();
@ -77,12 +84,19 @@ void GuiInputConfig::onInput(InputManager::InputButton button, bool keyDown)
SDL_Event* event = InputManager::lastEvent;
if(event->type == SDL_KEYUP)
{
if(DEBUG)
std::cout << " [KEYUP] (skipping)\n";
//keyboard key pressed; skip and continue
mInputNum++;
}
if(event->type == SDL_JOYBUTTONDOWN)
{
if(DEBUG)
std::cout << " [JOYBUTTONDOWN] button " << event->jbutton.button << "\n";
mButtonMap[event->jbutton.button] = (InputManager::InputButton)mInputNum;
std::cout << " Mapping " << sInputs[mInputNum] << " to button " << (int)event->jbutton.button << "\n";
mInputNum++;
@ -90,6 +104,9 @@ void GuiInputConfig::onInput(InputManager::InputButton button, bool keyDown)
if(event->type == SDL_JOYAXISMOTION)
{
if(DEBUG)
std::cout << " [JOYAXISMOTION] axis " << event->jaxis.axis << ", value " << event->jaxis.value << "\n";
//std::cout << "motion on axis " << event->jaxis.axis << " to value " << event->jaxis.value << "\n";
if(event->jaxis.axis == mLastAxis)
@ -122,6 +139,9 @@ void GuiInputConfig::onInput(InputManager::InputButton button, bool keyDown)
void GuiInputConfig::writeConfig()
{
if(DEBUG)
std::cout << " writing config...";
std::string path = InputManager::getConfigPath();
std::ofstream file(path.c_str());
@ -146,4 +166,7 @@ void GuiInputConfig::writeConfig()
}
file.close();
if(DEBUG)
std::cout << "done.\n";
}

View file

@ -20,7 +20,6 @@ private:
SDL_Joystick* mJoystick;
static std::string sInputs[];
static int sInputCount;
static std::string sConfigPath;
std::map<int, InputManager::InputButton> mButtonMap;
std::map<int, InputManager::InputButton> mAxisPosMap;

View file

@ -21,6 +21,7 @@ bool PARSEGAMELISTONLY = false;
bool IGNOREGAMELIST = false;
bool DRAWFRAMERATE = false;
bool DONTSHOWEXIT = false;
bool DEBUG = false;
namespace fs = boost::filesystem;
@ -52,6 +53,9 @@ int main(int argc, char* argv[])
}else if(strcmp(argv[i], "--no-exit") == 0)
{
DONTSHOWEXIT = true;
}else if(strcmp(argv[i], "--debug") == 0)
{
DEBUG = true;
}else if(strcmp(argv[i], "--help") == 0)
{
std::cout << "EmulationStation, a graphical front-end for ROM browsing.\n";
@ -62,6 +66,7 @@ int main(int argc, char* argv[])
std::cout << "--ignore-gamelist ignore the gamelist (useful for troubleshooting)\n";
std::cout << "--draw-framerate display the framerate\n";
std::cout << "--no-exit don't show the exit option in the menu\n";
std::cout << "--debug print additional output to console\n";
std::cout << "--help summon a sentient, angry tuba\n\n";
std::cout << "More information available in README.md.\n";
return 0;
@ -120,15 +125,29 @@ int main(int argc, char* argv[])
//choose which GUI to open depending on Input configuration
if(fs::exists(InputManager::getConfigPath()))
{
if(DEBUG)
std::cout << "Found input config in " << InputManager::getConfigPath() << "\n";
//an input config already exists - load it and proceed to the gamelist as usual.
InputManager::loadConfig();
GuiGameList::create();
}else{
if(DEBUG)
std::cout << "SDL_NumJoysticks() reports " << SDL_NumJoysticks() << " present.\n";
//if no input.cfg is present, but a joystick is connected, launch the input config GUI
if(SDL_NumJoysticks() > 0)
{
if(DEBUG)
std::cout << " at least one joystick detected, launching config GUI...\n";
new GuiInputConfig();
else
}else{
if(DEBUG)
std::cout << " no joystick detected, ignoring...\n";
GuiGameList::create();
}
}
}