Digital Joystick
Diff: Joystick.h
- Revision:
- 5:31e3324d4c4b
- Parent:
- 3:83b40e07476f
- Child:
- 6:d354f6e3bd9b
--- a/Joystick.h Tue Sep 28 16:32:20 2010 +0000 +++ b/Joystick.h Sat Feb 21 05:20:01 2015 +0000 @@ -5,97 +5,48 @@ //required to use mbed functions #include "mbed.h" -/** Struct: joyhv - * - * Used for holding a horizontal and vertical position as doubles - */ -struct joyhv { - double h; - double v; -}; +#define JOY_UP 0x01 +#define JOY_DOWN 0x02 +#define JOY_LEFT 0x04 +#define JOY_RIGHT 0x08 +#define JOY_PRESS 0x10 /** Class: Joystick * - * Used for reading from an analog joystick + * Used for reading from an digital joystick * * Example: * * > #include "mbed.h" * - * > Joystick joy(p20, p19, p18); + * > Joystick joystick(P2_3, P0_15, P2_4, P0_16, P0_17); */ - -class Joystick { -public: - /** Constructor: Joystick - * - * Variables: - * b - DigitalIn pin for button - * h - AnalogIn pin for horizontal - * v - AnalogIn pin for vertical - */ - Joystick(PinName b, PinName h, PinName v); - - /** Function: read - * Read the joystick position, represented as a joyhv value - h and v are doubles in the range [0.0, 1.0] - * - * Variables: - * returns - A structure of two double values representing the position of the joystick, - * measured as a percentage vertically (joyhv.v) or horizontally (joyhv.h) - */ - joyhv read(); - /** Function: getV - * Read the joystick's vertical position, represented as a double value in the range [0.0, 1.0] - * - * Variables: - * returns - A double values representing the vertical position of the joystick, - * measured as a percentage - */ - double getV(); - - /** Function: getH - * Read the joystick's horizontal position, represented as a double value in the range [0.0, 1.0] - * - * Variables: - * returns - A double values representing the horizontal position of the joystick, - * measured as a percentage - */ - double getH(); - - /** Function: rise - * Attach a function to call when a rising edge occurs on the button input - * - * Variables: - * fptr - A pointer to a void function, or 0 to set as none - */ - void rise (void (*fptr)(void)); - - /** Function: fall - * Attach a function to call when a falling edge occurs on the button input - * - * Variables: - * fptr - A pointer to a void function, or 0 to set as none - */ - void fall (void (*fptr)(void)); - - /** Function: operator joyhv - * An operator shorthand for <read()> - * - * The joyhv() operator can be used as a shorthand for <read()> to simplify common code sequences - * - */ - operator joyhv (); - - joyhv scale(joyhv read); - joyhv filter(joyhv read, double factor); +class Joystick { + public: + /** Create a Joystick HID for using regular mbed pins + * + * @param up Joystick Up + * @param down Joystick Down + * @param left Joystick Left + * @param right Joystick Right + * @param press Joystick Press + */ + Joystick(PinName up, PinName down, PinName left, PinName right, PinName press); - -private: - InterruptIn _b; - AnalogIn _h; - AnalogIn _v; + /** Function: getStatus + * Read the joystick status + * + * Variables: + * returns - A uint8_t values representing the bits + */ + uint8_t getStatus(); + + private: + + /** Regular mbed pins bus + */ + DigitalIn _up, _down, _left, _right, _press; }; - -#endif \ No newline at end of file +#endif