Skip to content

Commit f81df8c

Browse files
committed
First attempt to fix left/right rotation
My best guess about this issue was that the magnetic sensor is sometimes not calibrated and therefore returns wrong values. Switching to the uncalibrated magnetic sensor might fix this issue. This *will* need further testing.
1 parent 453e24a commit f81df8c

10 files changed

Lines changed: 33 additions & 19 deletions

File tree

.idea/gradle.xml

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ android {
1010
targetSdkVersion 23
1111
versionCode 141
1212
versionName "1.41"
13-
resConfigs "nodpi", "hdpi"
1413
}
1514
buildTypes {
1615
release {

app/src/main/java/fr/frazew/virtualgyroscope/XposedMod.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
244244
);
245245
XposedHelpers.callMethod(param.thisObject, "registerListener",
246246
specialListener,
247-
XposedHelpers.callMethod(param.thisObject, "getDefaultSensor", Sensor.TYPE_MAGNETIC_FIELD),
247+
XposedHelpers.callMethod(param.thisObject, "getDefaultSensor", Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED),
248248
param.args[2],
249249
(android.os.Handler) param.args[3]
250250
);
@@ -273,7 +273,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
273273
);
274274
XposedHelpers.callMethod(param.thisObject, "registerListenerImpl",
275275
specialListener,
276-
XposedHelpers.callMethod(param.thisObject, "getDefaultSensor", Sensor.TYPE_MAGNETIC_FIELD),
276+
XposedHelpers.callMethod(param.thisObject, "getDefaultSensor", Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED),
277277
XposedHelpers.callStaticMethod(android.hardware.SensorManager.class, "getDelay", param.args[2]),
278278
null,
279279
param.args[3],
@@ -304,7 +304,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
304304
);
305305
XposedHelpers.callMethod(param.thisObject, "registerListenerImpl",
306306
specialListener,
307-
XposedHelpers.callMethod(param.thisObject, "getDefaultSensor", Sensor.TYPE_MAGNETIC_FIELD),
307+
XposedHelpers.callMethod(param.thisObject, "getDefaultSensor", Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED),
308308
XposedHelpers.callStaticMethod(android.hardware.SensorManager.class, "getDelay", param.args[2]),
309309
(android.os.Handler)param.args[3],
310310
0,
@@ -335,7 +335,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
335335
);
336336
XposedHelpers.callMethod(param.thisObject, "registerListenerImpl",
337337
specialListener,
338-
XposedHelpers.callMethod(param.thisObject, "getDefaultSensor", Sensor.TYPE_MAGNETIC_FIELD),
338+
XposedHelpers.callMethod(param.thisObject, "getDefaultSensor", Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED),
339339
XposedHelpers.callStaticMethod(android.hardware.SensorManager.class, "getDelay", param.args[2]),
340340
(android.os.Handler)param.args[4],
341341
param.args[3],

app/src/main/java/fr/frazew/virtualgyroscope/hooks/SensorChangeHook.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,11 @@ protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Th
157157
if (s.getType() == Sensor.TYPE_ACCELEROMETER) {
158158
this.accelerometerValues = ((float[]) (param.args[1])).clone();
159159
}
160-
if (s.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
161-
this.magneticValues = ((float[]) (param.args[1])).clone();
160+
if (s.getType() == Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED) {
161+
this.magneticValues[0] = ((float[]) (param.args[1]))[0] - ((float[]) (param.args[1]))[3];
162+
this.magneticValues[1] = ((float[]) (param.args[1]))[1] - ((float[]) (param.args[1]))[4];
163+
this.magneticValues[2] = ((float[]) (param.args[1]))[2] - ((float[]) (param.args[1]))[5];
164+
162165
if (Math.abs(lastMagneticValuesIntervalRead - ((long[]) param.args[2])[0]) * NS2S >= 1) {
163166
this.oneSecondIntervalMagneticValues[this.magneticValuesIntervalCount] = this.magneticValues;
164167
this.lastMagneticValuesIntervalRead = ((long[]) param.args[2])[0];
@@ -238,8 +241,11 @@ protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Th
238241
if (s.getType() == Sensor.TYPE_ACCELEROMETER) {
239242
this.accelerometerValues = ((float[]) (param.args[1])).clone();
240243
}
241-
if (s.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
242-
this.magneticValues = ((float[]) (param.args[1])).clone();
244+
if (s.getType() == Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED) {
245+
this.magneticValues[0] = ((float[]) (param.args[1]))[0] - ((float[]) (param.args[1]))[3];
246+
this.magneticValues[1] = ((float[]) (param.args[1]))[1] - ((float[]) (param.args[1]))[4];
247+
this.magneticValues[2] = ((float[]) (param.args[1]))[2] - ((float[]) (param.args[1]))[5];
248+
243249
if (Math.abs(lastMagneticValuesIntervalRead - (long) param.args[3]) * NS2S >= 1) {
244250
this.oneSecondIntervalMagneticValues[this.magneticValuesIntervalCount] = this.magneticValues;
245251
this.lastMagneticValuesIntervalRead = (long) param.args[3];
@@ -322,9 +328,12 @@ protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Th
322328
this.accelerometerValues = ((float[]) (param.args[1])).clone();
323329
}
324330
}
325-
if (s.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
331+
if (s.getType() == Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED) {
326332
if (Util.checkSensorResolution(this.magneticValues, (float[]) param.args[1], XposedMod.MAGNETIC_ACCURACY)) {
327-
this.magneticValues = ((float[]) (param.args[1])).clone();
333+
this.magneticValues[0] = ((float[]) (param.args[1]))[0] - ((float[]) (param.args[1]))[3];
334+
this.magneticValues[1] = ((float[]) (param.args[1]))[1] - ((float[]) (param.args[1]))[4];
335+
this.magneticValues[2] = ((float[]) (param.args[1]))[2] - ((float[]) (param.args[1]))[5];
336+
328337
if (Math.abs(lastMagneticValuesIntervalRead - (long) param.args[3]) * NS2S >= 1) {
329338
this.oneSecondIntervalMagneticValues[this.magneticValuesIntervalCount] = this.magneticValues;
330339
this.lastMagneticValuesIntervalRead = (long) param.args[3];

app/src/main/java/fr/frazew/virtualgyroscope/hooks/SystemSensorManagerHook.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static List<Object> fillSensorLists(ArrayList<Sensor> fullSensorList, Spa
3535
minDelayAccelerometer = sensor.getMinDelay();
3636
XposedMod.ACCELEROMETER_ACCURACY = sensor.getResolution();
3737
}
38-
if (sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) XposedMod.MAGNETIC_ACCURACY = sensor.getResolution();
38+
if (sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED) XposedMod.MAGNETIC_ACCURACY = sensor.getResolution();
3939
}
4040

4141
XposedHelpers.findConstructorBestMatch(Sensor.class).setAccessible(true);

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:1.3.0'
8+
classpath 'com.android.tools.build:gradle:2.1.2'
99
// in the individual module build.gradle files
1010
}
1111
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Thu May 05 16:34:12 CEST 2016
1+
#Wed Aug 03 00:10:10 CEST 2016
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip

gradlew

100644100755
File mode changed.

0 commit comments

Comments
 (0)