Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added pins for Rev.2 Pi's and wrapper for piBoardRev #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ext/wiringpi/wiringpi.i
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

%apply unsigned char { uint8_t };

extern int piBoardRev (void) ;

extern int wiringPiSetup (void) ;
extern int wiringPiSetupSys (void) ;
extern int wiringPiSetupGpio (void) ;
Expand Down
28 changes: 22 additions & 6 deletions ext/wiringpi/wiringpi_wrap.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 2.0.7
* Version 2.0.8
*
* This file is not intended to be easily readable and contains a number of
* coding conventions designed to improve portability and efficiency. Do not make
Expand Down Expand Up @@ -1806,7 +1806,7 @@ static VALUE mWiringpi;
#define SWIG_RUBY_THREAD_END_BLOCK


#define SWIGVERSION 0x020007
#define SWIGVERSION 0x020008
#define SWIG_VERSION SWIGVERSION


Expand Down Expand Up @@ -1846,7 +1846,7 @@ SWIG_ruby_failed(void)
}


/*@SWIG:/usr/local/share/swig/2.0.7/ruby/rubyprimtypes.swg,19,%ruby_aux_method@*/
/*@SWIG:/usr/local/Cellar/swig/2.0.8/share/swig/2.0.8/ruby/rubyprimtypes.swg,19,%ruby_aux_method@*/
SWIGINTERN VALUE SWIG_AUX_NUM2LONG(VALUE *args)
{
VALUE obj = args[0];
Expand Down Expand Up @@ -1891,7 +1891,7 @@ SWIG_AsVal_int (VALUE obj, int *val)
}


/*@SWIG:/usr/local/share/swig/2.0.7/ruby/rubyprimtypes.swg,19,%ruby_aux_method@*/
/*@SWIG:/usr/local/Cellar/swig/2.0.8/share/swig/2.0.8/ruby/rubyprimtypes.swg,19,%ruby_aux_method@*/
SWIGINTERN VALUE SWIG_AUX_NUM2ULONG(VALUE *args)
{
VALUE obj = args[0];
Expand Down Expand Up @@ -2026,6 +2026,22 @@ SWIG_AsCharPtrAndSize(VALUE obj, char** cptr, size_t* psize, int *alloc)



SWIGINTERN VALUE
_wrap_piBoardRev(int argc, VALUE *argv, VALUE self) {
int result;
VALUE vresult = Qnil;

if ((argc < 0) || (argc > 0)) {
rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail;
}
result = (int)piBoardRev();
vresult = SWIG_From_int((int)(result));
return vresult;
fail:
return Qnil;
}


SWIGINTERN VALUE
_wrap_wiringPiSetup(int argc, VALUE *argv, VALUE self) {
int result;
Expand Down Expand Up @@ -2631,8 +2647,7 @@ SWIG_InitializeModule(void *clientdata) {
size_t i;
swig_module_info *module_head, *iter;
int found, init;

clientdata = clientdata;
(void *)clientdata;

/* check to see if the circular list has been setup, if not, set it up */
if (swig_module.next==0) {
Expand Down Expand Up @@ -2828,6 +2843,7 @@ SWIGEXPORT void Init_wiringpi(void) {
}

SWIG_RubyInitializeTrackings();
rb_define_module_function(mWiringpi, "piBoardRev", _wrap_piBoardRev, -1);
rb_define_module_function(mWiringpi, "wiringPiSetup", _wrap_wiringPiSetup, -1);
rb_define_module_function(mWiringpi, "wiringPiSetupSys", _wrap_wiringPiSetupSys, -1);
rb_define_module_function(mWiringpi, "wiringPiSetupGpio", _wrap_wiringPiSetupGpio, -1);
Expand Down
26 changes: 21 additions & 5 deletions lib/wiringpi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,14 @@ def serialGetchar

class GPIO

GPIO_PINS = [
GPIO_PINS_REV_1 = [
0,1,4,7,8,9,10,11,14,15,17,18,21,22,23,24,25 # seemingly random indeed!
]

GPIO_PINS_REV_2 = [
2,3,4,7,8,9,10,11,14,15,17,18,22,23,24,25,27 # replace 3 pins for Rev. 2 Pi's
]

PINS = [
0,1,2,3,4,5,6,7, # basic IO pins
8,9, # i2c with 1k8 pull up resistor
Expand All @@ -86,11 +90,13 @@ class GPIO

@mode = WPI_MODE_PINS

@gpio_pins = GPIO_PINS_REV_2

@@init = false # once wiringPiSetup has been called, we don't have to do it again

def initialize( mode=WPI_MODE_PINS )

@mode = mode
@mode = mode
self.wiringPiSetup unless @@init

end
Expand All @@ -102,6 +108,10 @@ def wiringPiMode( mode )

end

def piBoardRev
Wiringpi.piBoardRev
end

def wiringPiSetup

begin
Expand All @@ -112,6 +122,12 @@ def wiringPiSetup
elsif @mode == WPI_MODE_SYS
Wiringpi.wiringPiSetupSys
end

if self.piBoardRev == 1 # What PINs should we use for this board
@gpio_pins = GPIO_PINS_REV_1
else
@gpio_pins = GPIO_PINS_REV_2
end
rescue Exception=>e
raise e
end
Expand All @@ -123,13 +139,13 @@ def wiringPiSetup

def checkPin(pin)

( @mode = WPI_MODE_PINS and PINS.include?(pin) ) or ( @mode = WPI_MODE_GPIO and GPIO_PINS.include?(pin) )
( @mode = WPI_MODE_PINS and PINS.include?(pin) ) or ( @mode = WPI_MODE_GPIO and @gpio_pins.include?(pin) )

end

def pinError(pin)
"invalid #{pin}, available gpio pins: #{PINS}" if @mode == WPI_MODE_PINS
"invalid #{pin}, available gpio pins: #{GPIO_PINS}" if @mode == WPI_MODE_GPIO
"invalid #{pin}, available gpio pins: #{@gpio_pins}" if @mode == WPI_MODE_GPIO
end

def read(pin)
Expand Down Expand Up @@ -215,7 +231,7 @@ def readAll

if @mode == WPI_MODE_GPIO

GPIO_PINS.each do |pin|
@gpio_pins.each do |pin|

pinValues[pin] = self.read(pin)

Expand Down