X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FNetwork%2FATC-Inputs.cxx;h=4c6164928d1474ce6b6f41727b17a821975f56d2;hb=c1f250fd3340acb6b74603ba71771b441d7e7bb3;hp=d950dc8242f81ac5e7efef89dfe3d7069623e1e7;hpb=225af83b32d89746243e2c1202a6e2f643f504d3;p=flightgear.git diff --git a/src/Network/ATC-Inputs.cxx b/src/Network/ATC-Inputs.cxx index d950dc824..4c6164928 100644 --- a/src/Network/ATC-Inputs.cxx +++ b/src/Network/ATC-Inputs.cxx @@ -31,11 +31,17 @@ # include # include # include +# include +# include #endif +#include +#include + #include STL_STRING #include +#include #include
@@ -136,12 +142,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__ ) @@ -149,15 +157,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 ); @@ -192,7 +191,7 @@ bool FGATCInput::open() { ///////////////////////////////////////////////////////////////////// SG_LOG( SG_IO, SG_ALERT, - "Done initializing ATC 610x hardware." ); + "Done initializing ATC input hardware." ); is_open = true; @@ -225,18 +224,21 @@ bool FGATCInput::open() { ///////////////////////////////////////////////////////////////////// // scale a number between min and max (with center defined) to a scale -// from -1.0 to 1.0 -static double scale( int center, int min, int max, int value ) { +// from -1.0 to 1.0. The deadband value is symmetric, so specifying +// '1' will give you a deadband of +/-1 +static double scale( int center, int deadband, int min, int max, int value ) { // cout << center << " " << min << " " << max << " " << value << " "; double result; double range; - if ( value <= center ) { - range = center - min; - result = (value - center) / range; + if ( value <= (center - deadband) ) { + range = (center - deadband) - min; + result = (value - (center - deadband)) / range; + } else if ( value >= (center + deadband) ) { + range = max - (center + deadband); + result = (value - (center + deadband)) / range; } else { - range = max - center; - result = (value - center) / range; + result = 0.0; } if ( result < -1.0 ) result = -1.0; @@ -404,6 +406,7 @@ bool FGATCInput::do_analog_in() { int center = -1; int min = 0; int max = 1023; + int deadband = 0; float factor = 1.0; if ( cname == "channel" ) { SGPropertyNode *prop; @@ -438,6 +441,10 @@ bool FGATCInput::do_analog_in() { if ( prop != NULL ) { max = prop->getIntValue(); } + prop = child->getChild( "deadband" ); + if ( prop != NULL ) { + deadband = prop->getIntValue(); + } prop = child->getChild( "factor" ); if ( prop != NULL ) { factor = prop->getFloatValue(); @@ -459,7 +466,8 @@ bool FGATCInput::do_analog_in() { // "Cook" the raw value float scaled_value = 0.0f; if ( center >= 0 ) { - scaled_value = scale( center, min, max, raw_value ); + scaled_value = scale( center, deadband, + min, max, raw_value ); } else { scaled_value = scale( min, max, raw_value ); } @@ -474,7 +482,8 @@ bool FGATCInput::do_analog_in() { // "Cook" the raw value float scaled_value = 0.0f; if ( center >= 0 ) { - scaled_value = scale( center, min, max, raw_value ); + scaled_value = scale( center, deadband, + min, max, raw_value ); } else { scaled_value = scale( min, max, raw_value ); } @@ -624,6 +633,7 @@ bool FGATCInput::do_switches() { float factor = 1.0; int filter = -1; float scaled_value = 0.0f; + bool invert = false; // get common options @@ -647,6 +657,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(); @@ -667,6 +681,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; @@ -706,6 +725,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 @@ -869,17 +924,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 );