Test publish to check documentation
Diff: Gamepad.cpp
- Revision:
- 25:ec8f4bea154c
- Parent:
- 23:8e1a30a69caa
- Child:
- 28:bd21eff0a18a
--- a/Gamepad.cpp Fri Jan 31 10:49:11 2020 +0000 +++ b/Gamepad.cpp Sun Apr 05 19:59:03 2020 +0000 @@ -196,6 +196,29 @@ return d; } +int Gamepad::get_cardinal() +{ + float angle = get_angle(); // 0 to 360, -1 for centred + + int d = 0; + // partition 360 into segments and check which segment the angle is in + if (angle < 0.0f) { + d = 0; // check for -1.0 angle + } else if (angle < 22.5f) { // then keep going in 45 degree increments + d = 1; + } else if (angle < 112.5f) { + d = 2; + } else if (angle < 202.5f) { + d = 3; + } else if (angle < 292.5f) { + d = 4; + } else { + d = 1; + } + + return d; +} + void Gamepad::reset_buttons() { A_fall = B_fall = X_fall = Y_fall = start_fall = false;