diff --git a/Source/Android/app/src/main/AndroidManifest.xml b/Source/Android/app/src/main/AndroidManifest.xml index 623343a352..9988818067 100644 --- a/Source/Android/app/src/main/AndroidManifest.xml +++ b/Source/Android/app/src/main/AndroidManifest.xml @@ -4,6 +4,12 @@ + + diff --git a/Source/Android/app/src/main/assets/WiimoteNew.ini b/Source/Android/app/src/main/assets/WiimoteNew.ini index 2ebd9d61d9..ac47ee3828 100644 --- a/Source/Android/app/src/main/assets/WiimoteNew.ini +++ b/Source/Android/app/src/main/assets/WiimoteNew.ini @@ -135,6 +135,18 @@ Turntable/Stick/Radius = 100,000000 Turntable/Effect/Dial = `Axis 621` Turntable/Crossfade/Left = `Axis 623` Turntable/Crossfade/Right = `Axis 624` +IMUAccelerometer/Left = `Axis 625` +IMUAccelerometer/Right = `Axis 626` +IMUAccelerometer/Forward = `Axis 627` +IMUAccelerometer/Backward = `Axis 628` +IMUAccelerometer/Up = `Axis 629` +IMUAccelerometer/Down = `Axis 630` +IMUGyroscope/Pitch Up = `Axis 631` +IMUGyroscope/Pitch Down = `Axis 632` +IMUGyroscope/Roll Left = `Axis 633` +IMUGyroscope/Roll Right = `Axis 634` +IMUGyroscope/Yaw Left = `Axis 635` +IMUGyroscope/Yaw Right = `Axis 636` Source = 1 Rumble/Motor = `Rumble 700` [Wiimote2] @@ -274,6 +286,18 @@ Turntable/Stick/Radius = 100,000000 Turntable/Effect/Dial = `Axis 621` Turntable/Crossfade/Left = `Axis 623` Turntable/Crossfade/Right = `Axis 624` +IMUAccelerometer/Left = `Axis 625` +IMUAccelerometer/Right = `Axis 626` +IMUAccelerometer/Forward = `Axis 627` +IMUAccelerometer/Backward = `Axis 628` +IMUAccelerometer/Up = `Axis 629` +IMUAccelerometer/Down = `Axis 630` +IMUGyroscope/Pitch Up = `Axis 631` +IMUGyroscope/Pitch Down = `Axis 632` +IMUGyroscope/Roll Left = `Axis 633` +IMUGyroscope/Roll Right = `Axis 634` +IMUGyroscope/Yaw Left = `Axis 635` +IMUGyroscope/Yaw Right = `Axis 636` Source = 0 Rumble/Motor = `Rumble 700` [Wiimote3] @@ -413,6 +437,18 @@ Turntable/Stick/Radius = 100,000000 Turntable/Effect/Dial = `Axis 621` Turntable/Crossfade/Left = `Axis 623` Turntable/Crossfade/Right = `Axis 624` +IMUAccelerometer/Left = `Axis 625` +IMUAccelerometer/Right = `Axis 626` +IMUAccelerometer/Forward = `Axis 627` +IMUAccelerometer/Backward = `Axis 628` +IMUAccelerometer/Up = `Axis 629` +IMUAccelerometer/Down = `Axis 630` +IMUGyroscope/Pitch Up = `Axis 631` +IMUGyroscope/Pitch Down = `Axis 632` +IMUGyroscope/Roll Left = `Axis 633` +IMUGyroscope/Roll Right = `Axis 634` +IMUGyroscope/Yaw Left = `Axis 635` +IMUGyroscope/Yaw Right = `Axis 636` Source = 0 Rumble/Motor = `Rumble 700` [Wiimote4] @@ -552,5 +588,17 @@ Turntable/Stick/Radius = 100,000000 Turntable/Effect/Dial = `Axis 621` Turntable/Crossfade/Left = `Axis 623` Turntable/Crossfade/Right = `Axis 624` +IMUAccelerometer/Left = `Axis 625` +IMUAccelerometer/Right = `Axis 626` +IMUAccelerometer/Forward = `Axis 627` +IMUAccelerometer/Backward = `Axis 628` +IMUAccelerometer/Up = `Axis 629` +IMUAccelerometer/Down = `Axis 630` +IMUGyroscope/Pitch Up = `Axis 631` +IMUGyroscope/Pitch Down = `Axis 632` +IMUGyroscope/Roll Left = `Axis 633` +IMUGyroscope/Roll Right = `Axis 634` +IMUGyroscope/Yaw Left = `Axis 635` +IMUGyroscope/Yaw Right = `Axis 636` Source = 0 Rumble/Motor = `Rumble 700` diff --git a/Source/Android/app/src/main/assets/WiimoteProfile.ini b/Source/Android/app/src/main/assets/WiimoteProfile.ini index 2546736d13..503b8b8af0 100644 --- a/Source/Android/app/src/main/assets/WiimoteProfile.ini +++ b/Source/Android/app/src/main/assets/WiimoteProfile.ini @@ -135,4 +135,16 @@ Turntable/Stick/Radius = 100,000000 Turntable/Effect/Dial = `Axis 621` Turntable/Crossfade/Left = `Axis 623` Turntable/Crossfade/Right = `Axis 624` +IMUAccelerometer/Left = `Axis 625` +IMUAccelerometer/Right = `Axis 626` +IMUAccelerometer/Forward = `Axis 627` +IMUAccelerometer/Backward = `Axis 628` +IMUAccelerometer/Up = `Axis 629` +IMUAccelerometer/Down = `Axis 630` +IMUGyroscope/Pitch Up = `Axis 631` +IMUGyroscope/Pitch Down = `Axis 632` +IMUGyroscope/Roll Left = `Axis 633` +IMUGyroscope/Roll Right = `Axis 634` +IMUGyroscope/Yaw Left = `Axis 635` +IMUGyroscope/Yaw Right = `Axis 636` Rumble/Motor = `Rumble 700` 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; @@ -347,6 +350,22 @@ public final class EmulationActivity extends AppCompatActivity mPlatform = savedInstanceState.getInt(EXTRA_PLATFORM); } + @Override + protected void onResume() + { + super.onResume(); + if (!sIsGameCubeGame) + mMotionListener.enable(); + } + + @Override + protected void onPause() + { + super.onPause(); + if (!sIsGameCubeGame) + mMotionListener.disable(); + } + @Override protected void 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); + } +} diff --git a/Source/Android/jni/ButtonManager.cpp b/Source/Android/jni/ButtonManager.cpp index 1ba6de758e..bd02525db4 100644 --- a/Source/Android/jni/ButtonManager.cpp +++ b/Source/Android/jni/ButtonManager.cpp @@ -18,7 +18,7 @@ namespace ButtonManager namespace { constexpr char touchScreenKey[] = "Touchscreen"; -constexpr std::array configStrings{{ +constexpr std::array configStrings{{ // GC "InputA", "InputB", @@ -168,11 +168,24 @@ constexpr std::array configStrings{{ "TurntableEffDial", "TurntableCrossLeft", "TurntableCrossRight", + // Wiimote IMU + "WiimoteAccelLeft", + "WiimoteAccelRight", + "WiimoteAccelForward", + "WiimoteAccelBackward", + "WiimoteAccelUp", + "WiimoteAccelDown", + "WiimoteGyroPitchUp", + "WiimoteGyroPitchDown", + "WiimoteGyroRollLeft", + "WiimoteGyroRollRight", + "WiimoteGyroYawLeft", + "WiimoteGyroYawRight", // Rumble "Rumble", }}; -constexpr std::array configTypes{{ +constexpr std::array configTypes{{ // GC BUTTON_A, BUTTON_B, @@ -322,6 +335,19 @@ constexpr std::array configTypes{{ TURNTABLE_EFFECT_DIAL, TURNTABLE_CROSSFADE_LEFT, TURNTABLE_CROSSFADE_RIGHT, + // Wiimote IMU + WIIMOTE_ACCEL_LEFT, + WIIMOTE_ACCEL_RIGHT, + WIIMOTE_ACCEL_FORWARD, + WIIMOTE_ACCEL_BACKWARD, + WIIMOTE_ACCEL_UP, + WIIMOTE_ACCEL_DOWN, + WIIMOTE_GYRO_PITCH_UP, + WIIMOTE_GYRO_PITCH_DOWN, + WIIMOTE_GYRO_ROLL_LEFT, + WIIMOTE_GYRO_ROLL_RIGHT, + WIIMOTE_GYRO_YAW_LEFT, + WIIMOTE_GYRO_YAW_RIGHT, // Rumble RUMBLE, }}; @@ -562,6 +588,29 @@ void Init(const std::string& gameId) new sBind(a, TURNTABLE_CROSSFADE_LEFT, BIND_AXIS, TURNTABLE_CROSSFADE_LEFT, -1.0f)); AddBind(touchScreenKey, new sBind(a, TURNTABLE_CROSSFADE_RIGHT, BIND_AXIS, TURNTABLE_CROSSFADE_RIGHT, 1.0f)); + + // Wiimote IMU + AddBind(touchScreenKey, new sBind(a, WIIMOTE_ACCEL_LEFT, BIND_AXIS, WIIMOTE_ACCEL_LEFT, 1.0f)); + AddBind(touchScreenKey, + new sBind(a, WIIMOTE_ACCEL_RIGHT, BIND_AXIS, WIIMOTE_ACCEL_RIGHT, -1.0f)); + AddBind(touchScreenKey, + new sBind(a, WIIMOTE_ACCEL_FORWARD, BIND_AXIS, WIIMOTE_ACCEL_FORWARD, -1.0f)); + AddBind(touchScreenKey, + new sBind(a, WIIMOTE_ACCEL_BACKWARD, BIND_AXIS, WIIMOTE_ACCEL_BACKWARD, 1.0f)); + AddBind(touchScreenKey, new sBind(a, WIIMOTE_ACCEL_UP, BIND_AXIS, WIIMOTE_ACCEL_UP, 1.0f)); + AddBind(touchScreenKey, new sBind(a, WIIMOTE_ACCEL_DOWN, BIND_AXIS, WIIMOTE_ACCEL_DOWN, -1.0f)); + AddBind(touchScreenKey, + new sBind(a, WIIMOTE_GYRO_PITCH_UP, BIND_AXIS, WIIMOTE_GYRO_PITCH_UP, -1.0f)); + AddBind(touchScreenKey, + new sBind(a, WIIMOTE_GYRO_PITCH_DOWN, BIND_AXIS, WIIMOTE_GYRO_PITCH_DOWN, 1.0f)); + AddBind(touchScreenKey, + new sBind(a, WIIMOTE_GYRO_ROLL_LEFT, BIND_AXIS, WIIMOTE_GYRO_ROLL_LEFT, 1.0f)); + AddBind(touchScreenKey, + new sBind(a, WIIMOTE_GYRO_ROLL_RIGHT, BIND_AXIS, WIIMOTE_GYRO_ROLL_RIGHT, -1.0f)); + AddBind(touchScreenKey, + new sBind(a, WIIMOTE_GYRO_YAW_LEFT, BIND_AXIS, WIIMOTE_GYRO_YAW_LEFT, 1.0f)); + AddBind(touchScreenKey, + new sBind(a, WIIMOTE_GYRO_YAW_RIGHT, BIND_AXIS, WIIMOTE_GYRO_YAW_RIGHT, -1.0f)); } // Init our controller bindings IniFile ini; diff --git a/Source/Android/jni/ButtonManager.h b/Source/Android/jni/ButtonManager.h index b7fd2f7647..71722c54d6 100644 --- a/Source/Android/jni/ButtonManager.h +++ b/Source/Android/jni/ButtonManager.h @@ -176,6 +176,19 @@ enum ButtonType TURNTABLE_CROSSFADE = 622, // To Be Used on Java Side TURNTABLE_CROSSFADE_LEFT = 623, TURNTABLE_CROSSFADE_RIGHT = 624, + // Wiimote IMU + WIIMOTE_ACCEL_LEFT = 625, + WIIMOTE_ACCEL_RIGHT = 626, + WIIMOTE_ACCEL_FORWARD = 627, + WIIMOTE_ACCEL_BACKWARD = 628, + WIIMOTE_ACCEL_UP = 629, + WIIMOTE_ACCEL_DOWN = 630, + WIIMOTE_GYRO_PITCH_UP = 631, + WIIMOTE_GYRO_PITCH_DOWN = 632, + WIIMOTE_GYRO_ROLL_LEFT = 633, + WIIMOTE_GYRO_ROLL_RIGHT = 634, + WIIMOTE_GYRO_YAW_LEFT = 635, + WIIMOTE_GYRO_YAW_RIGHT = 636, // Rumble RUMBLE = 700, }; diff --git a/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp b/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp index 910b7553c9..78fc029374 100644 --- a/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp @@ -185,6 +185,20 @@ Touchscreen::Touchscreen(int padID) : _padID(padID) AddInput(new Axis(_padID, ButtonManager::TURNTABLE_CROSSFADE_RIGHT)); AddInput(new Axis(_padID, ButtonManager::TURNTABLE_EFFECT_DIAL)); + // Wiimote IMU + AddInput(new Axis(_padID, ButtonManager::WIIMOTE_ACCEL_LEFT)); + AddInput(new Axis(_padID, ButtonManager::WIIMOTE_ACCEL_RIGHT)); + AddInput(new Axis(_padID, ButtonManager::WIIMOTE_ACCEL_FORWARD)); + AddInput(new Axis(_padID, ButtonManager::WIIMOTE_ACCEL_BACKWARD)); + AddInput(new Axis(_padID, ButtonManager::WIIMOTE_ACCEL_UP)); + AddInput(new Axis(_padID, ButtonManager::WIIMOTE_ACCEL_DOWN)); + AddInput(new Axis(_padID, ButtonManager::WIIMOTE_GYRO_PITCH_UP)); + AddInput(new Axis(_padID, ButtonManager::WIIMOTE_GYRO_PITCH_DOWN)); + AddInput(new Axis(_padID, ButtonManager::WIIMOTE_GYRO_ROLL_LEFT)); + AddInput(new Axis(_padID, ButtonManager::WIIMOTE_GYRO_ROLL_RIGHT)); + AddInput(new Axis(_padID, ButtonManager::WIIMOTE_GYRO_YAW_LEFT)); + AddInput(new Axis(_padID, ButtonManager::WIIMOTE_GYRO_YAW_RIGHT)); + // Rumble AddOutput(new Motor(_padID, ButtonManager::RUMBLE)); }