Alex Louden / Joystick
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Joystick.h Source File

Joystick.h

00001 //remove repetition
00002 #ifndef MBED_JOYSTICK_H
00003 #define MBED_JOYSTICK_H
00004 
00005 //required to use mbed functions
00006 #include "mbed.h"
00007 
00008 /** Struct: joyhv
00009  *
00010  * Used for holding a horizontal and vertical position as doubles
00011  */
00012 struct joyhv {
00013     double h;
00014     double v;
00015 };
00016 
00017 /** Class: Joystick
00018  *
00019  * Used for reading from an analog joystick
00020  *
00021  * Example:
00022  *
00023  * > #include "mbed.h"
00024  *
00025  * > Joystick joy(p20, p19, p18);
00026  */
00027  
00028 class Joystick {
00029 public:
00030     /** Constructor: Joystick
00031      *
00032      * Variables: 
00033      * b - DigitalIn pin for button
00034      * h - AnalogIn pin for horizontal 
00035      * v - AnalogIn pin for vertical 
00036      */ 
00037     Joystick(PinName b, PinName h, PinName v);
00038     
00039     /** Function: read
00040      * Read the joystick position, represented as a joyhv value - h and v are doubles in the range [0.0, 1.0]
00041      *
00042      * Variables:
00043      *  returns - A structure of two double values representing the position of the joystick,
00044      *            measured as a percentage vertically (joyhv.v) or horizontally (joyhv.h)
00045      */
00046     joyhv read();
00047 
00048     /** Function: getV
00049      * Read the joystick's vertical position, represented as a double value in the range [0.0, 1.0]
00050      *
00051      * Variables:
00052      *  returns - A double values representing the vertical position of the joystick,
00053      *            measured as a percentage  
00054      */
00055     double getV();
00056     
00057     /** Function: getH
00058      * Read the joystick's horizontal position, represented as a double value in the range [0.0, 1.0]
00059      *
00060      * Variables:
00061      *  returns - A double values representing the horizontal position of the joystick,
00062      *            measured as a percentage  
00063      */
00064     double getH();
00065     
00066     /** Function: rise
00067      *  Attach a function to call when a rising edge occurs on the button input
00068      *
00069      * Variables:
00070      *  fptr - A pointer to a void function, or 0 to set as none
00071      */
00072     void rise (void (*fptr)(void));
00073     
00074     /** Function: fall
00075      *  Attach a function to call when a falling edge occurs on the button input
00076      *
00077      * Variables:
00078      *  fptr - A pointer to a void function, or 0 to set as none
00079      */
00080     void fall (void (*fptr)(void));
00081     
00082     /** Function: operator joyhv
00083      *  An operator shorthand for <read()>
00084      *
00085      * The joyhv() operator can be used as a shorthand for <read()> to simplify common code sequences
00086      *
00087      */
00088     operator joyhv ();
00089     
00090     joyhv scale(joyhv read);
00091     joyhv filter(joyhv read, double factor);
00092 
00093     
00094 private:
00095     InterruptIn _b;
00096     AnalogIn _h;
00097     AnalogIn _v;
00098 };
00099 
00100 
00101 #endif