- /* open device file */
- joystick_fd = open(fname, O_RDONLY);
- if (joystick_fd < 0) {
- perror ("js");
- return( 1 );
- }
-
- fgPrintf( FG_INPUT,FG_ALERT,
- "\nMove joystick around dead spot and press any joystick button.\n" );
- status = read(joystick_fd, &js, JS_RETURN);
- if (status != JS_RETURN) {
- perror("js");
- return( 1 );
- }
- button = js.buttons & 1 || js.buttons & 2;
- while(button == 0 ) {
- status = read(joystick_fd, &js, JS_RETURN);
- if (status != JS_RETURN) {
- perror("js");
- return( 1 );
- }
- button = js.buttons & 1 || js.buttons & 2;
- if( js.x > joy_x_dead_max )
- joy_x_dead_max = js.x;
- if( js.x < joy_x_dead_min )
- joy_x_dead_min = js.x;
- if( js.y > joy_y_dead_max )
- joy_y_dead_max = js.y;
- if( js.y < joy_y_dead_min )
- joy_y_dead_min = js.y;
-
- /* printf( "Xmin %d Xmax %d Ymin %d Ymax %d",
- joy_x_dead_min, joy_x_dead_max,
- joy_y_dead_min, joy_y_dead_max ); */
- }
- status = read(joystick_fd, &js, JS_RETURN);
- if (status != JS_RETURN) {
- perror("js");
- return( 1 );
- }
-
- fgPrintf( FG_INPUT, FG_DEBUG,
- "\nJoystick calibration: X_dead_min = %d, X_dead_max = %d\n",
- joy_x_dead_min, joy_x_dead_max );
- fgPrintf( FG_INPUT, FG_DEBUG,
- " Y_dead_min = %d, Y_dead_max = %d\n",
- joy_y_dead_min, joy_y_dead_max );
-
- sleep( 1 );
-
- fgPrintf( FG_INPUT, FG_DEBUG,
- "\nCenter joystick and press any joystick button.\n" );
- status = read(joystick_fd, &js, JS_RETURN);
- if (status != JS_RETURN) {
- perror("js");
- return( 1 );
- }
- button = js.buttons & 1 || js.buttons & 2;
- while(button == 0 ) {
- status = read(joystick_fd, &js, JS_RETURN);
- if (status != JS_RETURN) {
- perror("js");
- return( 1 );
- }
- button = js.buttons & 1 || js.buttons & 2;
- }
- status = read(joystick_fd, &js, JS_RETURN);
- if (status != JS_RETURN) {
- perror("js");
- return( 1 );
- }
- joy_x_ctr = js.x;
- joy_y_ctr = js.y;
-
- fgPrintf( FG_INPUT, FG_DEBUG,
- "Joystick calibration: X_ctr = %d, Y_ctr = %d\n",
- joy_x_ctr, joy_y_ctr );
-
- sleep( 1 );
-
- fgPrintf( FG_INPUT, FG_DEBUG,
- "\nMove joystick to upper left and press any joystick button.\n" );
- status = read(joystick_fd, &js, JS_RETURN);
- if (status != JS_RETURN) {
- perror("js");
- return( 1 );
- }
- button = js.buttons & 1 || js.buttons & 2;
- while(button == 0 ) {
- status = read(joystick_fd, &js, JS_RETURN);
- if (status != JS_RETURN) {
- perror("js");
- return( 1 );
- }
- button = js.buttons & 1 || js.buttons & 2;
- }
- status = read(joystick_fd, &js, JS_RETURN);
- if (status != JS_RETURN) {
- perror("js");
- return( 1 );
- }
- joy_x_min = js.x;
- joy_y_min = js.y;
- fgPrintf( FG_INPUT, FG_DEBUG,
- "Joystick calibration: X_min = %d, Y_min = %d\n",
- joy_x_min, joy_y_min );
-
- sleep( 1 );
-
- fgPrintf( FG_INPUT, FG_DEBUG,
- "\nMove joystick to lower right and press any joystick button.\n" );
- status = read(joystick_fd, &js, JS_RETURN);
- if (status != JS_RETURN) {
- perror("js");
- return( 1 );
- }
- button = js.buttons & 1 || js.buttons & 2;
- while(button == 0 ) {
- status = read(joystick_fd, &js, JS_RETURN);
- if (status != JS_RETURN) {
- perror("js");
- return( 1 );
- }
- button = js.buttons & 1 || js.buttons & 2;
- }
- status = read(joystick_fd, &js, JS_RETURN);
- if (status != JS_RETURN) {
- perror("js");
- return( 1 );
- }
- joy_x_max = js.x;
- joy_y_max = js.y;
-
- fgPrintf( FG_INPUT, FG_DEBUG,
- "Joystick calibration: X_max = %d, Y_max = %d\n",
- joy_x_max, joy_y_max );
-
- // joy_x_ctr = (joy_x_max-joy_x_min)/2;
- // joy_y_ctr = (joy_y_max-joy_y_min)/2;
- // printf("Joystick calibration: X_ctr = %d, Y_ctr = %d\n", joy_x_ctr, joy_y_ctr );
-
- return( joystick_fd );
-#else
- return( 1 );
-#endif
+ js0 = new jsJoystick ( 0 );
+ js1 = new jsJoystick ( 1 );
+
+ if ( js0->notWorking () ) {
+ // not working
+ } else {
+ // allocate storage for axes values
+ js_ax0 = new float [ js0->getNumAxes() ];
+
+ // configure
+ js0->setDeadBand( 0, 0.1 );
+ js0->setDeadBand( 1, 0.1 );
+
+ fgPrintf ( FG_INPUT, FG_INFO,
+ " Joystick 0 detected with %d axes\n",
+ js0->getNumAxes() );
+ }
+
+ if ( js1->notWorking () ) {
+ // not working
+ } else {
+ // allocate storage for axes values
+ js_ax1 = new float [ js1->getNumAxes() ];
+
+ // configure
+ js1->setDeadBand( 0, 0.1 );
+ js1->setDeadBand( 1, 0.1 );
+
+ fgPrintf ( FG_INPUT, FG_INFO,
+ " Joystick 1 detected with %d axes\n",
+ js1->getNumAxes() );
+ }
+
+ if ( js0->notWorking() && js1->notWorking() ) {
+ fgPrintf ( FG_INPUT, FG_INFO, " No joysticks detected\n" );
+ return 0;
+ }
+
+ return 1;