USB: Misc code cleanup

This commit is contained in:
Silent 2020-12-24 13:59:38 +01:00 committed by jackun
parent a1f213cfd0
commit 2c1ebae039
1 changed files with 56 additions and 69 deletions

View File

@ -106,7 +106,7 @@ namespace usb_pad
LONG GetAxisValueFromOffset(int axis, const DIJOYSTATE2& j) LONG GetAxisValueFromOffset(int axis, const DIJOYSTATE2& j)
{ {
#define LVX_OFFSET 8 // count POVs or not? constexpr int LVX_OFFSET = 8; // count POVs or not?
switch (axis) switch (axis)
{ {
case 0: case 0:
@ -210,7 +210,6 @@ namespace usb_pad
return j.rglFSlider[1]; return j.rglFSlider[1];
break; break;
} }
#undef LVX_OFFSET
return 0; return 0;
} }
@ -229,15 +228,15 @@ namespace usb_pad
{ {
if (m_type == CT_JOYSTICK) if (m_type == CT_JOYSTICK)
{ {
m_device->GetDeviceState(sizeof(DIJOYSTATE2), &m_controls); m_device->GetDeviceState(sizeof(m_controls.js2), &m_controls.js2);
} }
else if (m_type == CT_MOUSE) else if (m_type == CT_MOUSE)
{ {
m_device->GetDeviceState(sizeof(DIMOUSESTATE2), &m_controls); m_device->GetDeviceState(sizeof(m_controls.ms2), &m_controls.ms2);
} }
else if (m_type == CT_KEYBOARD) else if (m_type == CT_KEYBOARD)
{ {
m_device->GetDeviceState(sizeof(m_controls.kbd), &m_controls); m_device->GetDeviceState(sizeof(m_controls.kbd), &m_controls.kbd);
} }
return true; return true;
} }
@ -358,7 +357,7 @@ namespace usb_pad
void CreateFFB(int port, LPDIRECTINPUTDEVICE8 device, DWORD axis) void CreateFFB(int port, LPDIRECTINPUTDEVICE8 device, DWORD axis)
{ {
HRESULT hres = 0; HRESULT hres;
ReleaseFFB(port); ReleaseFFB(port);
if (!device) if (!device)
@ -366,8 +365,6 @@ namespace usb_pad
UpdateFFBSettings(port, device); UpdateFFBSettings(port, device);
try
{
rgdwAxes[0] = axis; rgdwAxes[0] = axis;
//LPDIRECTINPUTDEVICE8 device = joy->GetDevice(); //LPDIRECTINPUTDEVICE8 device = joy->GetDevice();
//create the constant force effect //create the constant force effect
@ -380,7 +377,7 @@ namespace usb_pad
ZeroMemory(&cRamp, sizeof(cRamp)); ZeroMemory(&cRamp, sizeof(cRamp));
//constantforce //constantforce
eff.dwSize = sizeof(DIEFFECT); eff.dwSize = sizeof(eff);
eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS;
eff.dwSamplePeriod = 0; eff.dwSamplePeriod = 0;
eff.dwGain = DI_FFNOMINALMAX; eff.dwGain = DI_FFNOMINALMAX;
@ -400,39 +397,35 @@ namespace usb_pad
cfw.lMagnitude = 0; cfw.lMagnitude = 0;
eff.cbTypeSpecificParams = sizeof(DICONSTANTFORCE); eff.cbTypeSpecificParams = sizeof(cfw);
eff.lpvTypeSpecificParams = &cfw; eff.lpvTypeSpecificParams = &cfw;
hres = device->CreateEffect(GUID_ConstantForce, &eff, &g_pEffectConstant[port], NULL); hres = device->CreateEffect(GUID_ConstantForce, &eff, &g_pEffectConstant[port], NULL);
cSpring.lNegativeCoefficient = 0; cSpring.lNegativeCoefficient = 0;
cSpring.lPositiveCoefficient = 0; cSpring.lPositiveCoefficient = 0;
effSpring.cbTypeSpecificParams = sizeof(DICONDITION); effSpring.cbTypeSpecificParams = sizeof(cSpring);
effSpring.lpvTypeSpecificParams = &cSpring; effSpring.lpvTypeSpecificParams = &cSpring;
hres = device->CreateEffect(GUID_Spring, &effSpring, &g_pEffectSpring[port], NULL); hres = device->CreateEffect(GUID_Spring, &effSpring, &g_pEffectSpring[port], NULL);
effFriction.cbTypeSpecificParams = sizeof(DICONDITION); effFriction.cbTypeSpecificParams = sizeof(cFriction);
effFriction.lpvTypeSpecificParams = &cFriction; effFriction.lpvTypeSpecificParams = &cFriction;
hres = device->CreateEffect(GUID_Friction, &effFriction, &g_pEffectFriction[port], NULL); hres = device->CreateEffect(GUID_Friction, &effFriction, &g_pEffectFriction[port], NULL);
effRamp.cbTypeSpecificParams = sizeof(DIRAMPFORCE); effRamp.cbTypeSpecificParams = sizeof(cRamp);
effRamp.lpvTypeSpecificParams = &cRamp; effRamp.lpvTypeSpecificParams = &cRamp;
hres = device->CreateEffect(GUID_RampForce, &effRamp, &g_pEffectRamp[port], NULL); hres = device->CreateEffect(GUID_RampForce, &effRamp, &g_pEffectRamp[port], NULL);
effDamper.cbTypeSpecificParams = sizeof(DICONDITION); effDamper.cbTypeSpecificParams = sizeof(cDamper);
effDamper.lpvTypeSpecificParams = &cDamper; effDamper.lpvTypeSpecificParams = &cDamper;
hres = device->CreateEffect(GUID_Damper, &effDamper, &g_pEffectDamper[port], NULL); hres = device->CreateEffect(GUID_Damper, &effDamper, &g_pEffectDamper[port], NULL);
FFB[port] = true; FFB[port] = true;
}
catch (...)
{
};
//start the effect //start the effect
if (g_pEffectConstant[port]) if (g_pEffectConstant[port])
{ {
g_pEffectConstant[port]->SetParameters(&eff, DIEP_START | DIEP_GAIN | DIEP_AXES | DIEP_DIRECTION); g_pEffectConstant[port]->Start(1, 0);
} }
} }
@ -468,9 +461,7 @@ namespace usb_pad
// enumerated axis in order to scale min/max values. // enumerated axis in order to scale min/max values.
if (pdidoi->dwType & DIDFT_AXIS) if (pdidoi->dwType & DIDFT_AXIS)
{ {
DIPROPRANGE diprg; DIPROPRANGE diprg { sizeof(diprg), sizeof(diprg.diph) };
diprg.diph.dwSize = sizeof(DIPROPRANGE);
diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
diprg.diph.dwHow = DIPH_BYID; diprg.diph.dwHow = DIPH_BYID;
diprg.diph.dwObj = pdidoi->dwType; // Specify the enumerated axis diprg.diph.dwObj = pdidoi->dwType; // Specify the enumerated axis
diprg.lMin = 0; diprg.lMin = 0;
@ -623,9 +614,7 @@ namespace usb_pad
if (!device) if (!device)
return; return;
//disable the auto-centering spring. //disable the auto-centering spring.
DIPROPDWORD dipdw; DIPROPDWORD dipdw { sizeof(dipdw), sizeof(dipdw.diph) };
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwObj = 0; dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE; dipdw.diph.dwHow = DIPH_DEVICE;
dipdw.dwData = onoff ? DIPROPAUTOCENTER_ON : DIPROPAUTOCENTER_OFF; dipdw.dwData = onoff ? DIPROPAUTOCENTER_ON : DIPROPAUTOCENTER_OFF;
@ -865,8 +854,7 @@ namespace usb_pad
auto device = joy->GetDevice(); auto device = joy->GetDevice();
device->SetDataFormat(&c_dfDIJoystick2); device->SetDataFormat(&c_dfDIJoystick2);
DIDEVCAPS diCaps; DIDEVCAPS diCaps { sizeof(diCaps) };
diCaps.dwSize = sizeof(DIDEVCAPS);
device->GetCapabilities(&diCaps); device->GetCapabilities(&diCaps);
if (diCaps.dwFlags & DIDC_FORCEFEEDBACK) if (diCaps.dwFlags & DIDC_FORCEFEEDBACK)
@ -920,8 +908,7 @@ namespace usb_pad
return false; return false;
auto device = g_pJoysticks[im.index]->GetDevice(); auto device = g_pJoysticks[im.index]->GetDevice();
DIDEVCAPS diCaps; DIDEVCAPS diCaps { sizeof(diCaps) };
diCaps.dwSize = sizeof(DIDEVCAPS);
device->GetCapabilities(&diCaps); device->GetCapabilities(&diCaps);
//has ffb? //has ffb?