]> git.mxchange.org Git - flightgear.git/blobdiff - src/Network/ATC-Inputs.cxx
Add an "additive-switch" type.
[flightgear.git] / src / Network / ATC-Inputs.cxx
index 16817743e2c076a41a1ae637c5e9d7c74a4764c1..2f63b1be462098884fb150f2cc7bb33cfc6337fe 100644 (file)
@@ -136,11 +136,14 @@ bool FGATCInput::open() {
     init_config();
 
     SG_LOG( SG_IO, SG_ALERT,
-           "Initializing ATC hardware, please wait ..." );
+           "Initializing ATC input hardware, please wait ..." );
 
-    snprintf( analog_in_file, 256, "/proc/atc610x/board%d/analog_in", board );
-    snprintf( radios_file, 256, "/proc/atc610x/board%d/radios", board );
-    snprintf( switches_file, 256, "/proc/atc610x/board%d/switches", board );
+    snprintf( analog_in_file, 256,
+              "/proc/atcflightsim/board%d/analog_in", board );
+    snprintf( radios_file, 256,
+              "/proc/atcflightsim/board%d/radios", board );
+    snprintf( switches_file, 256,
+              "/proc/atcflightsim/board%d/switches", board );
 
 #if defined( unix ) || defined( __CYGWIN__ )
 
@@ -182,7 +185,7 @@ bool FGATCInput::open() {
     /////////////////////////////////////////////////////////////////////
 
     SG_LOG( SG_IO, SG_ALERT,
-           "Done initializing ATC hardware." );
+           "Done initializing ATC input hardware." );
 
     is_open = true;
 
@@ -614,6 +617,7 @@ bool FGATCInput::do_switches() {
             float factor = 1.0;
             int filter = -1;
             float scaled_value = 0.0f;
+           bool invert = false;
 
             // get common options
 
@@ -637,6 +641,10 @@ bool FGATCInput::do_switches() {
             if ( prop != NULL ) {
                 factor = prop->getFloatValue();
             }
+            prop = child->getChild( "invert" );
+            if ( prop != NULL ) {
+                invert = prop->getBoolValue();
+            }
             prop = child->getChild( "steady-state-filter" );
             if ( prop != NULL ) {
                 filter = prop->getIntValue();
@@ -657,6 +665,11 @@ bool FGATCInput::do_switches() {
                 // Fetch the raw value
                 int raw_value = switch_matrix[board][row][col];
 
+               // Invert
+               if ( invert ) {
+                   raw_value = !raw_value;
+               }
+
                 // Cook the value
                 scaled_value = (float)raw_value * factor;
 
@@ -696,6 +709,42 @@ bool FGATCInput::do_switches() {
 
                 // Cook the value
                 scaled_value *= factor;
+            } else if ( cname == "additive-switch" ) {
+                float additive_value = 0.0f;
+               float increment = 0.0f;
+
+                SGPropertyNode *pos;
+                int k = 0;
+                while ( (pos = child->getChild("position", k++)) != NULL ) {
+                    // read the combo position entries from the property tree
+
+                    prop = pos->getChild( "row" );
+                    if ( prop != NULL ) {
+                        row = prop->getIntValue();
+                    }
+                    prop = pos->getChild( "col" );
+                    if ( prop != NULL ) {
+                        col = prop->getIntValue();
+                    }
+                    prop = pos->getChild( "value" );
+                    if ( prop != NULL ) {
+                        increment = prop->getFloatValue();
+                    }
+
+                    // Fetch the raw value
+                    int raw_value = switch_matrix[board][row][col];
+                    // cout << "sm[" << board << "][" << row << "][" << col
+                    //      << "] = " << raw_value << endl;
+
+                    if ( raw_value ) {
+                        // set scaled_value to the first combo_value
+                        // that matches and jump out of loop.
+                        additive_value += increment;
+                    }
+                }
+
+                // Cook the value
+                scaled_value = additive_value * factor;
             }
 
             // handle filter request.  The value of the switch must be
@@ -859,6 +908,10 @@ bool FGATCInput::close() {
 
 #if defined( unix ) || defined( __CYGWIN__ )
 
+    if ( !is_open ) {
+        return true;
+    }
+
     int result;
 
     result = ::close( analog_in_fd );