MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / AddDevice

Method AddDevice

pcsx2/Input/DInputSource.cpp:175–250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

173}
174
175bool DInputSource::AddDevice(ControllerData& cd, const std::string& name)
176{
177 HRESULT hr = cd.device->SetCooperativeLevel(m_toplevel_window, DISCL_BACKGROUND | DISCL_EXCLUSIVE);
178 if (FAILED(hr))
179 {
180 hr = cd.device->SetCooperativeLevel(m_toplevel_window, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE);
181 if (FAILED(hr))
182 {
183 Console.Error("Failed to set cooperative level for '%s'", name.c_str());
184 return false;
185 }
186
187 Console.Warning("Failed to set exclusive mode for '%s'", name.c_str());
188 }
189
190 hr = cd.device->SetDataFormat(&c_dfDIJoystick2);
191 if (FAILED(hr))
192 {
193 Console.Error("Failed to set data format for '%s'", name.c_str());
194 return false;
195 }
196
197 hr = cd.device->Acquire();
198 if (FAILED(hr))
199 {
200 Console.Error("Failed to acquire device '%s'", name.c_str());
201 return false;
202 }
203
204 DIDEVCAPS caps = {};
205 caps.dwSize = sizeof(caps);
206 hr = cd.device->GetCapabilities(&caps);
207 if (FAILED(hr))
208 {
209 Console.Error("Failed to get capabilities for '%s'", name.c_str());
210 return false;
211 }
212
213 static constexpr const u32 axis_offsets[] = {offsetof(DIJOYSTATE2, lX), offsetof(DIJOYSTATE2, lY), offsetof(DIJOYSTATE2, lZ),
214 offsetof(DIJOYSTATE2, lRz), offsetof(DIJOYSTATE2, lRx), offsetof(DIJOYSTATE2, lRy), offsetof(DIJOYSTATE2, rglSlider[0]),
215 offsetof(DIJOYSTATE2, rglSlider[1])};
216 for (const u32 offset : axis_offsets)
217 {
218 // ask for 16 bits of axis range
219 DIPROPRANGE range = {};
220 range.diph.dwSize = sizeof(range);
221 range.diph.dwHeaderSize = sizeof(range.diph);
222 range.diph.dwHow = DIPH_BYOFFSET;
223 range.diph.dwObj = static_cast<DWORD>(offset);
224 range.lMin = std::numeric_limits<s16>::min();
225 range.lMax = std::numeric_limits<s16>::max();
226 hr = cd.device->SetProperty(DIPROP_RANGE, &range.diph);
227
228 // did it apply?
229 if (SUCCEEDED(cd.device->GetProperty(DIPROP_RANGE, &range.diph)))
230 cd.axis_offsets.push_back(offset);
231 }
232

Callers

nothing calls this directly

Calls 12

minFunction · 0.50
maxFunction · 0.50
sizeFunction · 0.50
ErrorMethod · 0.45
c_strMethod · 0.45
WarningMethod · 0.45
AcquireMethod · 0.45
push_backMethod · 0.45
PollMethod · 0.45
WriteLnMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected