]> 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 0d11ca64e7ea154e0e8f24d8b7ac274f0d328cc5..2f63b1be462098884fb150f2cc7bb33cfc6337fe 100644 (file)
@@ -63,6 +63,7 @@ FGATCInput::FGATCInput( const int _board, const SGPath &_config_file ) :
 
 // Read analog inputs
 static void ATCReadAnalogInputs( int fd, unsigned char *analog_in_bytes ) {
+#if defined( unix ) || defined( __CYGWIN__ )
     // rewind
     lseek( fd, 0, SEEK_SET );
 
@@ -71,11 +72,13 @@ static void ATCReadAnalogInputs( int fd, unsigned char *analog_in_bytes ) {
        SG_LOG( SG_IO, SG_ALERT, "Read failed" );
        exit( -1 );
     }
+#endif
 }
 
 
 // Read status of radio switches and knobs
 static void ATCReadRadios( int fd, unsigned char *switch_data ) {
+#if defined( unix ) || defined( __CYGWIN__ )
     // rewind
     lseek( fd, 0, SEEK_SET );
 
@@ -84,11 +87,13 @@ static void ATCReadRadios( int fd, unsigned char *switch_data ) {
        SG_LOG( SG_IO, SG_ALERT, "Read failed" );
        exit( -1 );
     }
+#endif
 }
 
 
 // Read switch inputs
 static void ATCReadSwitches( int fd, unsigned char *switch_bytes ) {
+#if defined( unix ) || defined( __CYGWIN__ )
     // rewind
     lseek( fd, 0, SEEK_SET );
 
@@ -97,6 +102,7 @@ static void ATCReadSwitches( int fd, unsigned char *switch_bytes ) {
        SG_LOG( SG_IO, SG_ALERT, "Read failed" );
        exit( -1 );
     }
+#endif
 }
 
 
@@ -130,12 +136,14 @@ bool FGATCInput::open() {
     init_config();
 
     SG_LOG( SG_IO, SG_ALERT,
-           "Initializing ATC 610x hardware, please wait ..." );
+           "Initializing ATC input hardware, please wait ..." );
 
-    snprintf( lock_file, 256, "/proc/atc610x/board%d/lock", board );
-    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__ )
 
@@ -143,15 +151,6 @@ bool FGATCInput::open() {
     // Open the /proc files
     /////////////////////////////////////////////////////////////////////
 
-    lock_fd = ::open( lock_file, O_RDWR );
-    if ( lock_fd == -1 ) {
-       SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
-       char msg[256];
-       snprintf( msg, 256, "Error opening %s", lock_file );
-       perror( msg );
-       exit( -1 );
-    }
-
     analog_in_fd = ::open( analog_in_file, O_RDONLY );
     if ( analog_in_fd == -1 ) {
        SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
@@ -186,7 +185,7 @@ bool FGATCInput::open() {
     /////////////////////////////////////////////////////////////////////
 
     SG_LOG( SG_IO, SG_ALERT,
-           "Done initializing ATC 610x hardware." );
+           "Done initializing ATC input hardware." );
 
     is_open = true;
 
@@ -618,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
 
@@ -641,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();
@@ -661,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;
 
@@ -700,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
@@ -863,17 +908,12 @@ bool FGATCInput::close() {
 
 #if defined( unix ) || defined( __CYGWIN__ )
 
-    int result;
-
-    result = ::close( lock_fd );
-    if ( result == -1 ) {
-       SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
-       char msg[256];
-       snprintf( msg, 256, "Error closing %s", lock_file );
-       perror( msg );
-       exit( -1 );
+    if ( !is_open ) {
+        return true;
     }
 
+    int result;
+
     result = ::close( analog_in_fd );
     if ( result == -1 ) {
        SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );