ControllerInterface: SDL: Replace unclear bool parameter with enum class.

This commit is contained in:
Jordan Woyak 2019-01-17 10:13:32 -06:00
parent 4fb68c530b
commit 0bdfa19650
4 changed files with 22 additions and 18 deletions

View File

@ -248,10 +248,8 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index)
// LeftRight // LeftRight
if (supported_effects & SDL_HAPTIC_LEFTRIGHT) if (supported_effects & SDL_HAPTIC_LEFTRIGHT)
{ {
// Strong motor: AddOutput(new LeftRightEffect(m_haptic, LeftRightEffect::Motor::Strong));
AddOutput(new LeftRightEffect(m_haptic, true)); AddOutput(new LeftRightEffect(m_haptic, LeftRightEffect::Motor::Weak));
// Weak motor:
AddOutput(new LeftRightEffect(m_haptic, false));
} }
#endif #endif
} }
@ -344,8 +342,8 @@ Joystick::PeriodicEffect::PeriodicEffect(SDL_Haptic* haptic, u16 waveform)
m_effect.periodic.phase = 0; m_effect.periodic.phase = 0;
} }
Joystick::LeftRightEffect::LeftRightEffect(SDL_Haptic* haptic, bool use_strong_motor) Joystick::LeftRightEffect::LeftRightEffect(SDL_Haptic* haptic, Motor motor)
: HapticEffect(haptic), m_use_strong_motor(use_strong_motor) : HapticEffect(haptic), m_motor(motor)
{ {
m_effect.leftright = {}; m_effect.leftright = {};
m_effect.leftright.length = RUMBLE_LENGTH_MS; m_effect.leftright.length = RUMBLE_LENGTH_MS;
@ -380,7 +378,7 @@ std::string Joystick::PeriodicEffect::GetName() const
std::string Joystick::LeftRightEffect::GetName() const std::string Joystick::LeftRightEffect::GetName() const
{ {
return m_use_strong_motor ? "Strong" : "Weak"; return (Motor::Strong == m_motor) ? "Strong" : "Weak";
} }
void Joystick::HapticEffect::SetState(ControlState state) void Joystick::HapticEffect::SetState(ControlState state)
@ -432,8 +430,8 @@ bool Joystick::PeriodicEffect::UpdateParameters(s16 value)
bool Joystick::LeftRightEffect::UpdateParameters(s16 value) bool Joystick::LeftRightEffect::UpdateParameters(s16 value)
{ {
u16& level = u16& level = (Motor::Strong == m_motor) ? m_effect.leftright.large_magnitude :
m_use_strong_motor ? m_effect.leftright.large_magnitude : m_effect.leftright.small_magnitude; m_effect.leftright.small_magnitude;
const u16 old_level = level; const u16 old_level = level;
level = value; level = value;
@ -486,7 +484,7 @@ ControlState Joystick::Button::GetState() const
ControlState Joystick::Axis::GetState() const ControlState Joystick::Axis::GetState() const
{ {
return std::max(0.0, ControlState(SDL_JoystickGetAxis(m_js, m_index)) / m_range); return ControlState(SDL_JoystickGetAxis(m_js, m_index)) / m_range;
} }
ControlState Joystick::Hat::GetState() const ControlState Joystick::Hat::GetState() const

View File

@ -124,13 +124,19 @@ private:
class LeftRightEffect : public HapticEffect class LeftRightEffect : public HapticEffect
{ {
public: public:
LeftRightEffect(SDL_Haptic* haptic, bool use_strong_motor); enum class Motor : u8
{
Weak,
Strong,
};
LeftRightEffect(SDL_Haptic* haptic, Motor motor);
std::string GetName() const override; std::string GetName() const override;
private: private:
bool UpdateParameters(s16 value) override; bool UpdateParameters(s16 value) override;
const bool m_use_strong_motor; const Motor m_motor;
}; };
#endif #endif

View File

@ -251,8 +251,8 @@ evdevDevice::evdevDevice(const std::string& devnode) : m_devfile(devnode)
// Rumble (i.e. Left/Right) (i.e. Strong/Weak) effect // Rumble (i.e. Left/Right) (i.e. Strong/Weak) effect
if (libevdev_has_event_code(m_dev, EV_FF, FF_RUMBLE)) if (libevdev_has_event_code(m_dev, EV_FF, FF_RUMBLE))
{ {
AddOutput(new RumbleEffect(m_fd, RumbleEffect::Motor::STRONG)); AddOutput(new RumbleEffect(m_fd, RumbleEffect::Motor::Strong));
AddOutput(new RumbleEffect(m_fd, RumbleEffect::Motor::WEAK)); AddOutput(new RumbleEffect(m_fd, RumbleEffect::Motor::Weak));
} }
// TODO: Add leds as output devices // TODO: Add leds as output devices
@ -383,7 +383,7 @@ std::string evdevDevice::PeriodicEffect::GetName() const
std::string evdevDevice::RumbleEffect::GetName() const std::string evdevDevice::RumbleEffect::GetName() const
{ {
return (Motor::STRONG == m_motor) ? "Strong" : "Weak"; return (Motor::Strong == m_motor) ? "Strong" : "Weak";
} }
void evdevDevice::Effect::SetState(ControlState state) void evdevDevice::Effect::SetState(ControlState state)
@ -477,7 +477,7 @@ bool evdevDevice::PeriodicEffect::UpdateParameters(ControlState state)
bool evdevDevice::RumbleEffect::UpdateParameters(ControlState state) bool evdevDevice::RumbleEffect::UpdateParameters(ControlState state)
{ {
u16& value = (Motor::STRONG == m_motor) ? m_effect.u.rumble.strong_magnitude : u16& value = (Motor::Strong == m_motor) ? m_effect.u.rumble.strong_magnitude :
m_effect.u.rumble.weak_magnitude; m_effect.u.rumble.weak_magnitude;
const u16 old_value = value; const u16 old_value = value;

View File

@ -90,8 +90,8 @@ private:
public: public:
enum class Motor : u8 enum class Motor : u8
{ {
WEAK, Weak,
STRONG, Strong,
}; };
RumbleEffect(int fd, Motor motor); RumbleEffect(int fd, Motor motor);