evdev.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright 2015 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <libevdev/libevdev.h>
  5. #include <string>
  6. #include <vector>
  7. #include "InputCommon/ControllerInterface/ControllerInterface.h"
  8. namespace ciface::evdev
  9. {
  10. class InputBackend;
  11. std::unique_ptr<ciface::InputBackend> CreateInputBackend(ControllerInterface* controller_interface);
  12. class evdevDevice : public Core::Device
  13. {
  14. private:
  15. class Effect : public Core::Device::Output
  16. {
  17. public:
  18. Effect(int fd);
  19. ~Effect();
  20. void SetState(ControlState state) override;
  21. protected:
  22. virtual bool UpdateParameters(ControlState state) = 0;
  23. ff_effect m_effect = {};
  24. static constexpr int DISABLED_EFFECT_TYPE = 0;
  25. private:
  26. void UpdateEffect();
  27. int const m_fd;
  28. };
  29. class ConstantEffect : public Effect
  30. {
  31. public:
  32. ConstantEffect(int fd);
  33. bool UpdateParameters(ControlState state) override;
  34. std::string GetName() const override;
  35. };
  36. class PeriodicEffect : public Effect
  37. {
  38. public:
  39. PeriodicEffect(int fd, u16 waveform);
  40. bool UpdateParameters(ControlState state) override;
  41. std::string GetName() const override;
  42. };
  43. class RumbleEffect : public Effect
  44. {
  45. public:
  46. enum class Motor : u8
  47. {
  48. Weak,
  49. Strong,
  50. };
  51. RumbleEffect(int fd, Motor motor);
  52. bool UpdateParameters(ControlState state) override;
  53. std::string GetName() const override;
  54. private:
  55. const Motor m_motor;
  56. };
  57. public:
  58. Core::DeviceRemoval UpdateInput() override;
  59. bool IsValid() const override;
  60. evdevDevice(InputBackend* input_backend);
  61. ~evdevDevice();
  62. // Return true if node was "interesting".
  63. bool AddNode(std::string devnode, int fd, libevdev* dev);
  64. const char* GetUniqueID() const;
  65. const char* GetPhysicalLocation() const;
  66. std::string GetName() const override { return m_name; }
  67. std::string GetSource() const override { return "evdev"; }
  68. private:
  69. std::string m_name;
  70. struct Node
  71. {
  72. std::string devnode;
  73. int fd;
  74. libevdev* device;
  75. };
  76. std::vector<Node> m_nodes;
  77. InputBackend& m_input_backend;
  78. };
  79. } // namespace ciface::evdev