diff options
| author | zackhow <zackhow@gmail.com> | 2018-09-02 16:55:22 -0400 |
|---|---|---|
| committer | zackhow <zackhow@gmail.com> | 2018-09-07 08:54:03 -0400 |
| commit | 126ff8dc5f513b01c750cd15e19f9c1e7acf06db (patch) | |
| tree | bb5d1be0d899750aa840f1e3ccd82a294f9c7843 /Source/Core/InputCommon/ControllerInterface/Android/Android.cpp | |
| parent | 3405c7d420cb909e00a3140ab2e31b911afe176c (diff) | |
Android: Add rumble for phone
This currently only supports using the internal vibrate on a phone for rumble.
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/Android/Android.cpp')
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/Android/Android.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp b/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp index 983108f356..b5faf422de 100644 --- a/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp @@ -3,7 +3,9 @@ // Refer to the license.txt file included. #include "InputCommon/ControllerInterface/Android/Android.h" +#include <jni/AndroidCommon/IDCache.h> #include <sstream> +#include <thread> #include "InputCommon/ControllerInterface/ControllerInterface.h" namespace ciface @@ -190,6 +192,8 @@ Touchscreen::Touchscreen(int padID) : _padID(padID) new Axis(_padID, ButtonManager::TURNTABLE_CROSSFADE_RIGHT)); AddAnalogInputs(new Axis(_padID, ButtonManager::TURNTABLE_EFFECT_DIAL), new Axis(_padID, ButtonManager::TURNTABLE_EFFECT_DIAL)); + // Rumble + AddOutput(new Motor(_padID, ButtonManager::RUMBLE)); } // Buttons and stuff @@ -215,5 +219,34 @@ ControlState Touchscreen::Axis::GetState() const { return ButtonManager::GetAxisValue(_padID, _index) * _neg; } + +Touchscreen::Motor::~Motor() +{ +} + +std::string Touchscreen::Motor::GetName() const +{ + std::ostringstream ss; + ss << "Rumble " << (int)_index; + return ss.str(); +} + +void Touchscreen::Motor::SetState(ControlState state) +{ + if (state > 0) + { + std::thread(Rumble, _padID, state).detach(); + } +} + +void Touchscreen::Motor::Rumble(int padID, double state) +{ + JNIEnv* env; + IDCache::GetJavaVM()->AttachCurrentThread(&env, nullptr); + jmethodID rumbleMethod = + env->GetStaticMethodID(IDCache::GetNativeLibraryClass(), "rumble", "(ID)V"); + env->CallStaticVoidMethod(IDCache::GetNativeLibraryClass(), rumbleMethod, padID, state); + IDCache::GetJavaVM()->DetachCurrentThread(); +} } } |
