82int main(
int argc,
char *argv[] ) {
84 for (
int i = 1;
i < argc;
i++) {
85 if (strcmp(
"--help", argv[
i]) == 0) {
86 cout <<
"Usage:" << endl;
87 cout <<
" --help\t\t\tShow this help" << endl;
89 }
else if (strncmp(
"--fg-root=", argv[
i], 10) == 0) {
92 cout <<
"Unknown option \"" << argv[
i] <<
"\"" << endl;
106 cout <<
"Can't find any joysticks ..." << endl;
109 cout << endl <<
"Now measuring the dead band of your joystick. The dead band is the area " << endl
110 <<
"where the joystick is centered and should not generate any input. Move all " << endl
111 <<
"axes around in this dead zone during the ten seconds this test will take." << endl;
112 cout <<
"Press enter to continue." << endl;
113 cin.ignore(1024,
'\n');
115 cout << endl <<
"Dead band calibration finished. Press enter to start control assignment." << endl;
116 cin.ignore(1024,
'\n');
120 SGPropertyNode_ptr *jstree =
new SGPropertyNode_ptr[ jss->
getNumJoysticks() ];
123 <<
" \"" << jss->
getJoystick()->getName() <<
"\" has "
124 << jss->
getJoystick()->getNumAxes() <<
" axes" << endl;
132 SGPath templatefile(
getFGRoot(argc, argv) );
133 templatefile.append(
"Input");
134 templatefile.append(
"Joysticks");
135 templatefile.append(
"template.xml");
137 SGPropertyNode *templatetree =
new SGPropertyNode();
139 readProperties(templatefile, templatetree);
140 }
catch (sg_io_exception & e) {
141 cout << e.getFormattedMessage ();
145 for(PropertyList::iterator iter = axes.begin(); iter != axes.end(); ++iter) {
146 cout <<
"Move the control you wish to use for " << (*iter)->getStringValue(
"desc")
147 <<
" " << (*iter)->getStringValue(
"direction") << endl;
148 cout <<
"Pressing a button skips this axis" << endl;
154 <<
" to control " << (*iter)->getStringValue(
"desc") << endl;
157 copyProperties(*iter, axis);
165 cout <<
"Skipping control" << endl;
172 PropertyList buttons = templatetree->getChildren(
"button");
173 for(PropertyList::iterator iter = buttons.begin(); iter != buttons.end(); ++iter) {
174 cout <<
"Press the button you wish to use for " << (*iter)->getStringValue(
"desc") << endl;
175 cout <<
"Moving a joystick axis skips this button" << endl;
181 <<
" to control " << (*iter)->getStringValue(
"desc") << endl;
184 copyProperties(*iter, button);
189 cout <<
"Skipping control" << endl;
196 cout <<
"Your joystick settings are in ";
199 cout <<
"js" <<
i <<
".xml";
205 jstree[
i]->setStringValue(
"name", jss->
getJoystick(
i)->getName());
206 writeProperties(xfs[
i], jstree[
i],
true);
207 }
catch (sg_io_exception & e) {
208 cout << e.getFormattedMessage ();
212 cout <<
"." << endl <<
"Check and edit as desired. Once you are happy," << endl
213 <<
"move relevant js<n>.xml files to $FG_ROOT/Input/Joysticks/ (if you didn't use" << endl
214 <<
"an attached controller, you don't need to move the corresponding file)" << endl;
236 gethostname(_hostname, 256);
241 SG_LOG(SG_INPUT, SG_INFO,
"Scanning command line for: " << option );
243 int len = option.length();
246 SG_LOG( SG_INPUT, SG_DEBUG,
"argv[" <<
i <<
"] = " << argv[
i] );
248 string arg = argv[
i];
249 if ( arg.find( option ) == 0 ) {
250 return arg.substr( len );
262 sg_gzifstream in( path );
263 if ( !in.is_open() ) {
267 SG_LOG( SG_INPUT, SG_INFO,
"Scanning " << path <<
" for: " << option );
269 int len = option.length();
272 while ( ! in.eof() ) {
274 getline( in, line,
'\n' );
277 if ( line[line.length() - 1] < 32 ) {
278 line = line.substr( 0, line.length()-1 );
281 if ( line.find( option ) == 0 ) {
282 return line.substr( len );
335 if ( root.empty() ) {
336 char *envp = ::getenv(
"FG_ROOT" );
337 if ( envp != NULL ) {
344 if ( root.empty() ) {
345#if defined( __CYGWIN__ )
347#elif defined( _WIN32 )
349#elif defined(__APPLE__)
355 CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
358 CFURLRef dataDir = CFURLCreateCopyAppendingPathComponent(NULL, resourcesUrl, CFSTR(
"data"),
true);
361 CFStringRef path = CFURLCopyFileSystemPath(dataDir, kCFURLPOSIXPathStyle);
362 root = CFStringGetCStringPtr(path, CFStringGetSystemEncoding());
365 CFRelease(resourcesUrl);
373 SG_LOG(SG_INPUT, SG_INFO,
"fg_root = " << root );