28#include <simgear/debug/logstream.hxx>
29#include <simgear/io/iochannel.hxx>
30#include <simgear/misc/stdint.hxx>
39 SG_LOG( SG_IO, SG_INFO,
"/jsclient exists, activating JsClient remote joystick support");
41 for(
int i = 0;
i < 4; ++
i )
44 if( axisdef[
i] != NULL )
46 axisdefstr[
i] = axisdef[
i]->getStringValue();
47 SG_LOG( SG_IO, SG_INFO,
"jsclient axis[" <<
i <<
"] mapped to property " << axisdefstr[
i]);
61 SG_LOG( SG_IO, SG_ALERT,
"This shouldn't happen, but the channel "
62 <<
"is already in use, ignoring" );
69 SG_LOG( SG_IO, SG_ALERT,
"Error opening channel communication layer." );
82 int length = 4+4+4+4+4+4;
87 SG_LOG( SG_IO, SG_ALERT,
"JsClient protocol is read only" );
90 SG_LOG( SG_IO, SG_DEBUG,
"Searching for data." );
91 if ( io->get_type() == sgFileType ) {
92 if ( io->read( (
char *)(& buf), length ) == length ) {
93 SG_LOG( SG_IO, SG_DEBUG,
"Success reading data." );
94 int32_t *msg = (int32_t *)buf;
95 for(
int i = 0;
i < 4; ++
i )
97 axis[
i] = ((double)msg[
i] / 2147483647.0);
98 if ( fabs(axis[
i]) < 0.05 )
100 if( axisdefstr[
i].length() != 0 )
105 while ( io->read( (
char *)(& buf), length ) == length ) {
106 SG_LOG( SG_IO, SG_DEBUG,
"Success reading data." );
107 int32_t *msg = (int32_t *)buf;
108 SG_LOG( SG_IO, SG_DEBUG,
"ax0 = " << msg[0] <<
" ax1 = "
109 << msg[1] <<
"ax2 = " << msg[2] <<
"ax3 = " << msg[3]);
110 for(
int i = 0;
i < 4; ++
i )
112 axis[
i] = ((double)msg[
i] / 2147483647.0);
113 if ( fabs(axis[
i]) < 0.05 )
115 if( axisdefstr[
i].length() != 0 )
132 if ( ! io->close() ) {
SGProtocolDir get_direction() const
SGIOChannel * get_io_channel() const
void set_enabled(const bool b)
bool fgHasNode(const char *path)
Test whether a given node exists.
SGPropertyNode * fgGetNode(const char *path, bool create)
Get a property node.
bool fgSetFloat(const char *name, float val)
Set a float value for a property.