1
0
Fork 0

Merge branch 'torsten/js64'

This commit is contained in:
Tim Moore 2010-05-06 10:58:58 +02:00
commit ed36a06509
2 changed files with 16 additions and 17 deletions

View file

@ -27,6 +27,7 @@
#include <simgear/debug/logstream.hxx>
#include <simgear/io/iochannel.hxx>
#include <simgear/misc/stdint.hxx>
#include <Aircraft/aircraft.hxx>
#include <Main/fg_props.hxx>
@ -91,8 +92,7 @@ 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;
int32_t *msg = (int32_t *)buf;
for( int i = 0; i < 4; ++i )
{
axis[i] = ((double)msg[i] / 2147483647.0);
@ -105,8 +105,7 @@ bool FGJsClient::process() {
} 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]);
for( int i = 0; i < 4; ++i )

View file

@ -67,7 +67,7 @@ int main ( int argc, char ** argv )
ax = new float [ numaxes ] ;
activeaxes = numaxes;
if( numaxes < 4 )
if( numaxes > 4 )
{
printf("max 4 axes joysticks supported at the moment, however %i axes were detected\nWill only use the first 4 axes!\n", numaxes);
activeaxes = 4;
@ -101,25 +101,25 @@ int main ( int argc, char ** argv )
js->read( &b, ax );
for ( axis = 0 ; axis < activeaxes ; axis++ )
{
long axisvalue = (long int)(ax[axis]*2147483647.0);
printf("axisval=%li\n", axisvalue);
memcpy(packet+len, &axisvalue, 4);
len+=4;
int32_t axisvalue = (int32_t)(ax[axis]*2147483647.0);
printf("axisval=%li\n", (long)axisvalue);
memcpy(packet+len, &axisvalue, sizeof(axisvalue));
len+=sizeof(axisvalue);
}
// fill emtpy values into packes when less than 4 axes
for( ; axis < 4; axis++ )
{
long axisvalue = 0;
memcpy(packet+len, &axisvalue, 4);
len+=4;
int32_t axisvalue = 0;
memcpy(packet+len, &axisvalue, sizeof(axisvalue));
len+=sizeof(axisvalue);
}
long int b_l = b;
memcpy(packet+len, &b_l, 4);
len+=4;
int32_t b_l = b;
memcpy(packet+len, &b_l, sizeof(b_l));
len+=sizeof(b_l);
char termstr[5] = "\0\0\r\n";
memcpy(packet+len, &termstr, 4);
const char * termstr = "\0\0\r\n";
memcpy(packet+len, termstr, 4);
len += 4;
c.send( packet, len, 0 );