Skip to content

Commit

Permalink
refactor: using clamp instead of manual IFs
Browse files Browse the repository at this point in the history
  • Loading branch information
ABeltramo committed Nov 9, 2024
1 parent a1eda26 commit b151616
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/uhid/joypad_ps5.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <algorithm>
#include <climits>
#include <cmath>
#include <endian.h>
#include <filesystem>
Expand All @@ -9,7 +10,6 @@
#include <uhid/protected_types.hpp>
#include <uhid/ps5.hpp>
#include <uhid/uhid.hpp>
#include <climits>

namespace inputtino {

Expand Down Expand Up @@ -365,11 +365,7 @@ void PS5Joypad::set_on_rumble(const std::function<void(int, int)> &callback) {
* For a rationale behind this, see: https://github.com/LizardByte/Sunshine/issues/3247#issuecomment-2428065349
*/
static __le16 to_le_signed(float original, float value) {
if (value < SHRT_MIN) {
value = SHRT_MIN;
} else if (value > SHRT_MAX) {
value = SHRT_MAX;
}
value = std::clamp(value, static_cast<float>(SHRT_MIN), static_cast<float>(SHRT_MAX));
return htole16(value);
}

Expand Down

0 comments on commit b151616

Please sign in to comment.