Fixed gyroscope calibration not saved to settings file, fixes to gyroscope mouse input - it still does not work with finger hover

This commit is contained in:
pelya
2014-04-21 20:30:52 +03:00
parent 343bfe673a
commit 0c5df7594c
12 changed files with 68 additions and 44 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -136,7 +136,7 @@
<string name="controls_screenkb_drawsize">Größe der Schaltfläche Bilder</string>
<string name="cancel">Cancel</string>
<string name="controls_screenkb_custom">Custom</string>
<string name="hover_jitter_filter">Filter jitter for stylus/finger hover</string>
<string name="mouse_hover_jitter_filter">Filter jitter for stylus/finger hover</string>
<string name="remap_hwkeys_select_simple">Select action</string>
<string name="remap_hwkeys_select_more_keys">Show all keycodes</string>
<string name="display_size_small_touchpad">Small, touchpad mode</string>

View File

@@ -136,7 +136,7 @@
<string name="controls_screenkb_drawsize">Koko painike kuvia</string>
<string name="cancel">Cancel</string>
<string name="controls_screenkb_custom">Custom</string>
<string name="hover_jitter_filter">Filter jitter for stylus/finger hover</string>
<string name="mouse_hover_jitter_filter">Filter jitter for stylus/finger hover</string>
<string name="remap_hwkeys_select_simple">Select action</string>
<string name="remap_hwkeys_select_more_keys">Show all keycodes</string>
<string name="display_size_small_touchpad">Small, touchpad mode</string>

View File

@@ -173,7 +173,7 @@
<string name="no">No</string>
<string name="screenkb_custom_layout_help">Press BACK when done. Resize buttons by sliding on empty space.</string>
<string name="controls_screenkb_custom">Custom</string>
<string name="hover_jitter_filter">Filter jitter for stylus/finger hover</string>
<string name="mouse_hover_jitter_filter">Filter jitter for stylus/finger hover</string>
<string name="remap_hwkeys_select_simple">Select action</string>
<string name="remap_hwkeys_select_more_keys">Show all keycodes</string>
</resources>

View File

@@ -146,7 +146,7 @@
<string name="yes">Да</string>
<string name="no">Нет</string>
<string name="controls_screenkb_custom">Пользовательские настройки</string>
<string name="hover_jitter_filter">Фильтровать дрожание при поднесении стилуса/пальца к экрану</string>
<string name="mouse_hover_jitter_filter">Фильтровать дрожание при поднесении стилуса/пальца к экрану</string>
<string name="remap_hwkeys_select_simple">Выберите действие</string>
<string name="remap_hwkeys_select_more_keys">Показать все коды кнопок</string>
</resources>

View File

@@ -145,7 +145,7 @@
<string name="yes">Так</string>
<string name="no">Ні</string>
<string name="controls_screenkb_custom">Налаштування користувача</string>
<string name="hover_jitter_filter">Фільтрувати тремтіння при піднесенні стилуса/пальця до екрану</string>
<string name="mouse_hover_jitter_filter">Фільтрувати тремтіння при піднесенні стилуса/пальця до екрану</string>
<string name="remap_hwkeys_select_simple">Виберіть дію</string>
<string name="remap_hwkeys_select_more_keys">Показати всі коди кнопок</string>
</resources>

View File

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

View File

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