I'm submitting another patch for comments / suggestions.
I've added a listener to the setting-inhg property , and removed the settings check in the update loop , it is updated by the listener ... But trying to add a listener to the kpa property to convert and write to setting-inhg (also with a listener attached) causes an interesting problem. Any ideas or help would be appreciated . If the majority here thinks this is not a desirable addition , well at least it's a learning experience for me :) The reason I would like this added , once I find a solution to the listeners writing to each other , is that a 2d panel text layer can be scaled and formatted easily to get the Kpa , but I've always had to create a converted property with nasal for textranslate animations . Besides , as was pointed out on IRC , Mb / Kpa is a common measurement here.
Thanks
Index: altimeter.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/altimeter.cxx,v
retrieving revision 1.15
diff -U 3 -r1.15 altimeter.cxx
--- altimeter.cxx       3 Apr 2007 11:36:47 -0000       1.15
+++ altimeter.cxx       28 Nov 2008 05:38:29 -0000
@@ -28,6 +28,10 @@
 
 #include "altimeter.hxx"
 
+#define STD_INHG 29.921260
+#define KPA_FACTOR 3.386389
+#define INHG_FACTOR 0.2953
+
 Altimeter::Altimeter ( SGPropertyNode *node, double quantum )
     : _name(node->getStringValue("name", "altimeter")),
       _num(node->getIntValue("number", 0)),
@@ -37,7 +41,10 @@
 {}
 
 Altimeter::~Altimeter ()
-{}
+{
+    _setting_node->removeChangeListener(this);
+//    _kpa_node->removeChangeListener(this);
+}
 
 void
 Altimeter::init ()
@@ -47,15 +54,25 @@
 
     SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
     raw_PA = 0.0;
+    _inHG = STD_INHG;
     _pressure_node     = fgGetNode(_static_pressure.c_str(), true);
     _serviceable_node  = node->getChild("serviceable", 0, true);
     _setting_node      = node->getChild("setting-inhg", 0, true);
+    _kpa_node      = node->getChild("setting-kpa", 0, true);
     _press_alt_node    = node->getChild("pressure-alt-ft", 0, true);
     _mode_c_node       = node->getChild("mode-c-alt-ft", 0, true);
     _altitude_node     = node->getChild("indicated-altitude-ft", 0, true);
 
-    if (_setting_node->getDoubleValue() == 0)
-        _setting_node->setDoubleValue(29.921260);
+    if (_setting_node->getDoubleValue() == 0){
+        _setting_node->setDoubleValue(STD_INHG);
+        _kpa_node->setDoubleValue(STD_INHG * KPA_FACTOR);
+    } else {
+        _inHG = _setting_node->getDoubleValue();
+        _kpa_node->setDoubleValue(_inHG * KPA_FACTOR);
+    }
+
+    _setting_node->addChangeListener(this);
+//        _kpa_node->addChangeListener(this);
 }
 
 void
@@ -64,7 +81,7 @@
     if (_serviceable_node->getBoolValue()) {
         double trat = _tau > 0 ? dt/_tau : 100;
         double pressure = _pressure_node->getDoubleValue();
-        double setting = _setting_node->getDoubleValue();
+        double setting = _inHG;
         double press_alt = _press_alt_node->getDoubleValue();
         // The mechanism settles slowly toward new pressure altitude:
         raw_PA = fgGetLowPass(raw_PA, _altimeter.press_alt_ft(pressure), trat);
@@ -79,4 +96,10 @@
     }
 }
 
+void Altimeter::valueChanged(SGPropertyNode* prop)
+{
+    _inHG = _setting_node->getDoubleValue();
+    _kpa_node->setDoubleValue(_inHG * KPA_FACTOR);
+}
+
 // end of altimeter.cxx
Index: altimeter.hxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/altimeter.hxx,v
retrieving revision 1.8
diff -U 3 -r1.8 altimeter.hxx
--- altimeter.hxx       31 Mar 2007 09:36:20 -0000      1.8
+++ altimeter.hxx       28 Nov 2008 05:38:29 -0000
@@ -26,7 +26,7 @@
  *
  * /instrumentation/<name>/indicated-altitude-ft
  */
-class Altimeter : public SGSubsystem
+class Altimeter : public SGPropertyChangeListener,public SGSubsystem
 {
 
 public:
@@ -36,6 +36,7 @@
 
     virtual void init ();
     virtual void update (double dt);
+    virtual void valueChanged(SGPropertyNode* prop);
 
 private:
 
@@ -46,9 +47,11 @@
     double _quantum;
     double _kollsman;
     double raw_PA;
+    double _inHG;
 
     SGPropertyNode_ptr _serviceable_node;
     SGPropertyNode_ptr _setting_node;
+    SGPropertyNode_ptr _kpa_node;
     SGPropertyNode_ptr _pressure_node;
     SGPropertyNode_ptr _press_alt_node;
     SGPropertyNode_ptr _mode_c_node;
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to