diff --git a/lib/touch_controls/include/touch_joystick.h b/lib/touch_controls/include/touch_joystick.h index 59178a8..2e1f3ff 100644 --- a/lib/touch_controls/include/touch_joystick.h +++ b/lib/touch_controls/include/touch_joystick.h @@ -26,6 +26,8 @@ class TouchJoystick : public TouchControl bool invert_x; bool invert_y; + uint8_t mapped_id; + public: TouchJoystick() {} @@ -39,6 +41,9 @@ class TouchJoystick : public TouchControl void setInvertX(bool invert_x = 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); int16_t getX() {return x;} diff --git a/lib/touch_controls/src/touch_joystick.cpp b/lib/touch_controls/src/touch_joystick.cpp index 2fc2783..43fda44 100644 --- a/lib/touch_controls/src/touch_joystick.cpp +++ b/lib/touch_controls/src/touch_joystick.cpp @@ -55,6 +55,11 @@ void TouchJoystick::setInvertY(bool 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) { if (finger_id != -1 && finger_id != fid) diff --git a/src/input_mapper.cpp b/src/input_mapper.cpp index afb6ba9..d04a60e 100644 --- a/src/input_mapper.cpp +++ b/src/input_mapper.cpp @@ -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.setDeadZoneInner(dead_zone_inner); tjoystick_left.setDeadZoneOuter(dead_zone_outer); + tjoystick_left.setMappedId(0); pos_x = 31.25 * ppmX; pos_y = (103.9 - 31.25) * ppmY; @@ -107,6 +108,7 @@ namespace InputMapper //tjoystick_right.setTrackballFriction(0); tjoystick_right.setDeadZoneOuter(dead_zone_outer); tjoystick_right.setSensitivity(10); + tjoystick_right.setMappedId(1); pos_x = 20.636 * ppmX; pos_y = 20.636 * ppmY; @@ -192,7 +194,7 @@ namespace InputMapper res = tjoy->touch(fid, x, y); - device.joystick(id, tjoy->getX(), tjoy->getY()); + device.joystick(tjoy->getMappedId(), tjoy->getX(), tjoy->getY()); } break; @@ -202,7 +204,7 @@ namespace InputMapper 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; @@ -243,7 +245,7 @@ namespace InputMapper tmjoy->updateTrackball(time); - device.joystick(id, tmjoy->getX(), tmjoy->getY()); + device.joystick(tmjoy->getMappedId(), tmjoy->getX(), tmjoy->getY()); } break; @@ -258,24 +260,24 @@ namespace InputMapper void mapTriggers(uint32_t value[2]) { static const uint32_t max = 70; - static const uint32_t min = 2; + static const uint32_t min = 13; uint8_t mapped_value[2]; for (uint8_t i = 0; i < 2; ++i) { - if (value[i] < min) - { - mapped_value[i] = 0; - } - else if (value[i] > max) - { - mapped_value[i] = 255; - } - else - { - mapped_value[i] = (value[i] - min) * 255 / (max - min); - } + if (value[i] < min) + { + mapped_value[i] = 0; + } + else if (value[i] > max) + { + mapped_value[i] = 255; + } + else + { + mapped_value[i] = (value[i] - min) * 255 / (max - min); + } } device.triggers(mapped_value);