Doxyjen of the Bird.h

Dependencies:   mbed N5110

Committer:
Wuuu
Date:
Sun May 05 17:46:26 2019 +0000
Revision:
6:0912dfea40f5
Parent:
0:0aea7b9ba421
Final Submission. I have read and agreed with Statement of Academic Integrity.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wuuu 0:0aea7b9ba421 1 #ifndef GAMEPAD_H
Wuuu 0:0aea7b9ba421 2 #define GAMEPAD_H
Wuuu 0:0aea7b9ba421 3
Wuuu 0:0aea7b9ba421 4 #include <bitset>
Wuuu 0:0aea7b9ba421 5
Wuuu 0:0aea7b9ba421 6 // Forward declaration of the classes that we use from the mbed library
Wuuu 0:0aea7b9ba421 7 // This avoids the need for us to include the huge mbed.h header inside our
Wuuu 0:0aea7b9ba421 8 // own library API
Wuuu 0:0aea7b9ba421 9 namespace mbed
Wuuu 0:0aea7b9ba421 10 {
Wuuu 0:0aea7b9ba421 11 class AnalogIn;
Wuuu 0:0aea7b9ba421 12 class InterruptIn;
Wuuu 0:0aea7b9ba421 13 class PwmOut;
Wuuu 0:0aea7b9ba421 14 class Timeout;
Wuuu 0:0aea7b9ba421 15 }
Wuuu 0:0aea7b9ba421 16
Wuuu 0:0aea7b9ba421 17 #define TOL 0.1f
Wuuu 0:0aea7b9ba421 18 #define RAD2DEG 57.2957795131f
Wuuu 0:0aea7b9ba421 19
Wuuu 0:0aea7b9ba421 20 /** Enum for direction */
Wuuu 0:0aea7b9ba421 21 enum Direction {
Wuuu 0:0aea7b9ba421 22 CENTRE, /**< joystick centred */
Wuuu 0:0aea7b9ba421 23 N, /**< pushed North (0)*/
Wuuu 0:0aea7b9ba421 24 NE, /**< pushed North-East (45) */
Wuuu 0:0aea7b9ba421 25 E, /**< pushed East (90) */
Wuuu 0:0aea7b9ba421 26 SE, /**< pushed South-East (135) */
Wuuu 0:0aea7b9ba421 27 S, /**< pushed South (180) */
Wuuu 0:0aea7b9ba421 28 SW, /**< pushed South-West (225) */
Wuuu 0:0aea7b9ba421 29 W, /**< pushed West (270) */
Wuuu 0:0aea7b9ba421 30 NW /**< pushed North-West (315) */
Wuuu 0:0aea7b9ba421 31 };
Wuuu 0:0aea7b9ba421 32
Wuuu 0:0aea7b9ba421 33 /** Vector 2D struct */
Wuuu 0:0aea7b9ba421 34 struct Vector2D {
Wuuu 0:0aea7b9ba421 35 float x; /**< float for x value */
Wuuu 0:0aea7b9ba421 36 float y; /**< float for y value */
Wuuu 0:0aea7b9ba421 37 };
Wuuu 0:0aea7b9ba421 38
Wuuu 0:0aea7b9ba421 39 /** Polar coordinate struct */
Wuuu 0:0aea7b9ba421 40 struct Polar {
Wuuu 0:0aea7b9ba421 41 float mag; /**< float for magnitude */
Wuuu 0:0aea7b9ba421 42 float angle; /**< float for angle (in degrees) */
Wuuu 0:0aea7b9ba421 43 };
Wuuu 0:0aea7b9ba421 44
Wuuu 0:0aea7b9ba421 45 /** Gamepad Class
Wuuu 0:0aea7b9ba421 46 @brief Library for interfacing with ELEC2645 Gamepad PCB, University of Leeds
Wuuu 0:0aea7b9ba421 47 @author Dr Craig A. Evans
Wuuu 0:0aea7b9ba421 48 @author Dr Alex Valanvanis
Wuuu 0:0aea7b9ba421 49 @date Febraury 2017
Wuuu 0:0aea7b9ba421 50 */
Wuuu 0:0aea7b9ba421 51 class Gamepad
Wuuu 0:0aea7b9ba421 52 {
Wuuu 0:0aea7b9ba421 53 public:
Wuuu 0:0aea7b9ba421 54 /** Gamepad events
Wuuu 0:0aea7b9ba421 55 * @brief List of events that can be registered on the gamepad
Wuuu 0:0aea7b9ba421 56 */
Wuuu 0:0aea7b9ba421 57 enum GamepadEvent {
Wuuu 0:0aea7b9ba421 58 A_PRESSED, ///< Button A has been pressed
Wuuu 0:0aea7b9ba421 59 B_PRESSED, ///< Button B has been pressed
Wuuu 0:0aea7b9ba421 60 X_PRESSED, ///< Button X has been pressed
Wuuu 0:0aea7b9ba421 61 Y_PRESSED, ///< Button Y has been pressed
Wuuu 0:0aea7b9ba421 62 L_PRESSED, ///< Button L has been pressed
Wuuu 0:0aea7b9ba421 63 R_PRESSED, ///< Button R has been pressed
Wuuu 0:0aea7b9ba421 64 BACK_PRESSED, ///< Button "Back" has been pressed
Wuuu 0:0aea7b9ba421 65 START_PRESSED, ///< Button "Start" has been pressed
Wuuu 0:0aea7b9ba421 66 JOY_PRESSED, ///< Joystick button has been pressed
Wuuu 0:0aea7b9ba421 67 N_EVENTS ///< A dummy flag that marks the end of the list
Wuuu 0:0aea7b9ba421 68 };
Wuuu 0:0aea7b9ba421 69 private:
Wuuu 0:0aea7b9ba421 70 mbed::PwmOut *_led1;
Wuuu 0:0aea7b9ba421 71 mbed::PwmOut *_led2;
Wuuu 0:0aea7b9ba421 72 mbed::PwmOut *_led3;
Wuuu 0:0aea7b9ba421 73 mbed::PwmOut *_led4;
Wuuu 0:0aea7b9ba421 74 mbed::PwmOut *_led5;
Wuuu 0:0aea7b9ba421 75 mbed::PwmOut *_led6;
Wuuu 0:0aea7b9ba421 76
Wuuu 0:0aea7b9ba421 77 mbed::InterruptIn *_button_A;
Wuuu 0:0aea7b9ba421 78 mbed::InterruptIn *_button_B;
Wuuu 0:0aea7b9ba421 79 mbed::InterruptIn *_button_X;
Wuuu 0:0aea7b9ba421 80 mbed::InterruptIn *_button_Y;
Wuuu 0:0aea7b9ba421 81 mbed::InterruptIn *_button_L;
Wuuu 0:0aea7b9ba421 82 mbed::InterruptIn *_button_R;
Wuuu 0:0aea7b9ba421 83 mbed::InterruptIn *_button_back;
Wuuu 0:0aea7b9ba421 84 mbed::InterruptIn *_button_start;
Wuuu 0:0aea7b9ba421 85 mbed::InterruptIn *_button_joystick;
Wuuu 0:0aea7b9ba421 86
Wuuu 0:0aea7b9ba421 87 mbed::AnalogIn *_vert;
Wuuu 0:0aea7b9ba421 88 mbed::AnalogIn *_horiz;
Wuuu 0:0aea7b9ba421 89
Wuuu 0:0aea7b9ba421 90 mbed::PwmOut *_buzzer;
Wuuu 0:0aea7b9ba421 91 mbed::AnalogIn *_pot;
Wuuu 0:0aea7b9ba421 92
Wuuu 0:0aea7b9ba421 93 mbed::Timeout *_timeout;
Wuuu 0:0aea7b9ba421 94
Wuuu 0:0aea7b9ba421 95 std::bitset<N_EVENTS> _event_state; ///< A binary list of buttons that has been pressed
Wuuu 0:0aea7b9ba421 96
Wuuu 0:0aea7b9ba421 97 // centred x,y values
Wuuu 0:0aea7b9ba421 98 float _x0;
Wuuu 0:0aea7b9ba421 99 float _y0;
Wuuu 0:0aea7b9ba421 100
Wuuu 0:0aea7b9ba421 101 public:
Wuuu 0:0aea7b9ba421 102
Wuuu 0:0aea7b9ba421 103 /** Constructor */
Wuuu 0:0aea7b9ba421 104 Gamepad();
Wuuu 0:0aea7b9ba421 105
Wuuu 0:0aea7b9ba421 106 /** Destructor */
Wuuu 0:0aea7b9ba421 107 ~Gamepad();
Wuuu 0:0aea7b9ba421 108
Wuuu 0:0aea7b9ba421 109 /** Initialise all peripherals and configure interrupts */
Wuuu 0:0aea7b9ba421 110 void init();
Wuuu 0:0aea7b9ba421 111
Wuuu 0:0aea7b9ba421 112 /** Turn all LEDs on */
Wuuu 0:0aea7b9ba421 113 void leds_on();
Wuuu 0:0aea7b9ba421 114
Wuuu 0:0aea7b9ba421 115 /** Turn all LEDs off */
Wuuu 0:0aea7b9ba421 116 void leds_off();
Wuuu 0:0aea7b9ba421 117
Wuuu 0:0aea7b9ba421 118 /** Set all LEDs to duty-cycle
Wuuu 0:0aea7b9ba421 119 *@param value in range 0.0 to 1.0
Wuuu 0:0aea7b9ba421 120 */
Wuuu 0:0aea7b9ba421 121 void leds(float val) const;
Wuuu 0:0aea7b9ba421 122
Wuuu 0:0aea7b9ba421 123 /** Set LED to duty-cycle
Wuuu 0:0aea7b9ba421 124 *@param led number (0 to 5)
Wuuu 0:0aea7b9ba421 125 *@param value in range 0.0 to 1.0
Wuuu 0:0aea7b9ba421 126 */
Wuuu 0:0aea7b9ba421 127 void led(int n,float val) const;
Wuuu 0:0aea7b9ba421 128
Wuuu 0:0aea7b9ba421 129 /** Read potentiometer
Wuuu 0:0aea7b9ba421 130 *@returns potentiometer value in range 0.0 to 1.0
Wuuu 0:0aea7b9ba421 131 */
Wuuu 0:0aea7b9ba421 132 float read_pot() const;
Wuuu 0:0aea7b9ba421 133
Wuuu 0:0aea7b9ba421 134 /** Play tone on piezo
Wuuu 0:0aea7b9ba421 135 * @param frequency in Hz
Wuuu 0:0aea7b9ba421 136 * @param duration of tone in seconds
Wuuu 0:0aea7b9ba421 137 */
Wuuu 0:0aea7b9ba421 138 void tone(float frequency, float duration);
Wuuu 0:0aea7b9ba421 139
Wuuu 0:0aea7b9ba421 140 /**
Wuuu 0:0aea7b9ba421 141 * @brief Check whether an event flag has been set and clear it
Wuuu 0:0aea7b9ba421 142 * @param id[in] The ID of the event to test
Wuuu 0:0aea7b9ba421 143 * @return true if the event occurred
Wuuu 0:0aea7b9ba421 144 */
Wuuu 0:0aea7b9ba421 145 bool check_event(GamepadEvent const id);
Wuuu 0:0aea7b9ba421 146
Wuuu 0:0aea7b9ba421 147 /** Get magnitude of joystick movement
Wuuu 0:0aea7b9ba421 148 * @returns value in range 0.0 to 1.0
Wuuu 0:0aea7b9ba421 149 */
Wuuu 0:0aea7b9ba421 150
Wuuu 0:0aea7b9ba421 151 float get_mag();
Wuuu 0:0aea7b9ba421 152
Wuuu 0:0aea7b9ba421 153 /** Get angle of joystick movement
Wuuu 0:0aea7b9ba421 154 * @returns value in range 0.0 to 359.9. 0.0 corresponds to N, 180.0 to S. -1.0 is central
Wuuu 0:0aea7b9ba421 155 */
Wuuu 0:0aea7b9ba421 156 float get_angle();
Wuuu 0:0aea7b9ba421 157
Wuuu 0:0aea7b9ba421 158 /** Gets joystick direction
Wuuu 0:0aea7b9ba421 159 * @returns an enum: CENTRE, N, NE, E, SE, S, SW, W, NW,
Wuuu 0:0aea7b9ba421 160 */
Wuuu 0:0aea7b9ba421 161 Direction get_direction(); // N,NE,E,SE etc.
Wuuu 0:0aea7b9ba421 162
Wuuu 0:0aea7b9ba421 163 /** Gets raw cartesian co-ordinates of joystick
Wuuu 0:0aea7b9ba421 164 * @returns a struct with x,y members, each in the range 0.0 to 1.0
Wuuu 0:0aea7b9ba421 165 */
Wuuu 0:0aea7b9ba421 166 Vector2D get_coord(); // cartesian co-ordinates x,y
Wuuu 0:0aea7b9ba421 167
Wuuu 0:0aea7b9ba421 168 /** Gets cartesian coordinates mapped to circular grid
Wuuu 0:0aea7b9ba421 169 * @returns a struct with x,y members, each in the range 0.0 to 1.0
Wuuu 0:0aea7b9ba421 170 */
Wuuu 0:0aea7b9ba421 171 Vector2D get_mapped_coord(); // x,y mapped to circle
Wuuu 0:0aea7b9ba421 172
Wuuu 0:0aea7b9ba421 173 /** Gets polar coordinates of the joystick
Wuuu 0:0aea7b9ba421 174 * @returns a struct contains mag and angle
Wuuu 0:0aea7b9ba421 175 */
Wuuu 0:0aea7b9ba421 176 Polar get_polar(); // mag and angle in struct form
Wuuu 0:0aea7b9ba421 177
Wuuu 0:0aea7b9ba421 178 private:
Wuuu 0:0aea7b9ba421 179 void init_buttons();
Wuuu 0:0aea7b9ba421 180 void tone_off();
Wuuu 0:0aea7b9ba421 181
Wuuu 0:0aea7b9ba421 182 void a_isr();
Wuuu 0:0aea7b9ba421 183 void b_isr();
Wuuu 0:0aea7b9ba421 184 void x_isr();
Wuuu 0:0aea7b9ba421 185 void y_isr();
Wuuu 0:0aea7b9ba421 186 void l_isr();
Wuuu 0:0aea7b9ba421 187 void r_isr();
Wuuu 0:0aea7b9ba421 188 void back_isr();
Wuuu 0:0aea7b9ba421 189 void start_isr();
Wuuu 0:0aea7b9ba421 190 void joy_isr();
Wuuu 0:0aea7b9ba421 191 };
Wuuu 0:0aea7b9ba421 192
Wuuu 0:0aea7b9ba421 193 #endif