Ejemplo n.º 1
0
        private async Task init()
        {
            // ENSURE ITS DONE BEFORE PWM
            // LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();

            // await PwmController.GetControllersAsyn DOES NOT WORK ON RPi3B+ in preview builds but works on other models
            // var pwmControllers = await PwmController.GetControllersAsync(LightningPwmProvider.GetPwmProvider());

            // HENCE USING PwmProviderManager
            var pwmManager = new PwmProviderManager();

            // Add providers
            pwmManager.Providers.Add(new SoftPwm());
            // Get the well-known controller collection back
            var pwmControllers = await pwmManager.GetControllersAsync();

            // Using the first PWM controller
            this.pwmController = pwmControllers[0];
            this.pwmController.SetDesiredFrequency(50);

            this.panServo  = this.pwmController.OpenPin(panMotorPin);
            this.tiltServo = this.pwmController.OpenPin(TiltMotorPin);

            this.panServo.SetActiveDutyCyclePercentage(this.RestingPulseLegnth);
            this.panServo.Start();
            this.tiltServo.SetActiveDutyCyclePercentage(this.RestingPulseLegnth);
            this.tiltServo.Start();

            var task = Task.Run(() =>
            {
                System.Threading.Tasks.Task.Delay(250).Wait();
                this.tiltServo.Stop();
                this.panServo.Stop();
            });
        }
Ejemplo n.º 2
0
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            // Check presence of GPIO Controller
            // Since this is UWP, this application runs on desktop, mobile, as well as embedded devices
            // best to confirm we are running on an embedded device like R Pi
            GpioController gpio = GpioController.GetDefault();

            if (gpio == null)
            {
                Debug.WriteLine("This device does not have GPIO Controller.");
                return;
            }

            var pwmManager = new PwmProviderManager();

            pwmManager.Providers.Add(new SoftPwm());

            var pwmContollers = await pwmManager.GetControllersAsync();

            pwmController = pwmContollers[0];
            pwmController.SetDesiredFrequency(50);

            pwmPin = pwmController.OpenPin(servoPin);
            pwmPin.Start();

            timer = new DispatcherTimer
            {
                Interval = TimeSpan.FromSeconds(15)
            };
            timer.Tick += Timer_Tick;
            timer.Start();

            IsClockwise = false;
        }
Ejemplo n.º 3
0
        private async Task EnsureInitializedAsync()
        {
            if (_isInitialized)
            {
                return;
            }

            // Create PWM manager
            var pwmManager = new PwmProviderManager();

            // Add providers ~ pwmControllers
            //var provider = new PCA9685Provider(_i2Caddr);
            pwmManager.Providers.Add(new PCA9685());

            // Get the well-known controller collection back
            var pwmControllers = await pwmManager.GetControllersAsync();

            _pwmController = pwmControllers.Last();
            if (_frequency > _pwmController.MaxFrequency)
            {
                _frequency = _pwmController.MaxFrequency;
            }
            _pwmController.SetDesiredFrequency(_frequency);

            _isInitialized = true;
        }
Ejemplo n.º 4
0
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            // Start GPIO
            var gpioController = GpioController.GetDefault();

            // Create PWM manager
            var pwmManager = new PwmProviderManager();

            // Add providers
            pwmManager.Providers.Add(new SoftPwm());
            // pwmManager.Providers.Add(new PCA9685());

            // Get the well-known controller collection back
            var pwmControllers = await pwmManager.GetControllersAsync();

            // Using the first PWM controller
            var controller = pwmControllers[0];

            // Set desired frequency
            controller.SetDesiredFrequency(60);

            // Create light sensor
            led = new RgbLed()
            {
                // SoftPwm
                RedPin   = controller.OpenPin(4),
                GreenPin = controller.OpenPin(5),
                BluePin  = controller.OpenPin(6),

                // PCA9685
                //RedPin = controller.OpenPin(0),
                //GreenPin = controller.OpenPin(1),
                //BluePin = controller.OpenPin(2),
            };
        }
Ejemplo n.º 5
0
        public async Task load()
        {
            try
            {
                switch (pwmselect.SelectedIndex)
                {
                case 1:
                    if (LightningProvider.IsLightningEnabled)
                    {
                        LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
                        var pwmControllers = await PwmController.GetControllersAsync(LightningPwmProvider.GetPwmProvider());

                        pwmController = pwmControllers[int.Parse(pwmidhd.Text)];     // use the on-device controller
                        pwmController.SetDesiredFrequency(double.Parse(frahz.Text));

                        //var _pin = pwmController.OpenPin(22);
                        //_pin.SetActiveDutyCyclePercentage(.25);
                        //_pin.Start();
                    }
                    else
                    {
                        await new MessageDialog("驱动程序不正常").ShowAsync();
                    }
                    break;

                case 0:
                {
                    var pwmManager = new PwmProviderManager();
                    pwmManager.Providers.Add(new SoftPwm());
                    var pwmControllers = await pwmManager.GetControllersAsync();

                    //use the first available PWM controller an set refresh rate (Hz)
                    pwmController = pwmControllers[0];
                    pwmController.SetDesiredFrequency(double.Parse(frahz.Text));
                }

                break;

                default:
                    gpioController = await GpioController.GetDefaultAsync();

                    break;
                }
                pwmselect.IsEnabled = false;
            }
            catch (Exception err)
            {
                await new MessageDialog("初始化设备失败:" + err.ToString()).ShowAsync();
                throw;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// This constructor is void, You must configure this class by this.SetupBasic()
        /// </summary>

        /// <summary>
        /// Initialize of pwm (it must be used after constructor PwmBasic() )
        /// </summary>
        /// <param name="__pinNumber">Pin of RPi where this pwm must be work</param>
        /// <param name="__frequency">Frequency of pwm (can change this param later)</param>
        /// <returns></returns>
        protected async Task SetupPwmCore(int __pinNumber, double __frequency)
        {
            var gpioController = GpioController.GetDefault();
            var pwmManager     = new PwmProviderManager();

            pwmManager.Providers.Add(new SoftPwm());

            var pwmControllers = await pwmManager.GetControllersAsync();

            _pwmController = pwmControllers[0];
            Frequency      = __frequency;
            _pwmController.SetDesiredFrequency(frequency);

            _pwmPin = _pwmController.OpenPin(__pinNumber);
            State   = true;
        }
Ejemplo n.º 7
0
        public async void Setup(int _pinNumber, double _frequency)
        {
            var gpioController = GpioController.GetDefault();
            var pwmManager     = new PwmProviderManager();

            pwmManager.Providers.Add(new SoftPwm());

            var pwmControllers = await pwmManager.GetControllersAsync();

            _pwmController = pwmControllers[0];
            frequency      = _frequency; //TODO; get; set;
            _pwmController.SetDesiredFrequency(frequency);

            _pwmPin = _pwmController.OpenPin(_pinNumber);
            _pwmPin.Start();
        }
Ejemplo n.º 8
0
        async void InitPwm()
        {
            var gpio_controller = GpioController.GetDefault();
            var manager         = new PwmProviderManager();

            manager.Providers.Add(new SoftPwm());
            var controllers = await manager.GetControllersAsync();

            _controller = controllers[0];
            _controller.SetDesiredFrequency(120);

            _led = new RgbLed
            {
                RedPin   = _controller.OpenPin(PIN_R),
                GreenPin = _controller.OpenPin(PIN_G),
                BluePin  = _controller.OpenPin(PIN_B),
                Color    = Colors.Black
            };
        }