mirror of
https://github.com/NepEgor/OpenTrackpadController.git
synced 2024-11-15 18:12:46 +00:00
Touch State Enum
This commit is contained in:
parent
d11e86e9e8
commit
ed50a609ba
@ -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;}
|
||||
|
||||
|
@ -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;}
|
||||
};
|
||||
|
@ -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;}
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user