FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
SdlJoystick.h
1#pragma once
2
20#ifdef FH_VISUALIZATION
21
22#include "JoystickInput.h"
23
24#include <functional>
25#include <string>
26#include <vector>
27
28struct _SDL_Joystick;
29class ISimObjectCreator;
30
31namespace Ship
32{
33namespace joystick
34{
35
36class SdlJoystickPoller;
37
42void LogJoystickStatus(ISimObjectCreator* creator, const std::string& objectName, SdlJoystickPoller& poller,
43 const std::string& error);
44
45
50class SdlJoystickPoller
51{
52public:
53 SdlJoystickPoller() = default;
54 ~SdlJoystickPoller();
55 SdlJoystickPoller(const SdlJoystickPoller&) = delete;
56 SdlJoystickPoller& operator=(const SdlJoystickPoller&) = delete;
57
60 std::string Open(int deviceIndex);
61
64 std::string OpenAll();
65
67 void Close();
68
70 std::size_t NumOpen() const { return m_devices.size(); }
71
74 void Poll(JoystickListener& listener);
75
77 void SetDetachedCallback(std::function<void(const std::string&)> onDetached) { m_onDetached = std::move(onDetached); }
78
80 std::string Name(std::size_t i) const;
81
82private:
83 struct Device
84 {
85 _SDL_Joystick* joystick = nullptr;
86 DeviceTracker tracker;
87 };
88
89 bool InitSubsystem(std::string& error);
90
91 bool m_subsystem = false;
92 std::vector<Device> m_devices;
93 std::function<void(const std::string&)> m_onDetached;
94};
95
96} // namespace joystick
97} // namespace Ship
98
99#endif
Simple waypoint object.
Definition CableAttach.h:16