diff --git a/device.mk b/device.mk
index fa65b8e..918ef2e 100644
--- a/device.mk
+++ b/device.mk
@@ -107,6 +107,8 @@ PRODUCT_COPY_FILES += \
# Sensors
PRODUCT_PACKAGES += \
+ accelcal \
+ AccCalibration \
sensord \
sensors.msm8916
diff --git a/rootdir/etc/init.target.rc b/rootdir/etc/init.target.rc
index e7c2257..5c85abd 100644
--- a/rootdir/etc/init.target.rc
+++ b/rootdir/etc/init.target.rc
@@ -110,3 +110,10 @@ service sensord /system/bin/sensord
on property:init.svc.zygote=restarting
restart sensord
+service calibacc /system/bin/accelcal
+ class main
+ oneshot
+ disabled
+
+on property:sys.sensors.acc=*
+ start calibacc
diff --git a/sensors/calibration/AccelCalib/Android.mk b/sensors/calibration/AccelCalib/Android.mk
new file mode 100644
index 0000000..caa917b
--- /dev/null
+++ b/sensors/calibration/AccelCalib/Android.mk
@@ -0,0 +1,13 @@
+LOCAL_PATH:=$(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_CERTIFICATE := platform
+LOCAL_PRIVILEGED_MODULE := true
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := AccCalibration
+
+include $(BUILD_PACKAGE)
diff --git a/sensors/calibration/AccelCalib/AndroidManifest.xml b/sensors/calibration/AccelCalib/AndroidManifest.xml
new file mode 100644
index 0000000..945a5b8
--- /dev/null
+++ b/sensors/calibration/AccelCalib/AndroidManifest.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sensors/calibration/AccelCalib/res/values/strings.xml b/sensors/calibration/AccelCalib/res/values/strings.xml
new file mode 100644
index 0000000..926681a
--- /dev/null
+++ b/sensors/calibration/AccelCalib/res/values/strings.xml
@@ -0,0 +1,5 @@
+
+
+ Accelerometer Calibration
+ Accelerometer was recalibrated
+
diff --git a/sensors/calibration/AccelCalib/src/com/cyngn/cracklingacc/HintReceiver.java b/sensors/calibration/AccelCalib/src/com/cyngn/cracklingacc/HintReceiver.java
new file mode 100644
index 0000000..c225221
--- /dev/null
+++ b/sensors/calibration/AccelCalib/src/com/cyngn/cracklingacc/HintReceiver.java
@@ -0,0 +1,29 @@
+package com.cyngn.cracklingacc;
+
+import static com.android.internal.telephony.TelephonyIntents.SECRET_CODE_ACTION;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.BroadcastReceiver;
+import android.os.SystemProperties;
+import android.util.Log;
+import android.view.KeyEvent;
+import android.widget.Toast;
+
+import com.cyngn.cracklingacc.R;
+
+
+public class HintReceiver extends BroadcastReceiver {
+
+ private static final String SECRET_CODE_PREFIX = "android_secret_code://";
+
+ private static final String CALIB_MODE = "22235";
+ public HintReceiver() {
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ SystemProperties.set("sys.sensors.acc","calibrate");
+ Toast.makeText(context, R.string.acc_calibration_complete, Toast.LENGTH_LONG).show();
+ }
+}
diff --git a/sensors/calibration/Android.mk b/sensors/calibration/Android.mk
new file mode 100644
index 0000000..134701c
--- /dev/null
+++ b/sensors/calibration/Android.mk
@@ -0,0 +1,30 @@
+# Copyright (C) 2015 The CyanogenMod project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := accelcal.c
+
+LOCAL_PRELINK_MODULE := false
+
+LOCAL_MODULE := accelcal
+
+include $(BUILD_EXECUTABLE)
+
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/sensors/calibration/accelcal.c b/sensors/calibration/accelcal.c
new file mode 100644
index 0000000..0a10652
--- /dev/null
+++ b/sensors/calibration/accelcal.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2015 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include
+#include
+#include
+#include
+
+int main() {
+ FILE *f1, *f2, *f3;
+ int calibvals[3];
+
+
+ f1 = fopen("/sys/devices/virtual/bst/ACC/fast_calibration_x","w");
+ if (f1 == NULL) return -1;
+ f2 = fopen("/sys/devices/virtual/bst/ACC/fast_calibration_y","w");
+ if (f2 == NULL) return -1;
+ f3 = fopen("/sys/devices/virtual/bst/ACC/fast_calibration_z","w");
+ if (f3 == NULL) return -1;
+
+ fprintf(f1,"3");
+ fprintf(f2,"3");
+ fprintf(f3,"1");
+
+ fclose(f1);
+ fclose(f2);
+ fclose(f3);
+
+ f1 = fopen("/sys/devices/virtual/bst/ACC/offset_x","r");
+ if (f1 == NULL) return -1;
+ f2 = fopen("/sys/devices/virtual/bst/ACC/offset_y","r");
+ if (f2 == NULL) return -1;
+ f3 = fopen("/sys/devices/virtual/bst/ACC/offset_z","r");
+ if (f3 == NULL) return -1;
+
+ fscanf(f1,"%d",&calibvals[0]);
+ fscanf(f2,"%d",&calibvals[1]);
+ fscanf(f3,"%d",&calibvals[2]);
+
+ fclose(f1);
+ fclose(f2);
+ fclose(f3);
+
+ f1 = fopen("/data/misc/sensor/fast_calib_a","w");
+ if (f1 == NULL) return -2;
+ fprintf(f1,"%d,%d,%d",calibvals[0],calibvals[1],calibvals[2]);
+ fclose(f1);
+
+ return 0;
+}