Digital Joystick
Joystick.cpp@5:31e3324d4c4b, 2015-02-21 (annotated)
- Committer:
- LeoHsueh
- Date:
- Sat Feb 21 05:20:01 2015 +0000
- Revision:
- 5:31e3324d4c4b
- Parent:
- 4:beeaa40d49fa
- Child:
- 6:d354f6e3bd9b
joy lib
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alex89_2 | 0:9c486d50434e | 1 | #include "Joystick.h" |
alex89_2 | 0:9c486d50434e | 2 | |
LeoHsueh | 5:31e3324d4c4b | 3 | /** Create a Joystick HID for using regular mbed pins |
LeoHsueh | 5:31e3324d4c4b | 4 | * |
LeoHsueh | 5:31e3324d4c4b | 5 | * @param up Joystick Up |
LeoHsueh | 5:31e3324d4c4b | 6 | * @param down Joystick Down |
LeoHsueh | 5:31e3324d4c4b | 7 | * @param left Joystick Left |
LeoHsueh | 5:31e3324d4c4b | 8 | * @param right Joystick Right |
LeoHsueh | 5:31e3324d4c4b | 9 | * @param press Joystick Press |
LeoHsueh | 5:31e3324d4c4b | 10 | */ |
LeoHsueh | 5:31e3324d4c4b | 11 | Joystick::Joystick(PinName up, PinName down, PinName left, PinName right, PinName press) : |
LeoHsueh | 5:31e3324d4c4b | 12 | _up(up), _down(down), _left(left), _right(right), _press(press) { |
alex89_2 | 0:9c486d50434e | 13 | |
alex89_2 | 0:9c486d50434e | 14 | } |
alex89_2 | 0:9c486d50434e | 15 | |
LeoHsueh | 5:31e3324d4c4b | 16 | /** Function: getStatus |
LeoHsueh | 5:31e3324d4c4b | 17 | * Read the joystick status |
LeoHsueh | 5:31e3324d4c4b | 18 | * |
LeoHsueh | 5:31e3324d4c4b | 19 | * Variables: |
LeoHsueh | 5:31e3324d4c4b | 20 | * returns - A uint8_t values representing the bits |
LeoHsueh | 5:31e3324d4c4b | 21 | */ |
LeoHsueh | 5:31e3324d4c4b | 22 | uint8_t Joystick::getStatus() { |
LeoHsueh | 5:31e3324d4c4b | 23 | uint8_t ret = 0; |
LeoHsueh | 5:31e3324d4c4b | 24 | if (!_up) { |
LeoHsueh | 5:31e3324d4c4b | 25 | ret |= JOY_UP; |
LeoHsueh | 5:31e3324d4c4b | 26 | } |
LeoHsueh | 5:31e3324d4c4b | 27 | if (!_down) { |
LeoHsueh | 5:31e3324d4c4b | 28 | ret |= JOY_DOWN; |
LeoHsueh | 5:31e3324d4c4b | 29 | } |
LeoHsueh | 5:31e3324d4c4b | 30 | if (!_left) { |
LeoHsueh | 5:31e3324d4c4b | 31 | ret |= JOY_LEFT; |
LeoHsueh | 5:31e3324d4c4b | 32 | } |
LeoHsueh | 5:31e3324d4c4b | 33 | if (!_right) { |
LeoHsueh | 5:31e3324d4c4b | 34 | ret |= JOY_RIGHT; |
LeoHsueh | 5:31e3324d4c4b | 35 | } |
LeoHsueh | 5:31e3324d4c4b | 36 | if (!_press) { |
LeoHsueh | 5:31e3324d4c4b | 37 | ret |= JOY_PRESS; |
LeoHsueh | 5:31e3324d4c4b | 38 | } |
LeoHsueh | 5:31e3324d4c4b | 39 | return ret; |
alex89_2 | 0:9c486d50434e | 40 | } |