Class used to interface with the handheld gamepad.

Fork of Gamepad by Craig Evans

Revision:
3:964a6d95acdd
Parent:
1:6d25cd49059b
Child:
4:bafb7f483e93
diff -r ea5538fcfe2f -r 964a6d95acdd Gamepad.h
--- a/Gamepad.h	Sat Feb 04 16:21:19 2017 +0000
+++ b/Gamepad.h	Mon Feb 06 19:33:29 2017 +0000
@@ -2,8 +2,31 @@
 #define GAMEPAD_H
 
 #include "mbed.h"
-#include "N5110.h"
-#include "Joystick.h"
+
+#define TOL 0.1f
+#define RAD2DEG 57.2957795131f
+
+enum Direction {
+    CENTRE,  // 0
+    N,       // 1
+    NE,      // 2
+    E,       // 3
+    SE,      // 4
+    S,       // 5
+    SW,      // 6
+    W,       // 7
+    NW      // 8
+};
+
+struct Vector2D {
+    float x;
+    float y;
+};
+
+struct Polar {
+    float mag;
+    float angle;
+};
 
 class Gamepad
 {
@@ -12,8 +35,6 @@
 
     Gamepad();
     ~Gamepad();
-    N5110 *lcd;
-    Joystick *joystick;
 
     void init();
     void leds_on();
@@ -32,6 +53,12 @@
     bool back_pressed();
     bool start_pressed();
 
+    bool joystick_pressed();
+    float get_mag();
+    float get_angle();
+    Direction get_direction();    // N,NE,E,SE etc.
+
+
 private:
 
     PwmOut *led_1;
@@ -44,11 +71,15 @@
     InterruptIn *button_A;
     InterruptIn *button_B;
     InterruptIn *button_X;
-    InterruptIn *button_Y;  // changed pin
+    InterruptIn *button_Y;
     InterruptIn *button_back;
     InterruptIn *button_start;
     InterruptIn *button_L;
     InterruptIn *button_R;
+    InterruptIn *button_joystick;
+
+    AnalogIn *vert;
+    AnalogIn *horiz;
 
     PwmOut *buzzer;
     AnalogIn *pot;
@@ -57,6 +88,7 @@
 
     void init_buttons();
     void tone_off();
+
     void a_isr();
     void b_isr();
     void x_isr();
@@ -65,8 +97,20 @@
     void r_isr();
     void back_isr();
     void start_isr();
+    void joy_isr();
+    
+    Vector2D get_coord();         // cartesian co-ordinates x,y
+    Vector2D get_mapped_coord();  // x,y mapped to circle
+    Direction get_direction();    // N,NE,E,SE etc.
+    Polar get_polar();            // mag and angle in struct form
 
-    bool a_flag,b_flag,x_flag,y_flag,l_flag,r_flag,back_flag,start_flag;
+    bool a_flag,b_flag,x_flag,y_flag,l_flag,r_flag,back_flag,start_flag,joy_flag;
+    
+      // centred x,y values    
+    float _x0;
+    float _y0;
+
+
 
 };