예제 #1
0
 private void InitializeButton(GpioController controller)
 {
     ButtonPin = controller.OpenPin(ButtonPinNumber);
     ButtonPin.SetDriveMode(ButtonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp)
                         ? GpioPinDriveMode.InputPullUp
                         : GpioPinDriveMode.Input);
     ButtonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
 }
예제 #2
0
파일: Button.cs 프로젝트: shrekjxf/Rpi
 public Button(IGpioController controller, GpioEnum gpio, ILoggerService loggerService = null)
 {
     ButtonPin = controller.OpenPin(gpio);
     ButtonPin.SetDriveMode(GpioPinDriveModeEnum.InputPullUp);
     if (loggerService != null)
     {
         TurnedOn  += (s, a) => loggerService.Log(LogLevelEnum.Information, $"{Name} is turned on");
         TurnedOff += (s, a) => loggerService.Log(LogLevelEnum.Information, $"{Name} is turned off");
     }
 }
예제 #3
0
        public TreatDispenser(GpioController controller)
        {
            _ledPin    = LedPin.Initialize(controller, 18, LedPinState.Off);
            _buttonPin = ButtonPin.Initialize(controller, 23, PinMode.InputPullDown);

            _buttonPin.OnButtonUp += async(s, e) =>
            {
                await DispenseAsync().ConfigureAwait(false);
            };
        }
예제 #4
0
        public MainPageViewModel()
        {
            var pins = new List <GpioPin>();

            gpioController = GpioController.GetDefault();

            //Inicializa 15 pinos
            for (int i = 2; i <= 13; i++)
            {
                var pin = gpioController?.OpenPin(i);
                pin?.SetDriveMode(GpioPinDriveMode.Output);
                pins.Add(pin);
            }
            for (int i = 17; i <= 18; i++)
            {
                var pin = gpioController?.OpenPin(i);
                pin?.SetDriveMode(GpioPinDriveMode.Output);
                pins.Add(pin);
            }

            var pin20 = gpioController?.OpenPin(20);

            pin20?.SetDriveMode(GpioPinDriveMode.Output);
            pins.Add(pin20);

            CarroPins    = pins.Take(3).ToViewModelArray();                //Pins 0-2
            PedestrePins = pins.Skip(3).Take(2).ToViewModelArray();        //Pins 3-4

            DisplayPins        = pins.Skip(5).Take(7).ToViewModelArray();  //Pins 5-11
            DisplayControlPins = pins.Skip(12).Take(2).ToViewModelArray(); //Pins 12-13

            ScreenDigit1Pins = new GpioPin[7].ToViewModelArray();
            ScreenDigit2Pins = new GpioPin[7].ToViewModelArray();

            ButtonPin = pins.Last(); //Pin 14
            ButtonPin?.SetDriveMode(GpioPinDriveMode.InputPullUp);

            _numbers = new int[][]
            {
                new[] { 0, 1, 2, 3, 4, 5 },    // 0
                new[] { 1, 2 },                // 1
                new[] { 0, 1, 3, 4, 6 },       // 2
                new[] { 0, 1, 2, 3, 6 },       // 3
                new[] { 1, 2, 5, 6 },          // 4
                new[] { 0, 2, 3, 5, 6 },       // 5
                new[] { 2, 3, 4, 5, 6 },       // 6
                new[] { 0, 1, 2, 5 },          // 7
                new[] { 0, 1, 2, 3, 4, 5, 6 }, // 8
                new[] { 0, 1, 2, 3, 5, 6 }  // 9
            };

            Reset();
        }
예제 #5
0
파일: Button.cs 프로젝트: shrekjxf/Rpi
 public virtual async Task RunAsync()
 {
     while (true)
     {
         if (ButtonPin.Read() == GpioPinValueEnum.Low && !IsOn)
         {
             IsOn = true;
             OnButtonOn();
         }
         if (ButtonPin.Read() == GpioPinValueEnum.High && IsOn)
         {
             IsOn = false;
             OnButtonOff();
         }
         await Task.Delay(10);
     }
 }
예제 #6
0
 public override async Task RunAsync()
 {
     while (true)
     {
         if (ButtonPin.Read() == GpioPinValueEnum.Low)
         {
             // ReSharper disable once AssignmentInConditionalExpression
             if (IsOn = !IsOn)
             {
                 OnButtonOn();
             }
             else
             {
                 OnButtonOff();
             }
             await Task.Delay(200);
         }
         await Task.Delay(10);
     }
 }