2014-02-10 18:54:46 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2014-02-10 18:54:46 +00:00
|
|
|
// Refer to the license.txt file included.
|
2013-04-15 04:02:53 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "InputCommon/ControllerInterface/Android/Android.h"
|
2018-09-02 20:55:22 +00:00
|
|
|
#include <jni/AndroidCommon/IDCache.h>
|
2014-09-19 04:17:41 +00:00
|
|
|
#include <sstream>
|
2018-09-02 20:55:22 +00:00
|
|
|
#include <thread>
|
2016-06-12 15:08:04 +00:00
|
|
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
2013-04-15 04:02:53 +00:00
|
|
|
|
2019-06-17 20:39:24 +00:00
|
|
|
namespace ciface::Android
|
2013-04-15 04:02:53 +00:00
|
|
|
{
|
2016-10-16 20:39:05 +00:00
|
|
|
void PopulateDevices()
|
2013-04-15 04:02:53 +00:00
|
|
|
{
|
2016-06-12 15:08:04 +00:00
|
|
|
for (int i = 0; i < 8; ++i)
|
2016-06-25 19:46:39 +00:00
|
|
|
g_controller_interface.AddDevice(std::make_shared<Touchscreen>(i));
|
2013-04-15 04:02:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Touchscreens and stuff
|
|
|
|
std::string Touchscreen::GetName() const
|
|
|
|
{
|
|
|
|
return "Touchscreen";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Touchscreen::GetSource() const
|
|
|
|
{
|
|
|
|
return "Android";
|
|
|
|
}
|
|
|
|
|
2013-11-24 21:04:53 +00:00
|
|
|
Touchscreen::Touchscreen(int padID) : _padID(padID)
|
2013-04-15 04:02:53 +00:00
|
|
|
{
|
2015-07-22 02:28:32 +00:00
|
|
|
// GC
|
2013-11-24 21:04:53 +00:00
|
|
|
AddInput(new Button(_padID, ButtonManager::BUTTON_A));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::BUTTON_B));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::BUTTON_START));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::BUTTON_X));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::BUTTON_Y));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::BUTTON_Z));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::BUTTON_UP));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::BUTTON_DOWN));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::BUTTON_LEFT));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::BUTTON_RIGHT));
|
2019-01-07 23:24:22 +00:00
|
|
|
AddInput(new Axis(_padID, ButtonManager::STICK_MAIN_LEFT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::STICK_MAIN_RIGHT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::STICK_MAIN_UP));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::STICK_MAIN_DOWN));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::STICK_C_LEFT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::STICK_C_RIGHT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::STICK_C_UP));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::STICK_C_DOWN));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::TRIGGER_L));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::TRIGGER_R));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-07-22 02:28:32 +00:00
|
|
|
// Wiimote
|
|
|
|
AddInput(new Button(_padID, ButtonManager::WIIMOTE_BUTTON_A));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::WIIMOTE_BUTTON_B));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::WIIMOTE_BUTTON_MINUS));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::WIIMOTE_BUTTON_PLUS));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::WIIMOTE_BUTTON_HOME));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::WIIMOTE_BUTTON_1));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::WIIMOTE_BUTTON_2));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::WIIMOTE_UP));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::WIIMOTE_DOWN));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::WIIMOTE_LEFT));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::WIIMOTE_RIGHT));
|
2015-12-02 20:58:54 +00:00
|
|
|
AddInput(new Button(_padID, ButtonManager::WIIMOTE_IR_HIDE));
|
2016-01-04 12:35:04 +00:00
|
|
|
AddInput(new Button(_padID, ButtonManager::WIIMOTE_TILT_MODIFIER));
|
2015-12-02 20:58:54 +00:00
|
|
|
AddInput(new Button(_padID, ButtonManager::WIIMOTE_SHAKE_X));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::WIIMOTE_SHAKE_Y));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::WIIMOTE_SHAKE_Z));
|
2019-01-07 23:24:22 +00:00
|
|
|
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_IR_UP));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_IR_DOWN));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_IR_LEFT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_IR_RIGHT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_IR_FORWARD));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_IR_BACKWARD));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_SWING_UP));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_SWING_DOWN));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_SWING_LEFT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_SWING_RIGHT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_SWING_FORWARD));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_SWING_BACKWARD));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_TILT_LEFT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_TILT_RIGHT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_TILT_FORWARD));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::WIIMOTE_TILT_BACKWARD));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-12-02 20:58:54 +00:00
|
|
|
// Wii ext: Nunchuk
|
|
|
|
AddInput(new Button(_padID, ButtonManager::NUNCHUK_BUTTON_C));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::NUNCHUK_BUTTON_Z));
|
2016-01-04 12:35:04 +00:00
|
|
|
AddInput(new Button(_padID, ButtonManager::NUNCHUK_TILT_MODIFIER));
|
2015-12-02 20:58:54 +00:00
|
|
|
AddInput(new Button(_padID, ButtonManager::NUNCHUK_SHAKE_X));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::NUNCHUK_SHAKE_Y));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::NUNCHUK_SHAKE_Z));
|
2019-01-07 23:24:22 +00:00
|
|
|
AddInput(new Axis(_padID, ButtonManager::NUNCHUK_STICK_LEFT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::NUNCHUK_STICK_RIGHT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::NUNCHUK_STICK_UP));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::NUNCHUK_STICK_DOWN));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::NUNCHUK_SWING_LEFT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::NUNCHUK_SWING_RIGHT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::NUNCHUK_SWING_UP));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::NUNCHUK_SWING_DOWN));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::NUNCHUK_SWING_FORWARD));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::NUNCHUK_SWING_BACKWARD));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::NUNCHUK_TILT_LEFT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::NUNCHUK_TILT_RIGHT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::NUNCHUK_TILT_FORWARD));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::NUNCHUK_TILT_BACKWARD));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-12-02 20:58:54 +00:00
|
|
|
// Wii ext: Classic
|
|
|
|
AddInput(new Button(_padID, ButtonManager::CLASSIC_BUTTON_A));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::CLASSIC_BUTTON_B));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::CLASSIC_BUTTON_X));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::CLASSIC_BUTTON_Y));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::CLASSIC_BUTTON_MINUS));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::CLASSIC_BUTTON_PLUS));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::CLASSIC_BUTTON_HOME));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::CLASSIC_BUTTON_ZL));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::CLASSIC_BUTTON_ZR));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::CLASSIC_DPAD_UP));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::CLASSIC_DPAD_DOWN));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::CLASSIC_DPAD_LEFT));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::CLASSIC_DPAD_RIGHT));
|
2019-01-07 23:24:22 +00:00
|
|
|
AddInput(new Axis(_padID, ButtonManager::CLASSIC_STICK_LEFT_LEFT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::CLASSIC_STICK_LEFT_RIGHT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::CLASSIC_STICK_LEFT_UP));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::CLASSIC_STICK_LEFT_DOWN));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::CLASSIC_STICK_RIGHT_LEFT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::CLASSIC_STICK_RIGHT_RIGHT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::CLASSIC_STICK_RIGHT_UP));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::CLASSIC_STICK_RIGHT_DOWN));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::CLASSIC_TRIGGER_L));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::CLASSIC_TRIGGER_R));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-12-02 20:58:54 +00:00
|
|
|
// Wii-ext: Guitar
|
|
|
|
AddInput(new Button(_padID, ButtonManager::GUITAR_BUTTON_MINUS));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::GUITAR_BUTTON_PLUS));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::GUITAR_FRET_GREEN));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::GUITAR_FRET_RED));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::GUITAR_FRET_YELLOW));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::GUITAR_FRET_BLUE));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::GUITAR_FRET_ORANGE));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::GUITAR_STRUM_UP));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::GUITAR_STRUM_DOWN));
|
2019-01-07 23:24:22 +00:00
|
|
|
AddInput(new Axis(_padID, ButtonManager::GUITAR_STICK_LEFT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::GUITAR_STICK_RIGHT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::GUITAR_STICK_UP));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::GUITAR_STICK_DOWN));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::GUITAR_WHAMMY_BAR));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-12-02 20:58:54 +00:00
|
|
|
// Wii-ext: Drums
|
|
|
|
AddInput(new Button(_padID, ButtonManager::DRUMS_BUTTON_MINUS));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::DRUMS_BUTTON_PLUS));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::DRUMS_PAD_RED));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::DRUMS_PAD_YELLOW));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::DRUMS_PAD_BLUE));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::DRUMS_PAD_GREEN));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::DRUMS_PAD_ORANGE));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::DRUMS_PAD_BASS));
|
2019-01-07 23:24:22 +00:00
|
|
|
AddInput(new Axis(_padID, ButtonManager::DRUMS_STICK_LEFT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::DRUMS_STICK_RIGHT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::DRUMS_STICK_UP));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::DRUMS_STICK_DOWN));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-12-02 20:58:54 +00:00
|
|
|
// Wii-ext: Turntable
|
|
|
|
AddInput(new Button(_padID, ButtonManager::TURNTABLE_BUTTON_GREEN_LEFT));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::TURNTABLE_BUTTON_RED_LEFT));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::TURNTABLE_BUTTON_BLUE_LEFT));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::TURNTABLE_BUTTON_GREEN_RIGHT));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::TURNTABLE_BUTTON_RED_RIGHT));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::TURNTABLE_BUTTON_BLUE_RIGHT));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::TURNTABLE_BUTTON_MINUS));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::TURNTABLE_BUTTON_PLUS));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::TURNTABLE_BUTTON_HOME));
|
|
|
|
AddInput(new Button(_padID, ButtonManager::TURNTABLE_BUTTON_EUPHORIA));
|
2019-01-07 23:24:22 +00:00
|
|
|
AddInput(new Axis(_padID, ButtonManager::TURNTABLE_TABLE_LEFT_LEFT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::TURNTABLE_TABLE_LEFT_RIGHT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::TURNTABLE_TABLE_RIGHT_LEFT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::TURNTABLE_TABLE_RIGHT_RIGHT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::TURNTABLE_STICK_LEFT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::TURNTABLE_STICK_RIGHT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::TURNTABLE_STICK_UP));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::TURNTABLE_STICK_DOWN));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::TURNTABLE_CROSSFADE_LEFT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::TURNTABLE_CROSSFADE_RIGHT));
|
|
|
|
AddInput(new Axis(_padID, ButtonManager::TURNTABLE_EFFECT_DIAL));
|
|
|
|
|
2018-09-02 20:55:22 +00:00
|
|
|
// Rumble
|
|
|
|
AddOutput(new Motor(_padID, ButtonManager::RUMBLE));
|
2013-04-15 04:02:53 +00:00
|
|
|
}
|
|
|
|
// Buttons and stuff
|
|
|
|
|
|
|
|
std::string Touchscreen::Button::GetName() const
|
|
|
|
{
|
|
|
|
std::ostringstream ss;
|
2013-11-24 21:04:53 +00:00
|
|
|
ss << "Button " << (int)_index;
|
2013-04-15 04:02:53 +00:00
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
ControlState Touchscreen::Button::GetState() const
|
|
|
|
{
|
2013-11-24 21:04:53 +00:00
|
|
|
return ButtonManager::GetButtonPressed(_padID, _index);
|
2013-04-15 04:02:53 +00:00
|
|
|
}
|
2019-01-07 23:24:22 +00:00
|
|
|
|
2013-06-18 12:09:20 +00:00
|
|
|
std::string Touchscreen::Axis::GetName() const
|
|
|
|
{
|
|
|
|
std::ostringstream ss;
|
2013-11-24 21:04:53 +00:00
|
|
|
ss << "Axis " << (int)_index;
|
2013-06-18 12:09:20 +00:00
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
ControlState Touchscreen::Axis::GetState() const
|
|
|
|
{
|
2013-12-13 03:24:39 +00:00
|
|
|
return ButtonManager::GetAxisValue(_padID, _index) * _neg;
|
2013-06-18 12:09:20 +00:00
|
|
|
}
|
2018-09-02 20:55:22 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2019-05-29 12:22:26 +00:00
|
|
|
JNIEnv* env = IDCache::GetEnvForThread();
|
2019-01-22 00:11:11 +00:00
|
|
|
env->CallStaticVoidMethod(IDCache::GetNativeLibraryClass(), IDCache::GetDoRumble(), padID, state);
|
2018-09-02 20:55:22 +00:00
|
|
|
}
|
2019-06-17 20:39:24 +00:00
|
|
|
} // namespace ciface::Android
|