diff --git a/project/java/Accelerometer.java b/project/java/Accelerometer.java
index b786bfb22..5525199ea 100644
--- a/project/java/Accelerometer.java
+++ b/project/java/Accelerometer.java
@@ -89,7 +89,7 @@ class AccelerometerReader implements SensorEventListener
static class GyroscopeListener implements SensorEventListener
{
- public float x1, x2, xc, y1, y2, yc, z1, z2, zc;
+ public float x1 = 0.0f, x2 = 0.0f, xc = 0.0f, y1 = 0.0f, y2 = 0.0f, yc = 0.0f, z1 = 0.0f, z2 = 0.0f, zc = 0.0f;
public GyroscopeListener()
{
}
diff --git a/project/java/Globals.java b/project/java/Globals.java
index 781ecef17..81e72ddb9 100644
--- a/project/java/Globals.java
+++ b/project/java/Globals.java
@@ -102,7 +102,7 @@ class Globals
public static boolean MoveMouseWithJoystick = false;
public static int MoveMouseWithJoystickSpeed = 0;
public static int MoveMouseWithJoystickAccel = 0;
- public static boolean MoveMouseWithGyroscope = true;
+ public static boolean MoveMouseWithGyroscope = false;
public static int MoveMouseWithGyroscopeSpeed = 2;
public static boolean ClickMouseWithDpad = false;
public static boolean RelativeMouseMovement = ForceRelativeMouseMode; // Laptop touchpad mode
@@ -129,8 +129,6 @@ class Globals
public static boolean VideoLinearFilter = true;
public static boolean MultiThreadedVideo = false;
public static boolean BrokenLibCMessageShown = false;
- // Gyroscope calibration
- public static float gyro_x1, gyro_x2, gyro_xc, gyro_y1, gyro_y2, gyro_yc, gyro_z1, gyro_z2, gyro_zc;
public static boolean OuyaEmulation = false; // For debugging
public static boolean RedirectStdout = false; // For debugging
diff --git a/project/java/Settings.java b/project/java/Settings.java
index 7dddbb464..d88f7f61b 100644
--- a/project/java/Settings.java
+++ b/project/java/Settings.java
@@ -161,18 +161,20 @@ class Settings
out.writeBoolean(Globals.BrokenLibCMessageShown);
out.writeInt(Globals.TouchscreenKeyboardDrawSize);
out.writeInt(p.getApplicationVersion());
- out.writeFloat(Globals.gyro_x1);
- out.writeFloat(Globals.gyro_x2);
- out.writeFloat(Globals.gyro_xc);
- out.writeFloat(Globals.gyro_y1);
- out.writeFloat(Globals.gyro_y2);
- out.writeFloat(Globals.gyro_yc);
- out.writeFloat(Globals.gyro_z1);
- out.writeFloat(Globals.gyro_z2);
- out.writeFloat(Globals.gyro_zc);
+ out.writeFloat(AccelerometerReader.gyro.x1);
+ out.writeFloat(AccelerometerReader.gyro.x2);
+ out.writeFloat(AccelerometerReader.gyro.xc);
+ out.writeFloat(AccelerometerReader.gyro.y1);
+ out.writeFloat(AccelerometerReader.gyro.y2);
+ out.writeFloat(AccelerometerReader.gyro.yc);
+ out.writeFloat(AccelerometerReader.gyro.z1);
+ out.writeFloat(AccelerometerReader.gyro.z2);
+ out.writeFloat(AccelerometerReader.gyro.zc);
out.writeBoolean(Globals.OuyaEmulation);
out.writeBoolean(Globals.HoverJitterFilter);
+ out.writeBoolean(Globals.MoveMouseWithGyroscope);
+ out.writeInt(Globals.MoveMouseWithGyroscopeSpeed);
out.close();
settingsLoaded = true;
@@ -345,18 +347,20 @@ class Settings
Globals.BrokenLibCMessageShown = settingsFile.readBoolean();
Globals.TouchscreenKeyboardDrawSize = settingsFile.readInt();
int cfgVersion = settingsFile.readInt();
- Globals.gyro_x1 = settingsFile.readFloat();
- Globals.gyro_x2 = settingsFile.readFloat();
- Globals.gyro_xc = settingsFile.readFloat();
- Globals.gyro_y1 = settingsFile.readFloat();
- Globals.gyro_y2 = settingsFile.readFloat();
- Globals.gyro_yc = settingsFile.readFloat();
- Globals.gyro_z1 = settingsFile.readFloat();
- Globals.gyro_z2 = settingsFile.readFloat();
- Globals.gyro_zc = settingsFile.readFloat();
+ AccelerometerReader.gyro.x1 = settingsFile.readFloat();
+ AccelerometerReader.gyro.x2 = settingsFile.readFloat();
+ AccelerometerReader.gyro.xc = settingsFile.readFloat();
+ AccelerometerReader.gyro.y1 = settingsFile.readFloat();
+ AccelerometerReader.gyro.y2 = settingsFile.readFloat();
+ AccelerometerReader.gyro.yc = settingsFile.readFloat();
+ AccelerometerReader.gyro.z1 = settingsFile.readFloat();
+ AccelerometerReader.gyro.z2 = settingsFile.readFloat();
+ AccelerometerReader.gyro.zc = settingsFile.readFloat();
Globals.OuyaEmulation = settingsFile.readBoolean();
Globals.HoverJitterFilter = settingsFile.readBoolean();
+ Globals.MoveMouseWithGyroscope = settingsFile.readBoolean();
+ Globals.MoveMouseWithGyroscopeSpeed = settingsFile.readInt();
settingsLoaded = true;
diff --git a/project/java/SettingsMenuMisc.java b/project/java/SettingsMenuMisc.java
index a3d9b1968..164038b01 100644
--- a/project/java/SettingsMenuMisc.java
+++ b/project/java/SettingsMenuMisc.java
@@ -566,7 +566,7 @@ class SettingsMenuMisc extends SettingsMenu
}
boolean enabled()
{
- return Globals.AppUsesGyroscope;
+ return Globals.AppUsesGyroscope || Globals.MoveMouseWithGyroscope;
}
void run (final MainActivity p)
{
@@ -664,12 +664,12 @@ class SettingsMenuMisc extends SettingsMenu
AccelerometerReader.gyro.xc += x;
AccelerometerReader.gyro.yc += y;
AccelerometerReader.gyro.zc += z;
- AccelerometerReader.gyro.x1 = Math.min(AccelerometerReader.gyro.x1, x * 1.1f); // Small safety bound coefficient
- AccelerometerReader.gyro.x2 = Math.max(AccelerometerReader.gyro.x2, x * 1.1f);
- AccelerometerReader.gyro.y1 = Math.min(AccelerometerReader.gyro.y1, y * 1.1f);
- AccelerometerReader.gyro.y2 = Math.max(AccelerometerReader.gyro.y2, y * 1.1f);
- AccelerometerReader.gyro.z1 = Math.min(AccelerometerReader.gyro.z1, z * 1.1f);
- AccelerometerReader.gyro.z2 = Math.max(AccelerometerReader.gyro.z2, z * 1.1f);
+ AccelerometerReader.gyro.x1 = Math.min(AccelerometerReader.gyro.x1, x * 1.02f); // Small safety bound coefficient
+ AccelerometerReader.gyro.x2 = Math.max(AccelerometerReader.gyro.x2, x * 1.02f);
+ AccelerometerReader.gyro.y1 = Math.min(AccelerometerReader.gyro.y1, y * 1.02f);
+ AccelerometerReader.gyro.y2 = Math.max(AccelerometerReader.gyro.y2, y * 1.02f);
+ AccelerometerReader.gyro.z1 = Math.min(AccelerometerReader.gyro.z1, z * 1.02f);
+ AccelerometerReader.gyro.z2 = Math.max(AccelerometerReader.gyro.z2, z * 1.02f);
final Matrix m = new Matrix();
RectF src = new RectF(0, 0, bmp.getWidth(), bmp.getHeight());
RectF dst = new RectF( x * 5000 + p.getVideoLayout().getWidth()/2 - 50, y * 5000 + p.getVideoLayout().getHeight()/2 - 50,
@@ -694,6 +694,10 @@ class SettingsMenuMisc extends SettingsMenu
AccelerometerReader.gyro.xc /= (float)numEvents;
AccelerometerReader.gyro.yc /= (float)numEvents;
AccelerometerReader.gyro.zc /= (float)numEvents;
+ Log.i("SDL", "libSDL: gyroscope calibration: " +
+ AccelerometerReader.gyro.x1 + " < " + AccelerometerReader.gyro.xc + " > " + AccelerometerReader.gyro.x2 + " : " +
+ AccelerometerReader.gyro.y1 + " < " + AccelerometerReader.gyro.yc + " > " + AccelerometerReader.gyro.y2 + " : " +
+ AccelerometerReader.gyro.z1 + " < " + AccelerometerReader.gyro.zc + " > " + AccelerometerReader.gyro.z2);
}
p.runOnUiThread(new Runnable()
{
diff --git a/project/java/Video.java b/project/java/Video.java
index b032f96e6..da1743f5c 100644
--- a/project/java/Video.java
+++ b/project/java/Video.java
@@ -657,6 +657,8 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
Settings.nativeSetEnv( "DISPLAY_RESOLUTION_HEIGHT", String.valueOf(Math.min(mWidth, mHeight)) ); // In Kitkat with immersive mode, getWindowManager().getDefaultDisplay().getMetrics() return inaccurate height
accelerometer = new AccelerometerReader(context);
+ if( Globals.MoveMouseWithGyroscope )
+ startAccelerometerGyroscope(1);
// Tweak video thread priority, if user selected big audio buffer
if(Globals.AudioBufferConfig >= 2)
Thread.currentThread().setPriority( (Thread.NORM_PRIORITY + Thread.MIN_PRIORITY) / 2 ); // Lower than normal
@@ -760,12 +762,12 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
return context.isScreenKeyboardShown() ? 1 : 0;
}
- public void setScreenKeyboardHintMessage(String s)
+ public void setScreenKeyboardHintMessage(String s) // Called from native code
{
context.setScreenKeyboardHintMessage(s);
}
- public void startAccelerometerGyroscope(int started)
+ public void startAccelerometerGyroscope(int started) // Called from native code
{
accelerometer.openedBySDL = (started != 0);
if( accelerometer.openedBySDL && !mPaused )
diff --git a/project/java/translations/unsupported/values-de/strings.xml b/project/java/translations/unsupported/values-de/strings.xml
index 89d8a25fe..8d6551fda 100644
--- a/project/java/translations/unsupported/values-de/strings.xml
+++ b/project/java/translations/unsupported/values-de/strings.xml
@@ -136,7 +136,7 @@
Größe der Schaltfläche Bilder
Cancel
Custom
-Filter jitter for stylus/finger hover
+Filter jitter for stylus/finger hover
Select action
Show all keycodes
Small, touchpad mode
diff --git a/project/java/translations/unsupported/values-fi/strings.xml b/project/java/translations/unsupported/values-fi/strings.xml
index ed53e1491..105ca7913 100644
--- a/project/java/translations/unsupported/values-fi/strings.xml
+++ b/project/java/translations/unsupported/values-fi/strings.xml
@@ -136,7 +136,7 @@
Koko painike kuvia
Cancel
Custom
-Filter jitter for stylus/finger hover
+Filter jitter for stylus/finger hover
Select action
Show all keycodes
Small, touchpad mode
diff --git a/project/java/translations/values-fr/strings.xml b/project/java/translations/values-fr/strings.xml
index f76113c24..3c1ed1cc3 100644
--- a/project/java/translations/values-fr/strings.xml
+++ b/project/java/translations/values-fr/strings.xml
@@ -173,7 +173,7 @@
No
Press BACK when done. Resize buttons by sliding on empty space.
Custom
-Filter jitter for stylus/finger hover
+Filter jitter for stylus/finger hover
Select action
Show all keycodes
diff --git a/project/java/translations/values-ru/strings.xml b/project/java/translations/values-ru/strings.xml
index 71a9f33e6..ea560921f 100644
--- a/project/java/translations/values-ru/strings.xml
+++ b/project/java/translations/values-ru/strings.xml
@@ -146,7 +146,7 @@
Да
Нет
Пользовательские настройки
-Фильтровать дрожание при поднесении стилуса/пальца к экрану
+Фильтровать дрожание при поднесении стилуса/пальца к экрану
Выберите действие
Показать все коды кнопок
diff --git a/project/java/translations/values-uk/strings.xml b/project/java/translations/values-uk/strings.xml
index dbb411d75..30d085f2e 100644
--- a/project/java/translations/values-uk/strings.xml
+++ b/project/java/translations/values-uk/strings.xml
@@ -145,7 +145,7 @@
Так
Ні
Налаштування користувача
-Фільтрувати тремтіння при піднесенні стилуса/пальця до екрану
+Фільтрувати тремтіння при піднесенні стилуса/пальця до екрану
Виберіть дію
Показати всі коди кнопок
diff --git a/project/jni/application/xserver/AndroidAppSettings.cfg b/project/jni/application/xserver/AndroidAppSettings.cfg
index bbb3e09c1..add4e38f7 100644
--- a/project/jni/application/xserver/AndroidAppSettings.cfg
+++ b/project/jni/application/xserver/AndroidAppSettings.cfg
@@ -200,7 +200,7 @@ HiddenMenuOptions=''
# new SettingsMenuMisc.ShowReadme(), (AppUsesMouse \&\& \! ForceRelativeMouseMode \? new SettingsMenuMouse.DisplaySizeConfig(true) : new SettingsMenu.DummyMenu()), new SettingsMenuMisc.OptionalDownloadConfig(true), new SettingsMenuMisc.GyroscopeCalibration()
# Available menu items:
# SettingsMenu.OkButton SettingsMenu.DummyMenu SettingsMenu.MainMenu SettingsMenuMisc.DownloadConfig SettingsMenuMisc.OptionalDownloadConfig SettingsMenuMisc.AudioConfig SettingsMenuMisc.VideoSettingsConfig SettingsMenuMisc.ShowReadme SettingsMenuMisc.GyroscopeCalibration SettingsMenuMisc.ResetToDefaultsConfig SettingsMenuMouse.MouseConfigMainMenu SettingsMenuMouse.DisplaySizeConfig SettingsMenuMouse.LeftClickConfig SettingsMenuMouse.RightClickConfig SettingsMenuMouse.AdditionalMouseConfig SettingsMenuMouse.JoystickMouseConfig SettingsMenuMouse.TouchPressureMeasurementTool SettingsMenuMouse.CalibrateTouchscreenMenu SettingsMenuKeyboard.KeyboardConfigMainMenu SettingsMenuKeyboard.ScreenKeyboardSizeConfig SettingsMenuKeyboard.ScreenKeyboardDrawSizeConfig SettingsMenuKeyboard.ScreenKeyboardThemeConfig SettingsMenuKeyboard.ScreenKeyboardTransparencyConfig SettingsMenuKeyboard.RemapHwKeysConfig SettingsMenuKeyboard.RemapScreenKbConfig SettingsMenuKeyboard.ScreenGesturesConfig SettingsMenuKeyboard.CustomizeScreenKbLayout
-FirstStartMenuOptions='SettingsMenu.DummyMenu'
+FirstStartMenuOptions='SettingsMenuMisc.GyroscopeCalibration'
# Enable multi-ABI binary, with hardware FPU support - it will also work on old devices,
# but .apk size is 2x bigger (y) / (n) / (x86) / (all)
diff --git a/project/jni/sdl-1.2/src/video/android/SDL_androidinput.c b/project/jni/sdl-1.2/src/video/android/SDL_androidinput.c
index 00b956e45..9049530d2 100644
--- a/project/jni/sdl-1.2/src/video/android/SDL_androidinput.c
+++ b/project/jni/sdl-1.2/src/video/android/SDL_androidinput.c
@@ -134,7 +134,7 @@ static int hoverJitterFilter = 1;
static int hoverX, hoverY, hoverTime = 0, hoverMouseFreeze = 0, hoverDeadzone = 0;
static int rightMouseButtonLongPress = 1;
static int moveMouseWithGyroscope = 0;
-static float moveMouseWithGyroscopeSpeed = 1.0f;
+static float moveMouseWithGyroscopeSpeed = 2.0f;
static int moveMouseWithGyroscopeX = 0;
static int moveMouseWithGyroscopeY = 0;
@@ -863,8 +863,22 @@ static void ProcessMoveMouseWithGyroscope(float gx, float gy, float gz)
return;
gx += gz; // Ignore Z?
- gx *= moveMouseWithGyroscopeSpeed;
- gy *= moveMouseWithGyroscopeSpeed;
+ gx *= -moveMouseWithGyroscopeSpeed;
+ gy *= moveMouseWithGyroscopeSpeed; // Screen has Y coordinate inverted
+
+ //gx *= 10; // debug
+ //gy *= 10; // debug
+
+ static float subpixelX = 0.0f, subpixelY = 0.0f;
+
+ gx += subpixelX;
+ gy += subpixelY;
+ float t = truncf(gx);
+ subpixelX = gx - t;
+ gx = t;
+ t = truncf(gy);
+ subpixelY = gy - t;
+ gy = t;
// TODO: mutex here?
// If race condition happens, mouse will jump at random across the screen. Nothing serious.
@@ -1087,8 +1101,9 @@ JAVA_EXPORT_NAME(Settings_nativeSetMouseUsed) (JNIEnv* env, jobject thiz,
hoverJitterFilter = HoverJitterFilter;
rightMouseButtonLongPress = RightMouseButtonLongPress;
moveMouseWithGyroscope = MoveMouseWithGyroscope;
- moveMouseWithGyroscopeSpeed = 0.0625f * MoveMouseWithGyroscopeSpeed * MoveMouseWithGyroscopeSpeed + 0.375 * MoveMouseWithGyroscopeSpeed + 1.0f; // Scale value from 0.5 to 2, with 1 at the middle
- //__android_log_print(ANDROID_LOG_INFO, "libSDL", "relativeMovementSpeed %d relativeMovementAccel %d", relativeMovementSpeed, relativeMovementAccel);
+ moveMouseWithGyroscopeSpeed = 0.0625f * MoveMouseWithGyroscopeSpeed * MoveMouseWithGyroscopeSpeed + 0.125f * MoveMouseWithGyroscopeSpeed + 0.5f; // Scale value from 0.5 to 2, with 1 at the middle
+ moveMouseWithGyroscopeSpeed *= 2.0f;
+ __android_log_print(ANDROID_LOG_INFO, "libSDL", "moveMouseWithGyroscopeSpeed %d = %f", MoveMouseWithGyroscopeSpeed, moveMouseWithGyroscopeSpeed);
}
JNIEXPORT void JNICALL
@@ -1497,7 +1512,8 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
if( joystick->index == JOY_ACCELGYRO )
{
joystick->naxes = 8; // Normalized accelerometer = axes 0-1, gyroscope = axes 2-4, raw accelerometer = axes 5-7
- SDL_ANDROID_CallJavaStartAccelerometerGyroscope(1);
+ if( !moveMouseWithGyroscope )
+ SDL_ANDROID_CallJavaStartAccelerometerGyroscope(1);
}
if( joystick->index >= JOY_GAMEPAD1 && joystick->index <= JOY_GAMEPAD4 )
{
@@ -1517,7 +1533,7 @@ void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
{
SDL_ANDROID_CurrentJoysticks[joystick->index] = NULL;
- if( joystick->index == JOY_ACCELGYRO )
+ if( joystick->index == JOY_ACCELGYRO && !moveMouseWithGyroscope )
SDL_ANDROID_CallJavaStartAccelerometerGyroscope(0);
return;
}