blob: 1923c5398c32faa15e64e601402281e8cf164497 [file] [log] [blame]
Tyler Chatowd28951f2019-02-16 20:12:28 -08001#include "y2019/joystick_angle.h"
2
3namespace y2019 {
4namespace input {
5namespace joysticks {
6
7JoystickAngle GetJoystickPosition(const JoystickAxis &x_axis,
8 const JoystickAxis &y_axis,
9 const Data &data) {
10 return GetJoystickPosition(data.GetAxis(x_axis), data.GetAxis(y_axis));
11}
12
13JoystickAngle GetJoystickPosition(float x_axis, float y_axis) {
14 if (x_axis > kJoystickRight) {
15 if (y_axis < kJoystickDown) {
16 return JoystickAngle::kUpperRight;
17 } else if (y_axis > kJoystickUp) {
18 return JoystickAngle::kLowerRight;
19 } else {
20 return JoystickAngle::kMiddleRight;
21 }
22 } else if (x_axis < kJoystickLeft) {
23 if (y_axis < kJoystickDown) {
24 return JoystickAngle::kUpperLeft;
25 } else if (y_axis > kJoystickUp) {
26 return JoystickAngle::kLowerLeft;
27 } else {
28 return JoystickAngle::kMiddleLeft;
29 }
30 }
31 return JoystickAngle::kDefault;
32}
33
34} // namespace joysticks
35} // namespace input
36} // namespace y2019