예제 #1
0
        public static void CreateRampWithEvent(this UShortInputSig sig, ushort finalRampValue, uint timeToRampIn10msIntervals, RampChangeHandler changeHandler)
        {
            ushort currentValue = sig.UShortValue;

            if (currentValue == finalRampValue)
            {
                return;
            }

            if (changeHandler != null)
            {
                uint timems = timeToRampIn10msIntervals * 10;

                var sigChangeInterval = Math.Max(50, timems / (finalRampValue >= currentValue ? (finalRampValue - currentValue) : (currentValue - finalRampValue)));

                var uro = new UserRampObject
                {
                    sig = sig,
                    rampChangeHandler = changeHandler
                };

                uro.timerSigChange = new CTimer(RampTimerCallback, uro, sigChangeInterval, sigChangeInterval);
            }

            sig.CreateRamp(finalRampValue, timeToRampIn10msIntervals);
        }
예제 #2
0
파일: Extenstions.cs 프로젝트: uxav/lib2
        /// <summary>
        /// Ramp an analog value down at a rate determined by the total time from up to down
        /// </summary>
        /// <param name="sig">Analog sig to ramp down</param>
        /// <param name="changeCallback">Callback delegate to use to update the value when it changes</param>
        /// <param name="totalSeconds">Total time it should take to ramp down from 100 to 0%</param>
        public static void RampDown(this UShortInputSig sig, UShortInputSigRampingCallback changeCallback, double totalSeconds)
        {
            var ms           = totalSeconds * 1000;
            var relativeTime = sig.UShortValue / ms;

            sig.CreateRamp(ushort.MinValue, (uint)(relativeTime / 10));
            var t = new Thread(specific =>
            {
                var s = (UShortInputSig)specific;
                while (s.IsRamping)
                {
                    Thread.Sleep(10);
                    changeCallback(s);
                }
                changeCallback(s);
                return(null);
            }, changeCallback)
            {
                Name = string.Format("{0} RampDown Process", sig),
            };
        }
예제 #3
0
 public static void CreateRamp(this UShortInputSig sig, ushort finalRampValue, uint timeToRampIn10msIntervals)
 {
     sig.CreateRamp(finalRampValue, timeToRampIn10msIntervals);
 }