Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

inputDeviceJoystick.cpp File Reference

#include "inputDeviceJoystick.h"
#include <unistd.h>
#include <stdio.h>
#include <linux/joystick.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>

Go to the source code of this file.

Functions

DevicePlugInGetDevicePlugIn (void)
bool openDevice ()
void closeDevice ()
bool update ()
string name ()
int axes ()
int buttons ()
long axis (int nr)
bool buttonPressed (int nr)

Variables

int joyHandle
bool isPresent
struct js_event jsEvent
int intAxes
int intButtons
long intAxis [MAXAXES]
long maxAxis [MAXAXES]
bool intButton [MAXBUTTONS]
string intName


Function Documentation

DevicePlugIn * GetDevicePlugIn ( void)

Definition at line 46 of file inputDeviceJoystick.cpp.

00046 {
00047     return &inputPlugIn;
00048 }

int axes ( void)

Definition at line 171 of file inputDeviceJoystick.cpp.

00171 {
00172     if (isPresent) {
00173     return intAxes;
00174     } else return 0;
00175 }

long axis ( int nr)

Definition at line 203 of file inputDeviceJoystick.cpp.

00203 {
00204     if (isPresent) {
00205     if (nr < intAxes) {
00206         return (intAxis[nr]);
00207     } else {
00208         return 0;
00209     };
00210     } else {
00211     return 0;
00212     };
00213 }

bool buttonPressed ( int nr)

Definition at line 225 of file inputDeviceJoystick.cpp.

00225 {
00226     if (isPresent) {
00227     if (nr < intButtons) {
00228         return intButton[nr];
00229     } else {
00230         return false;
00231     };
00232     } else {
00233     return false;
00234     };
00235 }

int buttons ( void)

Definition at line 187 of file inputDeviceJoystick.cpp.

00187 {
00188     if (isPresent) {
00189     return intButtons;
00190     } else return 0;
00191 }

void closeDevice ( void)

Definition at line 104 of file inputDeviceJoystick.cpp.

00104 {
00105     close (joyHandle);
00106     return;
00107 }

string name ( void)

Definition at line 155 of file inputDeviceJoystick.cpp.

00155 {
00156     if (isPresent) {
00157     return intName;
00158     } else return "none found";
00159 }

bool openDevice ( void)

Definition at line 60 of file inputDeviceJoystick.cpp.

00060 {
00061     for (int i = 1; i <= MAXAXES; i++) {
00062     intAxis[i]=0;
00063     maxAxis[i]=1;
00064     };
00065     
00066     joyHandle = open ("/dev/js0", O_RDONLY | O_NONBLOCK);
00067     
00068     if (joyHandle) {
00069     isPresent = true;
00070     } else {
00071     isPresent = false;
00072     return false;
00073     };
00074     
00075     char tmp[128];
00076     
00077     ioctl (joyHandle, JSIOCGAXES, &intAxes);
00078     ioctl (joyHandle, JSIOCGBUTTONS, &intButtons);
00079     ioctl (joyHandle, JSIOCGNAME(128), tmp);
00080     
00081     intName.assign (tmp);
00082 
00083     for (int i=0; i < intAxes; i++) {
00084     intAxis[i]=0;
00085     };
00086     for (int i=0; i < intButtons; i++) {
00087     intButton[i]=false;
00088     };
00089     
00090     update ();
00091     return true;
00092 }

bool update ( void)

Definition at line 119 of file inputDeviceJoystick.cpp.

00119 {
00120     if (isPresent) {
00121 
00122     read (joyHandle, &jsEvent, sizeof (struct js_event));
00123     
00124         switch (jsEvent.type) {
00125         case 1 : {  if (jsEvent.value == 1) {
00126                 intButton[jsEvent.number]=true;
00127             } else {
00128                 intButton[jsEvent.number]=false;
00129             };
00130             break;
00131              };
00132         case 2 : {  intAxis[jsEvent.number] = jsEvent.value;
00133             break;
00134              };
00135         case 129:
00136         case 130:   break;
00137         default: {  printf ("unhandled InputDeviceJoystick event: type=%i, number=%i, value=%i\n", jsEvent.type, jsEvent.number, jsEvent.value);
00138             break;
00139              };
00140     };
00141     return true;
00142     } else return false;
00143 }

Variable Documentation

int intAxes

Definition at line 27 of file inputDeviceJoystick.cpp.

long intAxis[MAXAXES]

Definition at line 29 of file inputDeviceJoystick.cpp.

bool intButton[MAXBUTTONS]

Definition at line 31 of file inputDeviceJoystick.cpp.

int intButtons

Definition at line 28 of file inputDeviceJoystick.cpp.

string intName

Definition at line 32 of file inputDeviceJoystick.cpp.

bool isPresent

Definition at line 25 of file inputDeviceJoystick.cpp.

int joyHandle

Definition at line 24 of file inputDeviceJoystick.cpp.

struct js_event jsEvent

Definition at line 26 of file inputDeviceJoystick.cpp.

long maxAxis[MAXAXES]

Definition at line 30 of file inputDeviceJoystick.cpp.


Generated at Sat May 13 13:50:19 2000 for 3Dsia by doxygen 1.1.2 written by Dimitri van Heesch, © 1997-2000