/// <summary> /// Reads pin state and updates the stored states. /// </summary> public void ReadPin() { prevState = state; // Update previous state state = pinInterface.ReadState(); // Update current state isChanged = (prevState != state) ? true : false; // Check if changed return; }
//------------------------------------ Public Methods -----------------------------------// /// <summary> /// Checks if the indicated column is empty. /// </summary> /// <param name="columnID">Column ID, specified when the monitor was constructed.</param> /// <returns>true if column is empty, false o/w</returns> public bool IsEmpty(int columnID) { int index = this.FindIndex(columnID); // Find column ID GPIOController.State state = this.pins[index].state; // Get state return((state == GPIOController.State.High) ? true : false); // High = empty }
/// <summary> /// Sets up an input pin. /// </summary> /// <param name="pin">GPIO pin</param> /// <param name="id">Unique signal identifier</param> public InputPin(GPIOController.Pin pin, T id) { this.id = id; // Set ID this.state = GPIOController.State.Low; // Default states to Low this.prevState = GPIOController.State.Low; this.isChanged = false; this.pinInterface = new GPIOController(pin, GPIOController.Direction.In); // Set up for reading }
//------------------------------------ Public Methods -----------------------------------// // None //---------------------------------- Protected Methods ----------------------------------// /// <summary> /// Sets up a pin writing controller for the indicated GPIO pins /// </summary> /// <param name="pinNumbers">GPIO pin IDs to control</param> /// <param name="pinIDs">ID values assigned to the pins; independent of pinNumbers</param> protected void SetupPins(GPIOController.Pin[] pinNumbers, T[] pinIDs, GPIOController.State initialState) { if (pinNumbers.Length != pinIDs.Length) { throw new Exception("The number of pins and number of pin IDs should be the same"); } this.pinCount = pinNumbers.Length; // Get # pins this.pins = new OutputPin <T> [this.pinCount]; // Resize pin array // Set up each pin for (int i = 0; i < this.pinCount; i++) { this.pins[i] = new OutputPin <T>(pinNumbers[i], pinIDs[i], initialState); } return; }
/// <summary> /// Sets up an output pin. /// </summary> /// <param name="pin">GPIO pin</param> /// <param name="id">Unique signal identifier</param> public OutputPin(GPIOController.Pin pin, T id, GPIOController.State initialState) { this.id = id; // Set ID this.pinInterface = new GPIOController(pin, GPIOController.Direction.Out, initialState); // Set up for writing }