xbmc
PeripheralJoystick.h
1 /*
2  * Copyright (C) 2014-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "Peripheral.h"
12 #include "XBDateTime.h"
14 #include "input/joysticks/interfaces/IDriverReceiver.h"
15 #include "threads/CriticalSection.h"
16 
17 #include <memory>
18 #include <string>
19 #include <vector>
20 
21 #define JOYSTICK_PORT_UNKNOWN (-1)
22 
23 namespace KODI
24 {
25 namespace JOYSTICK
26 {
27 class CDeadzoneFilter;
28 class CKeymapHandling;
29 class CRumbleGenerator;
30 class IButtonMap;
31 class IDriverHandler;
32 class IInputHandler;
33 } // namespace JOYSTICK
34 } // namespace KODI
35 
36 namespace PERIPHERALS
37 {
38 class CPeripherals;
39 
42 {
43 public:
45  const PeripheralScanResult& scanResult,
46  CPeripheralBus* bus);
47 
48  ~CPeripheralJoystick(void) override;
49 
50  // implementation of CPeripheral
51  bool InitialiseFeature(const PeripheralFeature feature) override;
52  void OnUserNotification() override;
53  bool TestFeature(PeripheralFeature feature) override;
54  void RegisterJoystickDriverHandler(KODI::JOYSTICK::IDriverHandler* handler,
55  bool bPromiscuous) override;
56  void UnregisterJoystickDriverHandler(KODI::JOYSTICK::IDriverHandler* handler) override;
57  KODI::JOYSTICK::IDriverReceiver* GetDriverReceiver() override { return this; }
58  IKeymap* GetKeymap(const std::string& controllerId) override;
59  CDateTime LastActive() override { return m_lastActive; }
60  KODI::GAME::ControllerPtr ControllerProfile() const override;
61 
62  bool OnButtonMotion(unsigned int buttonIndex, bool bPressed);
63  bool OnHatMotion(unsigned int hatIndex, KODI::JOYSTICK::HAT_STATE state);
64  bool OnAxisMotion(unsigned int axisIndex, float position);
65  void OnInputFrame(void);
66 
67  // implementation of IDriverReceiver
68  bool SetMotorState(unsigned int motorIndex, float magnitude) override;
69 
73  const std::string& Provider(void) const { return m_strProvider; }
74 
84  int RequestedPort(void) const { return m_requestedPort; }
85 
89  unsigned int ButtonCount(void) const { return m_buttonCount; }
90  unsigned int HatCount(void) const { return m_hatCount; }
91  unsigned int AxisCount(void) const { return m_axisCount; }
92  unsigned int MotorCount(void) const { return m_motorCount; }
93  bool SupportsPowerOff(void) const { return m_supportsPowerOff; }
94 
98  void SetProvider(const std::string& provider) { m_strProvider = provider; }
99  void SetRequestedPort(int port) { m_requestedPort = port; }
100  void SetButtonCount(unsigned int buttonCount) { m_buttonCount = buttonCount; }
101  void SetHatCount(unsigned int hatCount) { m_hatCount = hatCount; }
102  void SetAxisCount(unsigned int axisCount) { m_axisCount = axisCount; }
103  void SetMotorCount(unsigned int motorCount); // specialized to update m_features
104  void SetSupportsPowerOff(bool bSupportsPowerOff); // specialized to update m_features
105 
106 protected:
107  void InitializeDeadzoneFiltering();
108 
109  void PowerOff();
110 
112  {
114  bool bPromiscuous;
115  };
116 
117  // State parameters
118  std::string m_strProvider;
119  int m_requestedPort;
120  unsigned int m_buttonCount;
121  unsigned int m_hatCount;
122  unsigned int m_axisCount;
123  unsigned int m_motorCount;
124  bool m_supportsPowerOff;
125  CDateTime m_lastActive;
126 
127  // Input clients
128  std::unique_ptr<KODI::JOYSTICK::CKeymapHandling> m_appInput;
129  std::unique_ptr<KODI::JOYSTICK::CRumbleGenerator> m_rumbleGenerator;
130  std::unique_ptr<KODI::JOYSTICK::IInputHandler> m_joystickMonitor;
131  std::unique_ptr<KODI::JOYSTICK::IButtonMap> m_buttonMap;
132  std::unique_ptr<KODI::JOYSTICK::CDeadzoneFilter> m_deadzoneFilter;
133  std::vector<DriverHandler> m_driverHandlers;
134 
135  // Synchronization parameters
136  CCriticalSection m_handlerMutex;
137 };
138 } // namespace PERIPHERALS
Definition: PeripheralTypes.h:318
const std::string & Provider(void) const
Get the name of the driver or API providing this joystick.
Definition: PeripheralJoystick.h:73
Definition: IInputHandler.h:16
unsigned int ButtonCount(void) const
Get the number of elements reported by the driver.
Definition: PeripheralJoystick.h:89
int RequestedPort(void) const
Get the specific port number requested by this joystick.
Definition: PeripheralJoystick.h:84
Definition: RetroPlayerInput.h:15
Interface defining methods to handle joystick events for raw driver elements (buttons, hats, axes)
Definition: IDriverHandler.h:21
Interface for mapping buttons to Kodi actions.
Definition: IKeymap.h:22
void SetProvider(const std::string &provider)
Set joystick properties.
Definition: PeripheralJoystick.h:98
Definition: PeripheralJoystick.h:40
Definition: PeripheralJoystick.h:111
Controller configuration window.
Definition: AudioDecoder.h:18
CDateTime LastActive() override
Return the last time this peripheral was active.
Definition: PeripheralJoystick.h:59
DateTime class, which uses FileTime as it&#39;s base.
Definition: XBDateTime.h:63
Definition: PeripheralBus.h:34
Definition: Peripheral.h:62
Interface for sending input events to joystick drivers.
Definition: IDriverReceiver.h:19
Definition: Peripherals.h:49