/// <summary> /// Gets the Broadcom GPIO pin number form the Raspberry Pi pin number /// </summary> /// <param name="pinNumber">The Raspberry Pi pin number</param> /// <returns>The equivalent Broadcom ID</returns> private static BroadcomPinNumber ConvertToBroadcom(RaspberryPinNumber pinNumber) { switch (pinNumber) { case RaspberryPinNumber.Seven: return(BroadcomPinNumber.Four); case RaspberryPinNumber.Zero: return(BroadcomPinNumber.Seventeen); case RaspberryPinNumber.One: return(BroadcomPinNumber.Eighteen); case RaspberryPinNumber.Two: return(BroadcomPinNumber.TwentyOne); case RaspberryPinNumber.Three: return(BroadcomPinNumber.TwentyTwo); case RaspberryPinNumber.Four: return(BroadcomPinNumber.TwentyThree); case RaspberryPinNumber.Five: return(BroadcomPinNumber.TwentyFour); case RaspberryPinNumber.Six: return(BroadcomPinNumber.TwentyFive); default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Closes a GPIO channel /// </summary> /// <param name="pinNumber">The Raspberry Pi pin number to configure</param> public void CloseChannel(RaspberryPinNumber pinNumber) { this.CloseChannel(ConvertToBroadcom(pinNumber)); }
/// <summary> /// Reads a value form a GPIO pin /// </summary> /// <param name="pinNumber">The pin number to read</param> /// <returns>The value at that pin</returns> /// <exception cref="InvalidOperationException"> /// Thrown when an attempt to use an incorrectly configured channel is made /// </exception> public bool ReadValue(RaspberryPinNumber pinNumber) { return(this.ReadValue(ConvertToBroadcom(pinNumber))); }
/// <summary> /// Configures a GPIO channel for use /// </summary> /// <param name="pinNumber">The Raspberry Pi pin number to configure</param> /// <param name="direction">The direction to configure the pin for</param> public void SetupChannel(RaspberryPinNumber pinNumber, Direction direction) { this.SetupChannel(ConvertToBroadcom(pinNumber), direction); }
/// <summary> /// Outputs a value to a GPIO pin /// </summary> /// <param name="pinNumber">The pin number to use</param> /// <param name="value">The value to output</param> /// <exception cref="InvalidOperationException"> /// Thrown when an attempt to use an incorrectly configured channel is made /// </exception> public void OutputValue(RaspberryPinNumber pinNumber, bool value) { this.OutputValue(ConvertToBroadcom(pinNumber), value); }
/// <summary> /// Gets the Broadcom GPIO pin number form the Raspberry Pi pin number /// </summary> /// <param name="pinNumber">The Raspberry Pi pin number</param> /// <returns>The equivalent Broadcom ID</returns> private static BroadcomPinNumber ConvertToBroadcom(RaspberryPinNumber pinNumber) { switch (pinNumber) { case RaspberryPinNumber.Seven: return BroadcomPinNumber.Four; case RaspberryPinNumber.Zero: return BroadcomPinNumber.Seventeen; case RaspberryPinNumber.One: return BroadcomPinNumber.Eighteen; case RaspberryPinNumber.Two: return BroadcomPinNumber.TwentyOne; case RaspberryPinNumber.Three: return BroadcomPinNumber.TwentyTwo; case RaspberryPinNumber.Four: return BroadcomPinNumber.TwentyThree; case RaspberryPinNumber.Five: return BroadcomPinNumber.TwentyFour; case RaspberryPinNumber.Six: return BroadcomPinNumber.TwentyFive; default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Reads a value form a GPIO pin /// </summary> /// <param name="pinNumber">The pin number to read</param> /// <returns>The value at that pin</returns> /// <exception cref="InvalidOperationException"> /// Thrown when an attempt to use an incorrectly configured channel is made /// </exception> public bool ReadValue(RaspberryPinNumber pinNumber) { return this.ReadValue(ConvertToBroadcom(pinNumber)); }