Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ArJoyHandler.h

00001 /*
00002 ActivMedia Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004,2005 ActivMedia Robotics, LLC
00004 
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 If you wish to redistribute ARIA under different terms, contact 
00021 ActivMedia Robotics for information about a commercial version of ARIA at 
00022 robots@activmedia.com or 
00023 ActivMedia Robotics, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 
00025 */
00026 
00027 #ifndef ARJOYHANDLER_H
00028 #define ARJOYHANDLER_H
00029 
00030 #include "ariaTypedefs.h"
00031 #include "ariaUtil.h"
00032 
00033 #ifdef WIN32
00034 #include <mmsystem.h>
00035 #else // if not win32
00036 #include <stdio.h>
00037 #include <unistd.h>
00038 #include <stdlib.h>
00039 #include <sys/ioctl.h>
00040 #include <fcntl.h>
00041 #endif
00042 #ifdef linux
00043 #include <linux/joystick.h>
00044 #endif
00045 
00046 
00047 
00049 
00069 class ArJoyHandler
00070 {
00071  public:
00073   ArJoyHandler(bool useOSCal = true, bool useOldJoystick = false);
00075   ~ArJoyHandler();
00077   bool init(void);
00079   bool haveJoystick(void) { return myInitialized; }
00081   void getDoubles(double *x, double *y, double *z = NULL);
00083   bool getButton(unsigned int button);
00085   bool haveZAxis(void) { return myHaveZ; }
00086 
00088   void setSpeeds(int x, int y, int z = 0) 
00089     { myTopX = x; myTopY = y; myTopZ = z; }
00091   void getAdjusted(int *x, int *y, int *z = NULL);
00092 
00094   unsigned int getNumAxes(void);
00096   double getAxis(unsigned int axis);
00098   unsigned int getNumButtons(void);
00099 
00101   void setUseOSCal(bool useOSCal);
00103   bool getUseOSCal(void);
00105   void startCal(void);
00107   void endCal(void);
00110   void getUnfiltered(int *x, int *y, int *z = NULL);
00112   void getStats(int *maxX, int *minX, int *maxY, int *minY, 
00113                  int *cenX, int *cenY);
00115   void setStats(int maxX, int minX, int maxY, int minY, 
00116                 int cenX, int cenY);
00118   void getSpeeds(int *x, int *y, int *z);
00119  protected:
00120   // function to get the data for OS dependent part
00121   void getData(void);
00122   int myMaxX, myMinX, myMaxY, myMinY, myCenX, myCenY, myTopX, myTopY, myTopZ;
00123   bool myHaveZ;
00124 
00125   std::map<unsigned int, int> myAxes;
00126   std::map<unsigned int, bool> myButtons;
00127 
00128   int myPhysMax;
00129   bool myInitialized;
00130   bool myUseOSCal;
00131   bool myUseOld;
00132   bool myFirstData;
00133   ArTime myLastDataGathered;
00134 #ifdef WIN32
00135   unsigned int myJoyID;
00136   int myLastZ;
00137   JOYINFO myJoyInfo;
00138   JOYCAPS myJoyCaps;
00139 #else // if not win32
00140   int myJoyNumber;
00141   char myJoyNameTemp[512];
00142   ArTime myLastOpenTry;
00143   void getOldData(void);
00144   void getNewData(void);
00145   #ifdef linux 
00146   struct JS_DATA_TYPE myJoyData; // structure for the buttons and x,y coords
00147   #else
00148   int myJoyData;
00149   #endif
00150   FILE * myOldJoyDesc;
00151   int myJoyDesc;
00152 #endif // linux
00153 };
00154 
00155 
00156 #endif // ARJOYHANDLER_H
00157 

Generated on Wed Oct 19 12:56:35 2005 for Aria by  doxygen 1.4.0