예제 #1
0
        private static Task ScheduleDevice(IPWMDevice motor)
        {
            int delayInMs = Convert.ToInt32(Math.Abs(motor.TargetDutyCycle) * REFRESH_PERIOD_IN_MS / 100.0);

            Task   t;
            double absDutyCycle = Math.Abs(motor.TargetDutyCycle);

            t = absDutyCycle > 90
                ? Task.Run(() => motor.TurnOn())
                : absDutyCycle < 10 ? Task.Run(() => motor.TurnOff()) : TurnOnThenOffAfterDelay(delayInMs, motor);
            return(t);
        }
예제 #2
0
        private static Task TurnOnThenOffAfterDelay(int delayInMs, IPWMDevice device)
        {
            device.TurnOn();

            return(Task.Delay(delayInMs).ContinueWith((_) => device.TurnOff()));
        }