From 3c66b868ac65136686d802552f89b635161f3c2c Mon Sep 17 00:00:00 2001 From: Kevin Date: Fri, 25 Jan 2013 17:39:36 +0100 Subject: [PATCH] Added pins for Rev.2 Pi's and wrapper for piBoardRev --- ext/wiringpi/WiringPi | 2 +- ext/wiringpi/wiringpi.i | 2 ++ ext/wiringpi/wiringpi_wrap.c | 28 ++++++++++++++++++++++------ lib/wiringpi.rb | 26 +++++++++++++++++++++----- 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/ext/wiringpi/WiringPi b/ext/wiringpi/WiringPi index 21f0472..dda3305 160000 --- a/ext/wiringpi/WiringPi +++ b/ext/wiringpi/WiringPi @@ -1 +1 @@ -Subproject commit 21f0472265d9e96a4f4d601afaaf7a04155530df +Subproject commit dda3305ce14a750e7529ff20b0acf9e53bd8eb7a diff --git a/ext/wiringpi/wiringpi.i b/ext/wiringpi/wiringpi.i index d94c846..6de7d88 100644 --- a/ext/wiringpi/wiringpi.i +++ b/ext/wiringpi/wiringpi.i @@ -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) ; diff --git a/ext/wiringpi/wiringpi_wrap.c b/ext/wiringpi/wiringpi_wrap.c index 0fd0b01..54193ff 100644 --- a/ext/wiringpi/wiringpi_wrap.c +++ b/ext/wiringpi/wiringpi_wrap.c @@ -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 @@ -1806,7 +1806,7 @@ static VALUE mWiringpi; #define SWIG_RUBY_THREAD_END_BLOCK -#define SWIGVERSION 0x020007 +#define SWIGVERSION 0x020008 #define SWIG_VERSION SWIGVERSION @@ -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]; @@ -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]; @@ -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; @@ -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) { @@ -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); diff --git a/lib/wiringpi.rb b/lib/wiringpi.rb index 5e87c7a..b170c74 100644 --- a/lib/wiringpi.rb +++ b/lib/wiringpi.rb @@ -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 @@ -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 @@ -102,6 +108,10 @@ def wiringPiMode( mode ) end + def piBoardRev + Wiringpi.piBoardRev + end + def wiringPiSetup begin @@ -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 @@ -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) @@ -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)