2015-06-29 00:17:35 +00:00
|
|
|
// Copyright 2015 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <libevdev/libevdev.h>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2016-07-14 15:50:35 +00:00
|
|
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
|
|
|
|
2019-06-17 20:39:24 +00:00
|
|
|
namespace ciface::evdev
|
2015-06-29 00:17:35 +00:00
|
|
|
{
|
2016-06-12 15:08:04 +00:00
|
|
|
void Init();
|
2016-10-16 20:39:05 +00:00
|
|
|
void PopulateDevices();
|
2016-07-14 15:50:35 +00:00
|
|
|
void Shutdown();
|
2015-06-29 00:17:35 +00:00
|
|
|
|
|
|
|
class evdevDevice : public Core::Device
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
class Button : public Core::Device::Input
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string GetName() const override;
|
|
|
|
Button(u8 index, u16 code, libevdev* dev) : m_index(index), m_code(code), m_dev(dev) {}
|
|
|
|
ControlState GetState() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const u8 m_index;
|
|
|
|
const u16 m_code;
|
|
|
|
libevdev* m_dev;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Axis : public Core::Device::Input
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string GetName() const override;
|
2015-07-04 12:14:15 +00:00
|
|
|
Axis(u8 index, u16 code, bool upper, libevdev* dev);
|
2015-06-29 00:17:35 +00:00
|
|
|
ControlState GetState() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const u16 m_code;
|
|
|
|
const u8 m_index;
|
|
|
|
int m_range;
|
2019-01-08 15:28:24 +00:00
|
|
|
int m_base;
|
2015-06-29 00:17:35 +00:00
|
|
|
libevdev* m_dev;
|
2016-06-24 08:43:46 +00:00
|
|
|
};
|
2015-06-29 00:17:35 +00:00
|
|
|
|
2019-01-08 15:28:24 +00:00
|
|
|
class Effect : public Core::Device::Output
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-01-08 15:28:24 +00:00
|
|
|
Effect(int fd);
|
|
|
|
~Effect();
|
2015-06-29 00:17:35 +00:00
|
|
|
void SetState(ControlState state) override;
|
|
|
|
|
2019-01-08 15:28:24 +00:00
|
|
|
protected:
|
|
|
|
virtual bool UpdateParameters(ControlState state) = 0;
|
|
|
|
|
|
|
|
ff_effect m_effect = {};
|
|
|
|
|
|
|
|
static constexpr int DISABLED_EFFECT_TYPE = 0;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void UpdateEffect();
|
|
|
|
|
|
|
|
int const m_fd;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ConstantEffect : public Effect
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ConstantEffect(int fd);
|
|
|
|
bool UpdateParameters(ControlState state) override;
|
|
|
|
std::string GetName() const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PeriodicEffect : public Effect
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PeriodicEffect(int fd, u16 waveform);
|
|
|
|
bool UpdateParameters(ControlState state) override;
|
|
|
|
std::string GetName() const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class RumbleEffect : public Effect
|
|
|
|
{
|
|
|
|
public:
|
2019-01-17 15:54:07 +00:00
|
|
|
enum class Motor : u8
|
|
|
|
{
|
2019-01-17 16:13:32 +00:00
|
|
|
Weak,
|
|
|
|
Strong,
|
2019-01-17 15:54:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
RumbleEffect(int fd, Motor motor);
|
2019-01-08 15:28:24 +00:00
|
|
|
bool UpdateParameters(ControlState state) override;
|
|
|
|
std::string GetName() const override;
|
|
|
|
|
2015-06-29 00:17:35 +00:00
|
|
|
private:
|
2019-01-17 15:54:07 +00:00
|
|
|
const Motor m_motor;
|
2015-06-29 00:17:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
void UpdateInput() override;
|
2016-07-14 15:50:35 +00:00
|
|
|
bool IsValid() const override;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-07-14 08:25:52 +00:00
|
|
|
evdevDevice(const std::string& devnode);
|
2015-06-29 00:17:35 +00:00
|
|
|
~evdevDevice();
|
|
|
|
|
|
|
|
std::string GetName() const override { return m_name; }
|
|
|
|
std::string GetSource() const override { return "evdev"; }
|
2019-01-08 15:28:24 +00:00
|
|
|
bool IsInteresting() const { return m_interesting; }
|
2018-04-12 12:18:04 +00:00
|
|
|
|
2015-06-29 00:17:35 +00:00
|
|
|
private:
|
|
|
|
const std::string m_devfile;
|
|
|
|
int m_fd;
|
|
|
|
libevdev* m_dev;
|
|
|
|
std::string m_name;
|
2019-01-08 15:28:24 +00:00
|
|
|
bool m_interesting = false;
|
2015-06-29 00:17:35 +00:00
|
|
|
};
|
2019-06-17 20:39:24 +00:00
|
|
|
} // namespace ciface::evdev
|