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));
     }
 }
Пример #2
0
        internal PwmPin(PwmController controller, IPwmControllerProvider provider, int pinNumber)
        {
            m_controller = controller;
            m_provider = provider;
            m_pinNumber = pinNumber;

            m_provider.AcquirePin(pinNumber);
        }
Пример #3
0
        public void Dispose()
        {
            _winController = null;

            foreach (Windows10PwmDriverChannel channel in _channelMap.Values)
            {
                channel.Dispose();
            }
            _channelMap.Clear();
        }
Пример #4
0
        static void LedInit(PwmController controller)
        {
            Red = controller.OpenPin(LedPinRed);
            Green = controller.OpenPin(LedPinGreen);
            Blue = controller.OpenPin(LedPinBlue);

            Red.Start();
            Green.Start();
            Blue.Start();
        }
Пример #5
0
        public static PwmController[] GetControllers(IPwmProvider provider)
        {
            // FUTURE: This should return "Task<IReadOnlyList<PwmController>>"

            var providers = provider.GetControllers();
            var controllers = new PwmController[providers.Length];

            for (int i = 0; i < providers.Length; ++i)
            {
                controllers[i] = new PwmController(providers[i]);
            }

            return controllers;
        }
Пример #6
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));

        }
Пример #7
0
        public Pwm(
            ObjectEnvironment environment,
            string id,
            string name,
            PwmController controller,
            string description = null,
            Object parent = null
            )
            : base(environment, id, name,
                new ObjectType("PWM", "PWM", "Pulse width modulation"),
                description, parent)
        {
            controller.ValidateNonNull(nameof(controller));
            Controller = controller;

            PinCount = new Property<int>(this, nameof(PinCount), "Pin count", Controller.PinCount);
            Items.Add(PinCount);

            DelegateCommand command;
            command = new DelegateCommand<int>(this,
                nameof(OpenPin), "Open pin",
                p => OpenPin(p),
                p => CanOpenPin(p),
                parameters: new CommandParameterInfo<int>("Number", "Number", "Pin number")
                );
            Items.Add(command);

            Frequency = new PhysicalProperty<double>(this,
                nameof(Frequency), "Frequency", Controller.ActualFrequency, Units.Hertz);
            Items.Add(Frequency);

            MinFrequency = new PhysicalProperty<double>(this,
                nameof(MinFrequency), "Minimum frequency", Controller.MinFrequency, Units.Hertz);
            Items.Add(MinFrequency);

            MaxFrequency = new PhysicalProperty<double>(this,
                nameof(MaxFrequency), "Maximum frequency", Controller.MaxFrequency, Units.Hertz);
            Items.Add(MaxFrequency);

            command = new DelegateCommand<double>(this,
                nameof(SetFrequency), "Set frequency",
                p => SetFrequency(p),
                p => CanSetFrequency(p),
                parameters: new CommandPhysicalParameterInfo<double>(Frequency)
                );
            Items.Add(command);
        }
Пример #8
0
        public Windows10PwmDriverChip(int chipIndex)
        {
            // Open the Windows PWM controller for the specified PWM chip
            string controllerFriendlyName = $"PWM{chipIndex}";
            string deviceSelector         = WinPwm.PwmController.GetDeviceSelector(controllerFriendlyName);

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

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

            string deviceId = deviceInformationCollection[0].Id;

            _winController = WinPwm.PwmController.FromIdAsync(deviceId).WaitForCompletion();
        }
Пример #9
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;
        }
Пример #10
0
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         m_provider.ReleasePin(m_pinNumber);
         m_controller = null;
         m_provider = null;
     }
 }