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>