Made joystick work with any finger

input_events
NepEgor 3 years ago
parent fe1de544fa
commit 57c04fd111

@ -42,7 +42,7 @@ class TouchJoystick
void setInvertX(bool invert_x = true);
void setInvertY(bool invert_y = true);
uint8_t touch(int32_t tx, int32_t ty, int16_t* rx = NULL, int16_t* ry = NULL);
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;}

@ -48,9 +48,9 @@ void TouchJoystick::setInvertY(bool invert_y)
this->invert_y = invert_y;
}
uint8_t TouchJoystick::touch(int32_t tx, int32_t ty, int16_t* rx, int16_t* ry)
int8_t TouchJoystick::touch(int32_t tx, int32_t ty, int16_t* rx, int16_t* ry)
{
uint8_t ret = 0;
uint8_t ret = 1;
tx -= pos_x;
ty -= pos_y;
@ -63,7 +63,7 @@ uint8_t TouchJoystick::touch(int32_t tx, int32_t ty, int16_t* rx, int16_t* ry)
x = usb_x;
y = usb_y;
ret = -1;
ret = 0;
}
else // between dead zones
if (t2 <= dead_zone_outer2)

@ -23,9 +23,9 @@ const uint8_t CLOCK_PIN_left = PB6;
// y_max 1872
const int32_t pos_x = 31.25 * 1872.0 / 62.5;
const int32_t pos_y = (103.9 - 31.25) * 3276.0 / 103.9;
const int32_t pos_r = 60 * 1872.0 / 62.5 / 2;
const int32_t pos_r = 70 * 1872.0 / 62.5 / 2;
const int32_t dead_zone_inner = 3 * 1872.0 / 62.5 / 2;
const int32_t dead_zone_outer = 20 * 1872.0 / 62.5 / 2;
const int32_t dead_zone_outer = 25 * 1872.0 / 62.5 / 2;
const int16_t usb_x = 512;
const int16_t usb_y = 512;
const int16_t usb_r = 512;
@ -89,7 +89,15 @@ void loop()
if (fp != NULL)
{
int16_t x, y;
tjoystick.touch(fp[0].y, fp[0].x, &x, &y);
for (uint8_t id = 0; id < TrackPad::fingers_num; ++id)
{
if (tjoystick.touch(fp[id].y, fp[id].x, &x, &y))
{
break;
}
}
testReport.x = x;
testReport.y = y;
}
@ -104,7 +112,7 @@ void loop()
//device.move(testReport.x, testReport.y);
HID_Custom_sendReport((uint8_t*)(&testReport), 6);
HID_Custom_sendReport((uint8_t*)(&testReport), sizeof(testReport));
//delay(100);
}

Loading…
Cancel
Save