Class used to interface with the handheld gamepad.

Fork of Gamepad by Craig Evans

Revision:
12:1b0b6355da4f
Parent:
11:ff86b2ffce01
Child:
13:ef5fc9f58805
--- a/Gamepad.h	Thu Mar 02 18:34:42 2017 +0000
+++ b/Gamepad.h	Fri Mar 03 12:35:43 2017 +0000
@@ -1,6 +1,8 @@
 #ifndef GAMEPAD_H
 #define GAMEPAD_H
 
+#include <bitset>
+
 #include "mbed.h"
 
 #define TOL 0.1f
@@ -31,6 +33,23 @@
     float angle; /**< float for angle (in degrees) */
 };
 
+
+/**
+ * List of events that can be registered on the gamepad
+ */
+enum GamepadEvent {
+    EVENT_A_PRESSED,     ///< Button A has been pressed
+    EVENT_B_PRESSED,     ///< Button B has been pressed
+    EVENT_X_PRESSED,     ///< Button X has been pressed
+    EVENT_Y_PRESSED,     ///< Button Y has been pressed
+    EVENT_L_PRESSED,     ///< Button L has been pressed
+    EVENT_R_PRESSED,     ///< Button R has been pressed
+    EVENT_BACK_PRESSED,  ///< Button "Back" has been pressed
+    EVENT_START_PRESSED, ///< Button "Start" has been pressed
+    EVENT_JOY_PRESSED,   ///< Joystick button has been pressed
+    N_EVENTS             ///< A dummy flag that marks the end of the list
+};
+
 /** Gamepad Class
 @brief Library for interfacing with ELEC2645 Gamepad PCB, University of Leeds
 @author Dr Craig A. Evans
@@ -64,15 +83,7 @@
 
     Timeout *_timeout;
 
-    bool _a_flag;
-    bool _b_flag;
-    bool _x_flag;
-    bool _y_flag;
-    bool _l_flag;
-    bool _r_flag;
-    bool _back_flag;
-    bool _start_flag;
-    bool _joy_flag;
+    std::bitset<N_EVENTS> _event_state; ///< A binary list of buttons that has been pressed
 
     // centred x,y values
     float _x0;
@@ -141,51 +152,13 @@
     */
     void tone(float frequency, float duration);
 
-    /** Check if A button pressed
-    * @returns true if yes, false if no
-    */
-    bool a_pressed();
-
-    /** Check if B button pressed
-    * @returns true if yes, false if no
-    */
-    bool b_pressed();
-
-    /** Check if X button pressed
-    * @returns true if yes, false if no
-    */
-    bool x_pressed();
-
-    /** Check if Y button pressed
-    * @returns true if yes, false if no
-    */
-    bool y_pressed();
-
-    /** Check if L button pressed
-    * @returns true if yes, false if no
-    */
-    bool l_pressed();
-
-    /** Check if R button pressed
-    * @returns true if yes, false if no
-    */
-    bool r_pressed();
-
-    /** Check if Back button pressed
-    * @returns true if yes, false if no
-    */
-    bool back_pressed();
-
-    /** Check if Start button pressed
-    * @returns true if yes, false if no
-    */
-    bool start_pressed();
-
-    /** Check if Joystick button pressed
-    * @returns true if yes, false if no
-    */
-    bool joystick_pressed();
-
+    /**
+     * @brief Check whether an event flag has been set and clear it
+     * @param id[in] The ID of the event to test
+     * @return true if the event occurred
+     */
+    bool check_event(GamepadEvent const id);
+    
     /** Get magnitude of joystick movement
     * @returns value in range 0.0 to 1.0
     */