private void Loop() { var oldValue = _input.Read(); _running = true; while (_running) { var newValue = _input.Read(); if (newValue == oldValue) { continue; } Interlocked.Increment(ref _counter); if (StateChanged != null) { var oldTmp = oldValue; Task.Factory.StartNew( () => { StateChanged(this, new PinStateChangedEventArgs(newValue, oldTmp, _input)); }); } oldValue = newValue; PinState = newValue; Thread.Sleep(1); } }
/// <summary> /// Start GPIO Clock /// </summary> public void StartGPIOClock() { BackupPinMode = GPIO.GetMode(GPIOClockPin); BackupPinValue = GPIO.Read(GPIOClockPin); GPIO.SetMode(GPIOClockPin, PinMode.GpioClock); GPIO.SetClock(GPIOClockPin, GPIOClockSpeed); UpdatePinStates(); Log.Add($"Pin {GPIOClockPin} in clock mode at {GPIOClockSpeed}"); }
public byte receive() { byte temp = 0; // Pull-up on _data.Write(true); for (int i = 0; i < 8; i++) { temp >>= 1; _clock.Write(false); if (_data.Read() == PinState.High) { temp |= 0x80; } _clock.Write(true); } _data.Write(false); return(temp); }