Class used to interface with the handheld gamepad.

Fork of Gamepad by Craig Evans

Revision:
14:688bdcbdd3a5
Parent:
13:ef5fc9f58805
Child:
16:3ea3d9714b0c
--- a/Gamepad.cpp	Fri Mar 03 12:51:13 2017 +0000
+++ b/Gamepad.cpp	Fri Mar 03 13:05:27 2017 +0000
@@ -4,33 +4,37 @@
 
 //////////// constructor/destructor ////////////
 Gamepad::Gamepad()
-{
-    _led1 = new PwmOut(PTA1);
-    _led2 = new PwmOut(PTA2);
-    _led3 = new PwmOut(PTC2);
-    _led4 = new PwmOut(PTC3);
-    _led5 = new PwmOut(PTC4);
-    _led6 = new PwmOut(PTD3);
-
-    _button_A = new InterruptIn(PTB9);
-    _button_B = new InterruptIn(PTD0);
-    _button_X = new InterruptIn(PTC17);
-    _button_Y = new InterruptIn(PTC12);  
-    _button_back = new InterruptIn(PTB19);
-    _button_start = new InterruptIn(PTC5);
-    _button_L = new InterruptIn(PTB18);
-    _button_R = new InterruptIn(PTB3);
-    _button_joystick = new InterruptIn(PTC16);
+    :
+    _led1(new PwmOut(PTA1)),
+    _led2(new PwmOut(PTA2)),
+    _led3(new PwmOut(PTC2)),
+    _led4(new PwmOut(PTC3)),
+    _led5(new PwmOut(PTC4)),
+    _led6(new PwmOut(PTD3)),
     
-    _vert = new AnalogIn(PTB10);
-    _horiz = new AnalogIn(PTB11);
-
-    _buzzer = new PwmOut(PTC10);
-    _pot = new AnalogIn(PTB2);
-
-    _timeout = new Timeout();
-
-}
+    _button_A(new InterruptIn(PTB9)),
+    _button_B(new InterruptIn(PTD0)),
+    _button_X(new InterruptIn(PTC17)),
+    _button_Y(new InterruptIn(PTC12)),
+    _button_L(new InterruptIn(PTB18)),
+    _button_R(new InterruptIn(PTB3)),
+    _button_back(new InterruptIn(PTB19)),
+    _button_start(new InterruptIn(PTC5)),
+    _button_joystick(new InterruptIn(PTC16)),
+    
+    _vert(new AnalogIn(PTB10)),
+    _horiz(new AnalogIn(PTB11)),
+    
+    _buzzer(new PwmOut(PTC10)),
+    _pot(new AnalogIn(PTB2)),
+    
+    _timeout(new Timeout()),
+    
+    _event_state(0),
+    
+    _x0(0),
+    _y0(0)
+{}
 
 Gamepad::~Gamepad()
 {
@@ -46,7 +50,7 @@
 {
     leds_off();
     init_buttons();
-    
+
     // read centred values of joystick
     _x0 = _horiz->read();
     _y0 = _vert->read();
@@ -86,22 +90,28 @@
     _led6->write(val);
 }
 
-void Gamepad::led1(float val) {
+void Gamepad::led1(float val)
+{
     _led1->write(1.0f-val);   // active-low so subtract from 1
 }
-void Gamepad::led2(float val) {
+void Gamepad::led2(float val)
+{
     _led2->write(1.0f-val);   // active-low so subtract from 1
 }
-void Gamepad::led3(float val) {
+void Gamepad::led3(float val)
+{
     _led3->write(1.0f-val);   // active-low so subtract from 1
 }
-void Gamepad::led4(float val) {
+void Gamepad::led4(float val)
+{
     _led4->write(1.0f-val);   // active-low so subtract from 1
 }
-void Gamepad::led5(float val) {
+void Gamepad::led5(float val)
+{
     _led5->write(1.0f-val);   // active-low so subtract from 1
 }
-void Gamepad::led6(float val) {
+void Gamepad::led6(float val)
+{
     _led6->write(1.0f-val);   // active-low so subtract from 1
 }