From 1d2070d0d30448f79d8e39c614db4375d23b58c4 Mon Sep 17 00:00:00 2001
From: wwylele <wwylele@gmail.com>
Date: Fri, 25 Mar 2016 11:39:59 +0300
Subject: [PATCH] implement GyroscopeCalibrateParam

---
 src/core/hle/service/hid/hid.cpp | 15 +++++++--------
 src/core/hle/service/hid/hid.h   | 14 +++++++++++++-
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index 56bf89fa82..b27ab6d9bd 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -251,14 +251,13 @@ void GetGyroscopeLowCalibrateParam(Service::Interface* self) {
 
     cmd_buff[1] = RESULT_SUCCESS.raw;
 
-    // currently don't understand the meaning of return value,
-    // so stubbed these with value from a real console.
-    // TODO(wwylele): implement this correctly
-    cmd_buff[2] = 0x19DDFFDC;
-    cmd_buff[3] = 0x0002E5DA;
-    cmd_buff[4] = 0xE5CE1A2D;
-    cmd_buff[5] = 0x19C6FFF3;
-    cmd_buff[6] = 0x001CE61E;
+    const s16 param_unit = 6700; // an approximate value taken from hw
+    GyroscopeCalibrateParam param = {
+        { 0, param_unit, -param_unit },
+        { 0, param_unit, -param_unit },
+        { 0, param_unit, -param_unit },
+    };
+    memcpy(&cmd_buff[2], &param, sizeof(param));
 
     LOG_WARNING(Service_HID, "(STUBBED) called");
 }
diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h
index ebe1375257..170d19ea81 100644
--- a/src/core/hle/service/hid/hid.h
+++ b/src/core/hle/service/hid/hid.h
@@ -160,6 +160,18 @@ struct SharedMem {
     } gyroscope;
 };
 
+/**
+ * Structure of calibrate params that GetGyroscopeLowCalibrateParam returns
+ */
+struct GyroscopeCalibrateParam {
+    struct {
+        // TODO (wwylele): figure out the exact meaning of these params
+        s16 zero_point;
+        s16 positive_unit_point;
+        s16 negative_unit_point;
+    } x, y, z;
+};
+
 // TODO: MSVC does not support using offsetof() on non-static data members even though this
 //       is technically allowed since C++11. This macro should be enabled once MSVC adds
 //       support for that.
@@ -284,7 +296,7 @@ void GetGyroscopeLowRawToDpsCoefficient(Service::Interface* self);
  *      None
  *  Outputs:
  *      1 : Result of function, 0 on success, otherwise error code
- *      2~6 : CalibrateParam?
+ *      2~6 (18 bytes) : struct GyroscopeCalibrateParam
  */
 void GetGyroscopeLowCalibrateParam(Service::Interface* self);