Classes | Public Member Functions | Public Attributes | Private Types | Private Member Functions | Private Attributes | Friends

control::Joystick Class Reference

Joystick control of a Craft, joystick calibration. More...

#include <_src_control_joystick.hh>

Inheritance diagram for control::Joystick:
base::Singleton

List of all members.

Classes

class  AxisMap
 Remaps joystick axises and indicates which axis had an event. Calling the If*() methods effectively remaps the axises (that is, remapping isn't done by changing the Event struct). More...
class  ButtonMap
 Remaps buttons. More...
struct  Calibration
 Defines a range of axis values for calibration. Roll/pitch/yaw axises have two ranges with a deadzone in between. Throttle axis has one range. More...

Public Member Functions

 DEFINE_GetInstance (Joystick) bool Enable(const bool enable
bool IfEnabled (void)
void SetCalibration (const Calibration &calibration)
Calibration GetCalibration (void)
bool MapAxis (const uint axisLogical, const uint axisReal)
bool MapButton (const uint buttonLogical, const uint buttonReal)
void EnableAutofire (bool f)
int GetAxisValue (const uint axis)
bool GetButtonValue (const uint button)

Public Attributes

CLASS_CONST uint MAX_AXIS = 4
 pitch,roll,yaw,throttle = 4
CLASS_CONST uint MAX_BUTTONS = 8
base::Event< input::JoystickEventmEventButton

Private Types

enum  eMove {
  eMove_AT_CENTER, eMove_PITCH_UP, eMove_PITCH_DOWN, eMove_ROLL_LEFT,
  eMove_ROLL_RIGHT, eMove_YAW_LEFT, eMove_YAW_RIGHT, eMove_THROTTLE
}

Private Member Functions

void Poll (void)
void ProcessAxisEvent (const input::JoystickEvent &event)
void ProcessButtonEvent (const input::JoystickEvent &eventUnmapped)
fp ComputeFraction (const input::JoystickEvent &event, const uint axis, const Calibration::AxisRange &axisRange, const int dir)
 DECLARE_SINGLETON_CLASS_VARS (Joystick) bool mEnabledBefore
 if joystick was really enabled before

Private Attributes

Calibration mCalibration
 defines range of axis values
AxisMap mAxisMap
 to configure axises
ButtonMap mButtonMap
 to configure buttons
input::JoystickEvent mEvent
 current event
input::JoystickEvent mPrevEvent
 updated only if buttons changed or autofire
bool mAutofire
TinyArray< MAX_AXIS, int > mAxisValues
 for calibration (not used internally)
TinyArray< MAX_BUTTONS, bool > mButtonValues
 for calibration (not used internally)
fp mRollFraction
 these continue axis movement
fp mPitchFraction
 until axis is moved to dead-zone
fp mYawFraction
const Milliseconds mTickFreq

Friends

class AxisMap

Detailed Description

Joystick control of a Craft, joystick calibration.

This is the client of the lower-level input::JoystickDevice. This handles axis events: the current Craft is rotated by axis events. This doesn't handle button events, rather, it defers them to a listener.

This class isn't derived from input::JoystickDevice. Instead, this class is a layer over it.

To register a button handler, register an event listener with Joystick::mEventButton (see base/event.hh).

Event classes: base::Event is an object for broadcasting to listeners. JoystickEvent is a simple struct.


Member Enumeration Documentation

enum control::Joystick::eMove [private]

Pitch/roll/yaw have two active segments/ranges with a deadzone between. Throttle has one segment/range.

Enumerator:
eMove_AT_CENTER 
eMove_PITCH_UP 
eMove_PITCH_DOWN 
eMove_ROLL_LEFT 
eMove_ROLL_RIGHT 
eMove_YAW_LEFT 
eMove_YAW_RIGHT 
eMove_THROTTLE 

Member Function Documentation

fp control::Joystick::ComputeFraction ( const input::JoystickEvent event,
const uint  axis,
const Calibration::AxisRange axisRange,
const int  dir 
) [private]
Returns:
Fraction of axis movement {0.0,..,+-1.0}. May return negative.
Parameters:
event 
axis AXIS_ROLL/PITCH/YAW
axisRange Calibration.AxisRange
dir +-1 which can reverse direction of axis.
control::Joystick::DECLARE_SINGLETON_CLASS_VARS ( Joystick   )  [private]

if joystick was really enabled before

control::Joystick::DEFINE_GetInstance ( Joystick   )  const
void control::Joystick::EnableAutofire ( bool  f  ) 

Enable/disable autofire.

int control::Joystick::GetAxisValue ( const uint  axis  ) 
Returns:
Axis value. For clients (not used internally).
bool control::Joystick::GetButtonValue ( const uint  button  ) 
Returns:
Button value. For clients (not used internally).
Joystick::Calibration control::Joystick::GetCalibration ( void   ) 
bool control::Joystick::IfEnabled ( void   ) 
Returns:
True if joystick is enabled.
bool control::Joystick::MapAxis ( const uint  axisLogical,
const uint  axisReal 
)

Map a joystick axis.

bool control::Joystick::MapButton ( const uint  buttonLogical,
const uint  buttonReal 
)

Map button.

void control::Joystick::Poll ( void   )  [private]

Poll joystick axises and buttons.

void control::Joystick::ProcessAxisEvent ( const input::JoystickEvent event  )  [private]

Process a joystick axis event.

Continuing axis movements: Imagine the joystick moved to top-left corner then moved up and down. The leftward movement remains in effect while the new events are occurring for up/down movements. Therefore, persistent variables are used to continue axis movement until the axis is moved to its dead-zone.

Remapping axises: Remapping an axis is done effectively by calling AxisMap::If*() (remapping isn't done by changing the Event struct).

void control::Joystick::ProcessButtonEvent ( const input::JoystickEvent eventUnmapped  )  [private]

Process a joystick button event.

void control::Joystick::SetCalibration ( const Calibration calibration  ) 

Set/get calibration.


Friends And Related Function Documentation

friend class AxisMap [friend]

Member Data Documentation

pitch,roll,yaw,throttle = 4

to configure axises

for calibration (not used internally)

to configure buttons

for calibration (not used internally)

defines range of axis values

until axis is moved to dead-zone

updated only if buttons changed or autofire

these continue axis movement


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Palomino Flight Simulator documents generated by doxygen 1.7.1 on Tue May 15 2012 22:40:11