]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/turn_indicator.cxx
James Turner:
[flightgear.git] / src / Instrumentation / turn_indicator.cxx
index 2a45657901073f6638f05f8a4cc301e7a88ba8a5..973b4054aad99d6f46df5edf915ace15cf5f8536 100644 (file)
@@ -3,6 +3,11 @@
 //
 // This file is in the Public Domain and comes with no warranty.
 
+#include <simgear/compiler.h>
+#include <iostream>
+#include <string>
+#include <sstream>
+
 #include "turn_indicator.hxx"
 #include <Main/fg_props.hxx>
 #include <Main/util.hxx>
 
 TurnIndicator::TurnIndicator ( SGPropertyNode *node) :
     _last_rate(0),
-    name("turn-indicator"),
-    num(0)
-{
-    int i;
-    for ( i = 0; i < node->nChildren(); ++i ) {
-        SGPropertyNode *child = node->getChild(i);
-        string cname = child->getName();
-        string cval = child->getStringValue();
-        if ( cname == "name" ) {
-            name = cval;
-        } else if ( cname == "number" ) {
-            num = child->getIntValue();
-        } else {
-            SG_LOG( SG_INSTR, SG_WARN, "Error in turn-indicator config logic" );
-            if ( name.length() ) {
-                SG_LOG( SG_INSTR, SG_WARN, "Section = " << name );
-            }
-        }
-    }
-}
-
-TurnIndicator::TurnIndicator () :
-    _last_rate(0)
+    _name(node->getStringValue("name", "turn-indicator")),
+    _num(node->getIntValue("number", 0))
 {
 }
 
@@ -49,9 +33,9 @@ void
 TurnIndicator::init ()
 {
     string branch;
-    branch = "/instrumentation/" + name;
+    branch = "/instrumentation/" + _name;
 
-    SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
+    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 = 
@@ -62,30 +46,35 @@ TurnIndicator::init ()
 void
 TurnIndicator::bind ()
 {
+    std::ostringstream temp;
     string branch;
-    branch = "/instrumentation/" + name + "/serviceable";
-    fgTie(branch.c_str(),
+    temp << _num;
+    branch = "/instrumentation/" + _name + "[" + temp.str() + "]";
+
+    fgTie((branch + "/serviceable").c_str(),
           &_gyro, &Gyro::is_serviceable, &Gyro::set_serviceable);
-    branch = "/instrumentation/" + name + "/spin";
-    fgTie(branch.c_str(),
+    fgTie((branch + "/spin").c_str(),
           &_gyro, &Gyro::get_spin_norm, &Gyro::set_spin_norm);
 }
 
 void
 TurnIndicator::unbind ()
 {
+    std::ostringstream temp;
     string branch;
-    branch = "/instrumentation/" + name + "/serviceable";
-    fgUntie(branch.c_str());
-    branch = "/instrumentation/" + name + "/spin";
-    fgUntie(branch.c_str());
+    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();