joystick id mapping

gyro
NepEgor 2 years ago
parent 95689796bb
commit e26b2900f5

@ -26,6 +26,8 @@ class TouchJoystick : public TouchControl
bool invert_x; bool invert_x;
bool invert_y; bool invert_y;
uint8_t mapped_id;
public: public:
TouchJoystick() {} TouchJoystick() {}
@ -39,6 +41,9 @@ class TouchJoystick : public TouchControl
void setInvertX(bool invert_x = true); void setInvertX(bool invert_x = true);
void setInvertY(bool invert_y = true); void setInvertY(bool invert_y = true);
void setMappedId(uint8_t mapped_id);
uint8_t getMappedId() {return mapped_id;}
int8_t touch(int8_t fid, int32_t tx, int32_t ty); int8_t touch(int8_t fid, int32_t tx, int32_t ty);
int16_t getX() {return x;} int16_t getX() {return x;}

@ -55,6 +55,11 @@ void TouchJoystick::setInvertY(bool invert_y)
this->invert_y = invert_y; this->invert_y = invert_y;
} }
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) int8_t TouchJoystick::touch(int8_t fid, int32_t tx, int32_t ty)
{ {
if (finger_id != -1 && finger_id != fid) if (finger_id != -1 && finger_id != fid)

@ -96,6 +96,7 @@ namespace InputMapper
tjoystick_left.init(pos_x, pos_y, pos_r, USB_Device::usb_joystick_x, USB_Device::usb_joystick_y, USB_Device::usb_joystick_r); tjoystick_left.init(pos_x, pos_y, pos_r, USB_Device::usb_joystick_x, USB_Device::usb_joystick_y, USB_Device::usb_joystick_r);
tjoystick_left.setDeadZoneInner(dead_zone_inner); tjoystick_left.setDeadZoneInner(dead_zone_inner);
tjoystick_left.setDeadZoneOuter(dead_zone_outer); tjoystick_left.setDeadZoneOuter(dead_zone_outer);
tjoystick_left.setMappedId(0);
pos_x = 31.25 * ppmX; pos_x = 31.25 * ppmX;
pos_y = (103.9 - 31.25) * ppmY; pos_y = (103.9 - 31.25) * ppmY;
@ -107,6 +108,7 @@ namespace InputMapper
//tjoystick_right.setTrackballFriction(0); //tjoystick_right.setTrackballFriction(0);
tjoystick_right.setDeadZoneOuter(dead_zone_outer); tjoystick_right.setDeadZoneOuter(dead_zone_outer);
tjoystick_right.setSensitivity(10); tjoystick_right.setSensitivity(10);
tjoystick_right.setMappedId(1);
pos_x = 20.636 * ppmX; pos_x = 20.636 * ppmX;
pos_y = 20.636 * ppmY; pos_y = 20.636 * ppmY;
@ -192,7 +194,7 @@ namespace InputMapper
res = tjoy->touch(fid, x, y); res = tjoy->touch(fid, x, y);
device.joystick(id, tjoy->getX(), tjoy->getY()); device.joystick(tjoy->getMappedId(), tjoy->getX(), tjoy->getY());
} }
break; break;
@ -202,7 +204,7 @@ namespace InputMapper
res = tmjoy->touch(fid, x, y, dx, dy, time); res = tmjoy->touch(fid, x, y, dx, dy, time);
device.joystick(id, tmjoy->getX(), tmjoy->getY()); device.joystick(tmjoy->getMappedId(), tmjoy->getX(), tmjoy->getY());
} }
break; break;
@ -243,7 +245,7 @@ namespace InputMapper
tmjoy->updateTrackball(time); tmjoy->updateTrackball(time);
device.joystick(id, tmjoy->getX(), tmjoy->getY()); device.joystick(tmjoy->getMappedId(), tmjoy->getX(), tmjoy->getY());
} }
break; break;
@ -258,24 +260,24 @@ namespace InputMapper
void mapTriggers(uint32_t value[2]) void mapTriggers(uint32_t value[2])
{ {
static const uint32_t max = 70; static const uint32_t max = 70;
static const uint32_t min = 2; static const uint32_t min = 13;
uint8_t mapped_value[2]; uint8_t mapped_value[2];
for (uint8_t i = 0; i < 2; ++i) for (uint8_t i = 0; i < 2; ++i)
{ {
if (value[i] < min) if (value[i] < min)
{ {
mapped_value[i] = 0; mapped_value[i] = 0;
} }
else if (value[i] > max) else if (value[i] > max)
{ {
mapped_value[i] = 255; mapped_value[i] = 255;
} }
else else
{ {
mapped_value[i] = (value[i] - min) * 255 / (max - min); mapped_value[i] = (value[i] - min) * 255 / (max - min);
} }
} }
device.triggers(mapped_value); device.triggers(mapped_value);

Loading…
Cancel
Save