public Windows10PwmDriverChannel(WinPwm.PwmController winController, int channelIndex)
 {
     _winPin = winController.OpenPin(channelIndex);
     if (_winPin == null)
     {
         throw new ArgumentOutOfRangeException($"The PWM chip is unable to open a channel at index {channelIndex}.", nameof(channelIndex));
     }
 }
Ejemplo n.º 2
0
        static void LedInit(PwmController controller)
        {
            Red = controller.OpenPin(LedPinRed);
            Green = controller.OpenPin(LedPinGreen);
            Blue = controller.OpenPin(LedPinBlue);

            Red.Start();
            Green.Start();
            Blue.Start();
        }
Ejemplo n.º 3
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            deferral = taskInstance.GetDeferral();
            // pwmController =  (await PwmController.GetControllersAsync(PwmPCA9685.PwmProviderPCA9685.GetPwmProvider()))[0];
            pwmController = (await PwmController.GetControllersAsync(PwmSoftware.PwmProviderSoftware.GetPwmProvider()))[0];
            pwmController.SetDesiredFrequency(50);
            motorPin = pwmController.OpenPin(13);
            motorPin.SetActiveDutyCyclePercentage(RestingPulseLegnth);
            motorPin.Start();
            secondMotorPin = pwmController.OpenPin(6);
            secondMotorPin.SetActiveDutyCyclePercentage(RestingPulseLegnth);
            secondMotorPin.Start();

            timer = ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick, TimeSpan.FromSeconds(2));

        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Windows10PwmChannel"/> class.
        /// </summary>
        /// <param name="chip">The PWM chip number.</param>
        /// <param name="channel">The PWM channel number.</param>
        /// <param name="frequency">The frequency in hertz.</param>
        /// <param name="dutyCycle">The duty cycle percentage represented as a value between 0.0 and 1.0.</param>
        public Windows10PwmChannel(
            int chip,
            int channel,
            int frequency    = 400,
            double dutyCycle = 0.5)
        {
            // When running on Hummingboard we require to use the default chip.
            var  deviceInfo     = new EasClientDeviceInformation();
            bool useDefaultChip = false;

            if (deviceInfo.SystemProductName.IndexOf("Hummingboard", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                useDefaultChip = true;
            }

            // Open the Windows PWM controller for the specified PWM chip.
            string deviceSelector = useDefaultChip ? WinPwm.PwmController.GetDeviceSelector() : WinPwm.PwmController.GetDeviceSelector($"PWM{chip}");

            DeviceInformationCollection?deviceInformationCollection = DeviceInformation.FindAllAsync(deviceSelector).WaitForCompletion();

            if (deviceInformationCollection is null || deviceInformationCollection.Count == 0)
            {
                throw new ArgumentException($"No PWM device exists for PWM chip at index {chip}.", nameof(chip));
            }

            string deviceId = deviceInformationCollection[0].Id;

            WinPwm.PwmController?winController = WinPwm.PwmController.FromIdAsync(deviceId).WaitForCompletion();

            if (winController is null)
            {
                throw new Exception("A PWM device could not be found.");
            }

            WinPwm.PwmPin?winPin = winController.OpenPin(channel);
            if (winPin is null)
            {
                throw new ArgumentOutOfRangeException(nameof(channel), $"The PWM chip is unable to open a channel at index {channel}.");
            }

            _winController = winController;
            _winPin        = winPin;
            Frequency      = frequency;
            DutyCycle      = dutyCycle;
        }
 public void Dispose()
 {
     this.Stop();
     _winPin?.Dispose();
     _winPin = null;
 }
Ejemplo n.º 6
0
 /// <inheritdoc/>
 public void Dispose()
 {
     if (bluePin != null)
     {
         if (bluePin.IsStarted) { bluePin.Stop(); }
         bluePin.Dispose();
         bluePin = null;
     }
     if (greenPin != null)
     {
         if (greenPin.IsStarted) { greenPin.Stop(); }
         greenPin.Dispose();
         greenPin = null;
     }
     if (redPin != null)
     {
         if (redPin.IsStarted) { redPin.Stop(); }
         redPin.Dispose();
         redPin = null;
     }
 }