ECRobot C++ API for LEGO MINDSTORMS NXT  1.0.10
device/PSPNx.h
00001 //
00002 // PSPNx.h
00003 //
00004 // Mindsensor PSPNx wrapper class
00005 //
00006 // 09.28.2008 Jon C. Martin
00007 //
00008 // Copyright 2009 by Takashi Chikamasa, Jon C. Martin and Robert W. Kramer
00009 //
00010 
00011 #ifndef _PSPNX_H
00012 #define _PSPNX_H
00013 
00014 #include "I2c.h"
00015 #include "Vector.h"
00016 using namespace ecrobot;
00017 
00018 namespace ecrobot
00019 {
00058 class PSPNx
00059 {
00060 public:
00064         enum eButtons
00065         {
00066                   SELECT =     1, 
00067                       LJ =     2, 
00068                       RJ =     4, 
00069                    START =     8, 
00070                       UP =    16, 
00071                    RIGHT =    32, 
00072                     DOWN =    64, 
00073                     LEFT =   128, 
00074                       L2 =   256, 
00075                       R2 =   512, 
00076                       L1 =  1024, 
00077                       R1 =  2048, 
00078                 TRIANGLE =  4096, 
00079                   CIRCLE =  8192, 
00080                    CROSS = 16384, 
00081                   SQUARE = 32768, 
00082         };
00083 
00087         static const U8 PSPNx_DEFAULT_ADDRESS = 0x02;
00088 
00092         static const U8 DATA_BUFFER_BYTE_SIZE = 6;
00093 
00104         explicit PSPNx(ePortS port, U8 address=PSPNx_DEFAULT_ADDRESS);
00105 
00106         //set the pad mode - mutually exclusive
00112         void setAnalog(void);
00118         void setDigital(void);
00119 
00120         //set other modes - ok to combine these
00126         void setEnergize(bool enable);
00132         void setADPA(bool enable);
00133 
00134         //call regularly
00140         void update(void);
00141 
00142         //poll methods for the stick.
00148         bool pressed(eButtons mask) const;
00154         bool held(eButtons mask) const;
00160         bool released(eButtons mask) const;
00161 
00169         VectorT<S8> getLeftStick(void) const;
00177         VectorT<S8> getRightStick(void) const;
00178 
00179         //raw gamepad info
00184         void get(U8 data[DATA_BUFFER_BYTE_SIZE]) const;
00185 
00186 private:
00187         enum
00188         {
00189                 Button_1,
00190                 Button_2,
00191                 LeftStick_X,
00192                 LeftStick_Y,
00193                 RightStick_X,
00194                 RightStick_Y,
00195         };
00196 
00197         I2c mI2c; // composite
00198 
00199         U8 mAddress;
00200         U8 mRawData[DATA_BUFFER_BYTE_SIZE];
00201         U16 mCurrentState;
00202         U16 mPreviousState;
00203         
00204         VectorT<S8> mLeftStick;
00205         VectorT<S8> mRightStick;
00206 };
00207 
00208 }
00209 
00210 #endif
00211 
 All Classes Files Functions Variables Enumerations Enumerator Friends Defines