From e19dffeacd700eb1a599796be03c7227bb81a568 Mon Sep 17 00:00:00 2001 From: NepEgor Date: Sat, 24 Sep 2022 21:00:00 +0400 Subject: [PATCH] reset joystick when mode shifting --- lib/touch_controls/include/touch_control.h | 2 ++ lib/touch_controls/include/touch_dpad.h | 2 ++ lib/touch_controls/include/touch_joystick.h | 2 ++ lib/touch_controls/include/touch_mouse_joystick.h | 2 ++ lib/touch_controls/src/touch_control.cpp | 6 ++++++ lib/touch_controls/src/touch_dpad.cpp | 6 ++++++ lib/touch_controls/src/touch_joystick.cpp | 7 +++++++ lib/touch_controls/src/touch_mouse_joystick.cpp | 9 +++++++++ src/input_mapper.cpp | 2 ++ 9 files changed, 38 insertions(+) diff --git a/lib/touch_controls/include/touch_control.h b/lib/touch_controls/include/touch_control.h index ff94340..e11f884 100644 --- a/lib/touch_controls/include/touch_control.h +++ b/lib/touch_controls/include/touch_control.h @@ -43,6 +43,8 @@ class TouchControl virtual void init(int32_t pos_x, int32_t pos_y, int32_t pos_r); + virtual void reset(); + 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 4afb18d..e8293d1 100644 --- a/lib/touch_controls/include/touch_dpad.h +++ b/lib/touch_controls/include/touch_dpad.h @@ -31,6 +31,8 @@ class TouchDpad : public TouchControl TouchDpad(int32_t pos_x, int32_t pos_y, int32_t pos_r, DpadType dpad_type = DPAD_TYPE_SECTOR_4); void init(int32_t pos_x, int32_t pos_y, int32_t pos_r, DpadType dpad_type = DPAD_TYPE_SECTOR_4); + + void reset(); void setDeadZoneInner(int32_t dead_zone_inner); diff --git a/lib/touch_controls/include/touch_joystick.h b/lib/touch_controls/include/touch_joystick.h index f2b25c3..b2ea4c4 100644 --- a/lib/touch_controls/include/touch_joystick.h +++ b/lib/touch_controls/include/touch_joystick.h @@ -35,6 +35,8 @@ class TouchJoystick : public TouchControl void init(int32_t pos_x, int32_t pos_y, int32_t pos_r, int16_t usb_x, int16_t usb_y, int16_t usb_r); + void reset(); + void setDeadZoneInner(int32_t dead_zone_inner); void setDeadZoneOuter(int32_t dead_zone_outer); diff --git a/lib/touch_controls/include/touch_mouse_joystick.h b/lib/touch_controls/include/touch_mouse_joystick.h index 0e7ccbf..a9caaf2 100644 --- a/lib/touch_controls/include/touch_mouse_joystick.h +++ b/lib/touch_controls/include/touch_mouse_joystick.h @@ -23,6 +23,8 @@ class TouchMouseJoystick : public TouchJoystick public: void init(int32_t pos_x, int32_t pos_y, int32_t pos_r, int16_t usb_x, int16_t usb_y, int16_t usb_r); + + void reset(); void setSensitivity(float sensitivity); diff --git a/lib/touch_controls/src/touch_control.cpp b/lib/touch_controls/src/touch_control.cpp index 66a9028..f49dad1 100644 --- a/lib/touch_controls/src/touch_control.cpp +++ b/lib/touch_controls/src/touch_control.cpp @@ -18,3 +18,9 @@ void TouchControl::init(int32_t pos_x, int32_t pos_y, int32_t pos_r) this->touching = TS_NONE; } + +void TouchControl::reset() +{ + this->finger_id = -1; + this->touching = TS_NONE; +} diff --git a/lib/touch_controls/src/touch_dpad.cpp b/lib/touch_controls/src/touch_dpad.cpp index ab94464..5be15be 100644 --- a/lib/touch_controls/src/touch_dpad.cpp +++ b/lib/touch_controls/src/touch_dpad.cpp @@ -31,6 +31,12 @@ void TouchDpad::init(int32_t pos_x, int32_t pos_y, int32_t pos_r, DpadType dpad_ this->button = 0; } +void TouchDpad::reset() +{ + TouchControl::reset(); + this->button = 0; +} + void TouchDpad::setDeadZoneInner(int32_t dead_zone_inner) { this->dead_zone_inner = dead_zone_inner; diff --git a/lib/touch_controls/src/touch_joystick.cpp b/lib/touch_controls/src/touch_joystick.cpp index 483eb14..fcb944d 100644 --- a/lib/touch_controls/src/touch_joystick.cpp +++ b/lib/touch_controls/src/touch_joystick.cpp @@ -31,6 +31,13 @@ void TouchJoystick::init(int32_t pos_x, int32_t pos_y, int32_t pos_r, int16_t us this->y = usb_y; } +void TouchJoystick::reset() +{ + TouchControl::reset(); + this->x = usb_x; + this->y = usb_y;; +} + void TouchJoystick::setDeadZoneInner(int32_t dead_zone_inner) { this->dead_zone_inner = dead_zone_inner; diff --git a/lib/touch_controls/src/touch_mouse_joystick.cpp b/lib/touch_controls/src/touch_mouse_joystick.cpp index a7e9afd..26bed2a 100644 --- a/lib/touch_controls/src/touch_mouse_joystick.cpp +++ b/lib/touch_controls/src/touch_mouse_joystick.cpp @@ -19,6 +19,15 @@ void TouchMouseJoystick::init(int32_t pos_x, int32_t pos_y, int32_t pos_r, int16 this->time0 = 0; } +void TouchMouseJoystick::reset() +{ + TouchJoystick::reset(); + this->trackball_vel_x = 0; + this->trackball_vel_y = 0; + this->dx = 0; + this->dy = 0; +} + void TouchMouseJoystick::setSensitivity(float sensitivity) { this->sensitivity = this->pos2usb * sensitivity; diff --git a/src/input_mapper.cpp b/src/input_mapper.cpp index 570363f..2509594 100644 --- a/src/input_mapper.cpp +++ b/src/input_mapper.cpp @@ -337,6 +337,8 @@ namespace InputMapper case HardwareButtons::BUMPER_LEFT: + tcontrols[1][0]->reset(); + if (value) { tcontrols[1][0] = &tjoystick_right_wheel;