Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux evdev controller backend fixes (and misc linux fixes) #3244

Merged
merged 5 commits into from
Aug 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ before_install:
brew update; brew update;
brew install ccache glew llvm40;
fi;
# We need to update binutils to a newer version to link against the ffmpeg libs on.
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then
sudo add-apt-repository ppa:jonathonf/binutils -y ;
sudo apt-get update ;
sudo apt-get install binutils -y;
ld --version ;
fi;

before_script:
- git submodule update --init asmjit 3rdparty/ffmpeg 3rdparty/pugixml 3rdparty/GSL 3rdparty/libpng Utilities/yaml-cpp 3rdparty/cereal 3rdparty/hidapi Vulkan/glslang Vulkan/Vulkan-LoaderAndValidationLayers
Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/ffmpeg
Submodule ffmpeg updated 67 files
+1 −1 linux/x86/include/libavutil/ffversion.h
+ linux/x86/lib/libavcodec.a
+ linux/x86/lib/libavformat.a
+ linux/x86/lib/libavutil.a
+ linux/x86/lib/libswresample.a
+ linux/x86/lib/libswscale.a
+807 −726 linux/x86_64/include/libavcodec/avcodec.h
+84 −0 linux/x86_64/include/libavcodec/avdct.h
+18 −4 linux/x86_64/include/libavcodec/d3d11va.h
+131 −0 linux/x86_64/include/libavcodec/dirac.h
+0 −9 linux/x86_64/include/libavcodec/dv_profile.h
+5 −5 linux/x86_64/include/libavcodec/dxva2.h
+66 −0 linux/x86_64/include/libavcodec/qsv.h
+16 −0 linux/x86_64/include/libavcodec/vaapi.h
+5 −7 linux/x86_64/include/libavcodec/vdpau.h
+88 −66 linux/x86_64/include/libavcodec/version.h
+126 −0 linux/x86_64/include/libavcodec/videotoolbox.h
+3 −3 linux/x86_64/include/libavcodec/vorbis_parser.h
+1 −1 linux/x86_64/include/libavcodec/xvmc.h
+159 −53 linux/x86_64/include/libavformat/avformat.h
+108 −2 linux/x86_64/include/libavformat/avio.h
+20 −6 linux/x86_64/include/libavformat/version.h
+83 −0 linux/x86_64/include/libavutil/aes_ctr.h
+8 −0 linux/x86_64/include/libavutil/attributes.h
+17 −0 linux/x86_64/include/libavutil/audio_fifo.h
+27 −6 linux/x86_64/include/libavutil/avstring.h
+7 −8 linux/x86_64/include/libavutil/avutil.h
+5 −0 linux/x86_64/include/libavutil/blowfish.h
+1 −0 linux/x86_64/include/libavutil/cast5.h
+1 −0 linux/x86_64/include/libavutil/channel_layout.h
+43 −13 linux/x86_64/include/libavutil/common.h
+3 −5 linux/x86_64/include/libavutil/cpu.h
+5 −0 linux/x86_64/include/libavutil/crc.h
+77 −0 linux/x86_64/include/libavutil/des.h
+3 −1 linux/x86_64/include/libavutil/dict.h
+1 −1 linux/x86_64/include/libavutil/eval.h
+2 −1 linux/x86_64/include/libavutil/ffversion.h
+21 −0 linux/x86_64/include/libavutil/fifo.h
+1 −0 linux/x86_64/include/libavutil/file.h
+41 −105 linux/x86_64/include/libavutil/frame.h
+3 −2 linux/x86_64/include/libavutil/hmac.h
+2 −2 linux/x86_64/include/libavutil/log.h
+2 −0 linux/x86_64/include/libavutil/macros.h
+89 −0 linux/x86_64/include/libavutil/mastering_display_metadata.h
+4 −3 linux/x86_64/include/libavutil/mathematics.h
+17 −0 linux/x86_64/include/libavutil/mem.h
+7 −0 linux/x86_64/include/libavutil/motion_vector.h
+26 −62 linux/x86_64/include/libavutil/opt.h
+29 −33 linux/x86_64/include/libavutil/pixdesc.h
+42 −122 linux/x86_64/include/libavutil/pixfmt.h
+66 −0 linux/x86_64/include/libavutil/rc4.h
+71 −0 linux/x86_64/include/libavutil/tea.h
+16 −0 linux/x86_64/include/libavutil/threadmessage.h
+138 −0 linux/x86_64/include/libavutil/tree.h
+33 −44 linux/x86_64/include/libavutil/version.h
+32 −2 linux/x86_64/include/libavutil/xtea.h
+2 −2 linux/x86_64/include/libswresample/swresample.h
+6 −6 linux/x86_64/include/libswresample/version.h
+7 −16 linux/x86_64/include/libswscale/swscale.h
+3 −10 linux/x86_64/include/libswscale/version.h
+ linux/x86_64/lib/libavcodec.a
+ linux/x86_64/lib/libavformat.a
+ linux/x86_64/lib/libavutil.a
+ linux/x86_64/lib/libswresample.a
+ linux/x86_64/lib/libswscale.a
+1 −0 linux_x86-64.sh
+1 −0 linux_x86.sh
90 changes: 80 additions & 10 deletions rpcs3/evdev_joystick_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <errno.h>
#include <cstring>
#include <cstdio>
#include <cmath>

evdev_joystick_config g_evdev_joystick_config;

Expand All @@ -20,8 +21,6 @@ namespace
const u32 THREAD_SLEEP_INACTIVE_USEC = 1000000;
const u32 READ_TIMEOUT = 10;
const u32 THREAD_TIMEOUT_USEC = 1000000;

const std::string EVENT_JOYSTICK = "event-joystick";
}

evdev_joystick_handler::evdev_joystick_handler() {}
Expand All @@ -41,17 +40,32 @@ void evdev_joystick_handler::Init(const u32 max_connect)
revaxis.emplace_back(g_evdev_joystick_config.rxreverse);
revaxis.emplace_back(g_evdev_joystick_config.ryreverse);

fs::dir devdir{"/dev/input/by-path"};
fs::dir devdir{"/dev/input/"};
fs::dir_entry et;

while (devdir.read(et))
{
// Does the entry name end with event-joystick?
if (et.name.size() > EVENT_JOYSTICK.size() &&
et.name.compare(et.name.size() - EVENT_JOYSTICK.size(),
EVENT_JOYSTICK.size(), EVENT_JOYSTICK) == 0)
// Check if the entry starts with event (a 5-letter word)
if (et.name.size() > 5 && et.name.compare(0, 5,"event") == 0)
{
joy_paths.emplace_back(fmt::format("/dev/input/by-path/%s", et.name));
int fd = open(("/dev/input/" + et.name).c_str(), O_RDONLY|O_NONBLOCK);
struct libevdev *dev = NULL;
int rc = 1;
rc = libevdev_new_from_fd(fd, &dev);
if (rc < 0)
{
// If it's just a bad file descriptor, don't bother logging, but otherwise, log it.
if (rc == -9)
LOG_WARNING(GENERAL, "Failed to connect to device at %s, the error was: %s", "/dev/input/" + et.name, strerror(-rc));
continue;
}
if (libevdev_has_event_type(dev, EV_KEY) &&
libevdev_has_event_code(dev, EV_ABS, ABS_X) &&
libevdev_has_event_code(dev, EV_ABS, ABS_Y))
{
// It's a joystick.
joy_paths.emplace_back(fmt::format("/dev/input/%s", et.name));
}
}
}

Expand All @@ -61,6 +75,7 @@ void evdev_joystick_handler::Init(const u32 max_connect)
{
joy_devs.push_back(nullptr);
joy_axis_maps.emplace_back(ABS_RZ - ABS_X, -1);
joy_axis.emplace_back(ABS_RZ - ABS_X, -1);
joy_button_maps.emplace_back(KEY_MAX - BTN_JOYSTICK, -1);
joy_hat_ids.emplace_back(-1);
m_pads.emplace_back(
Expand Down Expand Up @@ -111,6 +126,36 @@ void evdev_joystick_handler::update_devs()
m_info.now_connect = connected;
}

inline u16 Clamp0To255(f32 input)
{
if (input > 255.f)
return 255;
else if (input < 0.f)
return 0;
else return static_cast<u16>(input);
}

std::tuple<u16, u16> evdev_joystick_handler::ConvertToSquirclePoint(u16 inX, u16 inY)
{
// convert inX and Y to a (-1, 1) vector;
const f32 x = (inX - 127) / 127.f;
const f32 y = ((inY - 127) / 127.f);

// compute angle and len of given point to be used for squircle radius
const f32 angle = std::atan2(y, x);
const f32 r = std::sqrt(std::pow(x, 2.f) + std::pow(y, 2.f));

// now find len/point on the given squircle from our current angle and radius in polar coords
// https://thatsmaths.com/2016/07/14/squircles/
const f32 newLen = (1 + std::pow(std::sin(2 * angle), 2.f) / (g_evdev_joystick_config.squirclefactor / 1000.f)) * r;

// we now have len and angle, convert to cartisian

const int newX = Clamp0To255(((newLen * std::cos(angle)) + 1) * 127);
const int newY = Clamp0To255(((newLen * std::sin(angle)) + 1) * 127);
return std::tuple<u16, u16>(newX, newY);
}

bool evdev_joystick_handler::try_open_dev(u32 index)
{
libevdev*& dev = joy_devs[index];
Expand Down Expand Up @@ -395,8 +440,33 @@ void evdev_joystick_handler::thread_func()
LOG_ERROR(GENERAL, "Joystick #%d sent axis event for invalid axis %d", i, axis);
break;
}

pad.m_sticks[axis].m_value = scale_axis(evt.code, evt.value);

if (g_evdev_joystick_config.squirclejoysticks)
{
joy_axis[i][axis] = evt.value;
if (evt.code == ABS_X || evt.code == ABS_Y)
{
int Xaxis = joy_axis_maps[i][ABS_X];
int Yaxis = joy_axis_maps[i][ABS_Y];
pad.m_sticks[Xaxis].m_value = scale_axis(ABS_X, joy_axis[i][Xaxis]);
pad.m_sticks[Yaxis].m_value = scale_axis(ABS_Y, joy_axis[i][Yaxis]);

std::tie(pad.m_sticks[Xaxis].m_value, pad.m_sticks[Yaxis].m_value) =
ConvertToSquirclePoint(pad.m_sticks[Xaxis].m_value, pad.m_sticks[Yaxis].m_value);
}
else
{
int Xaxis = joy_axis_maps[i][ABS_RX];
int Yaxis = joy_axis_maps[i][ABS_RY];
pad.m_sticks[Xaxis].m_value = scale_axis(ABS_RX, joy_axis[i][Xaxis]);
pad.m_sticks[Yaxis].m_value = scale_axis(ABS_RY, joy_axis[i][Yaxis]);

std::tie(pad.m_sticks[Xaxis].m_value, pad.m_sticks[Yaxis].m_value) =
ConvertToSquirclePoint(pad.m_sticks[Xaxis].m_value, pad.m_sticks[Yaxis].m_value);
}
}
else
pad.m_sticks[axis].m_value = scale_axis(evt.code, evt.value);
}
break;
default:
Expand Down
6 changes: 5 additions & 1 deletion rpcs3/evdev_joystick_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <vector>
#include <thread>


enum { EVDEV_DPAD_HAT_AXIS_X = -1, EVDEV_DPAD_HAT_AXIS_Y = -2 };

struct evdev_joystick_config final : cfg::node
Expand Down Expand Up @@ -45,6 +44,8 @@ struct evdev_joystick_config final : cfg::node
cfg::_bool lyreverse{this, "Reverse left stick Y axis", false};

cfg::_bool axistrigger{this, "Z axis triggers", true};
cfg::_bool squirclejoysticks{this, "Squircle Joysticks", true};
cfg::int32 squirclefactor{this, "Squircle Factor", 5000};

bool load()
{
Expand Down Expand Up @@ -74,6 +75,7 @@ class evdev_joystick_handler final : public PadHandlerBase

private:
void update_devs();
std::tuple<u16, u16> ConvertToSquirclePoint(u16 inX, u16 inY);
bool try_open_dev(u32 index);
int scale_axis(int axis, int value);
void thread_func();
Expand All @@ -84,6 +86,8 @@ class evdev_joystick_handler final : public PadHandlerBase
std::vector<libevdev*> joy_devs;
std::vector<std::vector<int>> joy_button_maps;
std::vector<std::vector<int>> joy_axis_maps;
// joy_axis is only used for squircling
std::vector<std::vector<int>> joy_axis;
std::vector<int> joy_hat_ids;
bool axistrigger;
std::map<int, std::pair<int, int>> axis_ranges;
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/rpcs3qt/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void main_window::Init()
fs::stat_t st;
if (!fs::stat(fs::get_config_dir() + "rpcs3.pdb", st) || st.is_directory || st.size < 1024 * 1024 * 100)
#else
if (true)
if (false)
#endif
{
QMessageBox msg;
Expand Down