X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FNetwork%2Fjsclient.cxx;h=2ee35320daefd605f23a6a95cb93eebce4b4e90d;hb=50eb95dcadaf39d892212f2c5c6fe2459b190719;hp=7a59e78ea86ff9ceeadec97248fb7ee0c3f6dcca;hpb=e6cd7a0ed76cefe4a3fc0102d0038676f466bafe;p=flightgear.git diff --git a/src/Network/jsclient.cxx b/src/Network/jsclient.cxx index 7a59e78ea..2ee35320d 100644 --- a/src/Network/jsclient.cxx +++ b/src/Network/jsclient.cxx @@ -3,7 +3,7 @@ // Copyright (C) 2003 by Manuel Bessler and Stephen Lowry // // based on joyclient.cxx by Curtis Olson -// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org +// Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as @@ -17,20 +17,38 @@ // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // $Id$ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif #include #include +#include -#include +#include
#include "jsclient.hxx" FGJsClient::FGJsClient() { + active = fgHasNode("/jsclient"); // if exist, assume bindings are defined + SG_LOG( SG_IO, SG_INFO, "/jsclient exists, activating JsClient remote joystick support"); + + for( int i = 0; i < 4; ++i ) + { + axisdef[i] = fgGetNode("/jsclient/axis", i); + if( axisdef[i] != NULL ) + { + axisdefstr[i] = axisdef[i]->getStringValue(); + SG_LOG( SG_IO, SG_INFO, "jsclient axis[" << i << "] mapped to property " << axisdefstr[i]); + } + else + axisdefstr[i] = ""; + } } FGJsClient::~FGJsClient() { @@ -63,6 +81,8 @@ bool FGJsClient::process() { SGIOChannel *io = get_io_channel(); int length = 4+4+4+4+4+4; +// if( ! active ) +// return true; if ( get_direction() == SG_IO_OUT ) { SG_LOG( SG_IO, SG_ALERT, "JsClient protocol is read only" ); return false; @@ -71,40 +91,30 @@ bool FGJsClient::process() { if ( io->get_type() == sgFileType ) { if ( io->read( (char *)(& buf), length ) == length ) { SG_LOG( SG_IO, SG_DEBUG, "Success reading data." ); - long int *msg; - msg = (long int *)buf; - SG_LOG( SG_IO, SG_DEBUG, "ax0 = " << msg[0] << " ax1 = " - << msg[1] << "ax2 = " << msg[2] << "ax3 = " << msg[3]); - double axis1 = ((double)msg[0] / 2147483647.0); - double axis2 = ((double)msg[1] / 2147483647.0); - if ( fabs(axis1) < 0.05 ) { - axis1 = 0.0; - } - if ( fabs(axis2) < 0.05 ) { - axis2 = 0.0; + int32_t *msg = (int32_t *)buf; + for( int i = 0; i < 4; ++i ) + { + axis[i] = ((double)msg[i] / 2147483647.0); + if ( fabs(axis[i]) < 0.05 ) + axis[i] = 0.0; + if( axisdefstr[i].length() != 0 ) + fgSetFloat(axisdefstr[i].c_str(), axis[i]); } - globals->get_controls()->set_throttle(FGControls::ALL_ENGINES, axis1); -// globals->get_controls()->set_aileron( axis1 ); -// globals->get_controls()->set_elevator( -axis2 ); } } else { while ( io->read( (char *)(& buf), length ) == length ) { SG_LOG( SG_IO, SG_DEBUG, "Success reading data." ); - long int *msg; - msg = (long int *)buf; + int32_t *msg = (int32_t *)buf; SG_LOG( SG_IO, SG_DEBUG, "ax0 = " << msg[0] << " ax1 = " << msg[1] << "ax2 = " << msg[2] << "ax3 = " << msg[3]); - double axis1 = ((double)msg[0] / 2147483647.0); - double axis2 = ((double)msg[1] / 2147483647.0); - if ( fabs(axis1) < 0.05 ) { - axis1 = 0.0; - } - if ( fabs(axis2) < 0.05 ) { - axis2 = 0.0; + for( int i = 0; i < 4; ++i ) + { + axis[i] = ((double)msg[i] / 2147483647.0); + if ( fabs(axis[i]) < 0.05 ) + axis[i] = 0.0; + if( axisdefstr[i].length() != 0 ) + fgSetFloat(axisdefstr[i].c_str(), axis[i]); } - globals->get_controls()->set_throttle(FGControls::ALL_ENGINES, axis1); -// globals->get_controls()->set_aileron( axis1 ); -// globals->get_controls()->set_elevator( -axis2 ); } } }