ApolloInput Nova 0.2.0
Standalone virtual gamepad library
Loading...
Searching...
No Matches
null_backend.cpp
Go to the documentation of this file.
1
6
8
9#include <array>
10#include <utility>
11
12namespace apollo::input::detail {
13 namespace {
14 class NullDevice final: public Device {
15 public:
16 NullDevice(Profile profile, std::string name):
17 info_ {profile, profile_capabilities(profile), std::move(name)} {
18 }
19
20 const DeviceInfo &info() const override {
21 return info_;
22 }
23
24 bool connected() const override {
25 return connected_;
26 }
27
28 bool update(const GamepadState &state) override {
29 auto sanitized = state;
30 sanitize_gamepad_state(sanitized, deadzone_);
31 state_ = sanitized;
32 return connected_;
33 }
34
35 void set_deadzone(const AnalogDeadzone &deadzone) override {
36 deadzone_ = deadzone;
37 }
38
39 bool update_touchpad(const TouchpadState &state) override {
40 if (!connected_ || !info_.capabilities.touchpad) {
41 return false;
42 }
43 touchpad_ = state;
44 return true;
45 }
46
47 bool update_imu(const ImuSample &sample) override {
48 if (!connected_ || !info_.capabilities.imu) {
49 return false;
50 }
51 imu_ = sample;
52 return true;
53 }
54
55 void disconnect() override {
56 connected_ = false;
57 }
58
59 private:
60 DeviceInfo info_;
61 AnalogDeadzone deadzone_;
62 GamepadState state_ {};
63 TouchpadState touchpad_ {};
64 ImuSample imu_ {};
65 bool connected_ = true;
66 };
67
68 class NullBackend final: public Backend {
69 public:
70 const char *name() const override {
71 return "null";
72 }
73
74 bool available(std::string *error) const override {
75 if (error) {
76 error->clear();
77 }
78 return true;
79 }
80
81 std::unique_ptr<Device> create(Profile profile, const std::string &name, std::string *error) override {
82 if (error) {
83 error->clear();
84 }
85 return std::make_unique<NullDevice>(profile, name);
86 }
87
88 std::vector<Profile> supported_profiles() const override {
89 return {
101 };
102 }
103 };
104 } // namespace
105
106 std::unique_ptr<Backend> create_null_backend() {
107 return std::make_unique<NullBackend>();
108 }
109} // namespace apollo::input::detail
Backend and device interfaces for the Apollo input library.
Internal backend factory declarations.
std::unique_ptr< Backend > create_null_backend()
Create the null backend.
Capabilities profile_capabilities(Profile profile)
Features a profile can expose when the backend supports them.
Definition gamepad.cpp:201
Profile
Virtual controller profile exposed by a backend.
Definition gamepad.hpp:16
@ steam_controller
Valve Steam Controller layout.
Definition gamepad.hpp:25
@ dualsense_edge
DualSense Edge with rear paddles and extra function buttons.
Definition gamepad.hpp:23
@ xbox_elite
Xbox Elite Series 2 with rear paddles and Share.
Definition gamepad.hpp:20
@ steam_deck
Valve Steam Deck built-in controls.
Definition gamepad.hpp:26
void sanitize_gamepad_state(GamepadState &state, const AnalogDeadzone &deadzone={})
Remove stick drift, trigger resting noise, and center jitter.
Definition gamepad.cpp:484