Android: Native motion controls

This commit is contained in:
JosJuice
2019-10-28 16:40:14 +01:00
parent 6d193d3b5a
commit b143df91be
10 changed files with 264 additions and 3 deletions

View File

@ -4,6 +4,12 @@
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false"/>
<uses-feature
android:name="android.hardware.sensor.accelerometer"
android:required="false"/>
<uses-feature
android:name="android.hardware.sensor.gyroscope"
android:required="false"/>
<uses-feature
android:name="android.hardware.gamepad"
android:required="false"/>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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