Skip to content

Commit

Permalink
Add bindings for pin mapping and board revision methods
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewn committed Sep 25, 2013
1 parent 4951769 commit 8b7832d
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ext/wiringpi/wiringpi.i
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ extern void pwmWrite (int pin, int value) ;
extern int analogRead (int pin) ;
extern void analogWrite (int pin, int value) ;

// Raspberry Pi Specifics
extern int piBoardRev (void) ;
extern int wpiPinToGpio (int wPiPin) ;
extern int physPinToGpio (int physPin) ;

// Interrupts

extern int (*waitForInterrupt) (int pin, int mS) ;
Expand Down Expand Up @@ -135,4 +140,4 @@ extern void lcdPuts (int fd, char *string) ;
extern void lcdPrintf (int fd, char *message, ...) ;

extern int lcdInit (int rows, int cols, int bits, int rs, int strb,
int d0, int d1, int d2, int d3, int d4, int d5, int d6, int d7) ;
int d0, int d1, int d2, int d3, int d4, int d5, int d6, int d7) ;
67 changes: 67 additions & 0 deletions ext/wiringpi/wiringpi_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2328,6 +2328,70 @@ _wrap_analogWrite(int argc, VALUE *argv, VALUE self) {
}


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_wpiPinToGpio(int argc, VALUE *argv, VALUE self) {
int arg1 ;
int val1 ;
int ecode1 = 0 ;
int result;
VALUE vresult = Qnil;

if ((argc < 1) || (argc > 1)) {
rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail;
}
ecode1 = SWIG_AsVal_int(argv[0], &val1);
if (!SWIG_IsOK(ecode1)) {
SWIG_exception_fail(SWIG_ArgError(ecode1), Ruby_Format_TypeError( "", "int","wpiPinToGpio", 1, argv[0] ));
}
arg1 = (int)(val1);
result = (int)wpiPinToGpio(arg1);
vresult = SWIG_From_int((int)(result));
return vresult;
fail:
return Qnil;
}


SWIGINTERN VALUE
_wrap_physPinToGpio(int argc, VALUE *argv, VALUE self) {
int arg1 ;
int val1 ;
int ecode1 = 0 ;
int result;
VALUE vresult = Qnil;

if ((argc < 1) || (argc > 1)) {
rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail;
}
ecode1 = SWIG_AsVal_int(argv[0], &val1);
if (!SWIG_IsOK(ecode1)) {
SWIG_exception_fail(SWIG_ArgError(ecode1), Ruby_Format_TypeError( "", "int","physPinToGpio", 1, argv[0] ));
}
arg1 = (int)(val1);
result = (int)physPinToGpio(arg1);
vresult = SWIG_From_int((int)(result));
return vresult;
fail:
return Qnil;
}


SWIGINTERN VALUE
_wrap_waitForInterrupt_get(VALUE self) {
VALUE _val;
Expand Down Expand Up @@ -4256,6 +4320,9 @@ SWIGEXPORT void Init_wiringpi2(void) {
rb_define_module_function(mWiringpi2, "pwmWrite", _wrap_pwmWrite, -1);
rb_define_module_function(mWiringpi2, "analogRead", _wrap_analogRead, -1);
rb_define_module_function(mWiringpi2, "analogWrite", _wrap_analogWrite, -1);
rb_define_module_function(mWiringpi2, "piBoardRev", _wrap_piBoardRev, -1);
rb_define_module_function(mWiringpi2, "wpiPinToGpio", _wrap_wpiPinToGpio, -1);
rb_define_module_function(mWiringpi2, "physPinToGpio", _wrap_physPinToGpio, -1);
rb_define_singleton_method(mWiringpi2, "waitForInterrupt", _wrap_waitForInterrupt_get, 0);
rb_define_singleton_method(mWiringpi2, "waitForInterrupt=", _wrap_waitForInterrupt_set, 1);
rb_define_module_function(mWiringpi2, "wiringPiISR", _wrap_wiringPiISR, -1);
Expand Down
12 changes: 12 additions & 0 deletions lib/wiringpi/gpio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ def micros()
return Wiringpi2.micros()
end

def pi_board_rev()
return Wiringpi2.piBoardRev()
end

def wpi_pin_to_gpio(pin)
return Wiringpi2.wpiPinToGpio(pin)
end

def phys_pin_to_gpio(pin)
return Wiringpi2.physPinToGpio(pin)
end

def pwm_set_mode(mode)
return Wiringpi2.pwmSetMode(mode)
end
Expand Down

0 comments on commit 8b7832d

Please sign in to comment.