mod_base_joystick.hh

Go to the documentation of this file.
00001 /*
00008  * LEGAL:   COPYRIGHT (C) 2004 JIM E. BROOKS
00009  *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
00010  *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
00011  *****************************************************************************/
00012 
00013 #if COMPILING_MODULE
00014 #ifndef MOD_BASE_JOYSTICK_HH
00015 #define MOD_BASE_JOYSTICK_HH 1
00016 
00017 #include "inp_joystick.hh"
00018 using namespace inp;
00019 
00020 namespace mod_base {
00021 
00033 class Joystick
00034 {
00035 
00036 public:
00037     enum eMove
00038     {
00039         eMove_AT_CENTER,
00040         eMove_PITCH_UP,
00041         eMove_PITCH_DOWN,
00042         eMove_ROLL_LEFT,
00043         eMove_ROLL_RIGHT,
00044         eMove_YAW_LEFT,
00045         eMove_YAW_RIGHT,
00046         eMove_THROTTLE_SLOW,
00047         eMove_THROTTLE_FAST
00048     };
00049 
00050 public:
00052     enum eAxis3
00053     {
00054         eAxis3_DISABLED,
00055         eAxis3_THROTTLE,
00056         eAxis3_RUDDER
00057     };
00058 
00059 public:
00063     class Values
00064     {
00065     
00066     public:
00067         Values( void )
00068         {
00069             Reset();
00070         }
00071 
00072         void Reset( void )
00073         {
00074             mUp = mDown = mLeft = mRight = mSlow = mFast = INVALID;
00075         }
00076 
00077     public:
00078         enum    { INVALID = -99999 };
00079         int     mUp;
00080         int     mDown;
00081         int     mLeft;
00082         int     mRight;
00083         int     mSlow;  // axis3
00084         int     mFast;  // axis3
00085     };
00086 
00087 private:
00089     class TimerFunctor : public Timer::Functor
00090     {
00091     public:
00092                 TimerFunctor( mod_base::Joystick& joystick ) : mJoystick(joystick) { }
00093         void    operator()( const Milliseconds millisecElapsed );
00094         mod_base::Joystick&  mJoystick;
00095     };
00096     friend class TimerFunctor;
00097 
00098 public:
00099                     Joystick( void );
00100                     ~Joystick();
00101     void            Init( void );
00102     bool            IfEnabled( void );
00103     bool            Enable( bool enable = true );
00104     bool            Poll( void );
00105     TinyArray<3,Degree> GetResponse( void );
00106     Percent         GetResponsePercent( void );
00107     void            AdjustResponse( const Percent percent );
00108     void            SetResponse( Degree r0, Degree r1, Degree r2 );
00109     void            SetResponseForEye( void );
00110     void            SetResponseForCraft( void );
00111     bool            SetAxis3( eAxis3 a );
00112     eAxis3          GetAxis3( void );
00113     void            EnableAutofire( bool f );
00114     void            EnablePrint( bool f );
00115     bool            IfPrint( void );
00116     void            PrintRaw( int value, eMove move );
00117     void            RecordRaw( int value, eMove move );
00118     bool            IfCalibrationMode( void );
00119     void            SetCalibrationMode( bool f );
00120     const Values&   GetValues( void ) { return mValues; }       // used for calibration
00121     void            ResetValues( void ) { mValues.Reset(); }    // used for calibration
00122 
00123 private:
00124     void            EnableInitial( void );
00125     void            EnableSubsequent( bool enable );
00126     bool            IfBeyondCenter( int lo );
00127     fp              PositionAbs( int high );
00128 
00129 private:
00130     CLASS_VAR int           msInstanceCnt;
00131 
00132     // Joystick state.
00133     bool                    mEnableInitial;     
00134     inp::Joystick::Event    mEvent;             
00135     eAxis3                  mAxis3;
00136     bool                    mAutofire;
00137 
00138     // Joystick calibration.
00139     bool                    mCalibrating;
00140     Values                  mValues;
00141     bool                    mPrint;
00142 
00143     // Rate of rotation in degrees.
00144     // mResponse = mResponsePotential * mResponsePercent
00145     TinyArray<3,Degree>     mResponsePotential;     
00146     TinyArray<3,Degree>     mResponse;              
00147     Percent                 mResponsePercent;       
00148 };
00149 
00150 } // namespace mod_base
00151 
00152 #endif // MOD_BASE_JOYSTICK_HH
00153 #endif // COMPILING_MOD
Palomino 3D Engine documents generated by doxygen 1.5.3 on Fri Nov 23 11:26:12 2007