Use delegate method of grabbing struct reference

Might replace the delegate with a class method later
but this method works pretty well as is
This commit is contained in:
Travis Nickles 2017-12-11 03:57:48 -06:00
parent 05def00614
commit 41fa8cac82
2 changed files with 18 additions and 17 deletions

View File

@ -300,7 +300,7 @@ namespace DS4Windows
if (tempLightBarOnDuration != haptics.LightBarFlashDurationOn && tempLightBarOnDuration != 1 && haptics.LightBarFlashDurationOn == 0) if (tempLightBarOnDuration != haptics.LightBarFlashDurationOn && tempLightBarOnDuration != 1 && haptics.LightBarFlashDurationOn == 0)
haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = 1; haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = 1;
device.pushHapticState(haptics); device.pushHapticState(ref haptics);
} }
public static bool defaultLight = false, shuttingdown = false; public static bool defaultLight = false, shuttingdown = false;

View File

@ -1231,7 +1231,7 @@ namespace DS4Windows
{ {
if (testRumble.IsRumbleSet()) if (testRumble.IsRumbleSet())
{ {
pushHapticState(testRumble); pushHapticState(ref testRumble);
if (testRumble.RumbleMotorsExplicitlyOff) if (testRumble.RumbleMotorsExplicitlyOff)
testRumble.RumbleMotorsExplicitlyOff = false; testRumble.RumbleMotorsExplicitlyOff = false;
} }
@ -1295,42 +1295,43 @@ namespace DS4Windows
hapticStackIndex = 0; hapticStackIndex = 0;
} }
delegate void HapticItem(ref DS4HapticState haptic);
// Use the "most recently set" haptic state for each of light bar/motor. // Use the "most recently set" haptic state for each of light bar/motor.
private void setHapticState() private void setHapticState()
{ {
DS4Color lightBarColor = ligtBarColor;
byte lightBarFlashDurationOn = ledFlashOn, lightBarFlashDurationOff = ledFlashOff; byte lightBarFlashDurationOn = ledFlashOn, lightBarFlashDurationOff = ledFlashOff;
byte rumbleMotorStrengthLeftHeavySlow = leftHeavySlowRumble, byte rumbleMotorStrengthLeftHeavySlow = leftHeavySlowRumble,
rumbleMotorStrengthRightLightFast = rightLightFastRumble; rumbleMotorStrengthRightLightFast = rightLightFastRumble;
int hapticLen = hapticState.Length; int hapticLen = hapticState.Length;
for (int i=0; i < hapticLen; i++) for (int i=0; i < hapticLen; i++)
{ {
DS4HapticState haptic = hapticState[i];
if (i == hapticStackIndex) if (i == hapticStackIndex)
break; // rest haven't been used this time break; // rest haven't been used this time
if (haptic.IsLightBarSet()) ((HapticItem)((ref DS4HapticState haptic) => {
{ if (haptic.IsLightBarSet())
lightBarColor = haptic.LightBarColor; {
lightBarFlashDurationOn = haptic.LightBarFlashDurationOn; ligtBarColor = haptic.LightBarColor;
lightBarFlashDurationOff = haptic.LightBarFlashDurationOff; lightBarFlashDurationOn = haptic.LightBarFlashDurationOn;
} lightBarFlashDurationOff = haptic.LightBarFlashDurationOff;
}
if (haptic.IsRumbleSet()) if (haptic.IsRumbleSet())
{ {
rumbleMotorStrengthLeftHeavySlow = haptic.RumbleMotorStrengthLeftHeavySlow; rumbleMotorStrengthLeftHeavySlow = haptic.RumbleMotorStrengthLeftHeavySlow;
rumbleMotorStrengthRightLightFast = haptic.RumbleMotorStrengthRightLightFast; rumbleMotorStrengthRightLightFast = haptic.RumbleMotorStrengthRightLightFast;
} }
}))(ref hapticState[i]);
} }
ligtBarColor = lightBarColor;
ledFlashOn = lightBarFlashDurationOn; ledFlashOn = lightBarFlashDurationOn;
ledFlashOff = lightBarFlashDurationOff; ledFlashOff = lightBarFlashDurationOff;
leftHeavySlowRumble = rumbleMotorStrengthLeftHeavySlow; leftHeavySlowRumble = rumbleMotorStrengthLeftHeavySlow;
rightLightFastRumble = rumbleMotorStrengthRightLightFast; rightLightFastRumble = rumbleMotorStrengthRightLightFast;
} }
public void pushHapticState(DS4HapticState hs) public void pushHapticState(ref DS4HapticState hs)
{ {
int hapsLen = hapticState.Length; int hapsLen = hapticState.Length;
if (hapticStackIndex == hapsLen) if (hapticStackIndex == hapsLen)