Digital Joystick
Diff: Joystick.cpp
- Revision:
- 6:d354f6e3bd9b
- Parent:
- 5:31e3324d4c4b
--- a/Joystick.cpp Sat Feb 21 05:20:01 2015 +0000 +++ b/Joystick.cpp Thu Feb 26 11:50:10 2015 +0000 @@ -13,28 +13,61 @@ } -/** Function: getStatus +void Joystick::functions(FunctionPointer *functionNone, FunctionPointer *functionUp, FunctionPointer *functionDown, + FunctionPointer *functionLeft, FunctionPointer *functionRight, FunctionPointer *functionPress) { + _functionNone = functionNone; + _functionUp = functionUp; + _functionDown = functionDown; + _functionLeft = functionLeft; + _functionRight = functionRight; + _functionPress = functionPress; +} + +/** Get status * Read the joystick status * - * Variables: - * returns - A uint8_t values representing the bits + * @returns Status of joystick */ -uint8_t Joystick::getStatus() { - uint8_t ret = 0; +Joystick::Status Joystick::getStatus() { if (!_up) { - ret |= JOY_UP; + return up; } if (!_down) { - ret |= JOY_DOWN; + return down; } if (!_left) { - ret |= JOY_LEFT; + return left; } if (!_right) { - ret |= JOY_RIGHT; + return right; } if (!_press) { - ret |= JOY_PRESS; + return press; } - return ret; + return none; } + +void Joystick::poll() { + switch (getStatus()) { + case none: + _functionNone->call(); + break; + case up: + _functionUp->call(); + break; + case down: + _functionDown->call(); + break; + case left: + _functionLeft->call(); + break; + case right: + _functionRight->call(); + break; + case press: + _functionPress->call(); + break; + default: + break; + } +}