Skip to content

Commit

Permalink
Merge pull request WiringPi#3 from andrewn/new-binding-methods
Browse files Browse the repository at this point in the history
Fixes for compilation issues and bind new methods
  • Loading branch information
Gadgetoid committed Sep 25, 2013
2 parents 048f32f + b6a8798 commit 2951e8e
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ext/wiringpi/WiringPi/wiringPi/piNes.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
***********************************************************************
*/

#include <wiringPi.h>
#include "wiringPi.h"

#include "piNes.h"

Expand Down
2 changes: 1 addition & 1 deletion ext/wiringpi/WiringPi/wiringPi/wiringPi.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ int wiringPiFailure (char *message, ...)
vsnprintf (buffer, 1023, message, argp) ;
va_end (argp) ;

fprintf (stderr, buffer) ;
fprintf(stderr,"%s",buffer) ;
exit (EXIT_FAILURE) ;

return 0 ;
Expand Down
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
26 changes: 21 additions & 5 deletions lib/wiringpi/gpio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class GPIO
def initialize(&block)
Wiringpi2.wiringPiSetup
@pins = Array.new
instance_eval &block
instance_eval &block if block_given?
end

def read_byte(starting_pin)
Expand Down Expand Up @@ -53,6 +53,10 @@ def pin_mode(pin, mode)
Wiringpi2.pinMode(pin, mode)
end

def pull_up_dn_control(pin,mode)
Wiringpi2.pullUpDnControl(pin, mode)
end

def delay(ms)
Wiringpi2.delay(ms)
end
Expand All @@ -69,6 +73,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 All @@ -90,15 +106,15 @@ def wait_for_interrupt(pin, ms)
end

def wiringpi_isr(pin, mode, fn)
Wiringpi.wiringPiISR(pin, mode, fn)
Wiringpi2.wiringPiISR(pin, mode, fn)
end

def shift_out(dpin, cpin, order, val )
Wiringpi.shiftOut(dpin,cpin,order,val)
Wiringpi2.shiftOut(dpin,cpin,order,val)
end

def shift_in(dpin, cpin, order)
Wiringpi.shiftIn(dpin,cpin,order)
Wiringpi2.shiftIn(dpin,cpin,order)
end

def add_module(module_instance)
Expand All @@ -112,4 +128,4 @@ def add_module(module_instance)
end
end
end
end
end

0 comments on commit 2951e8e

Please sign in to comment.