#include <simgear/compiler.h>
+#if defined( unix ) || defined( __CYGWIN__ )
+# include <sys/types.h>
+# include <sys/stat.h>
+# include <fcntl.h>
+#endif
+
#include STL_STRING
#include <simgear/debug/logstream.hxx>
// Read analog inputs
static void ATCReadAnalogInputs( int fd, unsigned char *analog_in_bytes ) {
+#if defined( unix ) || defined( __CYGWIN__ )
// rewind
lseek( fd, 0, SEEK_SET );
SG_LOG( SG_IO, SG_ALERT, "Read failed" );
exit( -1 );
}
+#endif
}
// Read status of radio switches and knobs
static void ATCReadRadios( int fd, unsigned char *switch_data ) {
+#if defined( unix ) || defined( __CYGWIN__ )
// rewind
lseek( fd, 0, SEEK_SET );
SG_LOG( SG_IO, SG_ALERT, "Read failed" );
exit( -1 );
}
+#endif
}
// Read switch inputs
static void ATCReadSwitches( int fd, unsigned char *switch_bytes ) {
+#if defined( unix ) || defined( __CYGWIN__ )
// rewind
lseek( fd, 0, SEEK_SET );
SG_LOG( SG_IO, SG_ALERT, "Read failed" );
exit( -1 );
}
+#endif
}
init_config();
SG_LOG( SG_IO, SG_ALERT,
- "Initializing ATC 610x hardware, please wait ..." );
+ "Initializing ATC input hardware, please wait ..." );
- snprintf( lock_file, 256, "/proc/atc610x/board%d/lock", board );
- snprintf( analog_in_file, 256, "/proc/atc610x/board%d/analog_in", board );
- snprintf( radios_file, 256, "/proc/atc610x/board%d/radios", board );
- snprintf( switches_file, 256, "/proc/atc610x/board%d/switches", board );
+ snprintf( analog_in_file, 256,
+ "/proc/atcflightsim/board%d/analog_in", board );
+ snprintf( radios_file, 256,
+ "/proc/atcflightsim/board%d/radios", board );
+ snprintf( switches_file, 256,
+ "/proc/atcflightsim/board%d/switches", board );
+
+#if defined( unix ) || defined( __CYGWIN__ )
/////////////////////////////////////////////////////////////////////
// Open the /proc files
/////////////////////////////////////////////////////////////////////
- lock_fd = ::open( lock_file, O_RDWR );
- if ( lock_fd == -1 ) {
- SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
- char msg[256];
- snprintf( msg, 256, "Error opening %s", lock_file );
- perror( msg );
- exit( -1 );
- }
-
analog_in_fd = ::open( analog_in_file, O_RDONLY );
if ( analog_in_fd == -1 ) {
SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
exit( -1 );
}
+#endif
+
/////////////////////////////////////////////////////////////////////
// Finished initing hardware
/////////////////////////////////////////////////////////////////////
SG_LOG( SG_IO, SG_ALERT,
- "Done initializing ATC 610x hardware." );
+ "Done initializing ATC input hardware." );
is_open = true;
string type = "";
vector <SGPropertyNode *> output_nodes; output_nodes.clear();
int byte_num = -1;
- int right_shift = -1;
+ int right_shift = 0;
int mask = 0xff;
int factor = 1;
int offset = 0;
+ bool invert = false;
int scaled_value = 0;
-
// get common options
SGPropertyNode *prop;
if ( prop != NULL ) {
offset = prop->getIntValue();
}
+ prop = child->getChild( "invert" );
+ if ( prop != NULL ) {
+ invert = prop->getBoolValue();
+ }
// Fetch the raw value
int raw_value
= (radio_switch_data[byte_num] >> right_shift) & mask;
// Cook the value
+ if ( invert ) {
+ raw_value = !raw_value;
+ }
scaled_value = raw_value * factor + offset;
// update the property tree values
bool FGATCInput::close() {
- int result;
- result = ::close( lock_fd );
- if ( result == -1 ) {
- SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
- char msg[256];
- snprintf( msg, 256, "Error closing %s", lock_file );
- perror( msg );
- exit( -1 );
+#if defined( unix ) || defined( __CYGWIN__ )
+
+ if ( !is_open ) {
+ return true;
}
+ int result;
+
result = ::close( analog_in_fd );
if ( result == -1 ) {
SG_LOG( SG_IO, SG_ALERT, "errno = " << errno );
exit( -1 );
}
+#endif
+
return true;
}