diff --git a/lib/touch_controls/include/touch_control.h b/lib/touch_controls/include/touch_control.h index 89b060b..ff94340 100644 --- a/lib/touch_controls/include/touch_control.h +++ b/lib/touch_controls/include/touch_control.h @@ -7,13 +7,22 @@ class TouchControl { public: - enum ControlType: uint8_t{ + enum ControlType: uint8_t + { CT_NONE, CT_JOYSTICK, CT_MOUSE_JOYSTICK, CT_DPAD, }; + enum TouchState: uint8_t + { + TS_NONE, + TS_INNER_DZ, + TS_RANGE, + TS_EDGE_SPIN, + }; + protected: int32_t pos_x; @@ -25,7 +34,7 @@ class TouchControl int8_t finger_id; - int8_t touching; + TouchState touching; public: @@ -34,7 +43,7 @@ class TouchControl virtual void init(int32_t pos_x, int32_t pos_y, int32_t pos_r); - virtual int8_t touch(int8_t fid, int32_t tx, int32_t ty) = 0; + virtual TouchState touch(int8_t fid, int32_t tx, int32_t ty) = 0; int8_t getTouching() {return touching;} diff --git a/lib/touch_controls/include/touch_dpad.h b/lib/touch_controls/include/touch_dpad.h index bdeb1e2..4afb18d 100644 --- a/lib/touch_controls/include/touch_dpad.h +++ b/lib/touch_controls/include/touch_dpad.h @@ -40,7 +40,7 @@ class TouchDpad : public TouchControl void setInvertX(bool invert_x = true); void setInvertY(bool invert_y = true); - int8_t touch(int8_t fid, int32_t tx, int32_t ty); + TouchState touch(int8_t fid, int32_t tx, int32_t ty); uint8_t getButton() {return button;} }; diff --git a/lib/touch_controls/include/touch_joystick.h b/lib/touch_controls/include/touch_joystick.h index 2e1f3ff..f2b25c3 100644 --- a/lib/touch_controls/include/touch_joystick.h +++ b/lib/touch_controls/include/touch_joystick.h @@ -44,7 +44,7 @@ class TouchJoystick : public TouchControl void setMappedId(uint8_t mapped_id); uint8_t getMappedId() {return mapped_id;} - int8_t touch(int8_t fid, int32_t tx, int32_t ty); + TouchState touch(int8_t fid, int32_t tx, int32_t ty); int16_t getX() {return x;} int16_t getY() {return y;} diff --git a/lib/touch_controls/include/touch_mouse_joystick.h b/lib/touch_controls/include/touch_mouse_joystick.h index 60c402d..8ea7178 100644 --- a/lib/touch_controls/include/touch_mouse_joystick.h +++ b/lib/touch_controls/include/touch_mouse_joystick.h @@ -26,7 +26,7 @@ class TouchMouseJoystick : public TouchJoystick void setTrackballFriction(float trackball_friction); - int8_t touch(int8_t fid, int32_t tx, int32_t ty, int32_t tdx, int32_t tdy, uint32_t time); + TouchState touch(int8_t fid, int32_t tx, int32_t ty, int32_t tdx, int32_t tdy, uint32_t time); void updateTrackball(uint32_t time); }; diff --git a/lib/touch_controls/src/touch_control.cpp b/lib/touch_controls/src/touch_control.cpp index 3ba810b..66a9028 100644 --- a/lib/touch_controls/src/touch_control.cpp +++ b/lib/touch_controls/src/touch_control.cpp @@ -16,5 +16,5 @@ void TouchControl::init(int32_t pos_x, int32_t pos_y, int32_t pos_r) this->finger_id = -1; - this->touching = 0; + this->touching = TS_NONE; } diff --git a/lib/touch_controls/src/touch_dpad.cpp b/lib/touch_controls/src/touch_dpad.cpp index df0550c..ab94464 100644 --- a/lib/touch_controls/src/touch_dpad.cpp +++ b/lib/touch_controls/src/touch_dpad.cpp @@ -52,12 +52,12 @@ void TouchDpad::setInvertY(bool invert_y) #define XINPUT_DPAD_LEFT 0b0100 #define XINPUT_DPAD_RIGHT 0b1000 -int8_t TouchDpad::touch(int8_t fid, int32_t tx, int32_t ty) +TouchDpad::TouchState TouchDpad::touch(int8_t fid, int32_t tx, int32_t ty) { if (finger_id != -1 && finger_id != fid) { - touching = 0; - return 0; + touching = TS_NONE; + return touching; } tx -= pos_x; @@ -71,8 +71,8 @@ int8_t TouchDpad::touch(int8_t fid, int32_t tx, int32_t ty) if (t2 > pos_r2) { finger_id = -1; - touching = 0; - return 0; + touching = TS_NONE; + return touching; } else // inside inner dead_zone { @@ -80,11 +80,11 @@ int8_t TouchDpad::touch(int8_t fid, int32_t tx, int32_t ty) if (t2 < dead_zone_inner2) { - touching = 1; + touching = TS_INNER_DZ; } else // in bounds { - touching = 2; + touching = TS_RANGE; switch (dpad_type) { diff --git a/lib/touch_controls/src/touch_joystick.cpp b/lib/touch_controls/src/touch_joystick.cpp index 43fda44..483eb14 100644 --- a/lib/touch_controls/src/touch_joystick.cpp +++ b/lib/touch_controls/src/touch_joystick.cpp @@ -60,12 +60,12 @@ void TouchJoystick::setMappedId(uint8_t mapped_id) this->mapped_id = mapped_id; } -int8_t TouchJoystick::touch(int8_t fid, int32_t tx, int32_t ty) +TouchJoystick::TouchState TouchJoystick::touch(int8_t fid, int32_t tx, int32_t ty) { if (finger_id != -1 && finger_id != fid) { - touching = 0; - return 0; + touching = TS_NONE; + return touching; } tx -= pos_x; @@ -80,8 +80,8 @@ int8_t TouchJoystick::touch(int8_t fid, int32_t tx, int32_t ty) if (t2 > pos_r2) { finger_id = -1; - touching = 0; - return 0; + touching = TS_NONE; + return touching; } else // inside inner dead_zone { @@ -89,11 +89,11 @@ int8_t TouchJoystick::touch(int8_t fid, int32_t tx, int32_t ty) if (t2 < dead_zone_inner2) { - touching = 1; + touching = TS_INNER_DZ; } else // between dead zones { - touching = 2; + touching = TS_RANGE; if (t2 <= dead_zone_outer2) { diff --git a/lib/touch_controls/src/touch_mouse_joystick.cpp b/lib/touch_controls/src/touch_mouse_joystick.cpp index 3bb3ba6..35c0f0f 100644 --- a/lib/touch_controls/src/touch_mouse_joystick.cpp +++ b/lib/touch_controls/src/touch_mouse_joystick.cpp @@ -27,12 +27,12 @@ void TouchMouseJoystick::setTrackballFriction(float trackball_friction) this->trackball_friction = trackball_friction; } -int8_t TouchMouseJoystick::touch(int8_t fid, int32_t tx, int32_t ty, int32_t tdx, int32_t tdy, uint32_t time) +TouchMouseJoystick::TouchState TouchMouseJoystick::touch(int8_t fid, int32_t tx, int32_t ty, int32_t tdx, int32_t tdy, uint32_t time) { if (finger_id != -1 && finger_id != fid) { - touching = 0; - return 0; + touching = TS_NONE; + return touching; } tx -= pos_x; @@ -47,8 +47,8 @@ int8_t TouchMouseJoystick::touch(int8_t fid, int32_t tx, int32_t ty, int32_t tdx if (t2 > pos_r2) { finger_id = -1; - touching = 0; - return 0; + touching = TS_NONE; + return touching; } else // inside the range { @@ -56,7 +56,7 @@ int8_t TouchMouseJoystick::touch(int8_t fid, int32_t tx, int32_t ty, int32_t tdx if (t2 <= dead_zone_outer2) { - touching = 2; + touching = TS_RANGE; dx = sensitivity * -tdx; dy = sensitivity * -tdy; @@ -75,7 +75,7 @@ int8_t TouchMouseJoystick::touch(int8_t fid, int32_t tx, int32_t ty, int32_t tdx } else // in bounds outside of outer dead zone - edge spin { - touching = 3; + touching = TS_EDGE_SPIN; float len = sqrt(t2); diff --git a/src/input_mapper.cpp b/src/input_mapper.cpp index d7cfe22..1318568 100644 --- a/src/input_mapper.cpp +++ b/src/input_mapper.cpp @@ -298,7 +298,7 @@ namespace InputMapper case TouchControl::CT_JOYSTICK: { TouchJoystick* tjoy = (TouchJoystick*)tcontrols[id][c]; - if (tjoy->getTouching() > 0) + if (tjoy->getTouching() > TouchControl::TS_NONE) { x[tjoy->getMappedId()] += tjoy->getX(); y[tjoy->getMappedId()] += tjoy->getY(); @@ -310,12 +310,12 @@ namespace InputMapper case TouchControl::CT_MOUSE_JOYSTICK: { TouchMouseJoystick* tmjoy = (TouchMouseJoystick*)tcontrols[id][c]; - if (tmjoy->getTouching() == 2) + if (tmjoy->getTouching() == TouchControl::TS_RANGE) { dx[tmjoy->getMappedId()] += tmjoy->getX(); dy[tmjoy->getMappedId()] += tmjoy->getY(); } - else if (tmjoy->getTouching() == 3) // edje spin + else if (tmjoy->getTouching() == TouchControl::TS_EDGE_SPIN) { x[tmjoy->getMappedId()] += tmjoy->getX(); y[tmjoy->getMappedId()] += tmjoy->getY();