Пример #1
0
 public void PanRight()
 {
     mBottomPanServo.SetActiveDutyCyclePercentage(Math.Max(mBottomPanServo.GetActiveDutyCyclePercentage() - 0.01, 0));
     mBottomPanServo.Start();
     Task.Run(() =>
     {
         System.Threading.Tasks.Task.Delay(100).Wait();
         mBottomPanServo.Stop();
     });
 }
Пример #2
0
        static async Task MainAsync()
        {
            string input = "";
            bool   exit  = input.Equals("exit");

            UpBridge.Up upb = new UpBridge.Up();
            Console.WriteLine("UWP console PWM test:");
            PwmController controller = await PwmController.GetDefaultAsync();

            pin1.pin = 0;
            //print Board INFO
            Console.WriteLine(upb.BoardGetManufacture() + "\n"
                              + "Board Name:  " + upb.BoardGetName() + "\n"
                              + "BIOS Ver:    " + upb.BoardGetBIOSVersion() + "\n"
                              + "Firmware Ver:" + upb.BoardGetFirmwareVersion().ToString("X") + "\n");
            PwmPin pin = controller.OpenPin(0);

            Console.WriteLine(Usage);
            while (exit == false)
            {
                Console.Write(pin1.pin.ToString() + ">");
                input = Console.ReadLine();
                string[] inputnum = input.Split(' ');
                switch (inputnum[0].ToLower())
                {
                case "list":
                    pwmlist();
                    break;

                case "set":
                    if (inputnum.Length == 2)
                    {
                        int pin_convert;
                        if (int.TryParse(inputnum[1], out pin_convert))
                        {
                            if (pin_convert == pin1.pin)
                            {
                                Console.WriteLine("This Pin is currently setting");
                            }
                            else
                            {
                                pin1.pin = pin_convert;
                                try
                                {
                                    controller = await PwmController.GetDefaultAsync();

                                    pin = controller.OpenPin(pin1.pin);
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.Message);
                                }
                                Console.WriteLine("You select pin   " + pin1.pin + "   to set");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Please input : set {int}");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Please input : set {int}");
                    }
                    break;

                case "get":
                    if (inputnum.Length == 1)
                    {
                        Console.WriteLine("Pin  " + pin1.pin + "\n");
                        Console.WriteLine("Max Frequency    :   " + controller.MaxFrequency + "\n");
                        Console.WriteLine("Min Frequency    :   " + controller.MinFrequency + "\n");
                        Console.WriteLine("Actual Frequency :   " + controller.ActualFrequency + "\n");
                        Console.WriteLine("Duty Cycle       :   " + pin.GetActiveDutyCyclePercentage() + "\n");
                        Console.WriteLine("Pin Status       :   " + pin.IsStarted + "\n");
                    }
                    else
                    {
                        Console.WriteLine("Please input : get");
                    }
                    break;

                case "frequency":
                    if (inputnum.Length == 2)
                    {
                        try
                        {
                            if (double.TryParse(inputnum[1], out pin1.pin_ActualFrequency))
                            {
                                Console.WriteLine("Frequency set : " + pin1.pin_ActualFrequency);
                                controller.SetDesiredFrequency(pin1.pin_ActualFrequency);
                                pin.Start();
                            }
                            else
                            {
                                Console.WriteLine("Please input : frequency {double}");
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Please input : frequency {double}");
                    }
                    break;

                case "duty":
                    if (inputnum.Length == 2)
                    {
                        try
                        {
                            if (double.TryParse(inputnum[1], out pin1.pin_DutyCycle))
                            {
                                Console.WriteLine("duty set : " + pin1.pin_DutyCycle);
                                pin.SetActiveDutyCyclePercentage(pin1.pin_DutyCycle);
                                pin.Start();
                            }
                            else
                            {
                                Console.WriteLine("Please input : duty {double}");
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Please input : duty {double}");
                    }
                    break;

                case "exit":
                    exit = inputnum[0].Equals("exit");
                    pin.Dispose();
                    break;

                case "help":
                default:
                    Console.WriteLine(Usage);
                    break;
                }
            }
        }
Пример #3
0
 /// <summary>
 /// Get the percent, from 0 to 1, of the acive duty cycle of the PWM pin
 /// </summary>
 /// <returns>The floating point active duty cycle</returns>
 public double GetActiveDutyCyclePercentage()
 {
     return(_pwmPin.GetActiveDutyCyclePercentage());
 }