/joystickAppBoard class //Written by Napoleon Leoni; February 2014 //Simple class object to handle joystick state for the mbed application board //5 way Joystick ALPS SKRHADE010 //Down:p12; Left:p13 Centre:p14 Up:p15 Right:p16 #include "joystickAppBoard.h" // Joystick state definitions //#define JOYSTICKDOWN 0x01 //0b00001 d1 //#define JOYSTICKLEFT 0x02 //0b00010 d2 //#define JOYSTICKCENTER 0x04 //0b00100 d4 //#define JOYSTICKUP 0x08 //0b01000 d8 //#define JOYSTICKRIGHT 0x10 //0b10000 d16

Committer:
nleoni
Date:
Thu Feb 13 08:03:28 2014 +0000
Revision:
0:180cf3834ece
/joystickAppBoard class; //Written by Napoleon Leoni; February 2014; //Simple class object to handle joystick state for the mbed application board; //5 way Joystick    ALPS SKRHADE010; //Down:p12; Left:p13 Centre:p14 Up:p15 Right:p16;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nleoni 0:180cf3834ece 1 //joystickAppBoard class
nleoni 0:180cf3834ece 2 //Written by Napoleon Leoni; February 2014
nleoni 0:180cf3834ece 3 //Simple class object to handle joystick state for the mbed application board
nleoni 0:180cf3834ece 4 //5 way Joystick ALPS SKRHADE010
nleoni 0:180cf3834ece 5 //Down:p12; Left:p13 Centre:p14 Up:p15 Right:p16
nleoni 0:180cf3834ece 6
nleoni 0:180cf3834ece 7 #include "joystickAppBoard.h"
nleoni 0:180cf3834ece 8
nleoni 0:180cf3834ece 9 // Joystick state definitions
nleoni 0:180cf3834ece 10 //#define JOYSTICKDOWN 0x01 //0b00001 d1
nleoni 0:180cf3834ece 11 //#define JOYSTICKLEFT 0x02 //0b00010 d2
nleoni 0:180cf3834ece 12 //#define JOYSTICKCENTER 0x04 //0b00100 d4
nleoni 0:180cf3834ece 13 //#define JOYSTICKUP 0x08 //0b01000 d8
nleoni 0:180cf3834ece 14 //#define JOYSTICKRIGHT 0x10 //0b10000 d16
nleoni 0:180cf3834ece 15
nleoni 0:180cf3834ece 16 //***************************** TESTING ********************************************************//
nleoni 0:180cf3834ece 17 // TEST TEST DESCRIPTION STATUS //
nleoni 0:180cf3834ece 18 // 1 getJoystickState yields the right hex value as shown above PASS //
nleoni 0:180cf3834ece 19 // 2 Joystick posistion (up, down center, leff, right) are all PASS //
nleoni 0:180cf3834ece 20 // properly identified when the Joystick is actuated //
nleoni 0:180cf3834ece 21 //**********************************************************************************************//
nleoni 0:180cf3834ece 22
nleoni 0:180cf3834ece 23 //**********************************************************************************************//
nleoni 0:180cf3834ece 24 // void joystickAppBoard::joystickAppBoard(void){ //
nleoni 0:180cf3834ece 25 // Constructor, uses the predefined pins for the mbed app board to generater a BusIn object //
nleoni 0:180cf3834ece 26 // to read the joystick state
nleoni 0:180cf3834ece 27 // Inputs: void //
nleoni 0:180cf3834ece 28 //**********************************************************************************************//
nleoni 0:180cf3834ece 29 joystickAppBoard::joystickAppBoard(){
nleoni 0:180cf3834ece 30 this->joystickPins = new BusIn(p12,p13,p14,p15,p16);
nleoni 0:180cf3834ece 31 return;
nleoni 0:180cf3834ece 32 }
nleoni 0:180cf3834ece 33
nleoni 0:180cf3834ece 34 //**********************************************************************************************//
nleoni 0:180cf3834ece 35 // void joystickAppBoard::readJoystick(void){ //
nleoni 0:180cf3834ece 36 // reads and stores the current Joystick state as defined by an integer where each bit //
nleoni 0:180cf3834ece 37 // represents one of the joystick directions //
nleoni 0:180cf3834ece 38 // Inputs: void //
nleoni 0:180cf3834ece 39 //**********************************************************************************************//
nleoni 0:180cf3834ece 40 void joystickAppBoard::readJoystick(void){
nleoni 0:180cf3834ece 41 this->joystickState=this->joystickPins->read();
nleoni 0:180cf3834ece 42 }
nleoni 0:180cf3834ece 43
nleoni 0:180cf3834ece 44 //**********************************************************************************************//
nleoni 0:180cf3834ece 45 // int joystickAppBoard::getJoystickState(void){ //
nleoni 0:180cf3834ece 46 // returns the current Joystick states as defined above //
nleoni 0:180cf3834ece 47 // Inputs: void //
nleoni 0:180cf3834ece 48 //**********************************************************************************************//
nleoni 0:180cf3834ece 49 int joystickAppBoard::getJoystickState(void){
nleoni 0:180cf3834ece 50 return this->joystickState;
nleoni 0:180cf3834ece 51 }
nleoni 0:180cf3834ece 52
nleoni 0:180cf3834ece 53 //**********************************************************************************************//
nleoni 0:180cf3834ece 54 // int joystickAppBoard::isJoystickUp(void){ //
nleoni 0:180cf3834ece 55 // returns true if Joystick is up //
nleoni 0:180cf3834ece 56 // Inputs: void //
nleoni 0:180cf3834ece 57 //**********************************************************************************************//
nleoni 0:180cf3834ece 58 bool joystickAppBoard::isJoystickUp(void){ return ( (this->joystickState) & JOYSTICKUP); }
nleoni 0:180cf3834ece 59
nleoni 0:180cf3834ece 60 //**********************************************************************************************//
nleoni 0:180cf3834ece 61 // int joystickAppBoard::isJoystickDown(void){ //
nleoni 0:180cf3834ece 62 // returns true if Joystick is down //
nleoni 0:180cf3834ece 63 // Inputs: void //
nleoni 0:180cf3834ece 64 //**********************************************************************************************//
nleoni 0:180cf3834ece 65 bool joystickAppBoard::isJoystickDown(void){ return ( (this->joystickState) & JOYSTICKDOWN); }
nleoni 0:180cf3834ece 66
nleoni 0:180cf3834ece 67 //**********************************************************************************************//
nleoni 0:180cf3834ece 68 // int joystickAppBoard::isJoystickLeft(void){ //
nleoni 0:180cf3834ece 69 // returns true if Joystick is left //
nleoni 0:180cf3834ece 70 // Inputs: void //
nleoni 0:180cf3834ece 71 //**********************************************************************************************//
nleoni 0:180cf3834ece 72 bool joystickAppBoard::isJoystickLeft(void){ return ( (this->joystickState) & JOYSTICKLEFT); }
nleoni 0:180cf3834ece 73
nleoni 0:180cf3834ece 74 //**********************************************************************************************//
nleoni 0:180cf3834ece 75 // int joystickAppBoard::isJoystickRight(void){ //
nleoni 0:180cf3834ece 76 // returns true if Joystick is left //
nleoni 0:180cf3834ece 77 // Inputs: void //
nleoni 0:180cf3834ece 78 //**********************************************************************************************//
nleoni 0:180cf3834ece 79 bool joystickAppBoard::isJoystickRight(void){ return ( (this->joystickState) & JOYSTICKRIGHT); }
nleoni 0:180cf3834ece 80
nleoni 0:180cf3834ece 81 //**********************************************************************************************//
nleoni 0:180cf3834ece 82 // int joystickAppBoard::isJoystickCenter(void){ //
nleoni 0:180cf3834ece 83 // returns true if Joystick is center //
nleoni 0:180cf3834ece 84 // Inputs: void //
nleoni 0:180cf3834ece 85 //**********************************************************************************************//
nleoni 0:180cf3834ece 86 bool joystickAppBoard::isJoystickCenter(void){ return ( (this->joystickState) & JOYSTICKCENTER); }