From 751d36e7392b0b1637f17988cfc1ef0d7cd95753 Mon Sep 17 00:00:00 2001
From: Narr the Reg <juangerman-13@hotmail.com>
Date: Tue, 20 Dec 2022 19:10:42 -0600
Subject: input_common: Add support for joycon ring controller

---
 .../helpers/joycon_protocol/calibration.cpp        | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

(limited to 'src/input_common/helpers/joycon_protocol/calibration.cpp')

diff --git a/src/input_common/helpers/joycon_protocol/calibration.cpp b/src/input_common/helpers/joycon_protocol/calibration.cpp
index 5c29af545b..ce1ff7061d 100644
--- a/src/input_common/helpers/joycon_protocol/calibration.cpp
+++ b/src/input_common/helpers/joycon_protocol/calibration.cpp
@@ -128,6 +128,28 @@ DriverResult CalibrationProtocol::GetImuCalibration(MotionCalibration& calibrati
     return result;
 }
 
+DriverResult CalibrationProtocol::GetRingCalibration(RingCalibration& calibration,
+                                                     s16 current_value) {
+    // TODO: Get default calibration form ring itself
+    if (ring_data_max == 0 && ring_data_min == 0) {
+        ring_data_max = current_value + 800;
+        ring_data_min = current_value - 800;
+        ring_data_default = current_value;
+    }
+    if (ring_data_max < current_value) {
+        ring_data_max = current_value;
+    }
+    if (ring_data_min > current_value) {
+        ring_data_min = current_value;
+    }
+    calibration = {
+        .default_value = ring_data_default,
+        .max_value = ring_data_max,
+        .min_value = ring_data_min,
+    };
+    return DriverResult::Success;
+}
+
 void CalibrationProtocol::ValidateCalibration(JoyStickCalibration& calibration) {
     constexpr u16 DefaultStickCenter{2048};
     constexpr u16 DefaultStickRange{1740};
-- 
cgit v1.2.3-70-g09d2