private GpioPinValue[] CollectInput() { var unchangedCount = 0; var maxUnchangedCount = 100; var last = default(GpioPinValue?); var data = new List <GpioPinValue>(maxUnchangedCount * 2); while (true) { var current = pin.ReadValue(); data.Add(current); if (last != current) { unchangedCount = 0; last = current; } else { unchangedCount++; if (unchangedCount > maxUnchangedCount) { break; } } } return(data.ToArray()); }
/// <summary> /// Reads the temperature. /// </summary> /// <param name="S">if set to <c>true</c> [s].</param> /// <returns>Task<System.Single>.</returns> public TempertureAndHumidity Read() { Console.WriteLine("初始化状态:" + pin.ReadValue()); //只是初始化。构造函数那边做了,只是再次确保执行正确 //pin.PinMode = GpioPinDriveMode.Output; //pin.Write(GpioPinValue.High); //Console.WriteLine("初始化,拉高电平1秒"); Thread.Sleep(1000); //开始和传感器交互,等待交互数据。 WaitForRead(); //ReadData(out var temp, out var hum); return(new TempertureAndHumidity() { Humidity = 0, Temperture = 0 }); }
internal override GpioPinState GpioPinStateRead(int pin) { if (!PinController.IsValidPin(pin) || !IsDriverInitialized) { return(GpioPinState.Off); } GpioPin gpioPin = (GpioPin)Pi.Gpio[pin]; return((GpioPinState)gpioPin.ReadValue()); }
public GpioPinState GpioPinStateRead(int pin) { if (!IsValidPin(pin)) { Logger.Log("The specified pin is invalid."); return(GpioPinState.Off); } GpioPin gpioPin = (GpioPin)Pi.Gpio[pin]; return((GpioPinState)gpioPin.ReadValue()); }
internal override Pin GetPinConfig(int pinNumber) { if (!GpioCore.IsAllowedToExecute || !IsDriverInitialized) { return(new Pin()); } if (!PinController.IsValidPin(pinNumber)) { return(new Pin()); } GpioPin pin = (GpioPin)Pi.Gpio[pinNumber]; return(new Pin(pinNumber, (GpioPinState)pin.ReadValue(), (GpioPinMode)pin.PinMode)); }
public GpioPinConfig GetGpioConfig(int pinNumber) { if (!PiController.IsAllowedToExecute || !IsDriverProperlyInitialized) { return(new GpioPinConfig()); } if (!PiController.IsValidPin(pinNumber)) { Logger.Log("The specified pin is invalid."); return(new GpioPinConfig()); } GpioPin pin = (GpioPin)Pi.Gpio[pinNumber]; return(new GpioPinConfig(pinNumber, (GpioPinState)pin.ReadValue(), (GpioPinMode)pin.PinMode, false, 0)); }
public Pin?GetPinConfig(int pinNumber) { if (!PiGpioController.IsAllowedToExecute || !IsDriverProperlyInitialized) { return(null); } if (!PinController.IsValidPin(pinNumber)) { CastDriver <IGpioControllerDriver>(this).Logger.Log("The specified pin is invalid."); return(null); } GpioPin pin = (GpioPin)Pi.Gpio[pinNumber]; return(new Pin(pinNumber, (GpioPinState)pin.ReadValue(), (GpioPinMode)pin.PinMode)); }
public GpioPinState GpioPinStateRead(int pin) { if (!PinController.IsValidPin(pin) || !IsDriverProperlyInitialized) { CastDriver <IGpioControllerDriver>(this)?.Logger.Log("The specified pin is invalid."); return(GpioPinState.Off); } try { GpioPin gpioPin = (GpioPin)Pi.Gpio[pin]; return((GpioPinState)gpioPin.ReadValue()); } finally { Pin?pinConfig = GetPinConfig(pin); if (pinConfig != null) { CastDriver <IGpioControllerDriver>(this).UpdatePinConfig(pinConfig); } } }
private void ReadInputValues(object sender, ElapsedEventArgs e) { //Doorbell var doorbellOn = deviceStatusProvider.CurrentStatus.Doorbell == DoorbellStatus.On; var doorbellPinOn = doorbellPin.ReadValue() == GpioPinValue.High; if (doorbellOn != doorbellPinOn) { SendCommand(new UpdateDoorbell() { DesiredStatus = doorbellPinOn ? DoorbellStatus.On : DoorbellStatus.Off }); } //Doorlock var doorlockPinOn = doorlockPin.ReadValue() == GpioPinValue.High; switch (deviceStatusProvider.CurrentStatus.Alarm) { case AlarmStatus.On: if (!doorlockPinOn) { SendCommand(new UpdateAlarm() { DesiredStatus = AlarmStatus.Active }); } break; case AlarmStatus.Active: if (doorlockPinOn) { SendCommand(new UpdateAlarm() { DesiredStatus = AlarmStatus.Off }); } break; } }
static int SignalSensor(GpioPin pin) { var count = 0; var now = DateTime.Now; pin.PinMode = GpioPinDriveMode.Output; pin.Write(GpioPinValue.Low); Thread.Sleep(100); pin.PinMode = GpioPinDriveMode.Input; while (pin.ReadValue() == GpioPinValue.Low) { count++; if (IsDark(now)) { maxStrength = count; Console.WriteLine($"Pitch black value: {count}"); return(-1); } } return(count); }