diff options
| author | JosJuice <josjuice@gmail.com> | 2019-10-28 16:40:14 +0100 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2019-11-20 18:22:20 +0100 |
| commit | b143df91be5c7f18a61666baa4a5b673d2cfd2cd (patch) | |
| tree | 13188b3807a0eb9cc3b393127c820a5917d75208 /Source/Android/app/src/main/java/org | |
| parent | 6d193d3b5afa2a3f5e8960c18189eec949b7f1bb (diff) | |
Android: Native motion controls
Diffstat (limited to 'Source/Android/app/src/main/java/org')
4 files changed, 120 insertions, 1 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java index 0595100e09..5bb6a92b23 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java @@ -195,6 +195,18 @@ public final class NativeLibrary public static final int TURNTABLE_CROSSFADE = 622; public static final int TURNTABLE_CROSSFADE_LEFT = 623; public static final int TURNTABLE_CROSSFADE_RIGHT = 624; + public static final int WIIMOTE_ACCEL_LEFT = 625; + public static final int WIIMOTE_ACCEL_RIGHT = 626; + public static final int WIIMOTE_ACCEL_FORWARD = 627; + public static final int WIIMOTE_ACCEL_BACKWARD = 628; + public static final int WIIMOTE_ACCEL_UP = 629; + public static final int WIIMOTE_ACCEL_DOWN = 630; + public static final int WIIMOTE_GYRO_PITCH_UP = 631; + public static final int WIIMOTE_GYRO_PITCH_DOWN = 632; + public static final int WIIMOTE_GYRO_ROLL_LEFT = 633; + public static final int WIIMOTE_GYRO_ROLL_RIGHT = 634; + public static final int WIIMOTE_GYRO_YAW_LEFT = 635; + public static final int WIIMOTE_GYRO_YAW_RIGHT = 636; } /** diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java index ad97625af0..ac31446250 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java @@ -48,6 +48,7 @@ import org.dolphinemu.dolphinemu.utils.ControllerMappingHelper; import org.dolphinemu.dolphinemu.utils.FileBrowserHelper; import org.dolphinemu.dolphinemu.utils.Java_GCAdapter; import org.dolphinemu.dolphinemu.utils.Java_WiimoteAdapter; +import org.dolphinemu.dolphinemu.utils.MotionListener; import org.dolphinemu.dolphinemu.utils.Rumble; import org.dolphinemu.dolphinemu.utils.TvUtil; @@ -66,6 +67,7 @@ public final class EmulationActivity extends AppCompatActivity private EmulationFragment mEmulationFragment; private SharedPreferences mPreferences; + private MotionListener mMotionListener; private ControllerMappingHelper mControllerMappingHelper; private Settings mSettings; @@ -258,6 +260,7 @@ public final class EmulationActivity extends AppCompatActivity // first launch emulation and then ask the core which console we're emulating sIsGameCubeGame = Platform.fromNativeInt(mPlatform) == Platform.GAMECUBE; mDeviceHasTouchScreen = getPackageManager().hasSystemFeature("android.hardware.touchscreen"); + mMotionListener = new MotionListener(this); mControllerMappingHelper = new ControllerMappingHelper(); int themeId; @@ -348,6 +351,22 @@ public final class EmulationActivity extends AppCompatActivity } @Override + protected void onResume() + { + super.onResume(); + if (!sIsGameCubeGame) + mMotionListener.enable(); + } + + @Override + protected void onPause() + { + super.onPause(); + if (!sIsGameCubeGame) + mMotionListener.disable(); + } + + @Override protected void onStop() { super.onStop(); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java index 727240b478..2b54e2ac1a 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java @@ -34,7 +34,7 @@ public final class DirectoryInitialization "org.dolphinemu.dolphinemu.DIRECTORY_INITIALIZATION"; public static final String EXTRA_STATE = "directoryState"; - private static final Integer WiimoteNewVersion = 2; + private static final int WiimoteNewVersion = 3; // Last changed in PR 8439 private static volatile DirectoryInitializationState directoryState = null; private static String userPath; private static String internalPath; diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/MotionListener.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/MotionListener.java new file mode 100644 index 0000000000..98ee46a40e --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/MotionListener.java @@ -0,0 +1,88 @@ +package org.dolphinemu.dolphinemu.utils; + +import android.content.Context; +import android.hardware.Sensor; +import android.hardware.SensorEvent; +import android.hardware.SensorEventListener; +import android.hardware.SensorManager; + +import org.dolphinemu.dolphinemu.NativeLibrary; +import org.dolphinemu.dolphinemu.NativeLibrary.ButtonType; + +public class MotionListener implements SensorEventListener +{ + private final SensorManager mSensorManager; + private final Sensor mAccelSensor; + private final Sensor mGyroSensor; + + // The same sampling period as for Wii Remotes + private static final int SAMPLING_PERIOD_US = 1000000 / 200; + + public MotionListener(Context context) + { + mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); + mAccelSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); + mGyroSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); + } + + @Override + public void onSensorChanged(SensorEvent sensorEvent) + { + if (sensorEvent.sensor == mAccelSensor) + { + float x = -sensorEvent.values[0]; + float y = -sensorEvent.values[1]; + float z = sensorEvent.values[2]; + NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice, + ButtonType.WIIMOTE_ACCEL_LEFT, x); + NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice, + ButtonType.WIIMOTE_ACCEL_RIGHT, x); + NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice, + ButtonType.WIIMOTE_ACCEL_FORWARD, y); + NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice, + ButtonType.WIIMOTE_ACCEL_BACKWARD, y); + NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice, + ButtonType.WIIMOTE_ACCEL_UP, z); + NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice, + ButtonType.WIIMOTE_ACCEL_DOWN, z); + } + + if (sensorEvent.sensor == mGyroSensor) + { + float x = -sensorEvent.values[0]; + float y = -sensorEvent.values[1]; + float z = sensorEvent.values[2]; + NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice, + ButtonType.WIIMOTE_GYRO_PITCH_UP, x); + NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice, + ButtonType.WIIMOTE_GYRO_PITCH_DOWN, x); + NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice, + ButtonType.WIIMOTE_GYRO_ROLL_LEFT, y); + NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice, + ButtonType.WIIMOTE_GYRO_ROLL_RIGHT, y); + NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice, + ButtonType.WIIMOTE_GYRO_YAW_LEFT, z); + NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice, + ButtonType.WIIMOTE_GYRO_YAW_RIGHT, z); + } + } + + @Override + public void onAccuracyChanged(Sensor sensor, int i) + { + // We don't care about this + } + + public void enable() + { + if (mAccelSensor != null) + mSensorManager.registerListener(this, mAccelSensor, SAMPLING_PERIOD_US); + if (mGyroSensor != null) + mSensorManager.registerListener(this, mGyroSensor, SAMPLING_PERIOD_US); + } + + public void disable() + { + mSensorManager.unregisterListener(this); + } +} |
