static void Main(string[] args) { var gpio18 = new GPIO("18", GPIODirection.output); var gpio17 = new GPIO("17", GPIODirection.input); int hitCount = 0; Console.Write("How many button presses: "); int maxHitCount = Convert.ToInt32(Console.ReadLine()); if (gpio18.StreamGood && gpio17.StreamGood) { bool oldButtonState = false; while (hitCount < maxHitCount) { bool buttonState = gpio17.GetValue(); if (oldButtonState != buttonState && oldButtonState) { hitCount++; } gpio18.SetValue(buttonState); Thread.Sleep(200); oldButtonState = buttonState; } } else { Console.WriteLine("Cannot initialize streams....."); } Console.WriteLine("Exiting....."); }
public void ShouldReturnFalsewhenExportsFail() { var mock = new Mock <IFileWrapper>(); mock.Setup(fileWrapper => fileWrapper.Write("./sys/class/gpio/export", "20")).Throws(new Exception()); var device = new GPIO("20", mock.Object); var value = device.GetValue(); Assert.AreEqual(0, value); mock.Verify(fileWrapper => fileWrapper.Read("./sys/class/gpio/gpio20/value"), Times.Never()); mock.Verify(fileWrapper => fileWrapper.Write("./sys/class/gpio/gpio20/direction", "IN"), Times.Never()); mock.Verify(fileWrapper => fileWrapper.Write("./sys/class/gpio/export", "20"), Times.Once()); }
public void ShouldReturnTrueValue() { var mock = new Mock <IFileWrapper>(); mock.Setup(fileWrapper => fileWrapper.Read("./sys/class/gpio/gpio20/value")).Returns("1"); mock.Setup(fileWrapper => fileWrapper.Write("./sys/class/gpio/gpio20/direction", "IN")); mock.Setup(fileWrapper => fileWrapper.Write("./sys/class/gpio/export", "20")); var device = new GPIO("20", mock.Object); var value = device.GetValue(); Assert.AreEqual(1, value); mock.Verify(fileWrapper => fileWrapper.Read("./sys/class/gpio/gpio20/value"), Times.Once()); mock.Verify(fileWrapper => fileWrapper.Write("./sys/class/gpio/gpio20/direction", "IN"), Times.Once()); mock.Verify(fileWrapper => fileWrapper.Write("./sys/class/gpio/export", "20"), Times.Once()); }