Ejemplo n.º 1
0
        // NOTE: Frequency not supported
        public override void TriggerHapticVibration(uint deviceIndex, float durationSeconds = 0.01f, float frequency = 85.0f, float amplitude = 0.125f, float startSecondsFromNow = 0.0f)
        {
            InputDevice device;

            if (indexMap.TryGetDevice(deviceIndex, out device))
            {
                HapticCapabilities capabilities;
                if (device.TryGetHapticCapabilities(out capabilities))
                {
                    if (capabilities.supportsImpulse)
                    {
                        var now = Time.unscaledTime;
                        hapticStates[deviceIndex] = new HapticState()
                        {
                            amplitude = amplitude,
                            startTime = now + startSecondsFromNow,
                            endTime   = now + startSecondsFromNow + durationSeconds,
                        };

                        if (deviceIndex > maxHapticStateIndex)
                        {
                            maxHapticStateIndex = deviceIndex;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 /// Public functions for altoController class
 public void ChangeHaptic(HapticState newHaptic)
 {
     if (hapticState != newHaptic && !impacting)
     {
         hapticState = newHaptic;
     }
 }
Ejemplo n.º 3
0
        IEnumerator ChangeHapticTimer(float time, bool impact = false, HapticState nextState = HapticState.None)
        {
            yield return(new WaitForSeconds(time));

            hapticState = nextState;
            if (impact)
            {
                impacting = false;
            }
        }
Ejemplo n.º 4
0
 public void ImpactHaptic(HapticState nextHaptic, float timer = 0.75f)
 {
     hapticState = HapticState.Impact;
     impacting   = true;
     StartCoroutine(ChangeHapticTimer(timer, impacting, nextHaptic));
 }
Ejemplo n.º 5
0
 void Start()
 {
     hapticState = HapticState.None;
 }
Ejemplo n.º 6
0
        public static void updateLightBar(Device device, int deviceNum, State cState, StateExposed eState, Mouse tp)
        {
            LightBarColour color;

            if (!defualtLight && !forcelight[deviceNum])
            {
                if (UseCustomLed[deviceNum])
                {
                    if (LedAsBatteryIndicator[deviceNum])
                    {
                        var fullColor = CustomColour[deviceNum];
                        var lowColor  = LowColour[deviceNum];

                        color = getTransitionedColor(lowColor, fullColor, device.Battery);
                    }
                    else
                    {
                        color = CustomColour[deviceNum];
                    }
                }
                else
                {
                    if (Rainbow[deviceNum] > 0)
                    {
// Display rainbow
                        var now = DateTime.UtcNow;
                        if (now >= oldnow + TimeSpan.FromMilliseconds(10)) //update by the millisecond that way it's a smooth transtion
                        {
                            oldnow = now;
                            if (device.Charging)
                            {
                                counters[deviceNum] -= 1.5 * 3 / Rainbow[deviceNum];
                            }
                            else
                            {
                                counters[deviceNum] += 1.5 * 3 / Rainbow[deviceNum];
                            }
                        }
                        if (counters[deviceNum] < 0)
                        {
                            counters[deviceNum] = 180000;
                        }
                        if (counters[deviceNum] > 180000)
                        {
                            counters[deviceNum] = 0;
                        }
                        if (LedAsBatteryIndicator[deviceNum])
                        {
                            color = HuetoRGB((float)counters[deviceNum] % 360, (byte)(2.55 * device.Battery));
                        }
                        else
                        {
                            color = HuetoRGB((float)counters[deviceNum] % 360, 255);
                        }
                    }
                    else if (LedAsBatteryIndicator[deviceNum])
                    {
                        //if (device.Charging == false || device.Battery >= 100) // when charged, don't show the charging animation
                        {
                            var fullColor = MainColour[deviceNum];
                            var lowColor  = LowColour[deviceNum];

                            color = getTransitionedColor(lowColor, fullColor, (uint)device.Battery);
                        }
                    }
                    else
                    {
                        color = MainColour[deviceNum];
                    }
                }

                if (device.Battery <= FlashAt[deviceNum] && !defualtLight && !device.Charging)
                {
                    if (!(FlashColour[deviceNum].Red == 0 &&
                          FlashColour[deviceNum].Green == 0 &&
                          FlashColour[deviceNum].Blue == 0))
                    {
                        color = FlashColour[deviceNum];
                    }
                    if (FlashType[deviceNum] == 1)
                    {
                        if (fadetimer[deviceNum] <= 0)
                        {
                            fadedirection[deviceNum] = true;
                        }
                        else if (fadetimer[deviceNum] >= 100)
                        {
                            fadedirection[deviceNum] = false;
                        }
                        if (fadedirection[deviceNum])
                        {
                            fadetimer[deviceNum] += 1;
                        }
                        else
                        {
                            fadetimer[deviceNum] -= 1;
                        }
                        color = getTransitionedColor(color, new LightBarColour(0, 0, 0), fadetimer[deviceNum]);
                    }
                }

                if (IdleDisconnectTimeout[deviceNum] > 0 && LedAsBatteryIndicator[deviceNum] && (!device.Charging || device.Battery >= 100))
                {
//Fade lightbar by idle time
                    var timeratio = new TimeSpan(DateTime.UtcNow.Ticks - device.LastActive.Ticks);
                    var botratio  = timeratio.TotalMilliseconds;
                    var topratio  = TimeSpan.FromSeconds(IdleDisconnectTimeout[deviceNum]).TotalMilliseconds;
                    var ratio     = botratio / topratio * 100;
                    if (ratio >= 50 && ratio <= 100)
                    {
                        color = getTransitionedColor(color, new LightBarColour(0, 0, 0), (uint)((ratio - 50) * 2));
                    }
                    else if (ratio >= 100)
                    {
                        color = getTransitionedColor(color, new LightBarColour(0, 0, 0), 100);
                    }
                }
                if (device.Charging && device.Battery < 100)
                {
                    switch (ChargingType[deviceNum])
                    {
                    case 1:
                        if (fadetimer[deviceNum] <= 0)
                        {
                            fadedirection[deviceNum] = true;
                        }
                        else if (fadetimer[deviceNum] >= 105)
                        {
                            fadedirection[deviceNum] = false;
                        }
                        if (fadedirection[deviceNum])
                        {
                            fadetimer[deviceNum] += .1;
                        }
                        else
                        {
                            fadetimer[deviceNum] -= .1;
                        }
                        color = getTransitionedColor(color, new LightBarColour(0, 0, 0), fadetimer[deviceNum]);
                        break;

                    case 2:
                        counters[deviceNum] += .167;
                        color = HuetoRGB((float)counters[deviceNum] % 360, 255);
                        break;

                    case 3:
                        color = ChargingColour[deviceNum];
                        break;

                    default:
                        break;
                    }
                }
            }
            else if (forcelight[deviceNum])
            {
                color = forcedColor[deviceNum];
            }
            else if (shuttingdown)
            {
                color = new LightBarColour(0, 0, 0);
            }
            else
            {
                if (device.ConnectionType == ConnectionType.BT)
                {
                    color = new LightBarColour(32, 64, 64);
                }
                else
                {
                    color = new LightBarColour(0, 0, 0);
                }
            }
            var distanceprofile = ProfilePath[deviceNum].ToLower().Contains("distance") || tempprofilename[deviceNum].ToLower().Contains("distance");

            if (distanceprofile && !defualtLight)
            {
                //Thing I did for Distance
                var rumble = device.LeftHeavySlowRumble / 2.55f;
                var max    = Math.Max(color.Red, Math.Max(color.Green, color.Blue));
                if (device.LeftHeavySlowRumble > 100)
                {
                    color = getTransitionedColor(new LightBarColour(max, max, 0), new LightBarColour(255, 0, 0), rumble);
                }
                else
                {
                    color = getTransitionedColor(color, getTransitionedColor(new LightBarColour(max, max, 0), new LightBarColour(255, 0, 0), 39.6078f),
                                                 device.LeftHeavySlowRumble);
                }
            }
            var haptics = new HapticState
            {
                LightBarColour = color
            };

            if (haptics.IsLightBarSet())
            {
                if (forcelight[deviceNum] && forcedFlash[deviceNum] > 0)
                {
                    haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = (byte)(25 - forcedFlash[deviceNum]);
                    haptics.LightBarExplicitlyOff    = true;
                }
                else if (device.Battery <= FlashAt[deviceNum] && FlashType[deviceNum] == 0 && !defualtLight && !device.Charging)
                {
                    var level = device.Battery / 10;
                    //if (level >= 10)
                    //level = 0; // all values of ~0% or >~100% are rendered the same
                    haptics.LightBarFlashDurationOn  = BatteryIndicatorDurations[level, 0];
                    haptics.LightBarFlashDurationOff = BatteryIndicatorDurations[level, 1];
                }
                else if (distanceprofile && device.LeftHeavySlowRumble > 155) //also part of Distance
                {
                    haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = (byte)(-device.LeftHeavySlowRumble + 265);
                    haptics.LightBarExplicitlyOff    = true;
                }
                else
                {
                    //haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = 1;
                    haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = 0;
                    haptics.LightBarExplicitlyOff    = true;
                }
            }
            else
            {
                haptics.LightBarExplicitlyOff = true;
            }
            if (device.LightBarOnDuration != haptics.LightBarFlashDurationOn && device.LightBarOnDuration != 1 && haptics.LightBarFlashDurationOn == 0)
            {
                haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = 1;
            }
            if (device.LightBarOnDuration == 1) //helps better reset the color
            {
                System.Threading.Thread.Sleep(5);
            }
            device.pushHapticState(haptics);
        }