USB: Set FF gain for a device, not effects, apply settings before Test

Fixes Test not using new settings until the next time the setting dialog
is opened, also simplifies changing Gain
This commit is contained in:
Silent 2020-12-24 13:31:12 +01:00 committed by jackun
parent 2465b0e278
commit d65c4c1892
3 changed files with 29 additions and 8 deletions

View File

@ -928,11 +928,7 @@ namespace usb_pad
case IDOK:
{
INVERTFORCES[s->port] = SendDlgItemMessage(hWnd, IDC_CHECK1, BM_GETCHECK, 0, 0);
BYPASSCAL = SendDlgItemMessage(hWnd, IDC_CHECK2, BM_GETCHECK, 0, 0);
useRamp = !!SendDlgItemMessage(hWnd, IDC_CHECK3, BM_GETCHECK, 0, 0);
GAINZ[s->port][0] = SendMessage(GetDlgItem(hWnd, IDC_SLIDER4), TBM_GETPOS, 0, 0);
FFMULTI[s->port][0] = SendMessage(GetDlgItem(hWnd, IDC_SLIDER5), TBM_GETPOS, 0, 0);
ApplySettings(s->port);
SaveDInputConfig(s->port, s->dev_type);
SaveConfig(); // Force save to ini file
//Seems to create some dead locks
@ -957,6 +953,7 @@ namespace usb_pad
case IDC_BUTTON1:
{
//MessageBeep(MB_ICONEXCLAMATION);
ApplySettings(s->port);
TestForce(s->port);
}
break;
@ -1206,6 +1203,15 @@ namespace usb_pad
return FALSE;
}
void ApplySettings(int port)
{
INVERTFORCES[port] = SendDlgItemMessage(hWnd, IDC_CHECK1, BM_GETCHECK, 0, 0);
BYPASSCAL = SendDlgItemMessage(hWnd, IDC_CHECK2, BM_GETCHECK, 0, 0);
useRamp = !!SendDlgItemMessage(hWnd, IDC_CHECK3, BM_GETCHECK, 0, 0);
GAINZ[port][0] = SendMessage(GetDlgItem(hWnd, IDC_SLIDER4), TBM_GETPOS, 0, 0);
FFMULTI[port][0] = SendMessage(GetDlgItem(hWnd, IDC_SLIDER5), TBM_GETPOS, 0, 0);
}
void SaveDInputConfig(int port, const char* dev_type)
{
SaveSetting(TEXT("dinput"), TEXT("BYPASSCAL"), BYPASSCAL);
@ -1264,7 +1270,7 @@ namespace usb_pad
LoadSetting(section, TEXT("INVERTFORCES"), INVERTFORCES[port]);
if (!LoadSetting(section, TEXT("GAINZ"), GAINZ[port][0]))
GAINZ[port][0] = 10000;
GAINZ[port][0] = DI_FFNOMINALMAX;
if (!LoadSetting(section, TEXT("FFMULTI"), FFMULTI[port][0]))
FFMULTI[port][0] = 0;

View File

@ -364,6 +364,8 @@ namespace usb_pad
if (!device)
return;
UpdateFFBSettings(port, device);
try
{
rgdwAxes[0] = axis;
@ -381,7 +383,7 @@ namespace usb_pad
eff.dwSize = sizeof(DIEFFECT);
eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS;
eff.dwSamplePeriod = 0;
eff.dwGain = MIN(MAX(GAINZ[port][0], 0), 10000);
eff.dwGain = DI_FFNOMINALMAX;
eff.dwTriggerButton = DIEB_NOTRIGGER;
eff.dwTriggerRepeatInterval = 0;
eff.cAxes = countof(rgdwAxes);
@ -434,6 +436,15 @@ namespace usb_pad
}
}
void UpdateFFBSettings(int port, LPDIRECTINPUTDEVICE8 device)
{
DIPROPDWORD prop { sizeof(prop), sizeof(prop.diph) };
prop.diph.dwObj = 0;
prop.diph.dwHow = DIPH_DEVICE;
prop.dwData = std::clamp(GAINZ[port][0], 0, DI_FFNOMINALMAX);
device->SetProperty(DIPROP_FFGAIN, &prop.diph);
}
BOOL CALLBACK EnumJoysticksCallback(const DIDEVICEINSTANCE* pdidInstance,
VOID* pContext)
{
@ -1024,12 +1035,14 @@ namespace usb_pad
void TestForce(int port)
{
InputMapped im;
LPDIRECTINPUTDEVICE8 dev = nullptr;
if (GetInputMap(port, CID_STEERING, im))
dev = g_pJoysticks[im.index]->GetDevice();
// Gain value may have changed, so update it for the constant force effect
UpdateFFBSettings(port, dev);
SetConstantForce(port, DI_FFNOMINALMAX / 2);
Sleep(500);
SetConstantForce(port, -DI_FFNOMINALMAX / 2);

View File

@ -196,6 +196,7 @@ namespace usb_pad
extern std::vector<JoystickDevice*> g_pJoysticks;
extern std::map<int, InputMapped> g_Controls[2];
void ApplySettings(int port);
void LoadDInputConfig(int port, const char* dev_type);
void SaveDInputConfig(int port, const char* dev_type);
@ -213,6 +214,7 @@ namespace usb_pad
float GetAxisControl(int port, ControlID id);
void CreateFFB(int port, LPDIRECTINPUTDEVICE8 device, DWORD axis);
bool FindFFDevice(int port);
void UpdateFFBSettings(int port, LPDIRECTINPUTDEVICE8 device);
void AddInputMap(int port, int cid, const InputMapped& im);
void RemoveInputMap(int port, int cid);