Digital Joystick
Diff: Joystick.h
- Revision:
- 6:d354f6e3bd9b
- Parent:
- 5:31e3324d4c4b
--- a/Joystick.h Sat Feb 21 05:20:01 2015 +0000 +++ b/Joystick.h Thu Feb 26 11:50:10 2015 +0000 @@ -4,26 +4,44 @@ //required to use mbed functions #include "mbed.h" +#include "FunctionPointer.h" -#define JOY_UP 0x01 -#define JOY_DOWN 0x02 -#define JOY_LEFT 0x04 -#define JOY_RIGHT 0x08 -#define JOY_PRESS 0x10 +#define JOYSTICK_NONE 0x00 +#define JOYSTICK_UP 0x01 +#define JOYSTICK_DOWN 0x02 +#define JOYSTICK_LEFT 0x04 +#define JOYSTICK_RIGHT 0x08 +#define JOYSTICK_PRESS 0x10 -/** Class: Joystick +/** Digital Joystick class * - * Used for reading from an digital joystick + * Used for an digital joystick. * * Example: + * @code + * #include "mbed.h" + * #include "Joystick.h" * - * > #include "mbed.h" + * Joystick joystick(P2_3, P0_15, P2_4, P0_16, P0_17); * - * > Joystick joystick(P2_3, P0_15, P2_4, P0_16, P0_17); + * int main() { + * joystick.getStatus(); + * } + * + * @endcode */ class Joystick { public: + typedef enum { + none = JOYSTICK_NONE, + up = JOYSTICK_UP, + down = JOYSTICK_DOWN, + left = JOYSTICK_LEFT, + right = JOYSTICK_RIGHT, + press = JOYSTICK_PRESS + } Status; + /** Create a Joystick HID for using regular mbed pins * * @param up Joystick Up @@ -34,19 +52,44 @@ */ Joystick(PinName up, PinName down, PinName left, PinName right, PinName press); - /** Function: getStatus + void functions(FunctionPointer *functionNone, FunctionPointer *functionUp, FunctionPointer *functionDown, + FunctionPointer *functionLeft, FunctionPointer *functionRight, FunctionPointer *functionPress); + + /** Get status * Read the joystick status * - * Variables: - * returns - A uint8_t values representing the bits + * @code + * switch (joystick.getStatus()) { + * case Joystick::none: + * break; + * case Joystick::up: + * break; + * case Joystick::down: + * break; + * case Joystick::left: + * break; + * case Joystick::right: + * break; + * case Joystick::press: + * break; + * default: + * break; + * } + * @endcode + * + * @returns A uint8_t values representing the bits */ - uint8_t getStatus(); + Status getStatus(); + + void poll(); private: /** Regular mbed pins bus */ DigitalIn _up, _down, _left, _right, _press; + + FunctionPointer *_functionNone, *_functionUp, *_functionDown, *_functionLeft, *_functionRight, *_functionPress; }; #endif