ApolloInput Nova 0.2.0
Standalone virtual gamepad library
Loading...
Searching...
No Matches
backend.hpp
Go to the documentation of this file.
1
5#pragma once
6
8
9#include <functional>
10#include <memory>
11#include <string>
12#include <vector>
13
14namespace apollo::input {
15
25
35
39 struct Feedback {
41 std::uint16_t low_frequency = 0;
42 std::uint16_t high_frequency = 0;
43 std::uint8_t led_red = 0;
44 std::uint8_t led_green = 0;
45 std::uint8_t led_blue = 0;
46 std::uint8_t trigger = 0;
47 std::uint8_t trigger_mode = 0;
48 };
49
53 using FeedbackCallback = std::function<void(const Feedback &)>;
54
58 class Device {
59 public:
60 virtual ~Device() = default;
61
67 virtual const DeviceInfo &info() const = 0;
68
74 virtual bool connected() const = 0;
75
82 virtual bool update(const GamepadState &state) = 0;
83
92 virtual void set_deadzone(const AnalogDeadzone &deadzone) {
93 (void) deadzone;
94 }
95
102 virtual bool update_touchpad(const TouchpadState &state) {
103 (void) state;
104 return false;
105 }
106
113 virtual bool update_imu(const ImuSample &sample) {
114 (void) sample;
115 return false;
116 }
117
124 (void) callback;
125 }
126
130 virtual void disconnect() = 0;
131 };
132
136 class Backend {
137 public:
138 virtual ~Backend() = default;
139
145 virtual const char *name() const = 0;
146
153 virtual bool available(std::string *error = nullptr) const = 0;
154
163 virtual std::unique_ptr<Device> create(Profile profile, const std::string &name, std::string *error = nullptr) = 0;
164
178 std::unique_ptr<Device> create_compatible(Profile profile, const std::string &name, std::string *error = nullptr);
179
185 virtual std::vector<Profile> supported_profiles() const = 0;
186 };
187
194 std::unique_ptr<Backend> create_backend(BackendKind kind = BackendKind::automatic);
195
202 const char *to_string(BackendKind kind);
203
214 bool backend_from_string(const std::string &name, BackendKind &kind);
215
216} // namespace apollo::input
Factory for virtual input devices.
Definition backend.hpp:136
virtual std::unique_ptr< Device > create(Profile profile, const std::string &name, std::string *error=nullptr)=0
Create a virtual device.
std::unique_ptr< Device > create_compatible(Profile profile, const std::string &name, std::string *error=nullptr)
Create a device, falling back to a simpler compatible profile.
Definition backend.cpp:80
virtual ~Backend()=default
virtual const char * name() const =0
Stable backend name.
virtual std::vector< Profile > supported_profiles() const =0
Profiles supported by this backend.
virtual bool available(std::string *error=nullptr) const =0
Check whether the backend can work on this machine.
One created virtual input device.
Definition backend.hpp:58
virtual bool update_touchpad(const TouchpadState &state)
Submit a touchpad report when the backend supports it.
Definition backend.hpp:102
virtual bool update(const GamepadState &state)=0
Submit a complete gamepad report.
virtual bool update_imu(const ImuSample &sample)
Submit an IMU sample when the backend supports it.
Definition backend.hpp:113
virtual bool connected() const =0
Whether the device is still connected to its backend.
virtual ~Device()=default
virtual void set_deadzone(const AnalogDeadzone &deadzone)
Configure analog drift filtering for this device.
Definition backend.hpp:92
virtual void set_feedback_callback(FeedbackCallback callback)
Replace the feedback callback.
Definition backend.hpp:123
virtual void disconnect()=0
Remove the virtual device from the system.
virtual const DeviceInfo & info() const =0
Description of the virtual device.
Portable gamepad state, profiles, and capability definitions.
bool backend_from_string(const std::string &name, BackendKind &kind)
Parse a backend kind from its short name or a compatible alias.
Definition backend.cpp:70
std::function< void(const Feedback &)> FeedbackCallback
Callback invoked when the virtual device receives feedback.
Definition backend.hpp:53
BackendKind
Kind of backend selected by the caller.
Definition backend.hpp:19
@ vigem
ViGEmBus on Windows.
Definition backend.hpp:21
@ null_backend
No-op backend useful for tests and previews.
Definition backend.hpp:23
@ automatic
Best backend for the current platform.
Definition backend.hpp:20
@ uinput
Linux uinput.
Definition backend.hpp:22
FeedbackType
Feedback message received from the virtual device.
Definition backend.hpp:29
@ led
LED or lightbar.
Definition backend.hpp:31
@ rumble
Rumble motors.
Definition backend.hpp:30
@ adaptive_trigger
Adaptive trigger effect.
Definition backend.hpp:32
Profile
Virtual controller profile exposed by a backend.
Definition gamepad.hpp:16
const char * to_string(BackendKind kind)
Convert a backend kind to a stable short name.
Definition backend.cpp:61
std::unique_ptr< Backend > create_backend(BackendKind kind=BackendKind::automatic)
Create a backend for the current platform.
Definition backend.cpp:101
Host-side analog filtering used to remove drift and resting noise.
Definition gamepad.hpp:198
Description of a created virtual device.
Definition gamepad.hpp:217
Feedback payload from the operating system or a game.
Definition backend.hpp:39
std::uint8_t trigger
Trigger index for adaptive effects.
Definition backend.hpp:46
std::uint16_t low_frequency
Low-frequency rumble motor.
Definition backend.hpp:41
FeedbackType type
Feedback kind.
Definition backend.hpp:40
std::uint8_t led_blue
LED blue component.
Definition backend.hpp:45
std::uint16_t high_frequency
High-frequency rumble motor.
Definition backend.hpp:42
std::uint8_t led_green
LED green component.
Definition backend.hpp:44
std::uint8_t trigger_mode
Backend-defined effect mode.
Definition backend.hpp:47
std::uint8_t led_red
LED red component.
Definition backend.hpp:43
One complete gamepad input report.
Definition gamepad.hpp:105
Optional inertial measurement unit sample.
Definition gamepad.hpp:158
Optional touchpad report.
Definition gamepad.hpp:149