]> git.mxchange.org Git - flightgear.git/commitdiff
Add properties for raw axis and button values, for use
authorStuart Buchanan <stuart_d_buchanan@yahoo.co.uk>
Thu, 23 Aug 2012 20:52:30 +0000 (21:52 +0100)
committerStuart Buchanan <stuart_d_buchanan@yahoo.co.uk>
Thu, 23 Aug 2012 20:52:30 +0000 (21:52 +0100)
in joystick configuration function.  Also rationalize references to
/sim/fg-home into a global property.

src/Airports/groundnetwork.cxx
src/GUI/gui_funcs.cxx
src/Input/FGDeviceConfigurationMap.cxx
src/Input/FGJoystickInput.cxx
src/Input/FGJoystickInput.hxx
src/Main/fg_init.cxx
src/Main/globals.cxx
src/Main/globals.hxx
src/Main/options.cxx
src/Radio/antenna.cxx
src/Traffic/TrafficMgr.cxx

index c20cf2bea9b262613864f293fccdfc8a7a3d20ef..18db6c0a6f898511b275d136e126eac022f3166e 100644 (file)
@@ -272,7 +272,7 @@ FGGroundNetwork::~FGGroundNetwork()
     bool saveData = false;
     ofstream cachefile;
     if (fgGetBool("/sim/ai/groundnet-cache")) {
-        SGPath cacheData(fgGetString("/sim/fg-home"));
+        SGPath cacheData(globals->get_fg_home());
         cacheData.append("ai");
         string airport = parent->getId();
 
@@ -316,7 +316,7 @@ void FGGroundNetwork::saveElevationCache() {
     bool saveData = false;
     ofstream cachefile;
     if (fgGetBool("/sim/ai/groundnet-cache")) {
-        SGPath cacheData(fgGetString("/sim/fg-home"));
+        SGPath cacheData(globals->get_fg_home());
         cacheData.append("ai");
         string airport = parent->getId();
 
@@ -432,7 +432,7 @@ void FGGroundNetwork::init()
     //cerr << "Done initializing ground network" << endl;
     //exit(1);
     if (fgGetBool("/sim/ai/groundnet-cache")) {
-        SGPath cacheData(fgGetString("/sim/fg-home"));
+        SGPath cacheData(globals->get_fg_home());
         cacheData.append("ai");
         string airport = parent->getId();
 
index 82a48177235219eac056305a50e8321e183f8c8e..1da13da297f03124abd7ffe3210f6cf1c47ddca0 100644 (file)
@@ -483,7 +483,7 @@ namespace
             if (_path.create_dir( 0755 )) {
                 SG_LOG(SG_GENERAL, SG_ALERT, "Cannot create screenshot directory '"
                         << dir << "'. Trying home directory.");
-                dir = fgGetString("/sim/fg-home");
+                dir = globals->get_fg_home();
             }
 
             char filename[24];
@@ -588,7 +588,7 @@ bool fgDumpSnapShot ()
     if (path.create_dir( 0755 )) {
         SG_LOG(SG_GENERAL, SG_ALERT, "Cannot create screenshot directory '"
                 << dir << "'. Trying home directory.");
-        dir = fgGetString("/sim/fg-home");
+        dir = globals->get_fg_home();
     }
 
     char filename[24];
index 1991daaef741b3fc8a9437c94ca7e6fb1a7cf6c0..5680149f13efb8ab26fe0627536722a3f86b1171 100644 (file)
@@ -39,6 +39,7 @@ FGDeviceConfigurationMap::FGDeviceConfigurationMap( const char * relative_path,
   childname(aChildname)
 {
   int index = 1000;
+  scan_dir( SGPath(globals->get_fg_home(), relative_path), &index);
   scan_dir( SGPath(globals->get_fg_root(), relative_path), &index);
 
   PropertyList childNodes = base->getChildren(childname);
index 041fcc2e10bb9824f0d9457f0f83e304b7d9402e..046106abe9323ad4e77bd0ec73ace5f8c6572a47 100644 (file)
@@ -104,6 +104,7 @@ void FGJoystickInput::init()
   jsInit();
   SG_LOG(SG_INPUT, SG_DEBUG, "Initializing joystick bindings");
   SGPropertyNode_ptr js_nodes = fgGetNode("/input/joysticks", true);
+  status_node = fgGetNode("/devices/status/joysticks", true);
 
   FGDeviceConfigurationMap configMap("Input/Joysticks", js_nodes, "js-named");
 
@@ -310,6 +311,16 @@ void FGJoystickInput::update( double dt )
     js->read(&buttons, axis_values);
     if (js->notWorking()) // If js is disconnected
       continue;
+            
+    // Update device status    
+    SGPropertyNode_ptr status = status_node->getChild("joystick", i, true);
+    for (int j = 0; j < MAX_JOYSTICK_AXES; j++) {
+      status->getChild("axis", j, true)->setFloatValue(axis_values[j]);
+    }
+    
+    for (int j = 0; j < MAX_JOYSTICK_BUTTONS; j++) {
+      status->getChild("button", j, true)->setBoolValue((buttons & (1u << j)) > 0 );
+    }
 
                                 // Fire bindings for the axes.
     for (int j = 0; j < bindings[i].naxes; j++) {
index 45de33f94c6d04db6440fabf20ca0c08e47713f4..1ab5a6f59ed5d82a0925319f80542cc4660ae97f 100644 (file)
@@ -53,6 +53,7 @@ public:
 
 private:
    void _remove(bool all);
+   SGPropertyNode_ptr status_node;
 
   /**
    * Settings for a single joystick axis.
@@ -83,7 +84,7 @@ private:
     int nbuttons;
     axis * axes;
     FGButton * buttons;
-    bool predefined;
+    bool predefined;    
   };
   joystick bindings[MAX_JOYSTICKS];
 
index cb4a2e537c7100e7d5f7e0558269464ab07fc4b1..651b0d4438ecdbfa064dbbd63fa3fd329c26431c 100644 (file)
@@ -406,6 +406,8 @@ bool fgInitConfig ( int argc, char **argv )
     const char *fg_home = getenv("FG_HOME");
     if (fg_home)
       dataPath = fg_home;
+      
+    globals->set_fg_home(dataPath.c_str());
     
     simgear::Dir exportDir(simgear::Dir(dataPath).file("Export"));
     if (!exportDir.exists()) {
@@ -588,8 +590,8 @@ static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& par
         string fltType;
         string acOperator;
         SGPath acData;
-        try {
-            acData = fgGetString("/sim/fg-home");
+        try {          
+            acData = globals->get_fg_home();
             acData.append("aircraft-data");
             string acfile = fgGetString("/sim/aircraft") + string(".xml");
             acData.append(acfile);
index 8c8ca52bf75b68d116154d16e079e2998807be1e..a8df39d03403afbceff5917c6b2433d8d344e18f 100644 (file)
@@ -128,6 +128,7 @@ FGGlobals::FGGlobals() :
     event_mgr( new SGEventMgr ),
     sim_time_sec( 0.0 ),
     fg_root( "" ),
+    fg_home( "" ),
     time_params( NULL ),
     ephem( NULL ),
     mag( NULL ),
@@ -214,7 +215,6 @@ FGGlobals::~FGGlobals()
     locale = NULL;
 }
 
-
 // set the fg_root path
 void FGGlobals::set_fg_root (const string &root) {
     SGPath tmp(root);
@@ -242,6 +242,12 @@ void FGGlobals::set_fg_root (const string &root) {
       simgear::ResourceManager::PRIORITY_DEFAULT);
 }
 
+// set the fg_home path
+void FGGlobals::set_fg_home (const string &home) {
+    SGPath tmp(home);
+    fg_home = tmp.realpath();
+}
+
 void FGGlobals::append_fg_scenery (const string &paths)
 {
 //    fg_scenery.clear();
@@ -483,7 +489,7 @@ FGGlobals::saveUserSettings()
       // don't save settings more than once on shutdown
       haveUserSettings = false;
 
-      SGPath autosaveFile(fgGetString("/sim/fg-home"));
+      SGPath autosaveFile(globals->get_fg_home());
       autosaveFile.append( "autosave.xml" );
       autosaveFile.create_dir( 0700 );
       SG_LOG(SG_IO, SG_INFO, "Saving user settings to " << autosaveFile.str());
index 2ec9cc3771ff476ad6a7adfc1883fd869c4eb468..4079a4a9a27f64a21fe6f0bc63aea74477189e40 100644 (file)
@@ -98,6 +98,9 @@ private:
     // Root of FlightGear data tree
     std::string fg_root;
 
+    // Users home directory for data
+    std::string fg_home;
+
     // Roots of FlightGear scenery tree
     string_list fg_scenery;
 
@@ -192,6 +195,9 @@ public:
     inline const std::string &get_fg_root () const { return fg_root; }
     void set_fg_root (const std::string &root);
 
+    inline const std::string &get_fg_home () const { return fg_home; }
+    void set_fg_home (const std::string &home);
+
     inline const string_list &get_fg_scenery () const { return fg_scenery; }
     void append_fg_scenery (const std::string &scenery);
 
index d5cc06e9a437f3cede95373605534cab4d9a042c..98614e10f40135b2b48d4e79812331ef8163563d 100644 (file)
@@ -1182,7 +1182,7 @@ fgOptVersion( const char *arg )
     cerr << "Revision: " << REVISION << endl;
     cerr << "Build-Id: " << HUDSON_BUILD_ID << endl;
     cerr << "FG_ROOT=" << globals->get_fg_root() << endl;
-    cerr << "FG_HOME=" << fgGetString("/sim/fg-home") << endl;
+    cerr << "FG_HOME=" << globals->get_fg_home() << endl;
     cerr << "FG_SCENERY=";
 
     int didsome = 0;
@@ -2031,7 +2031,7 @@ void Options::processOptions()
   if (fgGetBool("/sim/terrasync/enabled")) {
     string terrasyncDir = fgGetString("/sim/terrasync/scenery-dir");
     if (terrasyncDir.empty()) {
-      SGPath p(fgGetString("/sim/fg-home"));
+      SGPath p(globals->get_fg_home());
       p.append("TerraSync");
       if (!p.exists()) {
         simgear::Dir dd(p);
index 8a55707d55abad517810b3604648a7bf0c119b87..fa5e00110ea53fe81d54400058fc26eb20097a88 100644 (file)
@@ -73,7 +73,7 @@ double FGRadioAntenna::calculate_gain(double bearing, double angle) {
 
 void FGRadioAntenna::load_NEC_antenna_pattern(string type) {
        
-       //SGPath pattern_file(fgGetString("/sim/fg-home"));
+       //SGPath pattern_file(globals->get_fg_home());
        SGPath pattern_file(globals->get_fg_root());
        pattern_file.append("Navaids/Antennas");
        pattern_file.append(type + ".txt");
index a4562d3b49a924a4a1dcfc152a5c2bf5b4719819..2de3be5d099e8ef8ac782d6e8490cc55283a1d10 100644 (file)
@@ -99,7 +99,7 @@ void FGTrafficManager::shutdown()
     bool saveData = false;
     ofstream cachefile;
     if (fgGetBool("/sim/traffic-manager/heuristics")) {
-        SGPath cacheData(fgGetString("/sim/fg-home"));
+        SGPath cacheData(globals->get_fg_home());
         cacheData.append("ai");
         string airport = fgGetString("/sim/presets/airport-id");
 
@@ -223,7 +223,7 @@ void FGTrafficManager::loadHeuristics()
     HeuristicMap heurMap;
     //cerr << "Processing Heuristics" << endl;
     // Load the heuristics data
-    SGPath cacheData(fgGetString("/sim/fg-home"));
+    SGPath cacheData(globals->get_fg_home());
     cacheData.append("ai");
     string airport = fgGetString("/sim/presets/airport-id");
     if ((airport) != "") {