forked from dolphin-emu/dolphin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GCPad.cpp
143 lines (119 loc) · 3.75 KB
/
GCPad.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
#include "Common/Common.h"
#include "Core/ConfigManager.h"
#include "Core/HW/GCPad.h"
#include "Core/HW/GCPadEmu.h"
#include "InputCommon/GCPadStatus.h"
#include "InputCommon/InputConfig.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
namespace Pad
{
static InputPlugin g_plugin("GCPadNew", _trans("Pad"), "GCPad");
InputPlugin *GetPlugin()
{
return &g_plugin;
}
void Shutdown()
{
std::vector<ControllerEmu*>::const_iterator
i = g_plugin.controllers.begin(),
e = g_plugin.controllers.end();
for ( ; i!=e; ++i )
delete *i;
g_plugin.controllers.clear();
g_controller_interface.Shutdown();
}
// if plugin isn't initialized, init and load config
void Initialize(void* const hwnd)
{
// add 4 gcpads
for (unsigned int i=0; i<4; ++i)
g_plugin.controllers.push_back(new GCPad(i));
g_controller_interface.SetHwnd(hwnd);
g_controller_interface.Initialize();
// load the saved controller config
g_plugin.LoadConfig(true);
}
void GetStatus(u8 _numPAD, GCPadStatus* _pPADStatus)
{
memset(_pPADStatus, 0, sizeof(*_pPADStatus));
_pPADStatus->err = PAD_ERR_NONE;
std::unique_lock<std::recursive_mutex> lk(g_plugin.controls_lock, std::try_to_lock);
if (!lk.owns_lock())
{
// if gui has lock (messing with controls), skip this input cycle
// center axes and return
_pPADStatus->stickX = GCPadStatus::MAIN_STICK_CENTER_X;
_pPADStatus->stickY = GCPadStatus::MAIN_STICK_CENTER_Y;
_pPADStatus->substickX = GCPadStatus::C_STICK_CENTER_X;
_pPADStatus->substickY = GCPadStatus::C_STICK_CENTER_Y;
return;
}
// if we are on the next input cycle, update output and input
// if we can get a lock
static int _last_numPAD = 4;
if (_numPAD <= _last_numPAD)
{
g_controller_interface.UpdateOutput();
g_controller_interface.UpdateInput();
}
_last_numPAD = _numPAD;
// get input
((GCPad*)g_plugin.controllers[_numPAD])->GetInput(_pPADStatus);
}
// __________________________________________________________________________________________________
// Function: Rumble
// Purpose: Pad rumble!
// input: _numPad - Which pad to rumble.
// _uType - Command type (Stop=0, Rumble=1, Stop Hard=2).
// _uStrength - Strength of the Rumble
// output: none
//
void Rumble(u8 _numPAD, unsigned int _uType, unsigned int _uStrength)
{
std::unique_lock<std::recursive_mutex> lk(g_plugin.controls_lock, std::try_to_lock);
if (lk.owns_lock())
{
// TODO: this has potential to not stop rumble if user is messing with GUI at the perfect time
// set rumble
if (1 == _uType && _uStrength > 2)
{
((GCPad*)g_plugin.controllers[ _numPAD ])->SetOutput(255);
}
else
{
((GCPad*)g_plugin.controllers[ _numPAD ])->SetOutput(0);
}
}
}
// __________________________________________________________________________________________________
// Function: Motor
// Purpose: For devices with constant Force feedback
// input: _numPAD - The pad to operate on
// _uType - 06 = Motor On, 04 = Motor Off
// _uStrength - 00 = Left Strong, 127 = Left Weak, 128 = Right Weak, 255 = Right Strong
// output: none
//
void Motor(u8 _numPAD, unsigned int _uType, unsigned int _uStrength)
{
std::unique_lock<std::recursive_mutex> lk(g_plugin.controls_lock, std::try_to_lock);
if (lk.owns_lock())
{
// TODO: this has potential to not stop rumble if user is messing with GUI at the perfect time
// set rumble
if (_uType == 6)
{
((GCPad*)g_plugin.controllers[ _numPAD ])->SetMotor(_uStrength);
}
}
}
bool GetMicButton(u8 pad)
{
std::unique_lock<std::recursive_mutex> lk(g_plugin.controls_lock, std::try_to_lock);
if (!lk.owns_lock())
return false;
return ((GCPad*)g_plugin.controllers[pad])->GetMicButton();
}
}