Updates to the jsclient remote joystick support code
This commit is contained in:
parent
f3bb344f4e
commit
97a8fc2cc8
3 changed files with 50 additions and 25 deletions
12
docs-mini/README.jsclient
Normal file
12
docs-mini/README.jsclient
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
Start flightgear with
|
||||||
|
fgfs --jsclient=socket,in,<hz>,,<port>,udp --prop:/jsclient/axis[i]="/property/you/want/to/control" --prop:/jsclient/axis[i+1]="/another/property/you/want/to/control" ...
|
||||||
|
eg:
|
||||||
|
# fgfs --aircraft=yf23-yasim --airport=KEMT --jsclient=socket,in,5,,16759,udp --prop:/jsclient/axis[0]="/controls/flight/spoilers" --prop:/jsclient/axis[1]="/radios/comm/volume"
|
||||||
|
|
||||||
|
|
||||||
|
Start the server on the machine with the remote gameport:
|
||||||
|
JsServer <host> <port>
|
||||||
|
eg:
|
||||||
|
# JsServer 192.168.1.1 16759
|
||||||
|
|
||||||
|
(JsServer can be started before or after fgfs)
|
|
@ -26,11 +26,26 @@
|
||||||
#include <simgear/io/iochannel.hxx>
|
#include <simgear/io/iochannel.hxx>
|
||||||
|
|
||||||
#include <Aircraft/aircraft.hxx>
|
#include <Aircraft/aircraft.hxx>
|
||||||
|
#include <Main/fg_props.hxx>
|
||||||
|
|
||||||
#include "jsclient.hxx"
|
#include "jsclient.hxx"
|
||||||
|
|
||||||
|
|
||||||
FGJsClient::FGJsClient() {
|
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() {
|
FGJsClient::~FGJsClient() {
|
||||||
|
@ -63,6 +78,8 @@ bool FGJsClient::process() {
|
||||||
SGIOChannel *io = get_io_channel();
|
SGIOChannel *io = get_io_channel();
|
||||||
int length = 4+4+4+4+4+4;
|
int length = 4+4+4+4+4+4;
|
||||||
|
|
||||||
|
// if( ! active )
|
||||||
|
// return true;
|
||||||
if ( get_direction() == SG_IO_OUT ) {
|
if ( get_direction() == SG_IO_OUT ) {
|
||||||
SG_LOG( SG_IO, SG_ALERT, "JsClient protocol is read only" );
|
SG_LOG( SG_IO, SG_ALERT, "JsClient protocol is read only" );
|
||||||
return false;
|
return false;
|
||||||
|
@ -73,19 +90,14 @@ bool FGJsClient::process() {
|
||||||
SG_LOG( SG_IO, SG_DEBUG, "Success reading data." );
|
SG_LOG( SG_IO, SG_DEBUG, "Success reading data." );
|
||||||
long int *msg;
|
long int *msg;
|
||||||
msg = (long int *)buf;
|
msg = (long int *)buf;
|
||||||
SG_LOG( SG_IO, SG_DEBUG, "ax0 = " << msg[0] << " ax1 = "
|
for( int i = 0; i < 4; ++i )
|
||||||
<< msg[1] << "ax2 = " << msg[2] << "ax3 = " << msg[3]);
|
{
|
||||||
double axis1 = ((double)msg[0] / 2147483647.0);
|
axis[i] = ((double)msg[i] / 2147483647.0);
|
||||||
double axis2 = ((double)msg[1] / 2147483647.0);
|
if ( fabs(axis[i]) < 0.05 )
|
||||||
if ( fabs(axis1) < 0.05 ) {
|
axis[i] = 0.0;
|
||||||
axis1 = 0.0;
|
if( axisdefstr[i].length() != 0 )
|
||||||
|
fgSetFloat(axisdefstr[i].c_str(), axis[i]);
|
||||||
}
|
}
|
||||||
if ( fabs(axis2) < 0.05 ) {
|
|
||||||
axis2 = 0.0;
|
|
||||||
}
|
|
||||||
globals->get_controls()->set_throttle(FGControls::ALL_ENGINES, axis1);
|
|
||||||
// globals->get_controls()->set_aileron( axis1 );
|
|
||||||
// globals->get_controls()->set_elevator( -axis2 );
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while ( io->read( (char *)(& buf), length ) == length ) {
|
while ( io->read( (char *)(& buf), length ) == length ) {
|
||||||
|
@ -94,17 +106,14 @@ bool FGJsClient::process() {
|
||||||
msg = (long int *)buf;
|
msg = (long int *)buf;
|
||||||
SG_LOG( SG_IO, SG_DEBUG, "ax0 = " << msg[0] << " ax1 = "
|
SG_LOG( SG_IO, SG_DEBUG, "ax0 = " << msg[0] << " ax1 = "
|
||||||
<< msg[1] << "ax2 = " << msg[2] << "ax3 = " << msg[3]);
|
<< msg[1] << "ax2 = " << msg[2] << "ax3 = " << msg[3]);
|
||||||
double axis1 = ((double)msg[0] / 2147483647.0);
|
for( int i = 0; i < 4; ++i )
|
||||||
double axis2 = ((double)msg[1] / 2147483647.0);
|
{
|
||||||
if ( fabs(axis1) < 0.05 ) {
|
axis[i] = ((double)msg[i] / 2147483647.0);
|
||||||
axis1 = 0.0;
|
if ( fabs(axis[i]) < 0.05 )
|
||||||
|
axis[i] = 0.0;
|
||||||
|
if( axisdefstr[i].length() != 0 )
|
||||||
|
fgSetFloat(axisdefstr[i].c_str(), axis[i]);
|
||||||
}
|
}
|
||||||
if ( fabs(axis2) < 0.05 ) {
|
|
||||||
axis2 = 0.0;
|
|
||||||
}
|
|
||||||
globals->get_controls()->set_throttle(FGControls::ALL_ENGINES, axis1);
|
|
||||||
// globals->get_controls()->set_aileron( axis1 );
|
|
||||||
// globals->get_controls()->set_elevator( -axis2 );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// jsclient.cxx -- simple UDP networked jsstick client
|
// jsclient.hxx -- simple UDP networked joystick client
|
||||||
//
|
//
|
||||||
// Copyright (C) 2003 by Manuel Bessler and Stephen Lowry
|
// Copyright (C) 2003 by Manuel Bessler and Stephen Lowry
|
||||||
//
|
//
|
||||||
// based on jsclient.cxx by Curtis Olson
|
// based on joyclient.hxx by Curtis Olson
|
||||||
// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
|
// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or
|
// This program is free software; you can redistribute it and/or
|
||||||
|
@ -41,7 +41,11 @@ class FGJsClient : public FGProtocol {
|
||||||
|
|
||||||
char buf[256];
|
char buf[256];
|
||||||
int length;
|
int length;
|
||||||
|
double axis[4];
|
||||||
|
SGPropertyNode *axisdef[4];
|
||||||
|
string axisdefstr[4];
|
||||||
|
bool active;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
FGJsClient();
|
FGJsClient();
|
||||||
|
|
Loading…
Reference in a new issue