]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/turn_indicator.cxx
Reset: work with threaded OSG modes
[flightgear.git] / src / Instrumentation / turn_indicator.cxx
index 84bfdbdf81661fcb0434bb3cd44a3c79fee7d7e0..06fd868e2ba8f313b10b35efe54f581fd64c74b6 100644 (file)
@@ -3,18 +3,30 @@
 //
 // This file is in the Public Domain and comes with no warranty.
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <simgear/compiler.h>
+#include <iostream>
+#include <string>
+#include <sstream>
+
 #include "turn_indicator.hxx"
 #include <Main/fg_props.hxx>
 #include <Main/util.hxx>
 
+using std::string;
 
 // Use a bigger number to be more responsive, or a smaller number
 // to be more sluggish.
-#define RESPONSIVENESS 1.0
+#define RESPONSIVENESS 0.5
 
 
-TurnIndicator::TurnIndicator () :
-    _last_rate(0)
+TurnIndicator::TurnIndicator ( SGPropertyNode *node) :
+    _last_rate(0),
+    _name(node->getStringValue("name", "turn-indicator")),
+    _num(node->getIntValue("number", 0))
 {
 }
 
@@ -25,35 +37,58 @@ TurnIndicator::~TurnIndicator ()
 void
 TurnIndicator::init ()
 {
+    string branch;
+    branch = "/instrumentation/" + _name;
+
+    SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
     _roll_rate_node = fgGetNode("/orientation/roll-rate-degps", true);
     _yaw_rate_node = fgGetNode("/orientation/yaw-rate-degps", true);
     _electric_current_node = 
         fgGetNode("/systems/electrical/outputs/turn-coordinator", true);
-    _rate_out_node = 
-        fgGetNode("/instrumentation/turn-indicator/indicated-turn-rate", true);
+    _rate_out_node = node->getChild("indicated-turn-rate", 0, true);
+
+    reinit();
+}
+
+void
+TurnIndicator::reinit ()
+{
+    _last_rate = 0;
+    _gyro.reinit();
 }
 
 void
 TurnIndicator::bind ()
 {
-    fgTie("/instrumentation/turn-indicator/serviceable",
+    std::ostringstream temp;
+    string branch;
+    temp << _num;
+    branch = "/instrumentation/" + _name + "[" + temp.str() + "]";
+
+    fgTie((branch + "/serviceable").c_str(),
           &_gyro, &Gyro::is_serviceable, &Gyro::set_serviceable);
-    fgTie("/instrumentation/turn-indicator/spin",
+    fgTie((branch + "/spin").c_str(),
           &_gyro, &Gyro::get_spin_norm, &Gyro::set_spin_norm);
 }
 
 void
 TurnIndicator::unbind ()
 {
-    fgUntie("/instrumentation/turn-indicator/serviceable");
-    fgUntie("/instrumentation/turn-indicator/spin");
+    std::ostringstream temp;
+    string branch;
+    temp << _num;
+    branch = "/instrumentation/" + _name + "[" + temp.str() + "]";
+
+    fgUntie((branch + "/serviceable").c_str());
+    fgUntie((branch + "/serviceable").c_str());
 }
 
 void
 TurnIndicator::update (double dt)
 {
                                 // Get the spin from the gyro
-    _gyro.set_power_norm(_electric_current_node->getDoubleValue()/60.0);
+    double power = _electric_current_node->getDoubleValue() / 12.0;
+    _gyro.set_power_norm(power);
     _gyro.update(dt);
     double spin = _gyro.get_spin_norm();