Android: Let WiimoteEmu know whether we have accelerometer/gyroscope

This commit is contained in:
JosJuice 2019-11-20 19:40:47 +01:00
parent 4d838212e2
commit c8b8a60033
5 changed files with 54 additions and 12 deletions

View File

@ -265,6 +265,9 @@ public final class NativeLibrary
Rumble.checkRumble(padID, state); Rumble.checkRumble(padID, state);
} }
public static native void SetMotionSensorsEnabled(boolean accelerometerEnabled,
boolean gyroscopeEnabled);
public static native void NewGameIniFile(); public static native void NewGameIniFile();
public static native void LoadGameIniFile(String gameId); public static native void LoadGameIniFile(String gameId);

View File

@ -101,10 +101,14 @@ public class MotionListener implements SensorEventListener
mSensorManager.registerListener(this, mAccelSensor, SAMPLING_PERIOD_US); mSensorManager.registerListener(this, mAccelSensor, SAMPLING_PERIOD_US);
if (mGyroSensor != null) if (mGyroSensor != null)
mSensorManager.registerListener(this, mGyroSensor, SAMPLING_PERIOD_US); mSensorManager.registerListener(this, mGyroSensor, SAMPLING_PERIOD_US);
NativeLibrary.SetMotionSensorsEnabled(mAccelSensor != null, mGyroSensor != null);
} }
public void disable() public void disable()
{ {
mSensorManager.unregisterListener(this); mSensorManager.unregisterListener(this);
NativeLibrary.SetMotionSensorsEnabled(false, false);
} }
} }

View File

@ -47,6 +47,8 @@
#include "DiscIO/Enums.h" #include "DiscIO/Enums.h"
#include "DiscIO/Volume.h" #include "DiscIO/Volume.h"
#include "InputCommon/ControllerInterface/Android/Android.h"
#include "UICommon/UICommon.h" #include "UICommon/UICommon.h"
#include "VideoCommon/OnScreenDisplay.h" #include "VideoCommon/OnScreenDisplay.h"
@ -200,6 +202,8 @@ JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePa
JNIEnv* env, jobject obj, jstring jDevice, jint Button, jint Action); JNIEnv* env, jobject obj, jstring jDevice, jint Button, jint Action);
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadMoveEvent( JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadMoveEvent(
JNIEnv* env, jobject obj, jstring jDevice, jint Axis, jfloat Value); JNIEnv* env, jobject obj, jstring jDevice, jint Axis, jfloat Value);
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetMotionSensorsEnabled(
JNIEnv* env, jobject obj, jboolean accelerometer_enabled, jboolean gyroscope_enabled);
JNIEXPORT jstring JNICALL JNIEXPORT jstring JNICALL
Java_org_dolphinemu_dolphinemu_NativeLibrary_GetVersionString(JNIEnv* env, jobject obj); Java_org_dolphinemu_dolphinemu_NativeLibrary_GetVersionString(JNIEnv* env, jobject obj);
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGitRevision(JNIEnv* env, JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGitRevision(JNIEnv* env,
@ -308,6 +312,12 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadMov
ButtonManager::GamepadAxisEvent(GetJString(env, jDevice), Axis, Value); ButtonManager::GamepadAxisEvent(GetJString(env, jDevice), Axis, Value);
} }
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetMotionSensorsEnabled(
JNIEnv* env, jobject obj, jboolean accelerometer_enabled, jboolean gyroscope_enabled)
{
ciface::Android::SetMotionSensorsEnabled(accelerometer_enabled, gyroscope_enabled);
}
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetVersionString(JNIEnv* env, JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetVersionString(JNIEnv* env,
jobject obj) jobject obj)
{ {

View File

@ -10,6 +10,21 @@
namespace ciface::Android namespace ciface::Android
{ {
static bool s_accelerometer_enabled = false;
static bool s_gyroscope_enabled = false;
void SetMotionSensorsEnabled(bool accelerometer_enabled, bool gyroscope_enabled)
{
const bool any_changes =
s_accelerometer_enabled != accelerometer_enabled || s_gyroscope_enabled != gyroscope_enabled;
s_accelerometer_enabled = accelerometer_enabled;
s_gyroscope_enabled = gyroscope_enabled;
if (any_changes)
g_controller_interface.RefreshDevices();
}
void PopulateDevices() void PopulateDevices()
{ {
for (int i = 0; i < 8; ++i) for (int i = 0; i < 8; ++i)
@ -186,18 +201,26 @@ Touchscreen::Touchscreen(int padID) : _padID(padID)
AddInput(new Axis(_padID, ButtonManager::TURNTABLE_EFFECT_DIAL)); AddInput(new Axis(_padID, ButtonManager::TURNTABLE_EFFECT_DIAL));
// Wiimote IMU // Wiimote IMU
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_ACCEL_LEFT)); // Only add inputs if we actually can receive data from the relevant sensor.
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_ACCEL_RIGHT)); // Whether inputs exist affects what WiimoteEmu gets when calling ControlReference::BoundCount.
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_ACCEL_FORWARD)); if (s_accelerometer_enabled)
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_ACCEL_BACKWARD)); {
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_ACCEL_UP)); AddInput(new Axis(_padID, ButtonManager::WIIMOTE_ACCEL_LEFT));
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_ACCEL_DOWN)); AddInput(new Axis(_padID, ButtonManager::WIIMOTE_ACCEL_RIGHT));
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_GYRO_PITCH_UP)); AddInput(new Axis(_padID, ButtonManager::WIIMOTE_ACCEL_FORWARD));
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_GYRO_PITCH_DOWN)); AddInput(new Axis(_padID, ButtonManager::WIIMOTE_ACCEL_BACKWARD));
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_GYRO_ROLL_LEFT)); AddInput(new Axis(_padID, ButtonManager::WIIMOTE_ACCEL_UP));
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_GYRO_ROLL_RIGHT)); AddInput(new Axis(_padID, ButtonManager::WIIMOTE_ACCEL_DOWN));
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_GYRO_YAW_LEFT)); }
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_GYRO_YAW_RIGHT)); if (s_gyroscope_enabled)
{
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 // Rumble
AddOutput(new Motor(_padID, ButtonManager::RUMBLE)); AddOutput(new Motor(_padID, ButtonManager::RUMBLE));

View File

@ -9,6 +9,8 @@
namespace ciface::Android namespace ciface::Android
{ {
void SetMotionSensorsEnabled(bool accelerometer_enabled, bool gyroscope_enabled);
void PopulateDevices(); void PopulateDevices();
class Touchscreen : public Core::Device class Touchscreen : public Core::Device