1 /*
2      PLIB - A Suite of Portable Game Libraries
3      Copyright (C) 1998,2002  Steve Baker
4 
5      This library is free software; you can redistribute it and/or
6      modify it under the terms of the GNU Library General Public
7      License as published by the Free Software Foundation; either
8      version 2 of the License, or (at your option) any later version.
9 
10      This library is distributed in the hope that it will be useful,
11      but WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      Library General Public License for more details.
14 
15      You should have received a copy of the GNU Library General Public
16      License along with this library; if not, write to the Free Software
17      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 
19      For further information visit http://plib.sourceforge.net
20 
21 */
22 
23 #include "config.h"
24 
25 #include "FlightGear_js.h"
26 
27 #include <simgear/debug/logstream.hxx>
28 
fudge_axis(float value,int axis) const29 float jsJoystick::fudge_axis ( float value, int axis ) const
30 {
31   if ( value < center[axis] )
32   {
33     float xx = (      value    - center[ axis ] ) /
34                ( center [ axis ] - min [ axis ] ) ;
35 
36     if ( xx < -saturate [ axis ] )
37                               return -1.0f ;
38 
39     if ( xx > -dead_band [ axis ] )
40                               return 0.0f ;
41 
42     xx = (        xx         + dead_band [ axis ] ) /
43          ( saturate [ axis ] - dead_band [ axis ] ) ;
44 
45     return ( xx < -1.0f ) ? -1.0f : xx ;
46   }
47   else
48   {
49     float xx = (     value    - center [ axis ] ) /
50                ( max [ axis ] - center [ axis ] ) ;
51 
52     if ( xx > saturate [ axis ] )
53                               return 1.0f ;
54 
55     if ( xx < dead_band [ axis ] )
56                               return 0.0f ;
57 
58     xx = (        xx         - dead_band [ axis ] ) /
59          ( saturate [ axis ] - dead_band [ axis ] ) ;
60 
61     return ( xx > 1.0f ) ? 1.0f : xx ;
62   }
63 }
64 
65 
read(int * buttons,float * axes)66 void jsJoystick::read ( int *buttons, float *axes )
67 {
68   if ( error )
69   {
70     if ( buttons )
71       *buttons = 0 ;
72 
73     if ( axes )
74       for ( int i = 0 ; i < num_axes ; i++ )
75         axes[i] = 0.0f ;
76 
77     return ;
78   }
79 
80   float raw_axes [ _JS_MAX_AXES ] ;
81 
82   rawRead ( buttons, raw_axes ) ;
83 
84   if ( axes )
85     for ( int i = 0 ; i < num_axes ; i++ )
86       axes[i] = fudge_axis ( raw_axes[i], i ) ;
87 }
88 
jsSetError(int level,const std::string & msg)89 void jsSetError(int level, const std::string& msg)
90 {
91   SG_LOG(SG_INPUT, static_cast<sgDebugPriority>(level), msg);
92 }
93