Applied tthierry's patch to fix compiling on FreeBSD.
[freeglut] / freeglut-1.3 / freeglut_joystick.c
index 202e576..7ac4c3d 100644 (file)
@@ -6,10 +6,6 @@
  * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
  * Written by Steve Baker, <sjbaker1@airmail.net>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
  * to deal in the Software without restriction, including without limitation
@@ -44,7 +40,7 @@
 #define G_LOG_DOMAIN "freeglut-joystick"
 
 #include "../include/GL/freeglut.h"
-#include "../include/GL/freeglut_internal.h"
+#include "freeglut_internal.h"
 
 /*
  * PWO: I don't like it at all. It's a mess. Could it be cleared?
@@ -126,7 +122,7 @@ struct tagSFG_Joystick
         int         tmp_buttons;
         float       tmp_axes[ _JS_MAX_AXES ];
 #   else
-        JS_DATA_TYPE js;
+        struct JS_DATA_TYPE js;
 #   endif
 
     char fname[ 128 ];
@@ -251,7 +247,7 @@ static void fghJoystickRawRead ( SFG_Joystick* joy, int* buttons, float* axes )
 
     if( status != JS_RETURN )
     {
-        g_warning( fname );
+        g_warning( joy->fname );
         joy->error = TRUE;
         return;
     }
@@ -417,7 +413,7 @@ static void fghJoystickOpen( SFG_Joystick* joy )
     if( joy->error )
       return ;
 
-    sprintf( joyfname, "%s/.joy%drc", g_getenv( "HOME" ), id );
+    sprintf( joyfname, "%s/.joy%drc", g_getenv( "HOME" ), joy->id );
 
     joyfile = fopen( joyfname, "r" );
     joy->error = (joyfile == NULL);
@@ -438,8 +434,8 @@ static void fghJoystickOpen( SFG_Joystick* joy )
 
     for( i=0 ; i<_JS_MAX_AXES ; i++ )
     {
-        dead_band[ i ] = 0.0f;
-        saturate [ i ] = 1.0f;
+        joy->dead_band[ i ] = 0.0f;
+        joy->saturate [ i ] = 1.0f;
     }
 #   else
 
@@ -466,9 +462,9 @@ static void fghJoystickOpen( SFG_Joystick* joy )
 
     do
     { 
-        fghJoystickRawRead( joy, NULL, center );
+        fghJoystickRawRead( joy, NULL, joy->center )
         counter++;
-    } while( !joy->error && counter < 100 && center[ 0 ] == 512.0f && center[ 1 ] == 512.0f );
+    } while( !joy->error && counter < 100 && joy->center[ 0 ] == 512.0f && joy->center[ 1 ] == 512.0f );
    
     if( counter >= 100 )
         joy->error = TRUE;
@@ -481,7 +477,7 @@ static void fghJoystickOpen( SFG_Joystick* joy )
         joy->center[ i ] =      0.0f;
         joy->min   [ i ] = -32767.0f;
 #       else
-        joy->max[ i ] = center[ i ] * 2.0f;
+        joy->max[ i ] = joy->center[ i ] * 2.0f;
         joy->min[ i ] = 0.0f;
 #       endif
         joy->dead_band[ i ] = 0.0f ;
@@ -542,6 +538,9 @@ void fgJoystickClose( void )
     if( fgJoystick->error != TRUE )
         close( fgJoystick->fd );
 #endif
+
+    free ( fgJoystick ) ;
+    fgJoystick = NULL ;  /* show joystick has been deinitialized */
 }
 
 /*
@@ -557,8 +556,8 @@ void fgJoystickPollWindow( SFG_Window* window )
      * Make sure the joystick device is initialized, the window seems valid
      * and that there is a joystick callback hooked to it:
      */
-    freeglut_return_if_fail( fgJoystick == NULL || window == NULL );
-    freeglut_return_if_fail( window->Callbacks.Joystick == NULL );
+    freeglut_return_if_fail( fgJoystick != NULL && window != NULL );
+    freeglut_return_if_fail( window->Callbacks.Joystick != NULL );
 
     /*
      * Poll the joystick now: