From 7f2d323272c3675fa0198a0e920650b8e609c1ee Mon Sep 17 00:00:00 2001 From: NepEgor Date: Fri, 5 Nov 2021 19:47:43 +0300 Subject: [PATCH] Removed old joystick --- .../old/test_joystick/test_touch_joystick.cpp | 38 ------- lib/touch_controls/old/touch_joystick.cpp | 102 ------------------ lib/touch_controls/old/touch_joystick.h | 55 ---------- 3 files changed, 195 deletions(-) delete mode 100644 lib/touch_controls/old/test_joystick/test_touch_joystick.cpp delete mode 100644 lib/touch_controls/old/touch_joystick.cpp delete mode 100644 lib/touch_controls/old/touch_joystick.h diff --git a/lib/touch_controls/old/test_joystick/test_touch_joystick.cpp b/lib/touch_controls/old/test_joystick/test_touch_joystick.cpp deleted file mode 100644 index 983675f..0000000 --- a/lib/touch_controls/old/test_joystick/test_touch_joystick.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "touch_joystick.h" - -#include - -int main() -{ - printf("\n"); - - int32_t pos_x = 150; - int32_t pos_y = 350; - int32_t pos_r = 2000; - - int16_t usb_x = 512; - int16_t usb_y = 512; - int16_t usb_r = 512; - - TouchJoystick tjoystick(pos_x, pos_y, pos_r, usb_x, usb_y, usb_r); - - int32_t touch_x = 10000; - int32_t touch_y = 200; - - int16_t x; - int16_t y; - - if (!tjoystick.touch(touch_x, touch_y, &x, &y)) - { - printf("USB coords: (%i, %i)\n", x, y); - } - else - { - printf("Touch out of bounds\n"); - } - - - printf("\n"); - - return 0; -} \ No newline at end of file diff --git a/lib/touch_controls/old/touch_joystick.cpp b/lib/touch_controls/old/touch_joystick.cpp deleted file mode 100644 index 44da9d1..0000000 --- a/lib/touch_controls/old/touch_joystick.cpp +++ /dev/null @@ -1,102 +0,0 @@ -#include "touch_joystick.h" - -#include - -TouchJoystick::TouchJoystick(int32_t pos_x, int32_t pos_y, int32_t pos_r, int16_t usb_x, int16_t usb_y, int16_t usb_r) -{ - init(pos_x, pos_y, pos_r, usb_x, usb_y, usb_r); -} - -void TouchJoystick::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) -{ - this->pos_x = pos_x; - this->pos_y = pos_y; - this->pos_r = pos_r; - this->pos_r2 = pos_r * pos_r; - - this->usb_x = usb_x; - this->usb_y = usb_y; - this->usb_r = usb_r; - - this->pos2usb = (float)usb_r / pos_r; - - this->dead_zone_inner = 0; - this->dead_zone_inner2 = 0; - this->dead_zone_outer = pos_r; - this->dead_zone_outer2 = pos_r2; - - this->invert_x = false; - this->invert_y = false; -} - -void TouchJoystick::setDeadZoneInner(int32_t dead_zone_inner) -{ - this->dead_zone_inner = dead_zone_inner; - this->dead_zone_inner2 = dead_zone_inner * dead_zone_inner; -} - -void TouchJoystick::setDeadZoneOuter(int32_t dead_zone_outer) -{ - this->dead_zone_outer = pos_r - dead_zone_outer; // argument is from the outer edge, atribute is from the center - this->dead_zone_outer2 = this->dead_zone_outer * this->dead_zone_outer; - - pos2usb = (float)usb_r / this->dead_zone_outer; -} - -void TouchJoystick::setInvertX(bool invert_x) -{ - this->invert_x = invert_x; -} - -void TouchJoystick::setInvertY(bool invert_y) -{ - this->invert_y = invert_y; -} - -int8_t TouchJoystick::touch(int32_t tx, int32_t ty, int16_t* rx, int16_t* ry) -{ - int8_t ret = 2; - - tx -= pos_x; - ty -= pos_y; - - int32_t t2 = tx * tx + ty * ty; - - x = usb_x; - y = usb_y; - - // outside the range - if (t2 > pos_r2) - { - ret = 0; - } - else // inside inner dead_zone - if (t2 < dead_zone_inner2) - { - ret = 1; - } - else // between dead zones - if (t2 <= dead_zone_outer2) - { - x = tx * pos2usb + usb_x; - y = ty * pos2usb + usb_y; - } - else // in bounds outside of outer dead zone - { - float len = sqrt(t2); - - x = (tx * dead_zone_outer / len) * pos2usb + usb_x; - y = (ty * dead_zone_outer / len) * pos2usb + usb_y; - } - - if (invert_x) x = usb_x + usb_r - x; - if (invert_y) y = usb_y + usb_r - y; - - if (rx != NULL && ry != NULL) - { - *rx = x; - *ry = y; - } - - return ret; -} \ No newline at end of file diff --git a/lib/touch_controls/old/touch_joystick.h b/lib/touch_controls/old/touch_joystick.h deleted file mode 100644 index 4548568..0000000 --- a/lib/touch_controls/old/touch_joystick.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef TOUCH_JOYSTICK_H -#define TOUCH_JOYSTICK_H - -#include -#include - -class TouchJoystick -{ - private: - - // position of joystick on trackpad - int32_t pos_x; - int32_t pos_y; - int32_t pos_r; - int32_t pos_r2; // pos_r ^ 2 - - int32_t dead_zone_inner; - int32_t dead_zone_inner2; // ^ 2 - int32_t dead_zone_outer; - int32_t dead_zone_outer2; // ^ 2 - - // joystick values for usb report - int16_t x; - int16_t y; - - int16_t usb_x; - int16_t usb_y; - int16_t usb_r; - - float pos2usb; - - bool invert_x; - bool invert_y; - - public: - - TouchJoystick() {} - TouchJoystick(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 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 setDeadZoneInner(int32_t dead_zone_inner); - void setDeadZoneOuter(int32_t dead_zone_outer); - - void setInvertX(bool invert_x = true); - void setInvertY(bool invert_y = true); - - int8_t touch(int32_t tx, int32_t ty, int16_t* rx = NULL, int16_t* ry = NULL); - - int16_t getX() {return x;} - int16_t getY() {return y;} - -}; - -#endif \ No newline at end of file