Compare commits

...

4 Commits

Author SHA1 Message Date
NepEgor 2688d5c281 mapping change 2 years ago
NepEgor e19dffeacd reset joystick when mode shifting 2 years ago
NepEgor 3b2be18f6b Change to Hall effect triggers 2 years ago
NepEgor 87776eed83 DISABLE_TRACKPADS macro for debug 2 years ago

@ -43,6 +43,8 @@ class TouchControl
virtual void init(int32_t pos_x, int32_t pos_y, int32_t pos_r); virtual void init(int32_t pos_x, int32_t pos_y, int32_t pos_r);
virtual void reset();
virtual TouchState 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;} int8_t getTouching() {return touching;}

@ -31,6 +31,8 @@ class TouchDpad : public TouchControl
TouchDpad(int32_t pos_x, int32_t pos_y, int32_t pos_r, DpadType dpad_type = DPAD_TYPE_SECTOR_4); TouchDpad(int32_t pos_x, int32_t pos_y, int32_t pos_r, DpadType dpad_type = DPAD_TYPE_SECTOR_4);
void init(int32_t pos_x, int32_t pos_y, int32_t pos_r, DpadType dpad_type = DPAD_TYPE_SECTOR_4); void init(int32_t pos_x, int32_t pos_y, int32_t pos_r, DpadType dpad_type = DPAD_TYPE_SECTOR_4);
void reset();
void setDeadZoneInner(int32_t dead_zone_inner); void setDeadZoneInner(int32_t dead_zone_inner);

@ -35,6 +35,8 @@ class TouchJoystick : public TouchControl
void init(int32_t pos_x, int32_t pos_y, int32_t pos_r, int16_t usb_x, int16_t usb_y, int16_t usb_r); void init(int32_t pos_x, int32_t pos_y, int32_t pos_r, int16_t usb_x, int16_t usb_y, int16_t usb_r);
void reset();
void setDeadZoneInner(int32_t dead_zone_inner); void setDeadZoneInner(int32_t dead_zone_inner);
void setDeadZoneOuter(int32_t dead_zone_outer); void setDeadZoneOuter(int32_t dead_zone_outer);

@ -23,6 +23,8 @@ class TouchMouseJoystick : public TouchJoystick
public: public:
void init(int32_t pos_x, int32_t pos_y, int32_t pos_r, int16_t usb_x, int16_t usb_y, int16_t usb_r); void init(int32_t pos_x, int32_t pos_y, int32_t pos_r, int16_t usb_x, int16_t usb_y, int16_t usb_r);
void reset();
void setSensitivity(float sensitivity); void setSensitivity(float sensitivity);

@ -18,3 +18,9 @@ void TouchControl::init(int32_t pos_x, int32_t pos_y, int32_t pos_r)
this->touching = TS_NONE; this->touching = TS_NONE;
} }
void TouchControl::reset()
{
this->finger_id = -1;
this->touching = TS_NONE;
}

@ -31,6 +31,12 @@ void TouchDpad::init(int32_t pos_x, int32_t pos_y, int32_t pos_r, DpadType dpad_
this->button = 0; this->button = 0;
} }
void TouchDpad::reset()
{
TouchControl::reset();
this->button = 0;
}
void TouchDpad::setDeadZoneInner(int32_t dead_zone_inner) void TouchDpad::setDeadZoneInner(int32_t dead_zone_inner)
{ {
this->dead_zone_inner = dead_zone_inner; this->dead_zone_inner = dead_zone_inner;

@ -31,6 +31,13 @@ void TouchJoystick::init(int32_t pos_x, int32_t pos_y, int32_t pos_r, int16_t us
this->y = usb_y; this->y = usb_y;
} }
void TouchJoystick::reset()
{
TouchControl::reset();
this->x = usb_x;
this->y = usb_y;;
}
void TouchJoystick::setDeadZoneInner(int32_t dead_zone_inner) void TouchJoystick::setDeadZoneInner(int32_t dead_zone_inner)
{ {
this->dead_zone_inner = dead_zone_inner; this->dead_zone_inner = dead_zone_inner;

@ -19,6 +19,15 @@ void TouchMouseJoystick::init(int32_t pos_x, int32_t pos_y, int32_t pos_r, int16
this->time0 = 0; this->time0 = 0;
} }
void TouchMouseJoystick::reset()
{
TouchJoystick::reset();
this->trackball_vel_x = 0;
this->trackball_vel_y = 0;
this->dx = 0;
this->dy = 0;
}
void TouchMouseJoystick::setSensitivity(float sensitivity) void TouchMouseJoystick::setSensitivity(float sensitivity)
{ {
this->sensitivity = this->pos2usb * sensitivity; this->sensitivity = this->pos2usb * sensitivity;

@ -60,7 +60,7 @@ namespace InputMapper
USB_Device::HOME, USB_Device::HOME,
USB_Device::FACE_A, USB_Device::FACE_A,
USB_Device::JOYSTICK_RIGHT, USB_Device::JOYSTICK_RIGHT,
USB_Device::FACE_A, USB_Device::FACE_B,
USB_Device::JOYSTICK_LEFT, USB_Device::JOYSTICK_LEFT,
}; };
@ -187,7 +187,7 @@ namespace InputMapper
gyro.setMappedId(1); gyro.setMappedId(1);
//gyro.setInvertX(); //gyro.setInvertX();
gyro.setInvertY(); gyro.setInvertY();
gyro.setSensitivity(0.75f); gyro.setSensitivity(1.0f);
gyro.setDeadzone(0); gyro.setDeadzone(0);
gyro.setMinDelta(1000); gyro.setMinDelta(1000);
gyro.setBindToX(Gyro::BIND_XZ); gyro.setBindToX(Gyro::BIND_XZ);
@ -297,24 +297,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 min[] = {522, 523};
static const uint32_t min = 13; static const uint32_t max[] = {797, 795};
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[i])
{ {
mapped_value[i] = 0; mapped_value[i] = 0;
} }
else if (value[i] > max) else if (value[i] > max[i])
{ {
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[i]) * 255 / (max[i] - min[i]);
} }
} }
@ -337,6 +337,8 @@ namespace InputMapper
case HardwareButtons::BUMPER_LEFT: case HardwareButtons::BUMPER_LEFT:
tcontrols[1][0]->reset();
if (value) if (value)
{ {
tcontrols[1][0] = &tjoystick_right_wheel; tcontrols[1][0] = &tjoystick_right_wheel;

@ -3,6 +3,8 @@
#include "trackpad.h" #include "trackpad.h"
#include "input_mapper.h" #include "input_mapper.h"
//#define DISABLE_TRACKPADS
const uint8_t pin_trigger[2] = {PA1, PA0}; const uint8_t pin_trigger[2] = {PA1, PA0};
const uint8_t pin_button[] = const uint8_t pin_button[] =
@ -10,27 +12,31 @@ const uint8_t pin_button[] =
PB12, 0, // START PB12, 0, // START
PB13, 0, // SELECT PB13, 0, // SELECT
PB5, 0, // BUMPER_LEFT PB5, 0, // BUMPER_LEFT
PA8, 1, // BUMPER_RIGHT PA8, 0, // BUMPER_RIGHT
PB1, 0, // HOME PB1, 0, // HOME
PB14, 1, // GRIP_A PB14, 0, // GRIP_A
PB15, 1, // GRIP_B PB15, 0, // GRIP_B
PA4, 0, // GRIP_X PA4, 0, // GRIP_X
PB4, 0, // GRIP_Y PB4, 0, // GRIP_Y
PC15, 0, // TRACKPAD_LEFT PC15, 0, // TRACKPAD_LEFT
PB3, 1, // TRACKPAD_RIGHT PB3, 0, // TRACKPAD_RIGHT
}; };
uint8_t button_state[sizeof(pin_button) / 2] = {0}; uint8_t button_state[sizeof(pin_button) / 2] = {0};
const uint8_t gyro_int = PC14;
#ifndef DISABLE_TRACKPADS
const uint8_t pin_trackpad_data[2] = {PA2, PB9}; const uint8_t pin_trackpad_data[2] = {PA2, PB9};
const uint8_t pin_trackpad_clock[2] = {PA3, PB8}; const uint8_t pin_trackpad_clock[2] = {PA3, PB8};
const uint8_t gyro_int = PC14;
TrackPad trackpad[2]; // 0 - left, 1 - right TrackPad trackpad[2]; // 0 - left, 1 - right
int32_t trackpad_maxX, trackpad_maxY; int32_t trackpad_maxX, trackpad_maxY;
#endif
void setup() void setup()
{ {
// Turn on LED // Turn on LED
@ -50,6 +56,8 @@ void setup()
pinMode(pin_button[i], pin_button[i + 1]? INPUT_PULLDOWN : INPUT_PULLUP); pinMode(pin_button[i], pin_button[i + 1]? INPUT_PULLDOWN : INPUT_PULLUP);
} }
#ifndef DISABLE_TRACKPADS
for (uint8_t i = 0; i < sizeof(pin_trackpad_clock); ++i) for (uint8_t i = 0; i < sizeof(pin_trackpad_clock); ++i)
{ {
trackpad[i].initialize(pin_trackpad_clock[i], pin_trackpad_data[i]); trackpad[i].initialize(pin_trackpad_clock[i], pin_trackpad_data[i]);
@ -58,6 +66,8 @@ void setup()
trackpad_maxX = trackpad[0].getMaxX(); trackpad_maxX = trackpad[0].getMaxX();
trackpad_maxY = trackpad[0].getMaxY(); trackpad_maxY = trackpad[0].getMaxY();
#endif
InputMapper::begin(); InputMapper::begin();
// Turn off LED // Turn off LED
@ -69,6 +79,8 @@ TouchEvent tevent[5];
void loop() void loop()
{ {
#ifndef DISABLE_TRACKPADS
for (uint8_t t = 0; t < 2; ++t) for (uint8_t t = 0; t < 2; ++t)
{ {
if (trackpad[t].poll(tevent, tevent_size) > 0) if (trackpad[t].poll(tevent, tevent_size) > 0)
@ -117,7 +129,18 @@ void loop()
} }
} }
#endif
uint32_t triggers[] = {analogRead(pin_trigger[0]), analogRead(pin_trigger[1])}; uint32_t triggers[] = {analogRead(pin_trigger[0]), analogRead(pin_trigger[1])};
//Serial.print(0);
//Serial.print('\t');
//Serial.print(triggers[0]);
//Serial.print('\t');
//Serial.print(triggers[1]);
//Serial.print('\t');
//Serial.println(1000);
InputMapper::mapTriggers(triggers); InputMapper::mapTriggers(triggers);
for (uint8_t i = 0; i < sizeof(pin_button); i += 2) for (uint8_t i = 0; i < sizeof(pin_button); i += 2)

Loading…
Cancel
Save