/// <summary> /// Sets up an interface for accessing the specified GPIO pin with the given direction and given initial value. /// </summary> /// <param name="gpioPin">The GPIO pin to be accessed.</param> /// <param name="direction">The direction the GPIO pin should have.</param> /// <param name="initialValue">The initial value the GPIO pin should have.</param> public GPIOPinDriver(Pin gpioPin, GPIODirection direction, GPIOState initialValue) { this._disposed = false; this.GPIOPin = gpioPin; this.Direction = direction; if (this.Direction == GPIODirection.Out) { this.State = initialValue; } }
/// <summary> /// Sets up an interface for accessing the specified GPIO pin with the given direction and given initial value. /// </summary> /// <param name="gpioPin">The GPIO pin to be accessed.</param> /// <param name="direction">The direction the GPIO pin should have.</param> /// <param name="initialValue">The initial value the GPIO pin should have.</param> public GPIOPinDriver(Pin gpioPin, GPIODirection direction, GPIOState initialValue, bool _bSimMode) { SetupPath(_bSimMode); this._disposed = false; this.GPIOPin = gpioPin; this.Direction = direction; if (this.Direction == GPIODirection.Out) { this.State = initialValue; } }
private static void ThreadWatcher() { CurrentState = new GPIOState(); while (true) { var sw1 = GPIO24_Sw1.Value != 0; lock (CurrentState) { if (CurrentState.sw1 != sw1) { CurrentState.sw1 = sw1; CurrentState.led1 = GPIO25_LED1.Value != 0; Console.WriteLine("Button Pressed"); } } Thread.Sleep(100); } }
private static void ThreadWatcher() { CurrentState = new GPIOState(); while (true) { var sw1 = GPIO24_Sw1.Value != 0; lock (CurrentState) { if (CurrentState.sw1 != sw1) { CurrentState.sw1 = sw1; CurrentState.led1 = GPIO25_LED1.Value != 0; if (CurrentState.sw1 == true) { GPIO.Instance.UpdateButtonStatus("Button Pressed!!"); Console.WriteLine("Button Pressed"); } else { GPIO.Instance.UpdateButtonStatus("Button Not Pressed!!"); Console.WriteLine("Button Not Pressed!"); } } } Thread.Sleep(100); } }
static void Main(string[] args) { InitiGPIO(); CurrentState = new GPIOState(); Halt = false; var baseAddress = "http://*:80/"; var isWin = Environment.OSVersion.Platform == PlatformID.Win32NT; if (isWin) { baseAddress = "http://*****:*****@"sys\class\gpio\gpio24\value"); var gpio24value = File.ReadAllLines(gpio24valuePath).First(); gpio24value = gpio24value == "0" ? "1" : "0"; File.WriteAllLines(gpio24valuePath, new[] { gpio24value }); } break; case "Q": Console.WriteLine("Stoping..."); Halt = true; var terminated = watcher.Join(1000); if (terminated == false) { watcher.Abort(); } httpHost.Dispose(); Console.WriteLine("Stoped."); return; default: break; } } }