Joe Shotton / ll16j23s_test_docs

Files at this revision

API Documentation at this revision

Comitter:
eencae
Date:
Tue Feb 07 11:50:26 2017 +0000
Parent:
8:7eaf26f4b5f2
Child:
10:a13d2f9d8a14
Commit message:
Added methods to access individual LEDs.

Changed in this revision

Gamepad.cpp Show annotated file Show diff for this revision Revisions of this file
Gamepad.h Show annotated file Show diff for this revision Revisions of this file
--- a/Gamepad.cpp	Tue Feb 07 10:53:46 2017 +0000
+++ b/Gamepad.cpp	Tue Feb 07 11:50:26 2017 +0000
@@ -1,23 +1,14 @@
-/**
-@file Gamepad.cpp
-
-@brief member function implementations
-
-@author Dr Craig A. Evans
-
-*/
-
 #include "Gamepad.h"
 
 //////////// constructor/destructor ////////////
 Gamepad::Gamepad()
 {
-    led_1 = new PwmOut(PTA1);
-    led_2 = new PwmOut(PTA2);
-    led_3 = new PwmOut(PTC2);
-    led_4 = new PwmOut(PTC3);
-    led_5 = new PwmOut(PTC4);
-    led_6 = new PwmOut(PTD3);
+    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);
@@ -41,7 +32,7 @@
 
 Gamepad::~Gamepad()
 {
-    delete led_1,led_2,led_3,led_4,led_5,led_6;
+    delete led1,led2,led3,led4,led5,led6;
     delete button_A,button_B,button_joystick,vert,horiz;
     delete button_X, button_Y, button_back, button_start;
     delete button_L, button_R, buzzer, pot, timeout;
@@ -66,15 +57,15 @@
 
 void Gamepad::leds_off()
 {
-    fade_leds(0.0);
+    set_leds(0.0);
 }
 
 void Gamepad::leds_on()
 {
-    fade_leds(1.0);
+    set_leds(1.0);
 }
 
-void Gamepad::fade_leds(float val)
+void Gamepad::set_leds(float val)
 {
     if (val < 0.0f) {
         val = 0.0f;
@@ -87,12 +78,31 @@
     // 0.0 corresponds to fully-off, 1.0 to fully-on
     val = 1.0f - val;
 
-    led_1->write(val);
-    led_2->write(val);
-    led_3->write(val);
-    led_4->write(val);
-    led_5->write(val);
-    led_6->write(val);
+    led1->write(val);
+    led2->write(val);
+    led3->write(val);
+    led4->write(val);
+    led5->write(val);
+    led6->write(val);
+}
+
+void Gamepad::set_led1(float val) {
+    led1->write(1.0f-val);   // active-low so subtract from 1
+}
+void Gamepad::set_led2(float val) {
+    led2->write(1.0f-val);   // active-low so subtract from 1
+}
+void Gamepad::set_led3(float val) {
+    led3->write(1.0f-val);   // active-low so subtract from 1
+}
+void Gamepad::set_led4(float val) {
+    led4->write(1.0f-val);   // active-low so subtract from 1
+}
+void Gamepad::set_led5(float val) {
+    led5->write(1.0f-val);   // active-low so subtract from 1
+}
+void Gamepad::set_led6(float val) {
+    led6->write(1.0f-val);   // active-low so subtract from 1
 }
 
 float Gamepad::read_pot()
--- a/Gamepad.h	Tue Feb 07 10:53:46 2017 +0000
+++ b/Gamepad.h	Tue Feb 07 11:50:26 2017 +0000
@@ -1,14 +1,3 @@
-/**
-@file Gamepad.h
-
-@brief Library for interfacing with ELEC2645 Gamepad PCB
-@brief University of Leeds
-
-@author Dr Craig A. Evans
-@date Febraury 2017
-
-*/
-
 #ifndef GAMEPAD_H
 #define GAMEPAD_H
 
@@ -17,153 +6,186 @@
 #define TOL 0.1f
 #define RAD2DEG 57.2957795131f
 
+/** Enum for direction */
 enum Direction {
-    CENTRE,  // 0
-    N,       // 1
-    NE,      // 2
-    E,       // 3
-    SE,      // 4
-    S,       // 5
-    SW,      // 6
-    W,       // 7
-    NW      // 8
+    CENTRE,  /**< joystick centred */
+    N,       /**< pushed North (0)*/
+    NE,      /**< pushed North-East (45) */
+    E,       /**< pushed East (90) */
+    SE,      /**< pushed South-East (135) */
+    S,       /**< pushed South (180) */
+    SW,      /**< pushed South-West (225) */
+    W,       /**< pushed West (270) */
+    NW       /**< pushed North-West (315) */
 };
 
+/** Vector 2D struct */
 struct Vector2D {
-    float x;
-    float y;
+    float x; /**< float for x value */
+    float y; /**< float for y value */
 };
 
+/** Polar coordinate struct */
 struct Polar {
-    float mag;
-    float angle;
+    float mag;  /**< float for magnitude */
+    float angle; /**< float for angle (in degrees) */
 };
 
+/** Gamepad Class
+@brief Library for interfacing with ELEC2645 Gamepad PCB, University of Leeds
+@author Dr Craig A. Evans
+@date Febraury 2017
+*/
 class Gamepad
 {
 
 public:
 
-    /** Constructor
-    */
+    /** Constructor */
     Gamepad();
 
-    /** Destructor
-    */
+    /** Destructor */
     ~Gamepad();
 
-    /** Initialise all peripherals and configure interrupts
-    */
+    /** Initialise all peripherals and configure interrupts */
     void init();
 
-    /** Turn all LEDs on
-    */
+    /** Turn all LEDs on */
     void leds_on();
 
-    /** Turn all LEDs off
-    */
+    /** Turn all LEDs off */
     void leds_off();
 
-    /** Fade all to set duty-cycle
-    @param value in range 0.0 to 1.0
+    /** Set all LEDs to duty-cycle
+    *@param value in range 0.0 to 1.0
+    */
+    void set_leds(float val);
+
+    /** Set LED to duty-cycle
+    *@param value in range 0.0 to 1.0
     */
-    void fade_leds(float val);
+    void set_led1(float val);
+
+    /** Set LED to duty-cycle
+      *@param value in range 0.0 to 1.0
+      */
+    void set_led2(float val);
+
+    /** Set LED to duty-cycle
+    *@param value in range 0.0 to 1.0
+    */
+    void set_led3(float val);
+
+    /** Set LED to duty-cycle
+    *@param value in range 0.0 to 1.0
+    */
+    void set_led4(float val);
+
+    /** Set LED to duty-cycle
+    *@param value in range 0.0 to 1.0
+    */
+    void set_led5(float val);
+
+    /** Set LED to duty-cycle
+    *@param value in range 0.0 to 1.0
+    */
+    void set_led6(float val);
 
     /** Read potentiometer
-    @returns potentiometer value in range 0.0 to 1.0
+    *@returns potentiometer value in range 0.0 to 1.0
     */
     float read_pot();
 
     /** Play tone on piezo
-    @param frequency in Hz
-    @param duration of tone in seconds
+    * @param frequency in Hz
+    * @param duration of tone in seconds
     */
     void tone(float frequency, float duration);
 
     /** Check if A button pressed
-    @returns true if yes, false if no
+    * @returns true if yes, false if no
     */
     bool a_pressed();
 
     /** Check if B button pressed
-    @returns true if yes, false if no
+    * @returns true if yes, false if no
     */
     bool b_pressed();
 
     /** Check if X button pressed
-    @returns true if yes, false if no
+    * @returns true if yes, false if no
     */
     bool x_pressed();
 
     /** Check if Y button pressed
-    @returns true if yes, false if no
+    * @returns true if yes, false if no
     */
     bool y_pressed();
 
     /** Check if L button pressed
-    @returns true if yes, false if no
+    * @returns true if yes, false if no
     */
     bool l_pressed();
 
     /** Check if R button pressed
-    @returns true if yes, false if no
+    * @returns true if yes, false if no
     */
     bool r_pressed();
 
     /** Check if Back button pressed
-    @returns true if yes, false if no
+    * @returns true if yes, false if no
     */
     bool back_pressed();
 
     /** Check if Start button pressed
-    @returns true if yes, false if no
+    * @returns true if yes, false if no
     */
     bool start_pressed();
 
     /** Check if Joystick button pressed
-    @returns true if yes, false if no
+    * @returns true if yes, false if no
     */
     bool joystick_pressed();
 
     /** Get magnitude of joystick movement
-    @returns value in range 0.0 to 1.0
+    * @returns value in range 0.0 to 1.0
     */
 
     float get_mag();
-    
+
     /** Get angle of joystick movement
-    @returns value in range 0.0 to 359.9. 0.0 corresponds to N, 180.0 to S. -1.0 is central
+    * @returns value in range 0.0 to 359.9. 0.0 corresponds to N, 180.0 to S. -1.0 is central
     */
     float get_angle();
-    
+
     /** Gets joystick direction
-    @returns an enum: CENTRE, N, NE, E, SE, S, SW, W, NW,
+    * @returns an enum: CENTRE, N, NE, E, SE, S, SW, W, NW,
     */
     Direction get_direction();    // N,NE,E,SE etc.
-    
+
     /** Gets raw cartesian co-ordinates of joystick
-    @returns a struct with x,y members, each in the range 0.0 to 1.0
+    * @returns a struct with x,y members, each in the range 0.0 to 1.0
     */
     Vector2D get_coord();         // cartesian co-ordinates x,y
-    
+
     /** Gets cartesian coordinates mapped to circular grid
-     @returns a struct with x,y members, each in the range 0.0 to 1.0
+    * @returns a struct with x,y members, each in the range 0.0 to 1.0
     */
     Vector2D get_mapped_coord();  // x,y mapped to circle
-    
+
     /** Gets polar coordinates of the joystick
-    @returns a struct contains mag and angle
+    * @returns a struct contains mag and angle
     */
     Polar get_polar();            // mag and angle in struct form
 
 private:
 
-    PwmOut *led_1;
-    PwmOut *led_2;
-    PwmOut *led_3;
-    PwmOut *led_4;
-    PwmOut *led_5;
-    PwmOut *led_6;
+    PwmOut *led1;
+    PwmOut *led2;
+    PwmOut *led3;
+    PwmOut *led4;
+    PwmOut *led5;
+    PwmOut *led6;
 
     InterruptIn *button_A;
     InterruptIn *button_B;