diff options
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface')
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/Android/Android.cpp | 33 | ||||
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/Android/Android.h | 13 |
2 files changed, 46 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(); +} } } diff --git a/Source/Core/InputCommon/ControllerInterface/Android/Android.h b/Source/Core/InputCommon/ControllerInterface/Android/Android.h index bf588719c2..deb23539ce 100644 --- a/Source/Core/InputCommon/ControllerInterface/Android/Android.h +++ b/Source/Core/InputCommon/ControllerInterface/Android/Android.h @@ -41,6 +41,19 @@ private: const ButtonManager::ButtonType _index; const float _neg; }; + class Motor : public Core::Device::Output + { + public: + Motor(int padID, ButtonManager::ButtonType index) : _padID(padID), _index(index) {} + ~Motor(); + std::string GetName() const override; + void SetState(ControlState state) override; + + private: + const int _padID; + const ButtonManager::ButtonType _index; + static void Rumble(int padID, double state); + }; public: Touchscreen(int padID); |
