|
|
|
@ -9,6 +9,12 @@ void TouchMouseJoustick::init(int32_t pos_x, int32_t pos_y, int32_t pos_r, int16
|
|
|
|
|
this->control_type = CT_MOUSE_JOYSTICK;
|
|
|
|
|
|
|
|
|
|
this->sensitivity = this->pos2usb;
|
|
|
|
|
|
|
|
|
|
this->trackball_friction = 0;
|
|
|
|
|
this->trackball_vel_x = 0;
|
|
|
|
|
this->trackball_vel_y = 0;
|
|
|
|
|
|
|
|
|
|
this->time0 = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TouchMouseJoustick::setSensitivity(float sensitivity)
|
|
|
|
@ -21,15 +27,14 @@ void TouchMouseJoustick::setTrackballFriction(float trackball_friction)
|
|
|
|
|
this->trackball_friction = trackball_friction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int8_t TouchMouseJoustick::touch(int8_t fid, int32_t tx, int32_t ty, int32_t tdx, int32_t tdy)
|
|
|
|
|
int8_t TouchMouseJoustick::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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int8_t ret = 2;
|
|
|
|
|
|
|
|
|
|
tx -= pos_x;
|
|
|
|
|
ty -= pos_y;
|
|
|
|
|
|
|
|
|
@ -42,6 +47,7 @@ int8_t TouchMouseJoustick::touch(int8_t fid, int32_t tx, int32_t ty, int32_t tdx
|
|
|
|
|
if (t2 > pos_r2)
|
|
|
|
|
{
|
|
|
|
|
finger_id = -1;
|
|
|
|
|
touching = 0;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else // inside the range
|
|
|
|
@ -50,26 +56,69 @@ int8_t TouchMouseJoustick::touch(int8_t fid, int32_t tx, int32_t ty, int32_t tdx
|
|
|
|
|
|
|
|
|
|
if (t2 <= dead_zone_outer2)
|
|
|
|
|
{
|
|
|
|
|
int32_t x32 = -tdx * sensitivity;
|
|
|
|
|
int32_t y32 = -tdy * sensitivity;
|
|
|
|
|
touching = 2;
|
|
|
|
|
|
|
|
|
|
xf = sensitivity * -tdx;
|
|
|
|
|
yf = sensitivity * -tdy;
|
|
|
|
|
|
|
|
|
|
x = x32 > usb_r? usb_r : (x32 < -usb_r? -usb_r : x32);
|
|
|
|
|
y = y32 > usb_r? usb_r : (y32 < -usb_r? -usb_r : y32);
|
|
|
|
|
xf = xf > usb_r? usb_r : (xf < -usb_r? -usb_r : xf);
|
|
|
|
|
yf = yf > usb_r? usb_r : (yf < -usb_r? -usb_r : yf);
|
|
|
|
|
|
|
|
|
|
x + usb_x;
|
|
|
|
|
y + usb_y;
|
|
|
|
|
float dt = time - time0;
|
|
|
|
|
time0 = time;
|
|
|
|
|
|
|
|
|
|
trackball_vel_x = xf / (dt * 1000.f);
|
|
|
|
|
trackball_vel_y = yf / (dt * 1000.f);
|
|
|
|
|
|
|
|
|
|
x = xf + usb_x;
|
|
|
|
|
y = yf + usb_y;
|
|
|
|
|
}
|
|
|
|
|
else // in bounds outside of outer dead zone - edge spin
|
|
|
|
|
{
|
|
|
|
|
touching = 3;
|
|
|
|
|
|
|
|
|
|
float len = sqrt(t2);
|
|
|
|
|
|
|
|
|
|
x = (tx * dead_zone_outer / len) * pos2usb + usb_x;
|
|
|
|
|
y = (ty * dead_zone_outer / len) * pos2usb + usb_y;
|
|
|
|
|
|
|
|
|
|
trackball_vel_x = 0;
|
|
|
|
|
trackball_vel_y = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (invert_x) x = 2 * usb_x - x;
|
|
|
|
|
if (invert_y) y = 2 * usb_y - y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
return touching;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TouchMouseJoustick::updateTrackball(uint32_t time)
|
|
|
|
|
{
|
|
|
|
|
if ((trackball_friction > 0) && !touching && (trackball_vel_x > 0))
|
|
|
|
|
{
|
|
|
|
|
if (xf > usb_x)
|
|
|
|
|
{
|
|
|
|
|
float dt = time - time0;
|
|
|
|
|
float dt2 = dt * dt;
|
|
|
|
|
|
|
|
|
|
float x1 = xf + trackball_vel_x * dt - trackball_friction * dt2;
|
|
|
|
|
if (x1 > usb_r)
|
|
|
|
|
{
|
|
|
|
|
x1 = usb_r;
|
|
|
|
|
}
|
|
|
|
|
x = usb_x + x1;
|
|
|
|
|
|
|
|
|
|
if (x < usb_x)
|
|
|
|
|
{
|
|
|
|
|
x = usb_x;
|
|
|
|
|
xf = usb_x;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
x = usb_x;
|
|
|
|
|
xf = usb_x;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|