@@ -57,34 +57,54 @@ public extern int PinCount
5757 /// Opens a pin in order for it to be ready to use.
5858 /// </summary>
5959 /// <param name="pinNumber">The pin number in the controller's numbering scheme.</param>
60+ /// <returns>The opened GPIO pin.</returns>
6061 /// <exception cref="InvalidOperationException">This exception will be thrown if the pin is already open.</exception>
61- public void OpenPin ( int pinNumber )
62+ public GpioPin OpenPin ( int pinNumber )
6263 {
63- var pin = new Gpio Pin ( pinNumber ) ;
64+ var gpioPin = InternalOpenPin ( pinNumber ) ;
6465
65- if ( pin . Init ( ) )
66- {
67- // add to array
68- s_GpioPins . Add ( new GpioPinBundle ( ) { PinNumber = pinNumber , GpioPin = pin } ) ;
66+ // add to array
67+ s_GpioPins . Add ( new GpioPinBundle ( ) { PinNumber = pinNumber , GpioPin = gpioPin } ) ;
6968
70- // done here
71- return ;
72- }
73-
74- throw new InvalidOperationException ( ) ;
69+ return gpioPin ;
7570 }
7671
7772 /// <summary>
7873 /// Opens a pin and sets it to a specific mode.
7974 /// </summary>
8075 /// <param name="pinNumber">The pin number in the controller's numbering scheme.</param>
8176 /// <param name="mode">The mode to be set.</param>
82- public void OpenPin (
77+ /// <returns>The opened GPIO pin.</returns>
78+ public GpioPin OpenPin (
8379 int pinNumber ,
8480 PinMode mode )
8581 {
86- OpenPin ( pinNumber ) ;
82+ var gpioPin = InternalOpenPin ( pinNumber ) ;
83+
8784 SetPinMode ( pinNumber , mode ) ;
85+
86+ // add to array
87+ s_GpioPins . Add ( new GpioPinBundle ( ) { PinNumber = pinNumber , GpioPin = gpioPin } ) ;
88+
89+ return gpioPin ;
90+ }
91+
92+ /// <summary>
93+ /// Opens a pin in order for it to be ready to use.
94+ /// </summary>
95+ /// <param name="pinNumber">The pin number in the controller's numbering scheme.</param>
96+ /// <exception cref="InvalidOperationException">This exception will be thrown if the pin is already open.</exception>
97+ private GpioPin InternalOpenPin ( int pinNumber )
98+ {
99+ var pin = new Gpio Pin( pinNumber ) ;
100+
101+ if ( pin . Init ( ) )
102+ {
103+ // done here
104+ return pin ;
105+ }
106+
107+ throw new InvalidOperationException ( ) ;
88108 }
89109
90110 /// <summary>
0 commit comments