sensors: Add a recalibration hook for the accelerometer

Dial *#*#ACCEL#*#*

Addresses CRACKLING-692

Change-Id: I55d034a8bb8de774ff89277845fef14863c5cccb
cm-14.0
Ricardo Cerqueira 10 years ago
parent a852e7137d
commit a6e6184b0c

@ -107,6 +107,8 @@ PRODUCT_COPY_FILES += \
# Sensors # Sensors
PRODUCT_PACKAGES += \ PRODUCT_PACKAGES += \
accelcal \
AccCalibration \
sensord \ sensord \
sensors.msm8916 sensors.msm8916

@ -110,3 +110,10 @@ service sensord /system/bin/sensord
on property:init.svc.zygote=restarting on property:init.svc.zygote=restarting
restart sensord restart sensord
service calibacc /system/bin/accelcal
class main
oneshot
disabled
on property:sys.sensors.acc=*
start calibacc

@ -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)

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2014 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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cyngn.cracklingacc"
android:versionCode="1"
android:versionName="1.0"
android:sharedUserId="android.uid.system">
<uses-sdk android:minSdkVersion="22" />
<application
android:label="@string/app_name" >
<receiver android:name=".HintReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SECRET_CODE" />
<data android:scheme="android_secret_code" android:host="22235" />
</intent-filter>
</receiver>
</application>
</manifest>

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="app_name">Accelerometer Calibration</string>
<string name="acc_calibration_complete">Accelerometer was recalibrated</string>
</resources>

@ -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();
}
}

@ -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))

@ -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 <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
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;
}
Loading…
Cancel
Save