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

ArJoyHandler_WIN.cpp

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 #include "ArExport.h"
00028 #include "ariaOSDef.h"
00029 #include "ArJoyHandler.h"
00030 
00031 bool ArJoyHandler::init(void)
00032 {
00033   myLastZ = 0;
00034 
00035   // first see if we can talk to the first joystick
00036   if (joyGetDevCaps(JOYSTICKID1,&myJoyCaps,sizeof(myJoyCaps)) == 
00037       JOYERR_NOERROR &&
00038       joyGetPos(JOYSTICKID1,&myJoyInfo) != JOYERR_UNPLUGGED) 
00039   {
00040     myJoyID = JOYSTICKID1;
00041     myPhysMax = myJoyCaps.wXmax - myJoyCaps.wXmin;
00042     myInitialized = true;
00043     startCal();
00044     endCal();
00045     return true;
00046   } 
00047   // we couldn't talk to the first one so try the second one
00048   else if (joyGetDevCaps(JOYSTICKID2,&myJoyCaps,sizeof(myJoyCaps)) == 
00049       JOYERR_NOERROR &&
00050       joyGetPos(JOYSTICKID2,&myJoyInfo) != JOYERR_UNPLUGGED) 
00051   {
00052     myJoyID = JOYSTICKID2;
00053     myPhysMax = myJoyCaps.wXmax - myJoyCaps.wXmin;
00054     myInitialized = true;
00055     startCal();
00056     endCal();
00057     return true;
00058   } 
00059   // we couldn't talk to either one
00060   else
00061   {
00062     myInitialized = false;
00063     return false;
00064   }
00065   getData();
00066 }
00067 
00068 void ArJoyHandler::getData(void)
00069 {
00070   int x, y, z;
00071   if (!myFirstData && myLastDataGathered.mSecSince() < 5)
00072     return;
00073 
00074   myFirstData = false;
00075   myLastDataGathered.setToNow();
00076   if (joyGetPos(myJoyID,&myJoyInfo) == JOYERR_UNPLUGGED) 
00077   {
00078     myAxes[1] = 0;
00079     myAxes[2] = 0;
00080     myAxes[3] = 0;
00081     myButtons[1] = 0;
00082     myButtons[2] = 0;
00083     myButtons[3] = 0;
00084     myButtons[4] = 0;
00085         
00086         // Reset the initialized flag so that the joystick button in the GUI
00087         // will be disabled.
00088     myInitialized = false;
00089  } 
00090   else
00091   {
00092     x = (int)(myJoyInfo.wXpos*256.0/myPhysMax)-128;
00093     y = (int)-((myJoyInfo.wYpos*256.0/myPhysMax)-128);
00094     z = (int)-((myJoyInfo.wZpos*256.0/myPhysMax)-128);
00095 
00096     if (myLastZ != z)
00097       myHaveZ = true;
00098     if (x > myMaxX)
00099       myMaxX = x;
00100     if (x < myMinX)
00101       myMinX = x;
00102     if (y > myMaxY)
00103       myMaxY = y;
00104     if (y < myMinY)
00105       myMinY = y;
00106 
00107     myAxes[1] = x;
00108     myAxes[2] = y;
00109     myAxes[3] = z;
00110         myLastZ = z;
00111         
00112     myButtons[1] = (myJoyInfo.wButtons & 1);
00113     myButtons[2] = (myJoyInfo.wButtons & 2);
00114     myButtons[3] = (myJoyInfo.wButtons & 4);
00115     myButtons[4] = (myJoyInfo.wButtons & 8);
00116   }
00117 }
00118 
00119 

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