Esempio n. 1
0
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            var controller = GpioController.GetDefault();
            var pin        = controller.OpenPin(18, GpioSharingMode.Exclusive);

            pin.SetDriveMode(GpioPinDriveMode.Output);


            Pwm   = new SofwarePwm(n => pin.Write(n ? GpioPinValue.High : GpioPinValue.Low), 10, 0);
            Servo = new ServoController(Pwm);
            Servo.Start(1);
            PropertyChanged(this, new PropertyChangedEventArgs("Angle"));
        }
Esempio n. 2
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            // Setup Netowrk Socket
            Server = new Socket(SocketType.Stream, ProtocolType.Tcp);
            Server.Bind(new IPEndPoint(IPAddress.Any, 1911));
            Server.Listen(100);

            // Setup Servos
            var controller = GpioController.GetDefault();

            // GPIO 18
            var pin = controller.OpenPin(18, GpioSharingMode.Exclusive);

            pin.SetDriveMode(GpioPinDriveMode.Output);
            Azimuth = new ServoController(new SofwarePwm(n => pin.Write(n ? GpioPinValue.High : GpioPinValue.Low), 50, 0));
            Azimuth.Start(90);

            // GPIO 23
            pin = controller.OpenPin(23, GpioSharingMode.Exclusive);
            pin.SetDriveMode(GpioPinDriveMode.Output);
            Inclenation = new ServoController(new SofwarePwm(n => pin.Write(n ? GpioPinValue.High : GpioPinValue.Low), 50, 0));
            Inclenation.Start(90);

            Server.Listen(10);
            var connectEvent = new AutoResetEvent(false);

            while (true)
            {
                SocketAsyncEventArgs e = new SocketAsyncEventArgs();
                e.Completed += AcceptCallback;
                if (!Server.AcceptAsync(e))
                {
                    AcceptCallback(Server, e);
                    connectEvent.Set();
                }

                connectEvent.WaitOne(1000);
            }
        }