+/////////////////////////////////////////////////////////////////////
+// Write the lanalog outputs
+/////////////////////////////////////////////////////////////////////
+
+bool FGATCOutput::do_analog_out() {
+ if ( analog_out_node != NULL ) {
+ for ( int i = 0; i < analog_out_node->nChildren(); ++i ) {
+ // read the next config entry from the property tree
+
+ SGPropertyNode *child = analog_out_node->getChild(i);
+ string cname = child->getName();
+ int index = child->getIndex();
+ string name = "";
+ string type = "";
+ SGPropertyNode *src_prop = NULL;
+ double x0 = 0.0, y0 = 0.0, x1 = 0.0, y1 = 0.0;
+ if ( cname == "analog-out" ) {
+ SGPropertyNode *prop;
+ prop = child->getChild( "name" );
+ if ( prop != NULL ) {
+ name = prop->getStringValue();
+ }
+ prop = child->getChild( "type" );
+ if ( prop != NULL ) {
+ type = prop->getStringValue();
+ }
+ prop = child->getChild( "prop" );
+ if ( prop != NULL ) {
+ src_prop = fgGetNode( prop->getStringValue(), true );
+ }
+ prop = child->getChild( "value-lo" );
+ if ( prop != NULL ) {
+ x0 = prop->getDoubleValue();
+ }
+ prop = child->getChild( "meter-lo" );
+ if ( prop != NULL ) {
+ y0 = prop->getDoubleValue();
+ }
+ prop = child->getChild( "value-hi" );
+ if ( prop != NULL ) {
+ x1 = prop->getDoubleValue();
+ }
+ prop = child->getChild( "meter-hi" );
+ if ( prop != NULL ) {
+ y1 = prop->getDoubleValue();
+ }
+ // crunch linear interpolation formula
+ double dx = x1 - x0;
+ double dy = y1 - y0;
+ double slope = dy / dx;
+ double value = src_prop->getDoubleValue();
+ int meter = (value - x0) * slope + y0;
+ if ( meter < 0 ) { meter = 0; }
+ if ( meter > 1023 ) { meter = 1023; }
+ analog_out_data[2*index] = meter / 256;
+ analog_out_data[2*index + 1] = meter - analog_out_data[2*index] * 256;
+ } else {
+ SG_LOG( SG_IO, SG_DEBUG,
+ "Input config error, expecting 'analog-out' but found "
+ << cname );
+ }
+ ATCSetAnalogOut( analog_out_fd, analog_out_data );
+ }
+ }
+
+ return true;
+}
+
+