napoleon leoni / joystickAppBoard
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers joystickAppBoard.cpp Source File

joystickAppBoard.cpp

00001 //joystickAppBoard class
00002 //Written by Napoleon Leoni; February 2014
00003 //Simple class object to handle joystick state for the mbed application board
00004 //5 way Joystick    ALPS SKRHADE010
00005 //Down:p12; Left:p13 Centre:p14 Up:p15 Right:p16
00006 
00007 #include "joystickAppBoard.h"
00008 
00009 // Joystick state definitions
00010 //#define JOYSTICKDOWN    0x01            //0b00001  d1
00011 //#define JOYSTICKLEFT    0x02            //0b00010  d2 
00012 //#define JOYSTICKCENTER  0x04            //0b00100  d4
00013 //#define JOYSTICKUP      0x08            //0b01000  d8
00014 //#define JOYSTICKRIGHT   0x10            //0b10000  d16
00015 
00016 //***************************** TESTING ********************************************************//
00017 //  TEST        TEST DESCRIPTION                                                STATUS          //
00018 //  1           getJoystickState yields the right hex value as shown above      PASS            //
00019 //  2           Joystick posistion (up, down center, leff, right) are all       PASS            //
00020 //              properly identified when the Joystick is actuated                               //
00021 //**********************************************************************************************//
00022 
00023 //**********************************************************************************************//
00024 // void joystickAppBoard::joystickAppBoard(void){                                                 //
00025 // Constructor, uses the predefined pins for the mbed app board to generater a BusIn object     //
00026 // to read the joystick state
00027 // Inputs: void                                                                                 //
00028 //**********************************************************************************************//
00029   joystickAppBoard::joystickAppBoard(){
00030     this->joystickPins = new BusIn(p12,p13,p14,p15,p16);
00031     return;
00032   }
00033   
00034 //**********************************************************************************************//
00035 // void joystickAppBoard::readJoystick(void){                                                   //
00036 // reads and stores the current Joystick state as defined by an integer where each bit          //
00037 // represents one of the joystick directions                                                    //
00038 // Inputs: void                                                                                 //
00039 //**********************************************************************************************//
00040   void joystickAppBoard::readJoystick(void){
00041       this->joystickState=this->joystickPins->read();
00042   }
00043   
00044 //**********************************************************************************************//
00045 // int joystickAppBoard::getJoystickState(void){                                                //
00046 // returns the current Joystick states as defined above                                         //
00047 // Inputs: void                                                                                 //
00048 //**********************************************************************************************//
00049   int joystickAppBoard::getJoystickState(void){
00050         return this->joystickState;
00051   }
00052   
00053 //**********************************************************************************************//
00054 // int joystickAppBoard::isJoystickUp(void){                                                    //
00055 // returns true if Joystick is up                                                               //
00056 // Inputs: void                                                                                 //
00057 //**********************************************************************************************//
00058   bool joystickAppBoard::isJoystickUp(void){ return ( (this->joystickState) & JOYSTICKUP); }
00059   
00060 //**********************************************************************************************//
00061 // int joystickAppBoard::isJoystickDown(void){                                                  //
00062 // returns true if Joystick is down                                                             //
00063 // Inputs: void                                                                                 //
00064 //**********************************************************************************************//
00065   bool joystickAppBoard::isJoystickDown(void){ return ( (this->joystickState) & JOYSTICKDOWN); }
00066 
00067 //**********************************************************************************************//
00068 // int joystickAppBoard::isJoystickLeft(void){                                                  //
00069 // returns true if Joystick is left                                                             //
00070 // Inputs: void                                                                                 //
00071 //**********************************************************************************************//
00072   bool joystickAppBoard::isJoystickLeft(void){ return ( (this->joystickState) & JOYSTICKLEFT); }
00073 
00074 //**********************************************************************************************//
00075 // int joystickAppBoard::isJoystickRight(void){                                                 //
00076 // returns true if Joystick is left                                                             //
00077 // Inputs: void                                                                                 //
00078 //**********************************************************************************************//
00079   bool joystickAppBoard::isJoystickRight(void){ return ( (this->joystickState) & JOYSTICKRIGHT); }
00080 
00081 //**********************************************************************************************//
00082 // int joystickAppBoard::isJoystickCenter(void){                                                //
00083 // returns true if Joystick is center                                                           //
00084 // Inputs: void                                                                                 //
00085 //**********************************************************************************************//
00086   bool joystickAppBoard::isJoystickCenter(void){ return ( (this->joystickState) & JOYSTICKCENTER); }