pigpio 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e26055fafbaad82ed0a2a348c852d3b4316eaa2a
4
- data.tar.gz: 78f95ef3d9aa8270d3b6ff31b738dccbf174d2ad
3
+ metadata.gz: 708839890d28a59c067039ff69500ef713b40e21
4
+ data.tar.gz: 4e0dc0d3ade529f3052618faf6ee117d0dde75c0
5
5
  SHA512:
6
- metadata.gz: 1f13e9605e253b8981c876b2af2d7608b56942b823fdad405d8f4843fb7015a49334bec1460d6a2e199791711e0e9470d122e3a82cf4a2b6696a768f1d5b7b66
7
- data.tar.gz: 8c620413e3f132d2fe26cd65cea62e2ba08c72c88f99782acd84b30a60ba2ef653f4d0101da2f75ed87d67424f910f98663dbf93ce4d076c098a347479a7b357
6
+ metadata.gz: 4c6e80cb17b8ee7832b7c488fbcb08cacb27d27080473983207b421af17e02f637512404498b6443db31f0bb35671d1aaffffc38062ce251f67db8806fbc4ace
7
+ data.tar.gz: 11b8ccc21407288eef3676a2c6327c862176b2561de3e2385d83dd82231d43ada587d5b573341019b8eb8a8543f01413037cfde9706907953ca2f68ca448fc59
data/.dockerignore CHANGED
@@ -4,3 +4,5 @@ tmp
4
4
  docs
5
5
  Gemfile.lock
6
6
  .rspec_status
7
+ values.txt
8
+ args.txt
data/.gitignore CHANGED
@@ -11,4 +11,6 @@ Makefile
11
11
  Gemfile.lock
12
12
  # rspec failure tracking
13
13
  .rspec_status
14
- rr.rb
14
+ rr.rb
15
+ values.txt
16
+ args.txt
data/Rakefile CHANGED
@@ -19,3 +19,9 @@ Rake::RDocTask.new do |rd|
19
19
  rd.rdoc_dir = "docs"
20
20
  rd.rdoc_files.include(RDOC_FILES)
21
21
  end
22
+
23
+ task :dummy do
24
+ cd("spec/ext") do
25
+ sh("ruby extconf.rb && make && \\cp -f libpigpiod_if2.so /usr/lib")
26
+ end
27
+ end
data/bin/Dockerfile CHANGED
@@ -4,6 +4,12 @@ ENV LANG C.UTF-8
4
4
  # for App
5
5
  ENV APP_HOME /myapp
6
6
  WORKDIR $APP_HOME
7
+ RUN mkdir -p $APP_HOME/lib/pigpio
8
+ ADD Gemfile $APP_HOME
9
+ ADD pigpio.gemspec $APP_HOME
10
+ ADD lib/pigpio/version.rb $APP_HOME/lib/pigpio
11
+ RUN bundle install
12
+
7
13
  ADD . $APP_HOME
8
14
 
9
15
  RUN cd spec/ext \
data/bin/docker.rb CHANGED
@@ -1,12 +1,22 @@
1
1
  root=File.expand_path('../../', __FILE__)
2
- if ARGV[0]=="clean"
2
+ if ARGV[0]=="c" || ARGV[0]=="clean"
3
3
  system"docker container prune"
4
4
  system"docker image prune"
5
+ system"docker image prune"
6
+ exit 0
7
+ end
8
+ if ARGV[0]=="v" || ARGV[0]=="volume"
9
+ Dir.chdir(root) do
10
+ system %q(docker build -t pigpio -f ./bin/Dockerfile .)
11
+ docker_run=%(docker run --rm -it -v "#{root}":/myapp -w /myapp #{ENV['DOCKER_OPT']} pigpio)
12
+ system("#{docker_run} cp -pf /tmp/Gemfile.lock /myapp")
13
+ system"#{docker_run} /bin/bash"
14
+ end
5
15
  exit 0
6
16
  end
7
17
  Dir.chdir(root) do
8
18
  system %q(docker build -t pigpio -f ./bin/Dockerfile .)
9
- docker_run=%(docker run --rm -it -v "#{root}":/myapp -w /myapp #{ENV['DOCKER_OPT']} pigpio)
19
+ docker_run=%(docker run --rm -it -w /myapp #{ENV['DOCKER_OPT']} pigpio)
10
20
  system("#{docker_run} cp -pf /tmp/Gemfile.lock /myapp")
11
21
  system"#{docker_run} /bin/bash"
12
22
  end
data/check.txt ADDED
@@ -0,0 +1,116 @@
1
+ o "pigpio_start",
2
+ o "pigpio_stop",
3
+ "set_mode",
4
+ "get_mode",
5
+ "set_pull_up_down",
6
+ "gpio_read",
7
+ "gpio_write",
8
+ o "time_time",
9
+ o "pigpio_error",
10
+ o "pigpiod_if_version",
11
+ "set_watchdog",
12
+ "set_glitch_filter",
13
+ "set_noise_filter",
14
+ o "get_current_tick",
15
+ o "get_hardware_revision",
16
+ o "get_pigpio_version",
17
+ "wave_clear",
18
+ "wave_add_new",
19
+ "wave_create",
20
+ "wave_delete",
21
+ "wave_send_once",
22
+ "wave_send_repeat",
23
+ "wave_send_using_mode",
24
+ "wave_tx_at",
25
+ "wave_tx_busy",
26
+ "wave_tx_stop",
27
+ "wave_get_micros",
28
+ "wave_get_high_micros",
29
+ "wave_get_max_micros",
30
+ "wave_get_pulses",
31
+ "wave_get_high_pulses",
32
+ "wave_get_max_pulses",
33
+ "wave_get_cbs",
34
+ "wave_get_high_cbs",
35
+ "wave_get_max_cbs",
36
+ "gpio_trigger",
37
+ "set_PWM_dutycycle",
38
+ "get_PWM_dutycycle",
39
+ "set_PWM_range",
40
+ "get_PWM_range",
41
+ "get_PWM_real_range",
42
+ "set_PWM_frequency",
43
+ "get_PWM_frequency",
44
+ "set_servo_pulsewidth",
45
+ "get_servo_pulsewidth",
46
+ "notify_open",
47
+ "notify_begin",
48
+ "notify_pause",
49
+ "notify_close",
50
+ "read_bank_1",
51
+ "read_bank_2",
52
+ "clear_bank_1",
53
+ "clear_bank_2",
54
+ "set_bank_1",
55
+ "set_bank_2",
56
+ "hardware_clock",
57
+ "hardware_PWM",
58
+ "wave_add_generic",
59
+ "wave_add_serial",
60
+ "wave_chain",
61
+ "callback",
62
+ "callback_cancel",
63
+ "wait_for_edge",
64
+ "event_callback",
65
+ "event_callback_cancel",
66
+ "wait_for_event",
67
+ "event_trigger",
68
+ "serial_open",
69
+ "serial_close",
70
+ "serial_write_byte",
71
+ "serial_read_byte",
72
+ "serial_write",
73
+ "serial_read",
74
+ "serial_data_available",
75
+ "bb_serial_read_open",
76
+ "bb_serial_read",
77
+ "bb_serial_read_close",
78
+ "bb_serial_invert",
79
+ "bb_spi_open",
80
+ "bb_spi_close",
81
+ "bb_spi_xfer",
82
+ "spi_open",
83
+ "spi_close",
84
+ "spi_read",
85
+ "spi_write",
86
+ "spi_xfer",
87
+ "i2c_open",
88
+ "i2c_close",
89
+ "i2c_write_quick",
90
+ "i2c_write_byte",
91
+ "i2c_read_byte",
92
+ "i2c_write_byte_data",
93
+ "i2c_write_word_data",
94
+ "i2c_read_byte_data",
95
+ "i2c_read_word_data",
96
+ "i2c_process_call",
97
+ "i2c_read_block_data",
98
+ "i2c_read_i2c_block_data",
99
+ "i2c_write_block_data",
100
+ "i2c_write_i2c_block_data",
101
+ "i2c_block_process_call",
102
+ "i2c_read_device",
103
+ "i2c_write_device",
104
+ "i2c_zip",
105
+ "bb_i2c_open",
106
+ "bb_i2c_close",
107
+ "bb_i2c_zip",
108
+ "store_script",
109
+ "run_script",
110
+ "script_status",
111
+ "stop_script",
112
+ "delete_script",
113
+ "bsc_xfer",
114
+ "bsc_i2c",
115
+ "get_pad_strength",
116
+ "set_pad_strength",
data/ext/pigpio/pigpio.c CHANGED
@@ -3,6 +3,68 @@
3
3
 
4
4
  #define TypedData_Get_Struct2(obj, type, data_type) ((type*)rb_check_typeddata((obj), (data_type)))
5
5
 
6
+ static VALUE cCallbackID;
7
+ static VALUE cCallbackError;
8
+
9
+
10
+ typedef int (*cancel_t)(unsigned);
11
+ typedef struct{
12
+ int id;
13
+ VALUE proc;
14
+ cancel_t cancel;
15
+ } callback_id_t;
16
+ void pigpio_rbst_callback_id_dmark(void* _self){
17
+ callback_id_t *self=(callback_id_t *)_self;
18
+ rb_gc_mark(self->proc);
19
+ }
20
+ void pigpio_rbst_callback_id_dfree(void* _self){
21
+ callback_id_t *self=(callback_id_t *)_self;
22
+ xfree(self);
23
+ }
24
+ size_t pigpio_rbst_callback_id_dsize(const void *_self){
25
+ return sizeof(callback_id_t);
26
+ }
27
+ const rb_data_type_t callback_id_data_type = { //https://gist.github.com/yugui/87ef6964d8a76794be6f
28
+ "struct@callback_id",{
29
+ pigpio_rbst_callback_id_dmark,
30
+ pigpio_rbst_callback_id_dfree,
31
+ pigpio_rbst_callback_id_dsize,
32
+ {0,0}
33
+ },0,NULL,0
34
+ };
35
+ VALUE pigpio_rbst_callback_id_make_inner(int id,VALUE proc,cancel_t cancel){
36
+ VALUE obj;
37
+ callback_id_t *st;
38
+ obj = TypedData_Make_Struct(cCallbackID, callback_id_t, &callback_id_data_type, st);
39
+ st->id=id;
40
+ st->proc=proc;
41
+ st->cancel=cancel;
42
+ return obj;
43
+ }
44
+ /*
45
+ get callback id.return Integer.
46
+ */
47
+ VALUE pigpio_rbst_callback_id_r_id(VALUE self){
48
+ callback_id_t *st=TypedData_Get_Struct2(self,callback_id_t,&callback_id_data_type);
49
+ return(INT2NUM(st->id));
50
+ }
51
+ /*
52
+ This function cancels a callback/event-callback.
53
+
54
+ The function returns 0 if OK, otherwise pigif_callback_not_found.
55
+
56
+ :call-seq:
57
+ cancel() -> Integer
58
+
59
+ See also: {pigpio site event_callback_cancel}[http://abyz.me.uk/rpi/pigpio/pdif2.html#event_callback_cancel]
60
+ See also: {pigpio site callback_cancel}[http://abyz.me.uk/rpi/pigpio/pdif2.html#callback_cancel]
61
+ */
62
+ VALUE pigpio_rbst_callback_id_cancel(VALUE self){
63
+ callback_id_t *st=TypedData_Get_Struct2(self,callback_id_t,&callback_id_data_type);
64
+ if(st->id<0){return INT2NUM(pigif_callback_not_found);}
65
+ return INT2NUM((*(st->cancel))(st->id));
66
+ }
67
+
6
68
  const rb_data_type_t bsc_xfer_data_type = { //https://gist.github.com/yugui/87ef6964d8a76794be6f
7
69
  "struct@bsc_xfer",{NULL,(void*)-1,0,{0,0}},0,NULL,0
8
70
  };
@@ -49,7 +111,7 @@ VALUE pigpio_rbst_bsc_xfer_w_txBuf(VALUE self,VALUE txBuf){
49
111
  /*
50
112
  Getter
51
113
  */
52
- VALUE ctest_rbst_bsc_xfer_r_rxBuf(VALUE self){
114
+ VALUE pigpio_rbst_bsc_xfer_r_rxBuf(VALUE self){
53
115
  bsc_xfer_t *st=TypedData_Get_Struct2(self,bsc_xfer_t,&bsc_xfer_data_type);
54
116
  VALUE rxBuf=rb_str_new("",st->rxCnt);
55
117
  char *buf=StringValuePtr(rxBuf);
@@ -73,7 +135,7 @@ Constructor of gpioPulse_t as Pigpio::Pulse class
73
135
  } gpioPulse_t;
74
136
  . .
75
137
  */
76
- VALUE ctest_rbst_gpioPulse_make(VALUE self,VALUE gpioOn,VALUE gpioOff,VALUE usDelay){
138
+ VALUE pigpio_rbst_gpioPulse_make(VALUE self,VALUE gpioOn,VALUE gpioOff,VALUE usDelay){
77
139
  VALUE obj;
78
140
  gpioPulse_t *st;
79
141
  obj = TypedData_Make_Struct(self, gpioPulse_t, &gpioPulse_data_type, st);
@@ -118,9 +180,10 @@ to be operated on.
118
180
  See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#pigpio_start]
119
181
  */
120
182
  VALUE pigpio_rbfn_pigpio_start(int argc, VALUE *argv, VALUE self){
183
+ int ret;
121
184
  VALUE addrStr; VALUE portStr;
122
185
  rb_scan_args(argc,argv,"02",&addrStr,&portStr);
123
- int ret=pigpio_start(
186
+ ret=pigpio_start(
124
187
  NIL_P(addrStr)? NULL : StringValueCStr(addrStr),
125
188
  NIL_P(portStr)? NULL : StringValueCStr(portStr));
126
189
  RB_GC_GUARD(addrStr);
@@ -1830,14 +1893,19 @@ GPIO has the identified edge.
1830
1893
  . .
1831
1894
 
1832
1895
  :call-seq:
1833
- callback(Integer pi,Integer user_gpio, Integer edge){|tick,level,user_gpio| } -> Integer
1896
+ callback(Integer pi,Integer user_gpio, Integer edge){|tick,level,user_gpio| } -> Pigpio::Callback
1897
+
1898
+ If you call this method without a block, this method raises an Pigpio::CallbackError exception.
1834
1899
 
1835
1900
  See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#callback_ex]
1836
1901
  */
1837
1902
  VALUE pigpio_rbfn_callback(int argc, VALUE *argv, VALUE self){
1903
+ int id;
1838
1904
  VALUE pi; VALUE user_gpio; VALUE edge; VALUE userdata;
1839
1905
  rb_scan_args(argc,argv,"3&",&pi,&user_gpio,&edge,&userdata);
1840
- return INT2NUM( callback_ex(NUM2INT(pi), NUM2UINT(user_gpio), NUM2UINT(edge), pigpio_rbbk_CBFuncEx, (void*)userdata));
1906
+ if(NIL_P(userdata)){rb_raise(cCallbackError,"No callback block.\n");}
1907
+ id=( callback_ex(NUM2INT(pi), NUM2UINT(user_gpio), NUM2UINT(edge), pigpio_rbbk_CBFuncEx, (void*)userdata));
1908
+ return pigpio_rbst_callback_id_make_inner(id,userdata,callback_cancel);
1841
1909
  }
1842
1910
  /*
1843
1911
  This function cancels a callback identified by its id.
@@ -1900,14 +1968,19 @@ The callback is called with the event id, and tick, whenever the
1900
1968
  event occurs.
1901
1969
 
1902
1970
  :call-seq:
1903
- event_callback(Integer pi,Integer event){|tick,event| } -> Integer
1971
+ event_callback(Integer pi,Integer event){|tick,event| } -> Pigpio::Callback
1972
+
1973
+ If you call this method without a block, this method raises an Pigpio::CallbackError exception.
1904
1974
 
1905
1975
  See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#event_callback_ex]
1906
1976
  */
1907
1977
  VALUE pigpio_rbfn_event_callback(int argc, VALUE *argv, VALUE self){
1978
+ int id;
1908
1979
  VALUE pi; VALUE event; VALUE userdata;
1909
1980
  rb_scan_args(argc,argv,"2&",&pi,&event,&userdata);
1910
- return INT2NUM( event_callback_ex(NUM2INT(pi), NUM2UINT(event), pigpio_rbbk_evtCBFuncEx, (void *)userdata));
1981
+ if(NIL_P(userdata)){rb_raise(cCallbackError,"No callback block.\n");}
1982
+ id=( event_callback_ex(NUM2INT(pi), NUM2UINT(event), pigpio_rbbk_evtCBFuncEx, (void *)userdata));
1983
+ return pigpio_rbst_callback_id_make_inner(id,userdata,event_callback_cancel);
1911
1984
  }
1912
1985
  /*
1913
1986
  This function cancels an event callback identified by its id.
@@ -3571,7 +3644,7 @@ This class has some constances for pigpio library.
3571
3644
  This class wrap gpioPulse_t.
3572
3645
  */
3573
3646
  cPulse = rb_define_class_under(cPigpio,"Pulse", rb_cData);
3574
- rb_define_singleton_method(cPulse, "make", ctest_rbst_gpioPulse_make, 3);
3647
+ rb_define_singleton_method(cPulse, "make", pigpio_rbst_gpioPulse_make, 3);
3575
3648
 
3576
3649
  /*
3577
3650
  This class wrap bsc_xfer_t.
@@ -3580,6 +3653,17 @@ This class has some constances for pigpio library.
3580
3653
  rb_define_singleton_method(cBscXfer, "make", pigpio_rbst_bsc_xfer_make, 0);
3581
3654
  rb_define_method(cBscXfer, "control=", pigpio_rbst_bsc_xfer_w_control, 1);
3582
3655
  rb_define_method(cBscXfer, "txBuf=", pigpio_rbst_bsc_xfer_w_txBuf, 1);
3583
- rb_define_method(cBscXfer, "rxBuf", ctest_rbst_bsc_xfer_r_rxBuf, 0);
3584
-
3656
+ rb_define_method(cBscXfer, "rxBuf", pigpio_rbst_bsc_xfer_r_rxBuf, 0);
3657
+ /*
3658
+ The class for callback.
3659
+ */
3660
+ cCallbackID = rb_define_class_under(cPigpio,"Callback", rb_cData);
3661
+ rb_define_method(cCallbackID, "id", pigpio_rbst_callback_id_r_id, 0);
3662
+ rb_define_method(cCallbackID, "cancel", pigpio_rbst_callback_id_cancel, 0);
3663
+ rb_gc_register_address(&cCallbackID);
3664
+ /*
3665
+ The class for callback error.
3666
+ */
3667
+ cCallbackError = rb_define_class_under(cPigpio,"CallbackError", rb_eException);
3668
+ rb_gc_register_address(&cCallbackError);
3585
3669
  }
data/lib/pigpio.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  require "pigpio/version"
2
2
  require "pigpio/constant"
3
3
  require "pigpio/pigpio"
4
+ require "pigpio/gpio"
5
+ require "pigpio/user_gpio"
6
+ require "pigpio/pwm"
7
+ require "pigpio/bank"
4
8
 
5
9
  class Pigpio
6
10
  def initialize(addr=nil,port=nil,&blk)
@@ -13,6 +17,9 @@ class Pigpio
13
17
  def connect
14
18
  @pi>=0
15
19
  end
20
+ def pi
21
+ @pi
22
+ end
16
23
  def stop
17
24
  IF.pigpio_stop(@pi)
18
25
  @pi=-1
@@ -26,128 +33,12 @@ class Pigpio
26
33
  def pigpio_version
27
34
  IF.get_pigpio_version(@pi)
28
35
  end
29
- class Bank
30
- Set={
31
- read: [:read_bank_1 ,:read_bank_2],
32
- clear: [:clear_bank_1,:clear_bank_2],
33
- set: [:set_bank_1 ,:set_bank_2],
34
- }
35
- def initialize(pi,num)
36
- @pi=pi
37
- @num=num
38
- end
39
- def read
40
- IF.send(Set[:read][@num],@pi)
41
- end
42
- def clear(bits)
43
- IF.send(Set[:clear][@num],@pi,bits)
44
- end
45
- def set(bits)
46
- IF.send(Set[:set][@num],@pi,bits)
47
- end
48
- end
36
+
49
37
  def bank(num)
50
38
  Bank.new(@pi,num)
51
39
  end
52
-
53
-
54
40
  def gpio(gpio)
55
- if gpio<32
56
- UserGPIO.new(@pi,gpio)
57
- else
58
- GPIO.new(@pi,gpio)
59
- end
60
- end
61
- class GPIO
62
- def initialize(pi,gpio)
63
- @pi=pi #0-15
64
- @gpio=gpio #0-53
65
- end
66
- def gpio
67
- @gpio
68
- end
69
- def mode=(mode)
70
- ret=IF.set_mode(@pi,@gpio,mode)
71
- end
72
- def mode
73
- ret=IF.get_mode(@pi,@gpio)
74
- end
75
- def pud(pud)
76
- ret=IF.set_pull_up_down(@pi,@gpio,pud)
77
- end
78
- def read
79
- ret=IF.gpio_read(@pi,@gpio)
80
- end
81
- def write(level)
82
- ret=IF.gpio_write(@pi,@gpio,level)
83
- end
84
- def hardware_clock(clkfreq)
85
- ret=IF.hardware_clock(@pi,@gpio,clkfreq)
86
- end
87
- def hardware_PWM(vPWMfreq,vPWMduty)
88
- ret=IF.hardware_PWM(@pi,@gpio,vPWMfreq,vPWMduty)
89
- end
90
- end
91
- class UserGPIO < GPIO
92
- def watchdog(timeout)
93
- ret=IF.set_watchdog(@pi,@gpio,timeout)
94
- end
95
- def glitch_filter(steady)
96
- ret=IF.set_glitch_filter(@pi,@gpio,steady)
97
- end
98
- def noise_filter(steady,active)
99
- ret=IF.set_noise_filter(@pi,@gpio,steady,active)
100
- end
101
- def callback(edge,&blk)
102
- @cid=IF.callback(@pi,@gpio,edge,&blk)
103
- end
104
- def cancel_callback
105
- ret=IF.callback_cancel(@cid) if @cid && @cid >=0
106
- @cid=nil
107
- ret
108
- end
109
- def wait_for_edge(edge,timeout)
110
- ret=IF.wait_for_edge(@pi,@gpio,edge,timeout)
111
- end
112
- def trigger(pulseLen,level)
113
- ret=IF.gpio_trigger(@pi,@gpio,pulseLen,level)
114
- end
115
- def pwm
116
- PWM.new(@pi,@gpio)
117
- end
118
- end
119
- class PWM
120
- def initialize(pi,gpio)
121
- @pi=pi
122
- @gpio=gpio
123
- end
124
- def dutycycle=(dutycycle)
125
- ret=IF.set_PWM_dutycycle(@pi,@gpio,dutycycle)
126
- end
127
- def dutycycle
128
- ret=IF.get_PWM_dutycycle(@pi,@gpio)
129
- end
130
- def range=(range)
131
- ret=IF.set_PWM_range(@pi,@gpio,range)
132
- end
133
- def range
134
- ret=IF.get_PWM_range(@pi,@gpio)
135
- end
136
- def real_range
137
- ret=IF.get_PWM_real_range(@pi,@gpio)
138
- end
139
- def frequency=(frequency)
140
- ret=IF.set_PWM_frequency(@pi,@gpio,frequency)
141
- end
142
- def frequency
143
- ret=IF.get_PWM_frequency(@pi,@gpio)
144
- end
145
- def servo_pulsewidth=(pulsewidth)
146
- ret=IF.set_servo_pulsewidth(@pi,@gpio,pulsewidth)
147
- end
148
- def servo_pulsewidth
149
- ret=IF.get_servo_pulsewidth(@pi,@gpio)
150
- end
41
+ (gpio<32 ? UserGPIO : GPIO).new(@pi,gpio)
151
42
  end
152
43
 
153
44
  end
@@ -0,0 +1,20 @@
1
+ class Pigpio::Bank
2
+ Set={
3
+ read: [:read_bank_1 ,:read_bank_2],
4
+ clear: [:clear_bank_1,:clear_bank_2],
5
+ set: [:set_bank_1 ,:set_bank_2],
6
+ }
7
+ def initialize(pi,num)
8
+ @pi=pi
9
+ @num=num
10
+ end
11
+ def read
12
+ IF.send(Set[:read][@num],@pi)
13
+ end
14
+ def clear(bits)
15
+ IF.send(Set[:clear][@num],@pi,bits)
16
+ end
17
+ def set(bits)
18
+ IF.send(Set[:set][@num],@pi,bits)
19
+ end
20
+ end
@@ -729,4 +729,19 @@ module Pigpio::Constant
729
729
  PI_DEFAULT_MEM_ALLOC_MODE =PI_MEM_ALLOC_AUTO
730
730
 
731
731
  PI_DEFAULT_CFG_INTERNALS =0
732
+
733
+ Pigif_bad_send = -2000
734
+ Pigif_bad_recv = -2001
735
+ Pigif_bad_getaddrinfo = -2002
736
+ Pigif_bad_connect = -2003
737
+ Pigif_bad_socket = -2004
738
+ Pigif_bad_noib = -2005
739
+ Pigif_duplicate_callback = -2006
740
+ Pigif_bad_malloc = -2007
741
+ Pigif_bad_callback = -2008
742
+ Pigif_notify_failed = -2009
743
+ Pigif_callback_not_found = -2010
744
+ Pigif_unconnected_pi = -2011
745
+ Pigif_too_many_pis = -2012
746
+
732
747
  end
@@ -0,0 +1,30 @@
1
+ class Pigpio::GPIO
2
+ def initialize(pi,gpio)
3
+ @pi=pi #0-15
4
+ @gpio=gpio #0-53
5
+ end
6
+ def gpio
7
+ [@pi,@gpio]
8
+ end
9
+ def mode=(mode)
10
+ ret=IF.set_mode(@pi,@gpio,mode)
11
+ end
12
+ def mode
13
+ ret=IF.get_mode(@pi,@gpio)
14
+ end
15
+ def pud(pud)
16
+ ret=IF.set_pull_up_down(@pi,@gpio,pud)
17
+ end
18
+ def read
19
+ ret=IF.gpio_read(@pi,@gpio)
20
+ end
21
+ def write(level)
22
+ ret=IF.gpio_write(@pi,@gpio,level)
23
+ end
24
+ def hardware_clock(clkfreq)
25
+ ret=IF.hardware_clock(@pi,@gpio,clkfreq)
26
+ end
27
+ def hardware_PWM(vPWMfreq,vPWMduty)
28
+ ret=IF.hardware_PWM(@pi,@gpio,vPWMfreq,vPWMduty)
29
+ end
30
+ end
data/lib/pigpio/pwm.rb ADDED
@@ -0,0 +1,33 @@
1
+ class Pigpio::PWM
2
+ def initialize(pi,gpio)
3
+ @pi=pi
4
+ @gpio=gpio
5
+ end
6
+ def dutycycle=(dutycycle)
7
+ ret=IF.set_PWM_dutycycle(@pi,@gpio,dutycycle)
8
+ end
9
+ def dutycycle
10
+ ret=IF.get_PWM_dutycycle(@pi,@gpio)
11
+ end
12
+ def range=(range)
13
+ ret=IF.set_PWM_range(@pi,@gpio,range)
14
+ end
15
+ def range
16
+ ret=IF.get_PWM_range(@pi,@gpio)
17
+ end
18
+ def real_range
19
+ ret=IF.get_PWM_real_range(@pi,@gpio)
20
+ end
21
+ def frequency=(frequency)
22
+ ret=IF.set_PWM_frequency(@pi,@gpio,frequency)
23
+ end
24
+ def frequency
25
+ ret=IF.get_PWM_frequency(@pi,@gpio)
26
+ end
27
+ def servo_pulsewidth=(pulsewidth)
28
+ ret=IF.set_servo_pulsewidth(@pi,@gpio,pulsewidth)
29
+ end
30
+ def servo_pulsewidth
31
+ ret=IF.get_servo_pulsewidth(@pi,@gpio)
32
+ end
33
+ end
@@ -0,0 +1,24 @@
1
+ require_relative "./gpio"
2
+ class ::Pigpio::UserGPIO < ::Pigpio::GPIO
3
+ def watchdog(timeout)
4
+ ret=IF.set_watchdog(@pi,@gpio,timeout)
5
+ end
6
+ def glitch_filter(steady)
7
+ ret=IF.set_glitch_filter(@pi,@gpio,steady)
8
+ end
9
+ def noise_filter(steady,active)
10
+ ret=IF.set_noise_filter(@pi,@gpio,steady,active)
11
+ end
12
+ def callback(edge,&blk)
13
+ IF.callback(@pi,@gpio,edge,&blk)
14
+ end
15
+ def wait_for_edge(edge,timeout)
16
+ ret=IF.wait_for_edge(@pi,@gpio,edge,timeout)
17
+ end
18
+ def trigger(pulseLen,level)
19
+ ret=IF.gpio_trigger(@pi,@gpio,pulseLen,level)
20
+ end
21
+ def pwm
22
+ PWM.new(@pi,@gpio)
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  class Pigpio
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pigpio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - nak1114
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-12 00:00:00.000000000 Z
11
+ date: 2019-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,10 +87,15 @@ files:
87
87
  - bin/console
88
88
  - bin/docker.rb
89
89
  - bin/setup
90
+ - check.txt
90
91
  - ext/pigpio/extconf.rb
91
92
  - ext/pigpio/pigpio.c
92
93
  - lib/pigpio.rb
94
+ - lib/pigpio/bank.rb
93
95
  - lib/pigpio/constant.rb
96
+ - lib/pigpio/gpio.rb
97
+ - lib/pigpio/pwm.rb
98
+ - lib/pigpio/user_gpio.rb
94
99
  - lib/pigpio/version.rb
95
100
  - pigpio.gemspec
96
101
  homepage: http://www.github.com/nak1114/ruby-extension-pigpio