18#ifndef HEADER_SDL_CONTROLLER_HPP
19#define HEADER_SDL_CONTROLLER_HPP
23#include <SDL_events.h>
24#include <SDL_gamecontroller.h>
25#include <SDL_joystick.h>
26#include <IEventReceiver.h>
30#include <SDL_version.h>
31#include <SDL_haptic.h>
38 SDL_GameController* m_game_controller;
40 SDL_Joystick* m_joystick;
55 irr::SEvent m_irr_event;
57 int16_t m_prev_axes[irr::SEvent::SJoystickEvent::NUMBER_OF_AXES];
59 uint64_t m_last_power_level_time;
61 void handleDirectScanCode(
const SDL_Event& event);
64 void updateAutoCenter(
int state);
71 const irr::SEvent& getEvent()
const {
return m_irr_event; }
73 SDL_JoystickID getInstanceID()
const {
return m_id; }
77 bool handleAxis(
const SDL_Event& event)
79 int axis_idx =
event.jaxis.axis;
80 if (axis_idx > m_axes)
82 m_irr_event.JoystickEvent.Axis[axis_idx] =
event.jaxis.value;
83 m_prev_axes[axis_idx] =
event.jaxis.value;
84 uint32_t value = 1 << axis_idx;
85 m_irr_event.JoystickEvent.AxisChanged = value;
89 bool handleHat(
const SDL_Event& event)
91 if (event.jhat.hat > m_hats)
93 std::bitset<4> new_hat_status;
95 switch (event.jhat.value)
98 new_hat_status[0] =
true;
100 case SDL_HAT_RIGHTUP:
101 new_hat_status[0] =
true;
102 new_hat_status[1] =
true;
105 new_hat_status[1] =
true;
107 case SDL_HAT_RIGHTDOWN:
108 new_hat_status[1] =
true;
109 new_hat_status[2] =
true;
112 new_hat_status[2] =
true;
114 case SDL_HAT_LEFTDOWN:
115 new_hat_status[2] =
true;
116 new_hat_status[3] =
true;
119 new_hat_status[3] =
true;
122 new_hat_status[3] =
true;
123 new_hat_status[0] =
true;
125 case SDL_HAT_CENTERED:
129 int hat_start = m_buttons - (m_hats * 4) + (event.jhat.hat * 4);
130 std::bitset<irr::SEvent::SJoystickEvent::NUMBER_OF_BUTTONS> states
131 (m_irr_event.JoystickEvent.ButtonStates);
132 for (
unsigned i = 0; i < 4; i++)
134 int hat_button_id = i + hat_start;
135 states[hat_button_id] = new_hat_status[i];
137 m_irr_event.JoystickEvent.ButtonStates = (irr::u32)states.to_ulong();
138 m_irr_event.JoystickEvent.AxisChanged = 0;
142 bool handleButton(
const SDL_Event& event)
144 if (event.jbutton.button > m_buttons)
147 handleDirectScanCode(event);
151 bool pressed =
event.jbutton.state == SDL_PRESSED;
152 std::bitset<irr::SEvent::SJoystickEvent::NUMBER_OF_BUTTONS> states
153 (m_irr_event.JoystickEvent.ButtonStates);
154 states[
event.jbutton.button] = pressed;
155 m_irr_event.JoystickEvent.ButtonStates = (irr::u32)states.to_ulong();
156 m_irr_event.JoystickEvent.AxisChanged = 0;
160 SDL_GameController* getGameController()
const {
return m_game_controller; }
162 void checkPowerLevel();
164 void doRumble(
float strength_low,
float strength_high, uint32_t duration_ms);
165 GamePadDevice* getGamePadDevice()
const {
return m_gamepad; }
specialisation of Inputdevice for gamepad type devices
Definition: gamepad_device.hpp:33
Definition: sdl_controller.hpp:36
void handleAxisInputSense(const SDL_Event &event)
SDL only sends event when axis moves, so we need to send previously saved event for correct input sen...
Definition: sdl_controller.cpp:229
Declares the general types that are used by the network.