Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: 25LCxxx_SPI CommonTypes Gameduino mbed
PanelControls.h
00001 /* 00002 * SOURCE FILE : PanelControls.h 00003 * 00004 * Responsible for reading joysticks and buttons. 00005 * This is the version for mbed LPC1768. 00006 * There is a version kicking around for the LPC11U24 that uses different inputs for joystick 2. 00007 * 00008 */ 00009 00010 #ifndef PanelControlsIncluded 00011 00012 #define PanelControlsIncluded 00013 00014 #include "mbed.h" 00015 #include "Types.h" 00016 00017 class PanelControls { 00018 00019 public : 00020 00021 /***************/ 00022 /* CONSTRUCTOR */ 00023 /***************/ 00024 PanelControls() : 00025 inputs( 0 ), 00026 bus( (BusIn*)NULL ) 00027 { 00028 } 00029 00030 /**************/ 00031 /* DESTRUCTOR */ 00032 /**************/ 00033 ~PanelControls() { 00034 delete bus; 00035 } 00036 00037 /*************************/ 00038 /* INITIALISE INPUT PINS */ 00039 /*************************/ 00040 void InitialisePins( void ) { 00041 // Create an input bus. 00042 bus = new BusIn( 00043 p23, p24, p25, p26, // joystick 1 up, down, left, right 00044 p21, p22, p27, p28, // joystick 2 up, down, left, right 00045 p29, p30 // button 1, button 2 00046 ); 00047 } 00048 00049 /*****************************/ 00050 /* READ ALL THE PANEL INPUTS */ 00051 /*****************************/ 00052 // Returns a bitmap of all the inputs. 00053 void Read( void ) { 00054 if( bus == (BusIn*)NULL ) { 00055 inputs = 0; 00056 } 00057 else { 00058 // Note that a closed contact registers as a zero 00059 // which is why the bitwise not operator (~) is used. 00060 inputs = ~*bus & 0x3FF; 00061 } 00062 } 00063 00064 // Masks to use with GetInputs method. 00065 enum Mask { 00066 Up1 = 1, 00067 Down1 = 2, 00068 Left1 = 4, 00069 Right1 = 8, 00070 Up2 = 16, 00071 Down2 = 32, 00072 Left2 = 64, 00073 Right2 = 128, 00074 Button1 = 256, 00075 Button2 = 512, 00076 }; 00077 00078 // Bit numbers indicating where readings for each joystick start in the map. 00079 // Can use these with right shift operator. 00080 enum Bits { 00081 Joy1 = 0, // joystick 1 readings start at bit 0 00082 Joy2 = 4, // joystick 2 readings start at bit 4 00083 Buttons = 8, // button readings start at bit 8 00084 }; 00085 00086 /***************************/ 00087 /* GET STATE OF THE INPUTS */ 00088 /***************************/ 00089 // Returns a bitmap of the state of the inputs 00090 // last time Read was called. 00091 UInt16 GetInputs( void ) { 00092 return inputs; 00093 } 00094 00095 private : 00096 00097 // Stored state of inputs. 00098 UInt16 inputs; 00099 00100 // Input bus used to read inputs. 00101 BusIn *bus; 00102 00103 }; 00104 00105 #endif 00106 00107 /* END of PanelControls.h */
Generated on Tue Jul 12 2022 21:10:36 by
1.7.2