summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerEmu
diff options
context:
space:
mode:
authorLC <mathew1800@gmail.com>2020-07-12 12:46:15 -0400
committerGitHub <noreply@github.com>2020-07-12 12:46:15 -0400
commit4d36f6a5b0cbdbc44c2fa47e36526833228114df (patch)
treeccc911f76df1023d262cb44f89c3737443a08789 /Source/Core/InputCommon/ControllerEmu
parentecc6af7f7f2dd91fd3318ff25c9d50d70176be2e (diff)
parent5299e902aa7fe9f474b5e3dd37a5a04f9f3e6bbb (diff)
Merge pull request #8936 from jordan-woyak/wiimote-extension-calibration-fix
ControllerInterface/Wiimote: Provide fallback values for extensions with bad calibration.
Diffstat (limited to 'Source/Core/InputCommon/ControllerEmu')
-rw-r--r--Source/Core/InputCommon/ControllerEmu/ControllerEmu.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h b/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h
index 3301672ccf..b6808f1c0b 100644
--- a/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h
+++ b/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h
@@ -14,6 +14,7 @@
#include "Common/BitUtils.h"
#include "Common/Common.h"
#include "Common/IniFile.h"
+#include "Common/MathUtil.h"
#include "InputCommon/ControlReference/ExpressionParser.h"
#include "InputCommon/ControllerInterface/Device.h"
@@ -37,6 +38,20 @@ struct TwoPointCalibration
TwoPointCalibration() = default;
TwoPointCalibration(const T& zero_, const T& max_) : zero{zero_}, max{max_} {}
+ // Sanity check is that max and zero are not equal.
+ constexpr bool IsSane() const
+ {
+ if constexpr (std::is_arithmetic_v<T>)
+ {
+ return max != zero;
+ }
+ else
+ {
+ return std::equal(std::begin(max.data), std::end(max.data), std::begin(zero.data),
+ std::not_equal_to<>());
+ }
+ }
+
static constexpr size_t BITS_OF_PRECISION = Bits;
T zero;
@@ -53,6 +68,28 @@ struct ThreePointCalibration
{
}
+ // Sanity check is that min and max are on opposite sides of the zero value.
+ constexpr bool IsSane() const
+ {
+ if constexpr (std::is_arithmetic_v<T>)
+ {
+ return MathUtil::Sign(zero - min) * MathUtil::Sign(zero - max) == -1;
+ }
+ else
+ {
+ for (size_t i = 0; i != std::size(zero.data); ++i)
+ {
+ if (MathUtil::Sign(zero.data[i] - min.data[i]) *
+ MathUtil::Sign(zero.data[i] - max.data[i]) !=
+ -1)
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+
static constexpr size_t BITS_OF_PRECISION = Bits;
T min;