pigpio 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +45 -0
  9. data/Rakefile +21 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/docs/Pigpio.html +2743 -0
  13. data/docs/Pigpio/IF.html +6894 -0
  14. data/docs/created.rid +5 -0
  15. data/docs/css/fonts.css +167 -0
  16. data/docs/css/rdoc.css +590 -0
  17. data/docs/fonts/Lato-Light.ttf +0 -0
  18. data/docs/fonts/Lato-LightItalic.ttf +0 -0
  19. data/docs/fonts/Lato-Regular.ttf +0 -0
  20. data/docs/fonts/Lato-RegularItalic.ttf +0 -0
  21. data/docs/fonts/SourceCodePro-Bold.ttf +0 -0
  22. data/docs/fonts/SourceCodePro-Regular.ttf +0 -0
  23. data/docs/images/add.png +0 -0
  24. data/docs/images/arrow_up.png +0 -0
  25. data/docs/images/brick.png +0 -0
  26. data/docs/images/brick_link.png +0 -0
  27. data/docs/images/bug.png +0 -0
  28. data/docs/images/bullet_black.png +0 -0
  29. data/docs/images/bullet_toggle_minus.png +0 -0
  30. data/docs/images/bullet_toggle_plus.png +0 -0
  31. data/docs/images/date.png +0 -0
  32. data/docs/images/delete.png +0 -0
  33. data/docs/images/find.png +0 -0
  34. data/docs/images/loadingAnimation.gif +0 -0
  35. data/docs/images/macFFBgHack.png +0 -0
  36. data/docs/images/package.png +0 -0
  37. data/docs/images/page_green.png +0 -0
  38. data/docs/images/page_white_text.png +0 -0
  39. data/docs/images/page_white_width.png +0 -0
  40. data/docs/images/plugin.png +0 -0
  41. data/docs/images/ruby.png +0 -0
  42. data/docs/images/tag_blue.png +0 -0
  43. data/docs/images/tag_green.png +0 -0
  44. data/docs/images/transparent.png +0 -0
  45. data/docs/images/wrench.png +0 -0
  46. data/docs/images/wrench_orange.png +0 -0
  47. data/docs/images/zoom.png +0 -0
  48. data/docs/index.html +82 -0
  49. data/docs/js/darkfish.js +161 -0
  50. data/docs/js/jquery.js +4 -0
  51. data/docs/js/navigation.js +142 -0
  52. data/docs/js/navigation.js.gz +0 -0
  53. data/docs/js/search.js +109 -0
  54. data/docs/js/search_index.js +1 -0
  55. data/docs/js/search_index.js.gz +0 -0
  56. data/docs/js/searcher.js +228 -0
  57. data/docs/js/searcher.js.gz +0 -0
  58. data/docs/table_of_contents.html +632 -0
  59. data/ext/pigpio/extconf.rb +5 -0
  60. data/ext/pigpio/pigpio.c +3547 -0
  61. data/lib/pigpio.rb +6 -0
  62. data/lib/pigpio/constant.rb +732 -0
  63. data/lib/pigpio/version.rb +3 -0
  64. data/pigpio.gemspec +45 -0
  65. metadata +168 -0
@@ -0,0 +1,5 @@
1
+ require 'mkmf'
2
+ dir_config('pigpio')
3
+ if find_header('pigpiod_if2.h','/usr/include/') && find_library('pigpiod_if2','gpio_read','/usr/lib/')
4
+ create_makefile('pigpio/pigpio')
5
+ end
@@ -0,0 +1,3547 @@
1
+ #include "ruby.h"
2
+ #include "pigpiod_if2.h"
3
+
4
+ #define TypedData_Get_Struct2(obj, type, data_type) ((type*)rb_check_typeddata((obj), (data_type)))
5
+
6
+ const rb_data_type_t bsc_xfer_data_type = { //https://gist.github.com/yugui/87ef6964d8a76794be6f
7
+ "struct@bsc_xfer",{NULL,(void*)-1,0,{0,0}},0,NULL,0
8
+ };
9
+ VALUE pigpio_rbst_bsc_xfer_make(VALUE self){
10
+ VALUE obj;
11
+ bsc_xfer_t *st;
12
+ obj = TypedData_Make_Struct(self, bsc_xfer_t, &bsc_xfer_data_type, st);
13
+ return obj;
14
+ }
15
+ VALUE pigpio_rbst_bsc_xfer_w_control(VALUE self,VALUE control){
16
+ bsc_xfer_t *st=TypedData_Get_Struct2(self,bsc_xfer_t,&bsc_xfer_data_type);
17
+ st->control=NUM2ULONG(control);
18
+ return self;
19
+ }
20
+ VALUE pigpio_rbst_bsc_xfer_w_txBuf(VALUE self,VALUE txBuf){
21
+ bsc_xfer_t *st=TypedData_Get_Struct2(self,bsc_xfer_t,&bsc_xfer_data_type);
22
+ int len=RSTRING_LEN(txBuf);
23
+ char *buf=StringValuePtr(txBuf);
24
+ st->txCnt=(len<BSC_FIFO_SIZE)?len:BSC_FIFO_SIZE;
25
+ for(int i=0;i<st->txCnt;i++){
26
+ st->txBuf[i]=*buf++;
27
+ }
28
+ RB_GC_GUARD(txBuf);
29
+ return self;
30
+ }
31
+ VALUE ctest_rbst_bsc_xfer_r_rxBuf(VALUE self){
32
+ bsc_xfer_t *st=TypedData_Get_Struct2(self,bsc_xfer_t,&bsc_xfer_data_type);
33
+ VALUE rxBuf=rb_str_new("",st->rxCnt);
34
+ char *buf=StringValuePtr(rxBuf);
35
+ for(int i=0;i<st->rxCnt;i++){
36
+ *buf++=st->rxBuf[i];
37
+ }
38
+ return rxBuf;
39
+ }
40
+
41
+ const rb_data_type_t gpioPulse_data_type = { //https://gist.github.com/yugui/87ef6964d8a76794be6f
42
+ "struct@gpioPulse",{NULL,(void*)-1,0,{0,0}},0,NULL,0
43
+ };
44
+ /*
45
+ Constructor of gpioPulse_t as PIGPIO::Pulse class
46
+ . .
47
+ typedef struct
48
+ {
49
+ uint32_t gpioOn;
50
+ uint32_t gpioOff;
51
+ uint32_t usDelay;
52
+ } gpioPulse_t;
53
+ . .
54
+ */
55
+ VALUE ctest_rbst_gpioPulse_make(VALUE self,VALUE gpioOn,VALUE gpioOff,VALUE usDelay){
56
+ VALUE obj;
57
+ gpioPulse_t *st;
58
+ obj = TypedData_Make_Struct(self, gpioPulse_t, &gpioPulse_data_type, st);
59
+ st->gpioOn =NUM2ULONG(gpioOn );
60
+ st->gpioOff=NUM2ULONG(gpioOff);
61
+ st->usDelay=NUM2ULONG(usDelay);
62
+ return obj;
63
+ }
64
+ void pigpio_rbbk_CBFuncEx(int pi, unsigned user_gpio, unsigned level, uint32_t tick, void *userdata){
65
+ (rb_funcall((VALUE)userdata, rb_intern("call"), 3,ULONG2NUM(tick),UINT2NUM(level),UINT2NUM(user_gpio)));
66
+ return;
67
+ }
68
+ void pigpio_rbbk_evtCBFuncEx(int pi, unsigned event, uint32_t tick, void *userdata){
69
+ (rb_funcall((VALUE)userdata, rb_intern("call"), 2,ULONG2NUM(tick),UINT2NUM(event)));
70
+ return;
71
+ }
72
+
73
+ /*
74
+ Connect to the pigpio daemon. Reserving command and
75
+ notification streams.
76
+
77
+ . .
78
+ addrStr: specifies the host or IP address of the Pi running the
79
+ pigpio daemon. It may be NULL in which case localhost
80
+ is used unless overridden by the PIGPIO_ADDR environment
81
+ variable.
82
+
83
+ portStr: specifies the port address used by the Pi running the
84
+ pigpio daemon. It may be NULL in which case "8888"
85
+ is used unless overridden by the PIGPIO_PORT environment
86
+ variable.
87
+ . .
88
+
89
+ Returns an integer value greater than or equal to zero if OK.
90
+
91
+ This value is passed to the GPIO routines to specify the Pi
92
+ to be operated on.
93
+
94
+ :call-seq:
95
+ pigpio_start(String address,String port) -> Integer
96
+
97
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#pigpio_start]
98
+ */
99
+ VALUE pigpio_rbfn_pigpio_start(VALUE self,VALUE addrStr, VALUE portStr){
100
+ int ret=pigpio_start(StringValueCStr(addrStr), StringValueCStr(portStr));
101
+ RB_GC_GUARD(addrStr);
102
+ RB_GC_GUARD(portStr);
103
+ return INT2NUM(ret);
104
+ }
105
+
106
+ VALUE pigpio_rbfn_pigpio_start_local(VALUE self){
107
+ return INT2NUM(pigpio_start(NULL, NULL));
108
+ }
109
+
110
+ /*
111
+ Terminates the connection to a pigpio daemon and releases
112
+ resources used by the library.
113
+
114
+ . .
115
+ pi: >=0 (as returned by [*pigpio_start*]).
116
+ . .
117
+
118
+ :call-seq:
119
+ pigpio_stop() -> Integer
120
+
121
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#pigpio_stop]
122
+ */
123
+ VALUE pigpio_rbfn_pigpio_stop(VALUE pi){
124
+ pigpio_stop(NUM2INT(pi));
125
+ return Qnil;
126
+ }
127
+
128
+ /*
129
+ Set the GPIO mode.
130
+
131
+ . .
132
+ pi: >=0 (as returned by [*pigpio_start*]).
133
+ gpio: 0-53.
134
+ mode: PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1,
135
+ PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5.
136
+ . .
137
+
138
+ Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE,
139
+ or PI_NOT_PERMITTED.
140
+
141
+ :call-seq:
142
+ set_mode(Integer pi,Integer gpio,Integer mode) -> Integer
143
+
144
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#set_mode]
145
+ */
146
+ VALUE pigpio_rbfn_set_mode(VALUE self,VALUE pi, VALUE gpio, VALUE mode){
147
+ return INT2NUM(set_mode(NUM2INT(pi), NUM2UINT(gpio), NUM2UINT(mode)));
148
+ }
149
+ /*
150
+ Get the GPIO mode.
151
+
152
+ . .
153
+ pi: >=0 (as returned by [*pigpio_start*]).
154
+ gpio: 0-53.
155
+ . .
156
+
157
+ Returns the GPIO mode if OK, otherwise PI_BAD_GPIO.
158
+
159
+ :call-seq:
160
+ get_mode(Integer pi,Integer gpio) -> Integer
161
+
162
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#get_mode]
163
+ */
164
+ VALUE pigpio_rbfn_get_mode(VALUE self,VALUE pi, VALUE gpio){
165
+ return INT2NUM(get_mode( NUM2INT(pi), NUM2UINT(gpio)));
166
+ }
167
+ /*
168
+ Set or clear the GPIO pull-up/down resistor.
169
+
170
+ . .
171
+ pi: >=0 (as returned by [*pigpio_start*]).
172
+ gpio: 0-53.
173
+ pud: PI_PUD_UP, PI_PUD_DOWN, PI_PUD_OFF.
174
+ . .
175
+
176
+ Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD,
177
+ or PI_NOT_PERMITTED.
178
+
179
+ :call-seq:
180
+ set_pull_up_down(Integer pi,Integer gpio,Integer pud) -> Integer
181
+
182
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#set_pull_up_down]
183
+ */
184
+ VALUE pigpio_rbfn_set_pull_up_down(VALUE self,VALUE pi, VALUE gpio, VALUE pud){
185
+ return INT2NUM(set_pull_up_down(NUM2INT(pi), NUM2UINT(gpio), NUM2UINT(pud)));
186
+ }
187
+ /*
188
+ Read the GPIO level.
189
+
190
+ . .
191
+ pi: >=0 (as returned by [*pigpio_start*]).
192
+ gpio:0-53.
193
+ . .
194
+
195
+ Returns the GPIO level if OK, otherwise PI_BAD_GPIO.
196
+
197
+ :call-seq:
198
+ gpio_read(Integer pi,Integer gpio) -> Integer
199
+
200
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#gpio_read]
201
+ */
202
+ VALUE pigpio_rbfn_gpio_read(VALUE self,VALUE pi, VALUE gpio){
203
+ return INT2NUM(gpio_read(NUM2INT(pi), NUM2UINT(gpio)));
204
+ }
205
+ /*
206
+ Write the GPIO level.
207
+
208
+ . .
209
+ pi: >=0 (as returned by [*pigpio_start*]).
210
+ gpio: 0-53.
211
+ level: 0, 1.
212
+ . .
213
+
214
+ Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL,
215
+ or PI_NOT_PERMITTED.
216
+
217
+ Notes
218
+
219
+ If PWM or servo pulses are active on the GPIO they are switched off.
220
+
221
+ :call-seq:
222
+ gpio_write(Integer pi,Integer gpio,Integer level) -> Integer
223
+
224
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#gpio_write]
225
+ */
226
+ VALUE pigpio_rbfn_gpio_write(VALUE self,VALUE pi, VALUE gpio, VALUE level){
227
+ return INT2NUM(gpio_write(NUM2INT(pi), NUM2UINT(gpio), NUM2UINT(level)));
228
+ }
229
+ /*
230
+ Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO.
231
+
232
+ . .
233
+ pi: >=0 (as returned by [*pigpio_start*]).
234
+ user_gpio: 0-31.
235
+ dutycycle: 0-range (range defaults to 255).
236
+ . .
237
+
238
+ Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE,
239
+ or PI_NOT_PERMITTED.
240
+ Notes
241
+
242
+ The [*set_PWM_range*] function may be used to change the
243
+ default range of 255.
244
+
245
+ :call-seq:
246
+ set_PWM_dutycycle(Integer pi,Integer user_gpio, VALUE dutycycle) -> Integer
247
+
248
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#set_PWM_dutycycle]
249
+ */
250
+ VALUE pigpio_rbfn_set_PWM_dutycycle(VALUE self, VALUE pi, VALUE user_gpio, VALUE dutycycle){
251
+ return INT2NUM( set_PWM_dutycycle(NUM2INT(pi), NUM2UINT(user_gpio), NUM2UINT(dutycycle)));
252
+ }
253
+ /*
254
+ Return the PWM dutycycle in use on a GPIO.
255
+
256
+ . .
257
+ pi: >=0 (as returned by [*pigpio_start*]).
258
+ user_gpio: 0-31.
259
+ . .
260
+
261
+ Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO.
262
+
263
+ For normal PWM the dutycycle will be out of the defined range
264
+ for the GPIO (see [*get_PWM_range*]).
265
+
266
+ If a hardware clock is active on the GPIO the reported dutycycle
267
+ will be 500000 (500k) out of 1000000 (1M).
268
+
269
+ If hardware PWM is active on the GPIO the reported dutycycle
270
+ will be out of a 1000000 (1M).
271
+
272
+ :call-seq:
273
+ get_PWM_dutycycle(Integer pi,Integer user_gpio) -> Integer
274
+
275
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#get_PWM_dutycycle]
276
+ */
277
+ VALUE pigpio_rbfn_get_PWM_dutycycle(VALUE self, VALUE pi, VALUE user_gpio){
278
+ return INT2NUM( get_PWM_dutycycle(NUM2INT(pi), NUM2UINT(user_gpio)));
279
+ }
280
+ /*
281
+ Set the range of PWM values to be used on the GPIO.
282
+
283
+ . .
284
+ pi: >=0 (as returned by [*pigpio_start*]).
285
+ user_gpio: 0-31.
286
+ range: 25-40000.
287
+ . .
288
+
289
+ Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE,
290
+ or PI_NOT_PERMITTED.
291
+
292
+ Notes
293
+
294
+ If PWM is currently active on the GPIO its dutycycle will be
295
+ scaled to reflect the new range.
296
+
297
+ The real range, the number of steps between fully off and fully on
298
+ for each of the 18 available GPIO frequencies is
299
+
300
+ . .
301
+ 25(#1), 50(#2), 100(#3), 125(#4), 200(#5), 250(#6),
302
+ 400(#7), 500(#8), 625(#9), 800(#10), 1000(#11), 1250(#12),
303
+ 2000(#13), 2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18)
304
+ . .
305
+
306
+ The real value set by set_PWM_range is (dutycycle * real range) / range.
307
+
308
+
309
+ :call-seq:
310
+ set_PWM_range(Integer pi,Integer user_gpio, Integer range) -> Integer
311
+
312
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#set_PWM_range]
313
+ */
314
+ VALUE pigpio_rbfn_set_PWM_range(VALUE self, VALUE pi, VALUE user_gpio, VALUE range){
315
+ return INT2NUM( set_PWM_range(NUM2INT(pi), NUM2UINT(user_gpio), NUM2UINT(range)));
316
+ }
317
+ /*
318
+ Get the range of PWM values being used on the GPIO.
319
+
320
+ . .
321
+ pi: >=0 (as returned by [*pigpio_start*]).
322
+ user_gpio: 0-31.
323
+ . .
324
+
325
+ Returns the dutycycle range used for the GPIO if OK,
326
+ otherwise PI_BAD_USER_GPIO.
327
+
328
+ If a hardware clock or hardware PWM is active on the GPIO the
329
+ reported range will be 1000000 (1M).
330
+
331
+ :call-seq:
332
+ get_PWM_range(Integer pi,Integer user_gpio) -> Integer
333
+
334
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#get_PWM_range]
335
+ */
336
+ VALUE pigpio_rbfn_get_PWM_range(VALUE self, VALUE pi, VALUE user_gpio){
337
+ return INT2NUM( get_PWM_range(NUM2INT(pi), NUM2UINT(user_gpio)));
338
+ }
339
+ /*
340
+ Get the real underlying range of PWM values being used on the GPIO.
341
+
342
+ . .
343
+ pi: >=0 (as returned by [*pigpio_start*]).
344
+ user_gpio: 0-31.
345
+ . .
346
+
347
+ Returns the real range used for the GPIO if OK,
348
+ otherwise PI_BAD_USER_GPIO.
349
+
350
+ If a hardware clock is active on the GPIO the reported
351
+ real range will be 1000000 (1M).
352
+
353
+ If hardware PWM is active on the GPIO the reported real range
354
+ will be approximately 250M divided by the set PWM frequency.
355
+
356
+ :call-seq:
357
+ get_PWM_real_range(Integer pi,Integer user_gpio) -> Integer
358
+
359
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#get_PWM_real_range]
360
+ */
361
+ VALUE pigpio_rbfn_get_PWM_real_range(VALUE self, VALUE pi, VALUE user_gpio){
362
+ return INT2NUM( get_PWM_real_range(NUM2INT(pi), NUM2UINT(user_gpio)));
363
+ }
364
+ /*
365
+ Set the frequency (in Hz) of the PWM to be used on the GPIO.
366
+
367
+ . .
368
+ pi: >=0 (as returned by [*pigpio_start*]).
369
+ user_gpio: 0-31.
370
+ frequency: >=0 (Hz).
371
+ . .
372
+
373
+ Returns the numerically closest frequency if OK, otherwise
374
+ PI_BAD_USER_GPIO or PI_NOT_PERMITTED.
375
+
376
+ If PWM is currently active on the GPIO it will be switched
377
+ off and then back on at the new frequency.
378
+
379
+ Each GPIO can be independently set to one of 18 different
380
+ PWM frequencies.
381
+
382
+ The selectable frequencies depend upon the sample rate which
383
+ may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The
384
+ sample rate is set when the pigpio daemon is started.
385
+
386
+ The frequencies for each sample rate are:
387
+
388
+ . .
389
+ Hertz
390
+
391
+ 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
392
+ 1250 1000 800 500 400 250 200 100 50
393
+
394
+ 2: 20000 10000 5000 4000 2500 2000 1250 1000 800
395
+ 625 500 400 250 200 125 100 50 25
396
+
397
+ 4: 10000 5000 2500 2000 1250 1000 625 500 400
398
+ 313 250 200 125 100 63 50 25 13
399
+ sample
400
+ rate
401
+ (us) 5: 8000 4000 2000 1600 1000 800 500 400 320
402
+ 250 200 160 100 80 50 40 20 10
403
+
404
+ 8: 5000 2500 1250 1000 625 500 313 250 200
405
+ 156 125 100 63 50 31 25 13 6
406
+
407
+ 10: 4000 2000 1000 800 500 400 250 200 160
408
+ 125 100 80 50 40 25 20 10 5
409
+ . .
410
+
411
+ :call-seq:
412
+ set_PWM_frequency(Integer pi,Integer user_gpio, Integer frequency) -> Integer
413
+
414
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#set_PWM_frequency]
415
+ */
416
+ VALUE pigpio_rbfn_set_PWM_frequency(VALUE self, VALUE pi, VALUE user_gpio, VALUE frequency){
417
+ return INT2NUM( set_PWM_frequency(NUM2INT(pi), NUM2UINT(user_gpio), NUM2UINT(frequency)));
418
+ }
419
+ /*
420
+ Get the frequency of PWM being used on the GPIO.
421
+
422
+ . .
423
+ pi: >=0 (as returned by [*pigpio_start*]).
424
+ user_gpio: 0-31.
425
+ . .
426
+
427
+ For normal PWM the frequency will be that defined for the GPIO by
428
+ [*set_PWM_frequency*].
429
+
430
+ If a hardware clock is active on the GPIO the reported frequency
431
+ will be that set by [*hardware_clock*].
432
+
433
+ If hardware PWM is active on the GPIO the reported frequency
434
+ will be that set by [*hardware_PWM*].
435
+
436
+ Returns the frequency (in hertz) used for the GPIO if OK,
437
+ otherwise PI_BAD_USER_GPIO.
438
+
439
+ :call-seq:
440
+ get_PWM_frequency(Integer pi,Integer user_gpio) -> Integer
441
+
442
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#get_PWM_frequency]
443
+ */
444
+ VALUE pigpio_rbfn_get_PWM_frequency(VALUE self, VALUE pi, VALUE user_gpio){
445
+ return INT2NUM( get_PWM_frequency(NUM2INT(pi), NUM2UINT(user_gpio)));
446
+ }
447
+ /*
448
+ Start (500-2500) or stop (0) servo pulses on the GPIO.
449
+
450
+ . .
451
+ pi: >=0 (as returned by [*pigpio_start*]).
452
+ user_gpio: 0-31.
453
+ pulsewidth: 0 (off), 500 (anti-clockwise) - 2500 (clockwise).
454
+ . .
455
+
456
+ Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or
457
+ PI_NOT_PERMITTED.
458
+
459
+ The selected pulsewidth will continue to be transmitted until
460
+ changed by a subsequent call to set_servo_pulsewidth.
461
+
462
+ The pulsewidths supported by servos varies and should probably be
463
+ determined by experiment. A value of 1500 should always be safe and
464
+ represents the mid-point of rotation.
465
+
466
+ You can DAMAGE a servo if you command it to move beyond its limits.
467
+
468
+ OTHER UPDATE RATES:
469
+
470
+ This function updates servos at 50Hz. If you wish to use a different
471
+ update frequency you will have to use the PWM functions.
472
+
473
+ . .
474
+ Update Rate (Hz) 50 100 200 400 500
475
+ 1E6/Hz 20000 10000 5000 2500 2000
476
+ . .
477
+
478
+ Firstly set the desired PWM frequency using [*set_PWM_frequency*].
479
+
480
+ Then set the PWM range using [*set_PWM_range*] to 1E6/Hz.
481
+ Doing this allows you to use units of microseconds when setting
482
+ the servo pulsewidth.
483
+
484
+ E.g. If you want to update a servo connected to GPIO 25 at 400Hz
485
+
486
+ . .
487
+ set_PWM_frequency(25, 400);
488
+ set_PWM_range(25, 2500);
489
+ . .
490
+
491
+ Thereafter use the [*set_PWM_dutycycle*] function to move the servo,
492
+ e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse.
493
+
494
+ :call-seq:
495
+ set_servo_pulsewidth(Integer pi,Integer user_gpio, Integer pulsewidth) -> Integer
496
+
497
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#set_servo_pulsewidth]
498
+ */
499
+ VALUE pigpio_rbfn_set_servo_pulsewidth(VALUE self, VALUE pi, VALUE user_gpio, VALUE pulsewidth){
500
+ return INT2NUM( set_servo_pulsewidth(NUM2INT(pi), NUM2UINT(user_gpio), NUM2UINT(pulsewidth)));
501
+ }
502
+ /*
503
+ Return the servo pulsewidth in use on a GPIO.
504
+
505
+ . .
506
+ pi: >=0 (as returned by [*pigpio_start*]).
507
+ user_gpio: 0-31.
508
+ . .
509
+
510
+ Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO.
511
+
512
+ :call-seq:
513
+ get_servo_pulsewidth(Integer pi,Integer user_gpio) -> Integer
514
+
515
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#get_servo_pulsewidth]
516
+ */
517
+ VALUE pigpio_rbfn_get_servo_pulsewidth(VALUE self, VALUE pi, VALUE user_gpio){
518
+ return INT2NUM( get_servo_pulsewidth(NUM2INT(pi), NUM2UINT(user_gpio)));
519
+ }
520
+ /*
521
+ Get a free notification handle.
522
+
523
+ . .
524
+ pi: >=0 (as returned by [*pigpio_start*]).
525
+ . .
526
+
527
+ Returns a handle greater than or equal to zero if OK,
528
+ otherwise PI_NO_HANDLE.
529
+
530
+ A notification is a method for being notified of GPIO state
531
+ changes via a pipe.
532
+
533
+ Pipes are only accessible from the local machine so this function
534
+ serves no purpose if you are using the library from a remote machine.
535
+ The in-built (socket) notifications provided by [*callback*]
536
+ should be used instead.
537
+
538
+ Notifications for handle x will be available at the pipe
539
+ named /dev/pigpiox (where x is the handle number).
540
+ E.g. if the function returns 15 then the notifications must be
541
+ read from /dev/pigpio15.
542
+
543
+ :call-seq:
544
+ notify_open(Integer pi) -> Integer
545
+
546
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#notify_open]
547
+ */
548
+ VALUE pigpio_rbfn_notify_open(VALUE self, VALUE pi){
549
+ return INT2NUM( notify_open(NUM2INT(pi)));
550
+ }
551
+ /*
552
+ Start notifications on a previously opened handle.
553
+
554
+ . .
555
+ pi: >=0 (as returned by [*pigpio_start*]).
556
+ handle: 0-31 (as returned by [*notify_open*])
557
+ bits: a mask indicating the GPIO to be notified.
558
+ . .
559
+
560
+ Returns 0 if OK, otherwise PI_BAD_HANDLE.
561
+
562
+ The notification sends state changes for each GPIO whose
563
+ corresponding bit in bits is set.
564
+
565
+ Each notification occupies 12 bytes in the fifo as follows:
566
+
567
+ . .
568
+ typedef struct
569
+ {
570
+ uint16_t seqno;
571
+ uint16_t flags;
572
+ uint32_t tick;
573
+ uint32_t level;
574
+ } gpioReport_t;
575
+ . .
576
+
577
+ seqno: starts at 0 each time the handle is opened and then increments
578
+ by one for each report.
579
+
580
+ flags: three flags are defined, PI_NTFY_FLAGS_WDOG,
581
+ PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT.
582
+
583
+ If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags
584
+ indicate a GPIO which has had a watchdog timeout.
585
+
586
+ If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive
587
+ signal on the pipe/socket and is sent once a minute in the absence
588
+ of other notification activity.
589
+
590
+ If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the flags
591
+ indicate an event which has been triggered.
592
+
593
+ tick: the number of microseconds since system boot. It wraps around
594
+ after 1h12m.
595
+
596
+ level: indicates the level of each GPIO. If bit 1<<x is set then
597
+ GPIO x is high.
598
+
599
+
600
+ :call-seq:
601
+ notify_begin(Integer pi,Integer handle, Integer bits) -> Integer
602
+
603
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#notify_begin]
604
+ */
605
+ VALUE pigpio_rbfn_notify_begin(VALUE self, VALUE pi, VALUE handle, VALUE bits){
606
+ return INT2NUM( notify_begin(NUM2INT(pi), NUM2UINT(handle), NUM2ULONG(bits)));
607
+ }
608
+ /*
609
+ Pause notifications on a previously opened handle.
610
+
611
+ . .
612
+ pi: >=0 (as returned by [*pigpio_start*]).
613
+ handle: 0-31 (as returned by [*notify_open*])
614
+ . .
615
+
616
+ Returns 0 if OK, otherwise PI_BAD_HANDLE.
617
+
618
+ Notifications for the handle are suspended until
619
+ [*notify_begin*] is called again.
620
+
621
+ :call-seq:
622
+ notify_pause(Integer pi,Integer handle) -> Integer
623
+
624
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#notify_pause]
625
+ */
626
+ VALUE pigpio_rbfn_notify_pause(VALUE self, VALUE pi, VALUE handle){
627
+ return INT2NUM( notify_pause(NUM2INT(pi), NUM2UINT(handle)));
628
+ }
629
+ /*
630
+ Stop notifications on a previously opened handle and
631
+ release the handle for reuse.
632
+
633
+ . .
634
+ pi: >=0 (as returned by [*pigpio_start*]).
635
+ handle: 0-31 (as returned by [*notify_open*])
636
+ . .
637
+
638
+ Returns 0 if OK, otherwise PI_BAD_HANDLE.
639
+
640
+ :call-seq:
641
+ notify_close(Integer pi,Integer handle) -> Integer
642
+
643
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#notify_close]
644
+ */
645
+ VALUE pigpio_rbfn_notify_close(VALUE self, VALUE pi, VALUE handle){
646
+ return INT2NUM( notify_close(NUM2INT(pi), NUM2UINT(handle)));
647
+ }
648
+ /*
649
+ Sets a watchdog for a GPIO.
650
+
651
+ . .
652
+ pi: >=0 (as returned by [*pigpio_start*]).
653
+ user_gpio: 0-31.
654
+ timeout: 0-60000.
655
+ . .
656
+
657
+ Returns 0 if OK, otherwise PI_BAD_USER_GPIO
658
+ or PI_BAD_WDOG_TIMEOUT.
659
+
660
+ The watchdog is nominally in milliseconds.
661
+
662
+ Only one watchdog may be registered per GPIO.
663
+
664
+ The watchdog may be cancelled by setting timeout to 0.
665
+
666
+ Once a watchdog has been started callbacks for the GPIO will be
667
+ triggered every timeout interval after the last GPIO activity.
668
+
669
+ The callback will receive the special level PI_TIMEOUT.
670
+
671
+ :call-seq:
672
+ set_watchdog(Integer pi,Integer user_gpio,Integer timeout) -> Integer
673
+
674
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#set_watchdog]
675
+ */
676
+ VALUE pigpio_rbfn_set_watchdog(VALUE self,VALUE pi, VALUE user_gpio, VALUE timeout){
677
+ return INT2NUM(set_watchdog(NUM2INT(pi), NUM2UINT(user_gpio), NUM2UINT(timeout)));
678
+ }
679
+ /*
680
+ Sets a glitch filter on a GPIO.
681
+
682
+ Level changes on the GPIO are not reported unless the level
683
+ has been stable for at least [*steady*] microseconds. The
684
+ level is then reported. Level changes of less than
685
+ [*steady*] microseconds are ignored.
686
+
687
+ . .
688
+ pi: >=0 (as returned by [*pigpio_start*]).
689
+ user_gpio: 0-31
690
+ steady: 0-300000
691
+ . .
692
+
693
+ Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
694
+
695
+ This filter affects the GPIO samples returned to callbacks set up
696
+ with [*callback*], [*callback_ex*] and [*wait_for_edge*].
697
+
698
+ It does not affect levels read by [*gpio_read*],
699
+ [*read_bank_1*], or [*read_bank_2*].
700
+
701
+ Each (stable) edge will be timestamped [*steady*] microseconds
702
+ after it was first detected.
703
+
704
+
705
+ :call-seq:
706
+ set_glitch_filter(Integer pi,Integer user_gpio,Integer steady) -> Integer
707
+
708
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#set_glitch_filter]
709
+ */
710
+ VALUE pigpio_rbfn_set_glitch_filter(VALUE self,VALUE pi, VALUE user_gpio, VALUE steady){
711
+ return INT2NUM(set_glitch_filter(NUM2INT(pi), NUM2UINT(user_gpio), NUM2UINT(steady)));
712
+ }
713
+ /*
714
+ Sets a noise filter on a GPIO.
715
+
716
+ Level changes on the GPIO are ignored until a level which has
717
+ been stable for [*steady*] microseconds is detected. Level changes
718
+ on the GPIO are then reported for [*active*] microseconds after
719
+ which the process repeats.
720
+
721
+ . .
722
+ pi: >=0 (as returned by [*pigpio_start*]).
723
+ user_gpio: 0-31
724
+ steady: 0-300000
725
+ active: 0-1000000
726
+ . .
727
+
728
+ Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
729
+
730
+ This filter affects the GPIO samples returned to callbacks set up
731
+ with [*callback*], [*callback_ex*] and [*wait_for_edge*].
732
+
733
+ It does not affect levels read by [*gpio_read*],
734
+ [*read_bank_1*], or [*read_bank_2*].
735
+
736
+ Level changes before and after the active period may
737
+ be reported. Your software must be designed to cope with
738
+ such reports.
739
+
740
+
741
+ :call-seq:
742
+ set_noise_filter(Integer pi,Integer user_gpio,Integer steady,Integer active) -> Integer
743
+
744
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#set_noise_filter]
745
+ */
746
+ VALUE pigpio_rbfn_set_noise_filter(VALUE self,VALUE pi, VALUE user_gpio, VALUE steady, VALUE active){
747
+ return INT2NUM(set_noise_filter(NUM2INT(pi), NUM2UINT(user_gpio), NUM2UINT(steady), NUM2UINT(active)));
748
+ }
749
+
750
+
751
+
752
+
753
+
754
+
755
+
756
+
757
+
758
+
759
+
760
+
761
+
762
+ /*
763
+ Return the current time in seconds since the Epoch.
764
+
765
+
766
+ :call-seq:
767
+ time_time() -> Float
768
+
769
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#time_time]
770
+ */
771
+ VALUE pigpio_rbfn_time_time(VALUE self){
772
+ return DBL2NUM(time_time());
773
+ }
774
+ /*
775
+ Return a text description for an error code.
776
+
777
+ . .
778
+ errnum: the error code.
779
+ . .
780
+
781
+
782
+ :call-seq:
783
+ pigpio_error(Integer errnum) -> String
784
+
785
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#pigpio_error]
786
+ */
787
+ VALUE pigpio_rbfn_pigpio_error(VALUE self,VALUE errnum){
788
+ return rb_utf8_str_new_cstr(pigpio_error(NUM2INT(errnum)));
789
+ }
790
+ /*
791
+ Return the pigpiod_if2 version.
792
+
793
+ :call-seq:
794
+ pigpiod_if_version() -> Integer
795
+
796
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#pigpiod_if_version]
797
+ */
798
+ VALUE pigpio_rbfn_pigpiod_if_version(VALUE self){
799
+ return UINT2NUM(pigpiod_if_version());
800
+ }
801
+ /*
802
+ Gets the current system tick.
803
+
804
+ . .
805
+ pi: >=0 (as returned by [*pigpio_start*]).
806
+ . .
807
+
808
+ Tick is the number of microseconds since system boot.
809
+
810
+ As tick is an unsigned 32 bit quantity it wraps around after
811
+ 2**32 microseconds, which is approximately 1 hour 12 minutes.
812
+
813
+ :call-seq:
814
+ get_current_tick(Integer pi) -> Integer
815
+
816
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#get_current_tick]
817
+ */
818
+ VALUE pigpio_rbfn_get_current_tick(VALUE self,VALUE pi){
819
+ return ULONG2NUM(get_current_tick(NUM2INT(pi)));
820
+ }
821
+ /*
822
+ Get the Pi's hardware revision number.
823
+
824
+ . .
825
+ pi: >=0 (as returned by [*pigpio_start*]).
826
+ . .
827
+
828
+ The hardware revision is the last few characters on the Revision line
829
+ of /proc/cpuinfo.
830
+
831
+ If the hardware revision can not be found or is not a valid
832
+ hexadecimal number the function returns 0.
833
+
834
+ The revision number can be used to determine the assignment of GPIO
835
+ to pins (see [*gpio*]).
836
+
837
+ There are at least three types of board.
838
+
839
+ Type 1 boards have hardware revision numbers of 2 and 3.
840
+
841
+ Type 2 boards have hardware revision numbers of 4, 5, 6, and 15.
842
+
843
+ Type 3 boards have hardware revision numbers of 16 or greater.
844
+
845
+ :call-seq:
846
+ get_hardware_revision(Integer pi) -> Integer
847
+
848
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#get_hardware_revision]
849
+ */
850
+ VALUE pigpio_rbfn_get_hardware_revision(VALUE self,VALUE pi){
851
+ return ULONG2NUM(get_hardware_revision(NUM2INT(pi)));
852
+ }
853
+ /*
854
+ Returns the pigpio version.
855
+
856
+ . .
857
+ pi: >=0 (as returned by [*pigpio_start*]).
858
+ . .
859
+
860
+ :call-seq:
861
+ get_pigpio_version(Integer pi) -> Integer
862
+
863
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#get_pigpio_version]
864
+ */
865
+ VALUE pigpio_rbfn_get_pigpio_version(VALUE self,VALUE pi){
866
+ return ULONG2NUM(get_pigpio_version(NUM2INT(pi)));
867
+ }
868
+ /*
869
+ This function clears all waveforms and any data added by calls to the
870
+ [*wave_add_**] functions.
871
+
872
+ . .
873
+ pi: >=0 (as returned by [*pigpio_start*]).
874
+ . .
875
+
876
+ Returns 0 if OK.
877
+
878
+ :call-seq:
879
+ wave_clear(Integer pi) -> Integer
880
+
881
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wave_clear]
882
+ */
883
+ VALUE pigpio_rbfn_wave_clear(VALUE self,VALUE pi){
884
+ return INT2NUM(wave_clear(NUM2INT(pi)));
885
+ }
886
+ /*
887
+ This function starts a new empty waveform. You wouldn't normally need
888
+ to call this function as it is automatically called after a waveform is
889
+ created with the [*wave_create*] function.
890
+
891
+ . .
892
+ pi: >=0 (as returned by [*pigpio_start*]).
893
+ . .
894
+
895
+ Returns 0 if OK.
896
+
897
+
898
+ :call-seq:
899
+ wave_add_new(Integer pi) -> Integer
900
+
901
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wave_add_new]
902
+ */
903
+ VALUE pigpio_rbfn_wave_add_new(VALUE self,VALUE pi){
904
+ return INT2NUM(wave_add_new(NUM2INT(pi)));
905
+ }
906
+ /*
907
+ This function adds a number of pulses to the current waveform.
908
+
909
+ . .
910
+ pi: >=0 (as returned by [*pigpio_start*]).
911
+ numPulses: the number of pulses.
912
+ pulses: an array of pulses.
913
+ . .
914
+
915
+ Returns the new total number of pulses in the current waveform if OK,
916
+ otherwise PI_TOO_MANY_PULSES.
917
+
918
+ The pulses are interleaved in time order within the existing waveform
919
+ (if any).
920
+
921
+ Merging allows the waveform to be built in parts, that is the settings
922
+ for GPIO#1 can be added, and then GPIO#2 etc.
923
+
924
+ If the added waveform is intended to start after or within the existing
925
+ waveform then the first pulse should consist solely of a delay.
926
+
927
+ :call-seq:
928
+ wave_add_generic(Integer pi,[PIGPIO::Pulse] pulses) -> Integer
929
+
930
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wave_add_generic]
931
+ */
932
+ VALUE pigpio_rbfn_wave_add_generic(VALUE self,VALUE pi, VALUE pulses){
933
+ unsigned numPulses=rb_array_len(pulses);
934
+ gpioPulse_t buf[numPulses];
935
+ gpioPulse_t *st;
936
+ unsigned i;
937
+ for(i=0;i<numPulses;i++){
938
+ TypedData_Get_Struct(rb_ary_entry(pulses,i),gpioPulse_t,&gpioPulse_data_type,st);
939
+ buf[i]=*st;
940
+ }
941
+ return INT2NUM( wave_add_generic(NUM2INT(pi),numPulses, buf));
942
+ }
943
+ /*
944
+ This function adds a waveform representing serial data to the
945
+ existing waveform (if any). The serial data starts offset
946
+ microseconds from the start of the waveform.
947
+
948
+ . .
949
+ pi: >=0 (as returned by [*pigpio_start*]).
950
+ user_gpio: 0-31.
951
+ baud: 50-1000000
952
+ data_bits: number of data bits (1-32)
953
+ stop_bits: number of stop half bits (2-8)
954
+ offset: >=0
955
+ numBytes: >=1
956
+ str: an array of chars.
957
+ . .
958
+
959
+ Returns the new total number of pulses in the current waveform if OK,
960
+ otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS,
961
+ PI_BAD_STOP_BITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET,
962
+ or PI_TOO_MANY_PULSES.
963
+
964
+ NOTES:
965
+
966
+ The serial data is formatted as one start bit, [*data_bits*] data bits,
967
+ and [*stop_bits*]/2 stop bits.
968
+
969
+ It is legal to add serial data streams with different baud rates to
970
+ the same waveform.
971
+
972
+ [*numBytes*] is the number of bytes of data in str.
973
+
974
+ The bytes required for each character depend upon [*data_bits*].
975
+
976
+ For [*data_bits*] 1-8 there will be one byte per character.
977
+ For [*data_bits*] 9-16 there will be two bytes per character.
978
+ For [*data_bits*] 17-32 there will be four bytes per character.
979
+
980
+ :call-seq:
981
+ wave_add_serial(Integer pi, Integer user_gpio, Integer baud, Integer data_bits, Integer stop_bits, Integer offset, String str) -> Integer
982
+
983
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wave_add_serial]
984
+ */
985
+ VALUE pigpio_rbfn_wave_add_serial(VALUE self,VALUE pi, VALUE user_gpio, VALUE baud, VALUE data_bits, VALUE stop_bits, VALUE offset, VALUE str){
986
+ int ret=wave_add_serial(NUM2INT(pi), NUM2UINT(user_gpio), NUM2UINT(baud), NUM2UINT(data_bits), NUM2UINT(stop_bits), NUM2UINT(offset),RSTRING_LEN(str),StringValuePtr(str));
987
+ RB_GC_GUARD(str);
988
+ return INT2NUM(ret);
989
+ }
990
+ /*
991
+ This function creates a waveform from the data provided by the prior
992
+ calls to the [*wave_add_**] functions. Upon success a wave id
993
+ greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM,
994
+ PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID.
995
+
996
+ . .
997
+ pi: >=0 (as returned by [*pigpio_start*]).
998
+ . .
999
+
1000
+ The data provided by the [*wave_add_**] functions is consumed by this
1001
+ function.
1002
+
1003
+ As many waveforms may be created as there is space available. The
1004
+ wave id is passed to [*wave_send_**] to specify the waveform to transmit.
1005
+
1006
+ Normal usage would be
1007
+
1008
+ Step 1. [*wave_clear*] to clear all waveforms and added data.
1009
+
1010
+ Step 2. [*wave_add_**] calls to supply the waveform data.
1011
+
1012
+ Step 3. [*wave_create*] to create the waveform and get a unique id
1013
+
1014
+ Repeat steps 2 and 3 as needed.
1015
+
1016
+ Step 4. [*wave_send_**] with the id of the waveform to transmit.
1017
+
1018
+ A waveform comprises one or more pulses. Each pulse consists of a
1019
+ PIGPIO::Pulse class.
1020
+
1021
+ The fields specify
1022
+
1023
+ 1) the GPIO to be switched on at the start of the pulse.
1024
+ 2) the GPIO to be switched off at the start of the pulse.
1025
+ 3) the delay in microseconds before the next pulse.
1026
+
1027
+ Any or all the fields can be zero. It doesn't make any sense to
1028
+ set all the fields to zero (the pulse will be ignored).
1029
+
1030
+ When a waveform is started each pulse is executed in order with the
1031
+ specified delay between the pulse and the next.
1032
+
1033
+ Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM,
1034
+ PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL.
1035
+
1036
+ :call-seq:
1037
+ wave_create(Integer pi) -> Integer
1038
+
1039
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wave_create]
1040
+ */
1041
+ VALUE pigpio_rbfn_wave_create(VALUE self,VALUE pi){
1042
+ return INT2NUM(wave_create(NUM2INT(pi)));
1043
+ }
1044
+ /*
1045
+ This function deletes the waveform with id wave_id.
1046
+
1047
+ . .
1048
+ pi: >=0 (as returned by [*pigpio_start*]).
1049
+ wave_id: >=0, as returned by [*wave_create*].
1050
+ . .
1051
+
1052
+ Wave ids are allocated in order, 0, 1, 2, etc.
1053
+
1054
+ Returns 0 if OK, otherwise PI_BAD_WAVE_ID.
1055
+
1056
+ :call-seq:
1057
+ wave_delete(Integer pi,Integer wave_id) -> Integer
1058
+
1059
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wave_delete]
1060
+ */
1061
+ VALUE pigpio_rbfn_wave_delete(VALUE self,VALUE pi, VALUE wave_id){
1062
+ return INT2NUM(wave_delete(NUM2INT(pi), NUM2UINT(wave_id)));
1063
+ }
1064
+ /*
1065
+ This function transmits the waveform with id wave_id. The waveform
1066
+ is sent once.
1067
+
1068
+ NOTE: Any hardware PWM started by [*hardware_PWM*] will be cancelled.
1069
+
1070
+ . .
1071
+ pi: >=0 (as returned by [*pigpio_start*]).
1072
+ wave_id: >=0, as returned by [*wave_create*].
1073
+ . .
1074
+
1075
+ Returns the number of DMA control blocks in the waveform if OK,
1076
+ otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE.
1077
+
1078
+ :call-seq:
1079
+ wave_send_once(Integer pi,Integer wave_id) -> Integer
1080
+
1081
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wave_send_once]
1082
+ */
1083
+ VALUE pigpio_rbfn_wave_send_once(VALUE self,VALUE pi, VALUE wave_id){
1084
+ return INT2NUM(wave_send_once(NUM2INT(pi),NUM2UINT(wave_id)));
1085
+ }
1086
+ /*
1087
+ This function transmits the waveform with id wave_id. The waveform
1088
+ cycles until cancelled (either by the sending of a new waveform or
1089
+ by [*wave_tx_stop*]).
1090
+
1091
+ NOTE: Any hardware PWM started by [*hardware_PWM*] will be cancelled.
1092
+
1093
+ . .
1094
+ pi: >=0 (as returned by [*pigpio_start*]).
1095
+ wave_id: >=0, as returned by [*wave_create*].
1096
+ . .
1097
+
1098
+ Returns the number of DMA control blocks in the waveform if OK,
1099
+ otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE.
1100
+
1101
+ :call-seq:
1102
+ wave_send_repeat(Integer pi,Integer wave_id) -> Integer
1103
+
1104
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wave_send_repeat]
1105
+ */
1106
+ VALUE pigpio_rbfn_wave_send_repeat(VALUE self,VALUE pi, VALUE wave_id){
1107
+ return INT2NUM(wave_send_repeat(NUM2INT(pi),NUM2UINT(wave_id)));
1108
+ }
1109
+ /*
1110
+ Transmits the waveform with id wave_id using mode mode.
1111
+
1112
+ . .
1113
+ pi: >=0 (as returned by [*pigpio_start*]).
1114
+ wave_id: >=0, as returned by [*wave_create*].
1115
+ mode: PI_WAVE_MODE_ONE_SHOT, PI_WAVE_MODE_REPEAT,
1116
+ PI_WAVE_MODE_ONE_SHOT_SYNC, or PI_WAVE_MODE_REPEAT_SYNC.
1117
+ . .
1118
+
1119
+ PI_WAVE_MODE_ONE_SHOT: same as [*wave_send_once*].
1120
+
1121
+ PI_WAVE_MODE_REPEAT same as [*wave_send_repeat*].
1122
+
1123
+ PI_WAVE_MODE_ONE_SHOT_SYNC same as [*wave_send_once*] but tries
1124
+ to sync with the previous waveform.
1125
+
1126
+ PI_WAVE_MODE_REPEAT_SYNC same as [*wave_send_repeat*] but tries
1127
+ to sync with the previous waveform.
1128
+
1129
+ WARNING: bad things may happen if you delete the previous
1130
+ waveform before it has been synced to the new waveform.
1131
+
1132
+ NOTE: Any hardware PWM started by [*hardware_PWM*] will be cancelled.
1133
+
1134
+ Returns the number of DMA control blocks in the waveform if OK,
1135
+ otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE.
1136
+
1137
+
1138
+ :call-seq:
1139
+ wave_send_using_mode(Integer pi,Integer wave_id) -> Integer
1140
+
1141
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wave_send_using_mode]
1142
+ */
1143
+ VALUE pigpio_rbfn_wave_send_using_mode(VALUE self,VALUE pi, VALUE wave_id, VALUE mode){
1144
+ return INT2NUM(wave_send_using_mode(NUM2INT(pi),NUM2UINT(wave_id),NUM2UINT(mode)));
1145
+ }
1146
+ /*
1147
+ This function transmits a chain of waveforms.
1148
+
1149
+ NOTE: Any hardware PWM started by [*hardware_PWM*] will be cancelled.
1150
+
1151
+ The waves to be transmitted are specified by the contents of buf
1152
+ which contains an ordered list of [*wave_id*]s and optional command
1153
+ codes and related data.
1154
+
1155
+ . .
1156
+ pi: >=0 (as returned by [*pigpio_start*]).
1157
+ buf: pointer to the wave_ids and optional command codes
1158
+ bufSize: the number of bytes in buf
1159
+ . .
1160
+
1161
+ Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER,
1162
+ PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID.
1163
+
1164
+ Each wave is transmitted in the order specified. A wave may
1165
+ occur multiple times per chain.
1166
+
1167
+ A blocks of waves may be transmitted multiple times by using
1168
+ the loop commands. The block is bracketed by loop start and
1169
+ end commands. Loops may be nested.
1170
+
1171
+ Delays between waves may be added with the delay command.
1172
+
1173
+ The following command codes are supported:
1174
+
1175
+ Name @ Cmd & Data @ Meaning
1176
+ Loop Start @ 255 0 @ Identify start of a wave block
1177
+ Loop Repeat @ 255 1 x y @ loop x + y*256 times
1178
+ Delay @ 255 2 x y @ delay x + y*256 microseconds
1179
+ Loop Forever @ 255 3 @ loop forever
1180
+
1181
+ If present Loop Forever must be the last entry in the chain.
1182
+
1183
+ The code is currently dimensioned to support a chain with roughly
1184
+ 600 entries and 20 loop counters.
1185
+
1186
+
1187
+ :call-seq:
1188
+ wave_chain(Integer pi, [Integer] buf) -> Integer
1189
+
1190
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wave_chain]
1191
+ */
1192
+ VALUE pigpio_rbfn_wave_chain(VALUE self,VALUE pi, VALUE buf){
1193
+ unsigned bufSize=rb_array_len(buf);
1194
+ char bufc[bufSize];
1195
+ unsigned i;
1196
+ for(i=0;i<bufSize;i++){
1197
+ bufc[i]=(char)FIX2INT(rb_ary_entry(buf,i));
1198
+ }
1199
+ return INT2NUM( wave_chain(NUM2INT(pi),bufc, bufSize));
1200
+ }
1201
+ /*
1202
+ This function returns the id of the waveform currently being
1203
+ transmitted.
1204
+
1205
+ . .
1206
+ pi: >=0 (as returned by [*pigpio_start*]).
1207
+ . .
1208
+
1209
+ Returns the waveform id or one of the following special values:
1210
+
1211
+ PI_WAVE_NOT_FOUND (9998) - transmitted wave not found.
1212
+ PI_NO_TX_WAVE (9999) - no wave being transmitted.
1213
+
1214
+ :call-seq:
1215
+ wave_tx_at(Integer pi) -> Integer
1216
+
1217
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wave_tx_at]
1218
+ */
1219
+ VALUE pigpio_rbfn_wave_tx_at(VALUE self,VALUE pi){
1220
+ return INT2NUM(wave_tx_at(NUM2INT(pi)));
1221
+ }
1222
+ /*
1223
+ This function checks to see if a waveform is currently being
1224
+ transmitted.
1225
+
1226
+ . .
1227
+ pi: >=0 (as returned by [*pigpio_start*]).
1228
+ . .
1229
+
1230
+ Returns 1 if a waveform is currently being transmitted, otherwise 0.
1231
+
1232
+ :call-seq:
1233
+ wave_tx_busy(Integer pi) -> Integer
1234
+
1235
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wave_tx_busy]
1236
+ */
1237
+ VALUE pigpio_rbfn_wave_tx_busy(VALUE self,VALUE pi){
1238
+ return INT2NUM(wave_tx_busy(NUM2INT(pi)));
1239
+ }
1240
+ /*
1241
+ This function stops the transmission of the current waveform.
1242
+
1243
+ . .
1244
+ pi: >=0 (as returned by [*pigpio_start*]).
1245
+ . .
1246
+
1247
+ Returns 0 if OK.
1248
+
1249
+ This function is intended to stop a waveform started with the repeat mode.
1250
+
1251
+ :call-seq:
1252
+ wave_tx_stop(Integer pi) -> Integer
1253
+
1254
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wave_tx_stop]
1255
+ */
1256
+ VALUE pigpio_rbfn_wave_tx_stop(VALUE self,VALUE pi){
1257
+ return INT2NUM(wave_tx_stop(NUM2INT(pi)));
1258
+ }
1259
+ /*
1260
+ This function returns the length in microseconds of the current
1261
+ waveform.
1262
+
1263
+ . .
1264
+ pi: >=0 (as returned by [*pigpio_start*]).
1265
+ . .
1266
+
1267
+ :call-seq:
1268
+ wave_get_micros(Integer pi) -> Integer
1269
+
1270
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wave_get_micros]
1271
+ */
1272
+ VALUE pigpio_rbfn_wave_get_micros(VALUE self,VALUE pi){
1273
+ return INT2NUM(wave_get_micros(NUM2INT(pi)));
1274
+ }
1275
+ /*
1276
+ This function returns the length in microseconds of the longest waveform
1277
+ created since the pigpio daemon was started.
1278
+
1279
+ . .
1280
+ pi: >=0 (as returned by [*pigpio_start*]).
1281
+ . .
1282
+
1283
+ :call-seq:
1284
+ wave_get_high_micros(Integer pi) -> Integer
1285
+
1286
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wave_get_high_micros]
1287
+ */
1288
+ VALUE pigpio_rbfn_wave_get_high_micros(VALUE self,VALUE pi){
1289
+ return INT2NUM(wave_get_high_micros(NUM2INT(pi)));
1290
+ }
1291
+ /*
1292
+ This function returns the maximum possible size of a waveform in
1293
+ microseconds.
1294
+
1295
+ . .
1296
+ pi: >=0 (as returned by [*pigpio_start*]).
1297
+ . .
1298
+
1299
+ :call-seq:
1300
+ wave_get_max_micros(Integer pi) -> Integer
1301
+
1302
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wave_get_max_micros]
1303
+ */
1304
+ VALUE pigpio_rbfn_wave_get_max_micros(VALUE self,VALUE pi){
1305
+ return INT2NUM(wave_get_max_micros(NUM2INT(pi)));
1306
+ }
1307
+ /*
1308
+ This function returns the length in pulses of the current waveform.
1309
+
1310
+ . .
1311
+ pi: >=0 (as returned by [*pigpio_start*]).
1312
+ . .
1313
+
1314
+ :call-seq:
1315
+ wave_get_pulses(Integer pi) -> Integer
1316
+
1317
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wave_get_pulses]
1318
+ */
1319
+ VALUE pigpio_rbfn_wave_get_pulses(VALUE self,VALUE pi){
1320
+ return INT2NUM(wave_get_pulses(NUM2INT(pi)));
1321
+ }
1322
+ /*
1323
+ This function returns the length in pulses of the longest waveform
1324
+ created since the pigpio daemon was started.
1325
+
1326
+ . .
1327
+ pi: >=0 (as returned by [*pigpio_start*]).
1328
+ . .
1329
+
1330
+ :call-seq:
1331
+ wave_get_high_pulses(Integer pi) -> Integer
1332
+
1333
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wave_get_high_pulses]
1334
+ */
1335
+ VALUE pigpio_rbfn_wave_get_high_pulses(VALUE self,VALUE pi){
1336
+ return INT2NUM(wave_get_high_pulses(NUM2INT(pi)));
1337
+ }
1338
+ /*
1339
+ This function returns the maximum possible size of a waveform in pulses.
1340
+
1341
+ . .
1342
+ pi: >=0 (as returned by [*pigpio_start*]).
1343
+ . .
1344
+
1345
+ :call-seq:
1346
+ wave_get_max_pulses(Integer pi,Integer gpio) -> Integer
1347
+
1348
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wave_get_max_pulses]
1349
+ */
1350
+ VALUE pigpio_rbfn_wave_get_max_pulses(VALUE self,VALUE pi){
1351
+ return INT2NUM(wave_get_max_pulses(NUM2INT(pi)));
1352
+ }
1353
+ /*
1354
+ This function returns the length in DMA control blocks of the current
1355
+ waveform.
1356
+
1357
+ . .
1358
+ pi: >=0 (as returned by [*pigpio_start*]).
1359
+ . .
1360
+
1361
+ :call-seq:
1362
+ wave_get_cbs(Integer pi) -> Integer
1363
+
1364
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wave_get_cbs]
1365
+ */
1366
+ VALUE pigpio_rbfn_wave_get_cbs(VALUE self,VALUE pi){
1367
+ return INT2NUM(wave_get_cbs(NUM2INT(pi)));
1368
+ }
1369
+ /*
1370
+ This function returns the length in DMA control blocks of the longest
1371
+ waveform created since the pigpio daemon was started.
1372
+
1373
+ . .
1374
+ pi: >=0 (as returned by [*pigpio_start*]).
1375
+ . .
1376
+
1377
+ :call-seq:
1378
+ wave_get_high_cbs(Integer pi) -> Integer
1379
+
1380
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wave_get_high_cbs]
1381
+ */
1382
+ VALUE pigpio_rbfn_wave_get_high_cbs(VALUE self,VALUE pi){
1383
+ return INT2NUM(wave_get_high_cbs(NUM2INT(pi)));
1384
+ }
1385
+ /*
1386
+ This function returns the maximum possible size of a waveform in DMA
1387
+ control blocks.
1388
+
1389
+ . .
1390
+ pi: >=0 (as returned by [*pigpio_start*]).
1391
+ . .
1392
+
1393
+ :call-seq:
1394
+ wave_get_max_cbs(Integer pi) -> Integer
1395
+
1396
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wave_get_max_cbs]
1397
+ */
1398
+ VALUE pigpio_rbfn_wave_get_max_cbs(VALUE self,VALUE pi){
1399
+ return INT2NUM(wave_get_max_cbs(NUM2INT(pi)));
1400
+ }
1401
+ /*
1402
+ This function sends a trigger pulse to a GPIO. The GPIO is set to
1403
+ level for pulseLen microseconds and then reset to not level.
1404
+
1405
+ . .
1406
+ pi: >=0 (as returned by [*pigpio_start*]).
1407
+ user_gpio: 0-31.
1408
+ pulseLen: 1-100.
1409
+ level: 0,1.
1410
+ . .
1411
+
1412
+ Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL,
1413
+ PI_BAD_PULSELEN, or PI_NOT_PERMITTED.
1414
+
1415
+ :call-seq:
1416
+ gpio_trigger(Integer pi,Integer user_gpio,Integer pulseLen,Integer level) -> Integer
1417
+
1418
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#gpio_trigger]
1419
+ */
1420
+ VALUE pigpio_rbfn_gpio_trigger(VALUE self,VALUE pi, VALUE user_gpio, VALUE pulseLen, VALUE level){
1421
+ return INT2NUM(gpio_trigger(NUM2INT(pi),NUM2UINT(user_gpio),NUM2UINT(pulseLen),NUM2UINT(level)));
1422
+ }
1423
+ /*
1424
+ This function stores a script for later execution.
1425
+
1426
+ See [[http://abyz.co.uk/rpi/pigpio/pigs.html#Scripts]] for details.
1427
+
1428
+ . .
1429
+ pi: >=0 (as returned by [*pigpio_start*]).
1430
+ script: the text of the script.
1431
+ . .
1432
+
1433
+ The function returns a script id if the script is valid,
1434
+ otherwise PI_BAD_SCRIPT.
1435
+
1436
+ :call-seq:
1437
+ store_script(Integer pi,String script) -> Integer
1438
+
1439
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#store_script]
1440
+ */
1441
+ VALUE pigpio_rbfn_store_script(VALUE self,VALUE pi, VALUE script){
1442
+ //rb_gc_disable();
1443
+ int ret=store_script(NUM2INT(pi), StringValueCStr(script));
1444
+ //rb_gc_enable();
1445
+ RB_GC_GUARD(script);
1446
+ return INT2NUM(ret);
1447
+ }
1448
+ /*
1449
+ This function runs a stored script.
1450
+
1451
+ . .
1452
+ pi: >=0 (as returned by [*pigpio_start*]).
1453
+ script_id: >=0, as returned by [*store_script*].
1454
+ numPar: 0-10, the number of parameters.
1455
+ param: an array of parameters.
1456
+ . .
1457
+
1458
+ The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or
1459
+ PI_TOO_MANY_PARAM
1460
+
1461
+ param is an array of up to 10 parameters which may be referenced in
1462
+ the script as p0 to p9.
1463
+
1464
+ :call-seq:
1465
+ rb_array_len(Integer pi,Integer script_id,[Integer] param) -> Integer
1466
+
1467
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#rb_array_len]
1468
+ */
1469
+ VALUE pigpio_rbfn_run_script(VALUE self,VALUE pi, VALUE script_id, VALUE param){
1470
+ unsigned numPar=rb_array_len(param);
1471
+ uint32_t paramc[10];
1472
+ int ret;
1473
+ for(int i=(numPar<10)?numPar:10;i>=0;i--){
1474
+ paramc[i]=rb_ary_entry(param,i);
1475
+ }
1476
+ ret=run_script(NUM2INT(pi), NUM2UINT(script_id), numPar, paramc);
1477
+ RB_GC_GUARD(param);
1478
+ return INT2NUM(ret);
1479
+ }
1480
+ /*
1481
+ This function returns the run status of a stored script as well
1482
+ as the current values of parameters 0 to 9.
1483
+
1484
+ . .
1485
+ pi: >=0 (as returned by [*pigpio_start*]).
1486
+ script_id: >=0, as returned by [*store_script*].
1487
+ param: an array to hold the returned 10 parameters.
1488
+ . .
1489
+
1490
+ The function returns greater than or equal to 0 if OK,
1491
+ otherwise PI_BAD_SCRIPT_ID.
1492
+
1493
+ The run status may be
1494
+
1495
+ . .
1496
+ PI_SCRIPT_INITING
1497
+ PI_SCRIPT_HALTED
1498
+ PI_SCRIPT_RUNNING
1499
+ PI_SCRIPT_WAITING
1500
+ PI_SCRIPT_FAILED
1501
+ . .
1502
+
1503
+ The current value of script parameters 0 to 9 are returned in param.
1504
+
1505
+ :call-seq:
1506
+ script_status(Integer pi,Integer script_id) -> [Integer,[Integer]param]
1507
+
1508
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#script_status]
1509
+ */
1510
+ VALUE pigpio_rbfn_script_status(VALUE self,VALUE pi, VALUE script_id){
1511
+ uint32_t paramc[10];
1512
+ int ret=script_status(NUM2INT(pi), NUM2UINT(script_id), paramc);
1513
+ VALUE param=rb_ary_new_capa(10);
1514
+ for(int i=0;i<10;i++){
1515
+ rb_ary_store(param,i,ULONG2NUM(paramc[i]));
1516
+ }
1517
+ return rb_ary_new_from_args(2,param,INT2NUM(ret));
1518
+ }
1519
+ /*
1520
+ This function stops a running script.
1521
+
1522
+ . .
1523
+ pi: >=0 (as returned by [*pigpio_start*]).
1524
+ script_id: >=0, as returned by [*store_script*].
1525
+ . .
1526
+
1527
+ The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
1528
+
1529
+ :call-seq:
1530
+ stop_script(Integer pi,Integer script_id) -> Integer
1531
+
1532
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#stop_script]
1533
+ */
1534
+ VALUE pigpio_rbfn_stop_script(VALUE self,VALUE pi, VALUE script_id){
1535
+ return INT2NUM( stop_script(NUM2INT(pi), NUM2UINT(script_id)));
1536
+ }
1537
+ /*
1538
+ This function deletes a stored script.
1539
+
1540
+ . .
1541
+ pi: >=0 (as returned by [*pigpio_start*]).
1542
+ script_id: >=0, as returned by [*store_script*].
1543
+ . .
1544
+
1545
+ The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
1546
+
1547
+ :call-seq:
1548
+ delete_script(Integer pi,Integer script_id) -> Integer
1549
+
1550
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#delete_script]
1551
+ */
1552
+ VALUE pigpio_rbfn_delete_script(VALUE self,VALUE pi, VALUE script_id){
1553
+ return INT2NUM( delete_script(NUM2INT(pi), NUM2UINT(script_id)));
1554
+ }
1555
+ /*
1556
+ Read the levels of the bank 1 GPIO (GPIO 0-31).
1557
+
1558
+ . .
1559
+ pi: >=0 (as returned by [*pigpio_start*]).
1560
+ . .
1561
+
1562
+ The returned 32 bit integer has a bit set if the corresponding
1563
+ GPIO is logic 1. GPIO n has bit value (1<<n).
1564
+
1565
+ :call-seq:
1566
+ read_bank_1(Integer pi) -> Integer
1567
+
1568
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#read_bank_1]
1569
+ */
1570
+ VALUE pigpio_rbfn_read_bank_1(VALUE self, VALUE pi){
1571
+ return ULONG2NUM( read_bank_1(NUM2INT(pi)));
1572
+ }
1573
+ /*
1574
+ Read the levels of the bank 2 GPIO (GPIO 32-53).
1575
+
1576
+ . .
1577
+ pi: >=0 (as returned by [*pigpio_start*]).
1578
+ . .
1579
+
1580
+ The returned 32 bit integer has a bit set if the corresponding
1581
+ GPIO is logic 1. GPIO n has bit value (1<<(n-32)).
1582
+
1583
+ :call-seq:
1584
+ read_bank_2(Integer pi) -> Integer
1585
+
1586
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#read_bank_2]
1587
+ */
1588
+ VALUE pigpio_rbfn_read_bank_2(VALUE self, VALUE pi){
1589
+ return ULONG2NUM( read_bank_2(NUM2INT(pi)));
1590
+ }
1591
+ /*
1592
+ Clears GPIO 0-31 if the corresponding bit in bits is set.
1593
+
1594
+ . .
1595
+ pi: >=0 (as returned by [*pigpio_start*]).
1596
+ bits: a bit mask with 1 set if the corresponding GPIO is
1597
+ to be cleared.
1598
+ . .
1599
+
1600
+ Returns 0 if OK, otherwise PI_SOME_PERMITTED.
1601
+
1602
+ A status of PI_SOME_PERMITTED indicates that the user is not
1603
+ allowed to write to one or more of the GPIO.
1604
+
1605
+ :call-seq:
1606
+ clear_bank_1(Integer pi,Integer bits) -> Integer
1607
+
1608
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#clear_bank_1]
1609
+ */
1610
+ VALUE pigpio_rbfn_clear_bank_1(VALUE self, VALUE pi, VALUE bits){
1611
+ return INT2NUM( clear_bank_1(NUM2INT(pi), NUM2ULONG(bits)));
1612
+ }
1613
+ /*
1614
+ Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set.
1615
+
1616
+ . .
1617
+ pi: >=0 (as returned by [*pigpio_start*]).
1618
+ bits: a bit mask with 1 set if the corresponding GPIO is
1619
+ to be cleared.
1620
+ . .
1621
+
1622
+ Returns 0 if OK, otherwise PI_SOME_PERMITTED.
1623
+
1624
+ A status of PI_SOME_PERMITTED indicates that the user is not
1625
+ allowed to write to one or more of the GPIO.
1626
+
1627
+ :call-seq:
1628
+ clear_bank_2(Integer pi,Integer bits) -> Integer
1629
+
1630
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#clear_bank_2]
1631
+ */
1632
+ VALUE pigpio_rbfn_clear_bank_2(VALUE self, VALUE pi, VALUE bits){
1633
+ return INT2NUM( clear_bank_2(NUM2INT(pi), NUM2ULONG(bits)));
1634
+ }
1635
+ /*
1636
+ Sets GPIO 0-31 if the corresponding bit in bits is set.
1637
+
1638
+ . .
1639
+ pi: >=0 (as returned by [*pigpio_start*]).
1640
+ bits: a bit mask with 1 set if the corresponding GPIO is
1641
+ to be set.
1642
+ . .
1643
+
1644
+ Returns 0 if OK, otherwise PI_SOME_PERMITTED.
1645
+
1646
+ A status of PI_SOME_PERMITTED indicates that the user is not
1647
+ allowed to write to one or more of the GPIO.
1648
+
1649
+ :call-seq:
1650
+ set_bank_1(Integer pi,Integer bits) -> Integer
1651
+
1652
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#set_bank_1]
1653
+ */
1654
+ VALUE pigpio_rbfn_set_bank_1(VALUE self, VALUE pi, VALUE bits){
1655
+ return INT2NUM( set_bank_1(NUM2INT(pi), NUM2ULONG(bits)));
1656
+ }
1657
+ /*
1658
+ Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set.
1659
+
1660
+ . .
1661
+ pi: >=0 (as returned by [*pigpio_start*]).
1662
+ bits: a bit mask with 1 set if the corresponding GPIO is
1663
+ to be set.
1664
+ . .
1665
+
1666
+ Returns 0 if OK, otherwise PI_SOME_PERMITTED.
1667
+
1668
+ A status of PI_SOME_PERMITTED indicates that the user is not
1669
+ allowed to write to one or more of the GPIO.
1670
+
1671
+ :call-seq:
1672
+ set_bank_2(Integer pi,Integer bits) -> Integer
1673
+
1674
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#set_bank_2]
1675
+ */
1676
+ VALUE pigpio_rbfn_set_bank_2(VALUE self, VALUE pi, VALUE bits){
1677
+ return INT2NUM( set_bank_2(NUM2INT(pi), NUM2ULONG(bits)));
1678
+ }
1679
+ /*
1680
+ Starts a hardware clock on a GPIO at the specified frequency.
1681
+ Frequencies above 30MHz are unlikely to work.
1682
+
1683
+ . .
1684
+ pi: >=0 (as returned by [*pigpio_start*]).
1685
+ gpio: see description
1686
+ frequency: 0 (off) or 4689-250000000 (250M)
1687
+ . .
1688
+
1689
+ Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO,
1690
+ PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS.
1691
+
1692
+ The same clock is available on multiple GPIO. The latest
1693
+ frequency setting will be used by all GPIO which share a clock.
1694
+
1695
+ The GPIO must be one of the following.
1696
+
1697
+ . .
1698
+ 4 clock 0 All models
1699
+ 5 clock 1 All models but A and B (reserved for system use)
1700
+ 6 clock 2 All models but A and B
1701
+ 20 clock 0 All models but A and B
1702
+ 21 clock 1 All models but A and Rev.2 B (reserved for system use)
1703
+
1704
+ 32 clock 0 Compute module only
1705
+ 34 clock 0 Compute module only
1706
+ 42 clock 1 Compute module only (reserved for system use)
1707
+ 43 clock 2 Compute module only
1708
+ 44 clock 1 Compute module only (reserved for system use)
1709
+ . .
1710
+
1711
+ Access to clock 1 is protected by a password as its use will likely
1712
+ crash the Pi. The password is given by or'ing 0x5A000000 with the
1713
+ GPIO number.
1714
+
1715
+ :call-seq:
1716
+ hardware_clock(Integer pi,Integer gpio, Integer clkfreq) -> Integer
1717
+
1718
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#hardware_clock]
1719
+ */
1720
+ VALUE pigpio_rbfn_hardware_clock(VALUE self, VALUE pi, VALUE gpio, VALUE clkfreq){
1721
+ return INT2NUM( hardware_clock(NUM2INT(pi), NUM2UINT(gpio), NUM2UINT(clkfreq)));
1722
+ }
1723
+ /*
1724
+ Starts hardware PWM on a GPIO at the specified frequency and dutycycle.
1725
+ Frequencies above 30MHz are unlikely to work.
1726
+
1727
+ NOTE: Any waveform started by [*wave_send_**] or [*wave_chain*]
1728
+ will be cancelled.
1729
+
1730
+ This function is only valid if the pigpio main clock is PCM. The
1731
+ main clock defaults to PCM but may be overridden when the pigpio
1732
+ daemon is started (option -t).
1733
+
1734
+ . .
1735
+ pi: >=0 (as returned by [*pigpio_start*]).
1736
+ gpio: see descripton
1737
+ PWMfreq: 0 (off) or 1-125000000 (125M)
1738
+ PWMduty: 0 (off) to 1000000 (1M)(fully on)
1739
+ . .
1740
+
1741
+ Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO,
1742
+ PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ,
1743
+ or PI_HPWM_ILLEGAL.
1744
+
1745
+ The same PWM channel is available on multiple GPIO. The latest
1746
+ frequency and dutycycle setting will be used by all GPIO which
1747
+ share a PWM channel.
1748
+
1749
+ The GPIO must be one of the following.
1750
+
1751
+ . .
1752
+ 12 PWM channel 0 All models but A and B
1753
+ 13 PWM channel 1 All models but A and B
1754
+ 18 PWM channel 0 All models
1755
+ 19 PWM channel 1 All models but A and B
1756
+
1757
+ 40 PWM channel 0 Compute module only
1758
+ 41 PWM channel 1 Compute module only
1759
+ 45 PWM channel 1 Compute module only
1760
+ 52 PWM channel 0 Compute module only
1761
+ 53 PWM channel 1 Compute module only
1762
+ . .
1763
+
1764
+ The actual number of steps beween off and fully on is the
1765
+ integral part of 250 million divided by PWMfreq.
1766
+
1767
+ The actual frequency set is 250 million / steps.
1768
+
1769
+ There will only be a million steps for a PWMfreq of 250.
1770
+ Lower frequencies will have more steps and higher
1771
+ frequencies will have fewer steps. PWMduty is
1772
+ automatically scaled to take this into account.
1773
+
1774
+ :call-seq:
1775
+ hardware_PWM(Integer pi,Integer gpio, Integer PWMfreq, Integer PWMduty) -> Integer
1776
+
1777
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#hardware_PWM]
1778
+ */
1779
+ VALUE pigpio_rbfn_hardware_PWM(VALUE self, VALUE pi, VALUE gpio, VALUE PWMfreq, VALUE PWMduty){
1780
+ return INT2NUM( hardware_PWM(NUM2INT(pi), NUM2UINT(gpio), NUM2UINT(PWMfreq), NUM2ULONG(PWMduty)));
1781
+ }
1782
+
1783
+ /*
1784
+ This function initialises a new callback.
1785
+
1786
+ . .
1787
+ pi: >=0 (as returned by [*pigpio_start*]).
1788
+ user_gpio: 0-31.
1789
+ edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
1790
+ . .
1791
+
1792
+ The function returns a callback id if OK, otherwise pigif_bad_malloc,
1793
+ pigif_duplicate_callback, or pigif_bad_callback.
1794
+
1795
+ The callback is called with the GPIO, edge, and tick, whenever the
1796
+ GPIO has the identified edge.
1797
+
1798
+ . .
1799
+ Parameter Value Meaning
1800
+
1801
+ GPIO 0-31 The GPIO which has changed state
1802
+
1803
+ edge 0-2 0 = change to low (a falling edge)
1804
+ 1 = change to high (a rising edge)
1805
+ 2 = no level change (a watchdog timeout)
1806
+
1807
+ tick 32 bit The number of microseconds since boot
1808
+ WARNING: this wraps around from
1809
+ 4294967295 to 0 roughly every 72 minutes
1810
+ . .
1811
+
1812
+ :call-seq:
1813
+ callback(Integer pi,Integer user_gpio, Integer edge){|tick,level,user_gpio| } -> Integer
1814
+
1815
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#callback_ex]
1816
+ */
1817
+ VALUE pigpio_rbfn_callback(int argc, VALUE *argv, VALUE self){
1818
+ VALUE pi; VALUE user_gpio; VALUE edge; VALUE userdata;
1819
+ rb_scan_args(argc,argv,"3&",&pi,&user_gpio,&edge,&userdata);
1820
+ return INT2NUM( callback_ex(NUM2INT(pi), NUM2UINT(user_gpio), NUM2UINT(edge), pigpio_rbbk_CBFuncEx, (void*)userdata));
1821
+ }
1822
+ /*
1823
+ This function cancels a callback identified by its id.
1824
+
1825
+ . .
1826
+ callback_id: >=0, as returned by a call to [*callback*] or [*callback_ex*].
1827
+ . .
1828
+
1829
+ The function returns 0 if OK, otherwise pigif_callback_not_found.
1830
+
1831
+ :call-seq:
1832
+ callback_cancel(Integer callback_id) -> Integer
1833
+
1834
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#callback_cancel]
1835
+ */
1836
+ VALUE pigpio_rbfn_callback_cancel(VALUE self,VALUE callback_id){
1837
+ return INT2NUM( callback_cancel(NUM2UINT(callback_id)));
1838
+ }
1839
+ /*
1840
+ This function waits for an edge on the GPIO for up to timeout
1841
+ seconds.
1842
+
1843
+ . .
1844
+ pi: >=0 (as returned by [*pigpio_start*]).
1845
+ user_gpio: 0-31.
1846
+ edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
1847
+ timeout: >=0.
1848
+ . .
1849
+
1850
+ The function returns when the edge occurs or after the timeout.
1851
+
1852
+ Do not use this function for precise timing purposes,
1853
+ the edge is only checked 20 times a second. Whenever
1854
+ you need to know the accurate time of GPIO events use
1855
+ a [*callback*] function.
1856
+
1857
+ The function returns 1 if the edge occurred, otherwise 0.
1858
+
1859
+ :call-seq:
1860
+ wait_for_edge(Integer pi,Integer user_gpio, Integer edge, Float timeout) -> Integer
1861
+
1862
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wait_for_edge]
1863
+ */
1864
+ VALUE pigpio_rbfn_wait_for_edge(VALUE self,VALUE pi, VALUE user_gpio, VALUE edge, VALUE timeout){
1865
+ return INT2NUM( wait_for_edge(NUM2INT(pi), NUM2UINT(user_gpio), NUM2UINT(edge), NUM2DBL(timeout)));
1866
+ }
1867
+
1868
+ /*
1869
+ This function initialises an event callback.
1870
+
1871
+ . .
1872
+ pi: >=0 (as returned by [*pigpio_start*]).
1873
+ event: 0-31.
1874
+ . .
1875
+
1876
+ The function returns a callback id if OK, otherwise pigif_bad_malloc,
1877
+ pigif_duplicate_callback, or pigif_bad_callback.
1878
+
1879
+ The callback is called with the event id, and tick, whenever the
1880
+ event occurs.
1881
+
1882
+ :call-seq:
1883
+ event_callback(Integer pi,Integer event){|tick,event| } -> Integer
1884
+
1885
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#event_callback_ex]
1886
+ */
1887
+ VALUE pigpio_rbfn_event_callback(int argc, VALUE *argv, VALUE self){
1888
+ VALUE pi; VALUE event; VALUE userdata;
1889
+ rb_scan_args(argc,argv,"2&",&pi,&event,&userdata);
1890
+ return INT2NUM( event_callback_ex(NUM2INT(pi), NUM2UINT(event), pigpio_rbbk_evtCBFuncEx, (void *)userdata));
1891
+ }
1892
+ /*
1893
+ This function cancels an event callback identified by its id.
1894
+
1895
+ . .
1896
+ callback_id: >=0, as returned by a call to [*event_callback*] or [*event_callback_ex*].
1897
+ . .
1898
+
1899
+ The function returns 0 if OK, otherwise pigif_callback_not_found.
1900
+
1901
+ :call-seq:
1902
+ event_callback_cancel(Integer callback_id) -> Integer
1903
+
1904
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#event_callback_cancel]
1905
+ */
1906
+ VALUE pigpio_rbfn_event_callback_cancel(VALUE self,VALUE callback_id){
1907
+ return INT2NUM( event_callback_cancel(NUM2UINT(callback_id) ));
1908
+ }
1909
+ /*
1910
+ This function waits for an event for up to timeout seconds.
1911
+
1912
+ . .
1913
+ pi: >=0 (as returned by [*pigpio_start*]).
1914
+ event: 0-31.
1915
+ timeout: >=0.
1916
+ . .
1917
+
1918
+ The function returns when the event occurs or after the timeout.
1919
+
1920
+ The function returns 1 if the event occurred, otherwise 0.
1921
+
1922
+ :call-seq:
1923
+ wait_for_event(Integer pi,Integer event, Float timeout) -> Integer
1924
+
1925
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#wait_for_event]
1926
+ */
1927
+ VALUE pigpio_rbfn_wait_for_event(VALUE self,VALUE pi, VALUE event, VALUE timeout){
1928
+ return INT2NUM( wait_for_event(NUM2INT(pi), NUM2UINT(event), NUM2DBL(timeout)));
1929
+ }
1930
+ /*
1931
+ This function signals the occurrence of an event.
1932
+
1933
+ . .
1934
+ pi: >=0 (as returned by [*pigpio_start*]).
1935
+ event: 0-31.
1936
+ . .
1937
+
1938
+ Returns 0 if OK, otherwise PI_BAD_EVENT_ID.
1939
+
1940
+ An event is a signal used to inform one or more consumers
1941
+ to start an action. Each consumer which has registered an interest
1942
+ in the event (e.g. by calling [*event_callback*]) will be informed by
1943
+ a callback.
1944
+
1945
+ One event, PI_EVENT_BSC (31) is predefined. This event is
1946
+ auto generated on BSC slave activity.
1947
+
1948
+ The meaning of other events is arbitrary.
1949
+
1950
+ Note that other than its id and its tick there is no data associated
1951
+ with an event.
1952
+
1953
+ :call-seq:
1954
+ event_trigger(Integer pi,Integer event) -> Integer
1955
+
1956
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#event_trigger]
1957
+ */
1958
+ VALUE pigpio_rbfn_event_trigger(VALUE self,VALUE pi, VALUE event){
1959
+ return INT2NUM( event_trigger(NUM2INT(pi), NUM2UINT(event)));
1960
+ }
1961
+
1962
+ /*
1963
+ This function opens a serial device at a specified baud rate
1964
+ with specified flags. The device name must start with
1965
+ /dev/tty or /dev/serial.
1966
+
1967
+
1968
+ . .
1969
+ pi: >=0 (as returned by [*pigpio_start*]).
1970
+ ser_tty: the serial device to open.
1971
+ baud: the baud rate in bits per second, see below.
1972
+ ser_flags: 0.
1973
+ . .
1974
+
1975
+ Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or
1976
+ PI_SER_OPEN_FAILED.
1977
+
1978
+ The baud rate must be one of 50, 75, 110, 134, 150,
1979
+ 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200,
1980
+ 38400, 57600, 115200, or 230400.
1981
+
1982
+ No flags are currently defined. This parameter should be set to zero.
1983
+
1984
+ :call-seq:
1985
+ serial_open(Integer pi,String ser_tty, Integer baud, Integer ser_flags) -> Integer
1986
+
1987
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#serial_open]
1988
+ */
1989
+ VALUE pigpio_rbfn_serial_open(VALUE self, VALUE pi, VALUE ser_tty, VALUE baud, VALUE ser_flags){
1990
+ int ret=serial_open(NUM2INT(pi), StringValueCStr(ser_tty), NUM2UINT(baud), NUM2UINT(ser_flags));
1991
+ RB_GC_GUARD(ser_tty);
1992
+ return INT2NUM(ret);
1993
+ }
1994
+ /*
1995
+ This function closes the serial device associated with handle.
1996
+
1997
+ . .
1998
+ pi: >=0 (as returned by [*pigpio_start*]).
1999
+ handle: >=0, as returned by a call to [*serial_open*].
2000
+ . .
2001
+
2002
+ Returns 0 if OK, otherwise PI_BAD_HANDLE.
2003
+
2004
+ :call-seq:
2005
+ serial_close(Integer pi,Integer handle) -> Integer
2006
+
2007
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#serial_close]
2008
+ */
2009
+ VALUE pigpio_rbfn_serial_close(VALUE self, VALUE pi, VALUE handle){
2010
+ return INT2NUM( serial_close(NUM2INT(pi), NUM2UINT(handle)));
2011
+ }
2012
+ /*
2013
+ This function writes bVal to the serial port associated with handle.
2014
+
2015
+ . .
2016
+ pi: >=0 (as returned by [*pigpio_start*]).
2017
+ handle: >=0, as returned by a call to [*serial_open*].
2018
+ . .
2019
+
2020
+ Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
2021
+ PI_SER_WRITE_FAILED.
2022
+
2023
+ :call-seq:
2024
+ serial_write_byte(Integer pi,Integer handle, Integer bVal) -> Integer
2025
+
2026
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#serial_write_byte]
2027
+ */
2028
+ VALUE pigpio_rbfn_serial_write_byte(VALUE self, VALUE pi, VALUE handle, VALUE bVal){
2029
+ return INT2NUM( serial_write_byte(NUM2INT(pi), NUM2UINT(handle), NUM2UINT(bVal)));
2030
+ }
2031
+ /*
2032
+ This function reads a byte from the serial port associated with handle.
2033
+
2034
+ . .
2035
+ pi: >=0 (as returned by [*pigpio_start*]).
2036
+ handle: >=0, as returned by a call to [*serial_open*].
2037
+ . .
2038
+
2039
+ Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE,
2040
+ PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED.
2041
+
2042
+ If no data is ready PI_SER_READ_NO_DATA is returned.
2043
+
2044
+ :call-seq:
2045
+ serial_read_byte(Integer pi,Integer handle) -> Integer
2046
+
2047
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#serial_read_byte]
2048
+ */
2049
+ VALUE pigpio_rbfn_serial_read_byte(VALUE self, VALUE pi, VALUE handle){
2050
+ return INT2NUM( serial_read_byte(NUM2INT(pi), NUM2UINT(handle)));
2051
+ }
2052
+ /*
2053
+ This function writes count bytes from buf to the the serial port
2054
+ associated with handle.
2055
+
2056
+ . .
2057
+ pi: >=0 (as returned by [*pigpio_start*]).
2058
+ handle: >=0, as returned by a call to [*serial_open*].
2059
+ buf: the array of bytes to write.
2060
+ . .
2061
+
2062
+ Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
2063
+ PI_SER_WRITE_FAILED.
2064
+
2065
+ :call-seq:
2066
+ serial_write(Integer pi,Integer handle, String buf) -> Integer
2067
+
2068
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#serial_write]
2069
+ */
2070
+ VALUE pigpio_rbfn_serial_write(VALUE self, VALUE pi, VALUE handle, VALUE buf){
2071
+ int ret=serial_write(NUM2INT(pi), NUM2UINT(handle), StringValuePtr(buf), RSTRING_LEN(buf));
2072
+ RB_GC_GUARD(buf);
2073
+ return INT2NUM(ret);
2074
+ }
2075
+ /*
2076
+ This function reads up to count bytes from the the serial port
2077
+ associated with handle and writes them to buf.
2078
+
2079
+ . .
2080
+ pi: >=0 (as returned by [*pigpio_start*]).
2081
+ handle: >=0, as returned by a call to [*serial_open*].
2082
+ buf: an array to receive the read data.
2083
+ count: the maximum number of bytes to read.
2084
+ . .
2085
+
2086
+ Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE,
2087
+ PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED.
2088
+
2089
+ If no data is ready zero is returned.
2090
+
2091
+ :call-seq:
2092
+ serial_read(Integer pi,Integer handle, Integer count) -> Integer (When onError)
2093
+ serial_read(Integer pi,Integer handle, Integer count) -> String buf (When Success)
2094
+
2095
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#serial_read]
2096
+ */
2097
+ VALUE pigpio_rbfn_serial_read(VALUE self, VALUE pi, VALUE handle, VALUE count){
2098
+ unsigned countc=NUM2UINT(count);
2099
+ VALUE buf=rb_str_new("",countc);//#<Encoding:ASCII-8BIT>;
2100
+ int ret=serial_read(NUM2INT(pi), NUM2UINT(handle), (void*)StringValuePtr(buf), countc);
2101
+ return (ret < 0)?INT2NUM(ret):rb_str_resize(buf,ret);
2102
+ //if(ret < 0){buf=Qnil;}
2103
+ //return rb_ary_new_from_args(2,buf,INT2NUM(ret));
2104
+ }
2105
+ /*
2106
+ Returns the number of bytes available to be read from the
2107
+ device associated with handle.
2108
+
2109
+ . .
2110
+ pi: >=0 (as returned by [*pigpio_start*]).
2111
+ handle: >=0, as returned by a call to [*serial_open*].
2112
+ . .
2113
+
2114
+ Returns the number of bytes of data available (>=0) if OK,
2115
+ otherwise PI_BAD_HANDLE.
2116
+
2117
+ :call-seq:
2118
+ serial_data_available(Integer pi,Integer handle) -> Integer
2119
+
2120
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#serial_data_available]
2121
+ */
2122
+ VALUE pigpio_rbfn_serial_data_available(VALUE self, VALUE pi, VALUE handle){
2123
+ return INT2NUM( serial_data_available(NUM2INT(pi), NUM2UINT(handle)));
2124
+ }
2125
+ /*
2126
+ This function opens a GPIO for bit bang reading of serial data.
2127
+
2128
+ . .
2129
+ pi: >=0 (as returned by [*pigpio_start*]).
2130
+ user_gpio: 0-31.
2131
+ baud: 50-250000
2132
+ data_bits: 1-32
2133
+ . .
2134
+
2135
+ Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD,
2136
+ or PI_GPIO_IN_USE.
2137
+
2138
+ The serial data is returned in a cyclic buffer and is read using
2139
+ bb_serial_read.
2140
+
2141
+ It is the caller's responsibility to read data from the cyclic buffer
2142
+ in a timely fashion.
2143
+
2144
+ :call-seq:
2145
+ bb_serial_read_open(Integer pi,Integer user_gpio, Integer baud, Integer data_bits) -> Integer
2146
+
2147
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#bb_serial_read_open]
2148
+ */
2149
+ VALUE pigpio_rbfn_bb_serial_read_open(VALUE self, VALUE pi, VALUE user_gpio, VALUE baud, VALUE data_bits){
2150
+ return INT2NUM( bb_serial_read_open(NUM2INT(pi), NUM2UINT(user_gpio), NUM2UINT(baud), NUM2UINT(data_bits)));
2151
+ }
2152
+ /*
2153
+ This function copies up to bufSize bytes of data read from the
2154
+ bit bang serial cyclic buffer to the buffer starting at buf.
2155
+
2156
+ . .
2157
+ pi: >=0 (as returned by [*pigpio_start*]).
2158
+ user_gpio: 0-31, previously opened with [*bb_serial_read_open*].
2159
+ buf: an array to receive the read bytes.
2160
+ bufSize: >=0
2161
+ . .
2162
+
2163
+ Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO
2164
+ or PI_NOT_SERIAL_GPIO.
2165
+
2166
+ The bytes returned for each character depend upon the number of
2167
+ data bits [*data_bits*] specified in the [*bb_serial_read_open*] command.
2168
+
2169
+ * For [*data_bits*] 1-8 there will be one byte per character.
2170
+ * For [*data_bits*] 9-16 there will be two bytes per character.
2171
+ * For [*data_bits*] 17-32 there will be four bytes per character.
2172
+
2173
+ :call-seq:
2174
+ bb_serial_read(Integer pi,Integer user_gpio, Integer bufSize) -> Integer (When onError)
2175
+ bb_serial_read(Integer pi,Integer user_gpio, Integer bufSize) -> String (When Success)
2176
+
2177
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#bb_serial_read]
2178
+ */
2179
+ VALUE pigpio_rbfn_bb_serial_read(VALUE self, VALUE pi, VALUE user_gpio, VALUE bufSize){
2180
+ size_t countc=NUM2SIZET(bufSize);
2181
+ VALUE buf=rb_str_new("",countc);//#<Encoding:ASCII-8BIT>;
2182
+ int ret=bb_serial_read(NUM2INT(pi), NUM2UINT(user_gpio), (void*)StringValuePtr(buf), countc);
2183
+ return (ret < 0)?INT2NUM(ret):rb_str_resize(buf,ret);
2184
+ //if(ret < 0){buf=Qnil;}
2185
+ //return rb_ary_new_from_args(2,buf,INT2NUM(ret));
2186
+ }
2187
+ /*
2188
+ This function closes a GPIO for bit bang reading of serial data.
2189
+
2190
+ . .
2191
+ pi: >=0 (as returned by [*pigpio_start*]).
2192
+ user_gpio: 0-31, previously opened with [*bb_serial_read_open*].
2193
+ . .
2194
+
2195
+ Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO.
2196
+
2197
+ :call-seq:
2198
+ bb_serial_read_close(Integer pi,Integer user_gpio) -> Integer
2199
+
2200
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#bb_serial_read_close]
2201
+ */
2202
+ VALUE pigpio_rbfn_bb_serial_read_close(VALUE self, VALUE pi, VALUE user_gpio){
2203
+ return INT2NUM( bb_serial_read_close(NUM2INT(pi), NUM2UINT(user_gpio)));
2204
+ }
2205
+ /*
2206
+ This function inverts serial logic for big bang serial reads.
2207
+
2208
+ . .
2209
+ pi: >=0 (as returned by [*pigpio_start*]).
2210
+ user_gpio: 0-31, previously opened with [*bb_serial_read_open*].
2211
+ invert: 0-1, 1 invert, 0 normal.
2212
+ . .
2213
+
2214
+ Returns 0 if OK, otherwise PI_NOT_SERIAL_GPIO or PI_BAD_SER_INVERT.
2215
+
2216
+ :call-seq:
2217
+ bb_serial_invert(Integer pi,Integer user_gpio, Integer invert) -> Integer
2218
+
2219
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#bb_serial_invert]
2220
+ */
2221
+ VALUE pigpio_rbfn_bb_serial_invert(VALUE self, VALUE pi, VALUE user_gpio, VALUE invert){
2222
+ return INT2NUM( bb_serial_invert(NUM2INT(pi), NUM2UINT(user_gpio), NUM2UINT(invert)));
2223
+ }
2224
+
2225
+
2226
+ /*
2227
+ This function selects a set of GPIO for bit banging SPI at a
2228
+ specified baud rate.
2229
+
2230
+ . .
2231
+ pi: >=0 (as returned by [*pigpio_start*]).
2232
+ CS: 0-31
2233
+ MISO: 0-31
2234
+ MOSI: 0-31
2235
+ SCLK: 0-31
2236
+ baud: 50-250000
2237
+ spi_flags: see below
2238
+ . .
2239
+
2240
+ spi_flags consists of the least significant 22 bits.
2241
+
2242
+ . .
2243
+ 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
2244
+ 0 0 0 0 0 0 R T 0 0 0 0 0 0 0 0 0 0 0 p m m
2245
+ . .
2246
+
2247
+ mm defines the SPI mode, defaults to 0
2248
+
2249
+ . .
2250
+ Mode CPOL CPHA
2251
+ 0 0 0
2252
+ 1 0 1
2253
+ 2 1 0
2254
+ 3 1 1
2255
+ . .
2256
+
2257
+ p is 0 if CS is active low (default) and 1 for active high.
2258
+
2259
+ T is 1 if the least significant bit is transmitted on MOSI first, the
2260
+ default (0) shifts the most significant bit out first.
2261
+
2262
+ R is 1 if the least significant bit is received on MISO first, the
2263
+ default (0) receives the most significant bit first.
2264
+
2265
+ The other bits in flags should be set to zero.
2266
+
2267
+ Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or
2268
+ PI_GPIO_IN_USE.
2269
+
2270
+ If more than one device is connected to the SPI bus (defined by
2271
+ SCLK, MOSI, and MISO) each must have its own CS.
2272
+
2273
+ ...
2274
+ bb_spi_open(pi,10, MISO, MOSI, SCLK, 10000, 0); // device 1
2275
+ bb_spi_open(pi,11, MISO, MOSI, SCLK, 20000, 3); // device 2
2276
+ ...
2277
+
2278
+ :call-seq:
2279
+ bb_spi_open(Integer pi,Integer CS, Integer MISO, Integer MOSI, Integer SCLK, Integer baud, Integer spi_flags) -> Integer
2280
+
2281
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#bb_spi_open]
2282
+ */
2283
+ VALUE pigpio_rbfn_bb_spi_open(VALUE self, VALUE pi, VALUE CS, VALUE MISO, VALUE MOSI, VALUE SCLK, VALUE baud, VALUE spi_flags){
2284
+ return INT2NUM( bb_spi_open(NUM2INT(pi), NUM2UINT(CS), NUM2UINT(MISO), NUM2UINT(MOSI), NUM2UINT(SCLK), NUM2UINT(baud), NUM2UINT(spi_flags)));
2285
+ }
2286
+ /*
2287
+ This function stops bit banging SPI on a set of GPIO
2288
+ opened with [*bbSPIOpen*].
2289
+
2290
+ . .
2291
+ pi: >=0 (as returned by [*pigpio_start*]).
2292
+ CS: 0-31, the CS GPIO used in a prior call to [*bb_spi_open*]
2293
+ . .
2294
+
2295
+ Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO.
2296
+
2297
+ :call-seq:
2298
+ bb_spi_close(Integer pi,Integer CS) -> Integer
2299
+
2300
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#bb_spi_close]
2301
+ */
2302
+ VALUE pigpio_rbfn_bb_spi_close(VALUE self, VALUE pi, VALUE CS){
2303
+ return INT2NUM( bb_spi_close(NUM2INT(pi), NUM2UINT(CS)));
2304
+ }
2305
+ /*
2306
+ This function executes a bit banged SPI transfer.
2307
+
2308
+ . .
2309
+ pi: >=0 (as returned by [*pigpio_start*]).
2310
+ CS: 0-31 (as used in a prior call to [*bb_spi_open*])
2311
+ txBuf: binary string buffer to hold data to be sent
2312
+ rxBuf: binary string buffer to hold returned data
2313
+ . .
2314
+
2315
+ Returns >= 0 if OK (the number of bytes read), otherwise
2316
+ PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER.
2317
+
2318
+ :call-seq:
2319
+ bb_spi_xfer(Integer pi,Integer CS, String txBuf) -> Integer (When onError)
2320
+ bb_spi_xfer(Integer pi,Integer CS, String txBuf) -> String rxBuf (When Success)
2321
+
2322
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#bb_spi_xfer]
2323
+ */
2324
+ VALUE pigpio_rbfn_bb_spi_xfer(VALUE self, VALUE pi, VALUE CS, VALUE txBuf){
2325
+ unsigned countc=RSTRING_LEN(txBuf);
2326
+ VALUE rxBuf=rb_str_new("",countc);//#<Encoding:ASCII-8BIT>;
2327
+ int ret=bb_spi_xfer(NUM2INT(pi), NUM2UINT(CS), StringValuePtr(txBuf), StringValuePtr(rxBuf), countc);
2328
+ RB_GC_GUARD(txBuf);
2329
+ return (ret < 0)?INT2NUM(ret):rb_str_resize(rxBuf,ret);
2330
+ //if(ret < 0){rxBuf=Qnil;}
2331
+ //return rb_ary_new_from_args(2,rxBuf,INT2NUM(ret));
2332
+ }
2333
+ /*
2334
+ This function returns a handle for the SPI device on channel.
2335
+ Data will be transferred at baud bits per second. The flags may
2336
+ be used to modify the default behaviour of 4-wire operation, mode 0,
2337
+ active low chip select.
2338
+
2339
+ An auxiliary SPI device is available on all models but the
2340
+ A and B and may be selected by setting the A bit in the
2341
+ flags. The auxiliary device has 3 chip selects and a
2342
+ selectable word size in bits.
2343
+
2344
+ . .
2345
+ pi: >=0 (as returned by [*pigpio_start*]).
2346
+ spi_channel: 0-1 (0-2 for the auxiliary device).
2347
+ baud: 32K-125M (values above 30M are unlikely to work).
2348
+ spi_flags: see below.
2349
+ . .
2350
+
2351
+ Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL,
2352
+ PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED.
2353
+
2354
+ spi_flags consists of the least significant 22 bits.
2355
+
2356
+ . .
2357
+ 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
2358
+ b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m
2359
+ . .
2360
+
2361
+ mm defines the SPI mode.
2362
+
2363
+ Warning: modes 1 and 3 do not appear to work on the auxiliary device.
2364
+
2365
+ . .
2366
+ Mode POL PHA
2367
+ 0 0 0
2368
+ 1 0 1
2369
+ 2 1 0
2370
+ 3 1 1
2371
+ . .
2372
+
2373
+ px is 0 if CEx is active low (default) and 1 for active high.
2374
+
2375
+ ux is 0 if the CEx GPIO is reserved for SPI (default) and 1 otherwise.
2376
+
2377
+ A is 0 for the standard SPI device, 1 for the auxiliary SPI.
2378
+
2379
+ W is 0 if the device is not 3-wire, 1 if the device is 3-wire. Standard
2380
+ SPI device only.
2381
+
2382
+ nnnn defines the number of bytes (0-15) to write before switching
2383
+ the MOSI line to MISO to read data. This field is ignored
2384
+ if W is not set. Standard SPI device only.
2385
+
2386
+ T is 1 if the least significant bit is transmitted on MOSI first, the
2387
+ default (0) shifts the most significant bit out first. Auxiliary SPI
2388
+ device only.
2389
+
2390
+ R is 1 if the least significant bit is received on MISO first, the
2391
+ default (0) receives the most significant bit first. Auxiliary SPI
2392
+ device only.
2393
+
2394
+ bbbbbb defines the word size in bits (0-32). The default (0)
2395
+ sets 8 bits per word. Auxiliary SPI device only.
2396
+
2397
+ The [*spi_read*], [*spi_write*], and [*spi_xfer*] functions
2398
+ transfer data packed into 1, 2, or 4 bytes according to
2399
+ the word size in bits.
2400
+
2401
+ For bits 1-8 there will be one byte per character.
2402
+ For bits 9-16 there will be two bytes per character.
2403
+ For bits 17-32 there will be four bytes per character.
2404
+
2405
+ Multi-byte transfers are made in least significant byte first order.
2406
+
2407
+ E.g. to transfer 32 11-bit words buf should contain 64 bytes
2408
+ and count should be 64.
2409
+
2410
+ E.g. to transfer the 14 bit value 0x1ABC send the bytes 0xBC followed
2411
+ by 0x1A.
2412
+
2413
+ The other bits in flags should be set to zero.
2414
+
2415
+ :call-seq:
2416
+ spi_open(Integer pi,Integer spi_channel, Integer baud, Integer spi_flags) -> Integer
2417
+
2418
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#spi_open]
2419
+ */
2420
+ VALUE pigpio_rbfn_spi_open(VALUE self, VALUE pi, VALUE spi_channel, VALUE baud, VALUE spi_flags){
2421
+ return INT2NUM( spi_open(NUM2INT(pi), NUM2UINT(spi_channel), NUM2UINT(baud), NUM2UINT(spi_flags)));
2422
+ }
2423
+ /*
2424
+ This functions closes the SPI device identified by the handle.
2425
+
2426
+ . .
2427
+ pi: >=0 (as returned by [*pigpio_start*]).
2428
+ handle: >=0, as returned by a call to [*spi_open*].
2429
+ . .
2430
+
2431
+ Returns 0 if OK, otherwise PI_BAD_HANDLE.
2432
+
2433
+ :call-seq:
2434
+ spi_close(Integer pi,Integer handle) -> Integer
2435
+
2436
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#spi_close]
2437
+ */
2438
+ VALUE pigpio_rbfn_spi_close(VALUE self, VALUE pi, VALUE handle){
2439
+ return INT2NUM( spi_close(NUM2INT(pi), NUM2UINT(handle)));
2440
+ }
2441
+ /*
2442
+ This function reads count bytes of data from the SPI
2443
+ device associated with the handle.
2444
+
2445
+ . .
2446
+ pi: >=0 (as returned by [*pigpio_start*]).
2447
+ handle: >=0, as returned by a call to [*spi_open*].
2448
+ buf: an array to receive the read data bytes.
2449
+ count: the number of bytes to read.
2450
+ . .
2451
+
2452
+ Returns the number of bytes transferred if OK, otherwise
2453
+ PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED.
2454
+
2455
+ :call-seq:
2456
+ spi_read(Integer pi,Integer handle, Integer count) -> Integer (When onError)
2457
+ spi_read(Integer pi,Integer handle, Integer count) -> String buf (When Success)
2458
+
2459
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#spi_read]
2460
+ */
2461
+ VALUE pigpio_rbfn_spi_read(VALUE self, VALUE pi, VALUE handle, VALUE count){
2462
+ unsigned countc=NUM2UINT(count);
2463
+ VALUE buf=rb_str_new("",countc);//#<Encoding:ASCII-8BIT>;
2464
+ int ret=spi_read(NUM2INT(pi), NUM2UINT(handle), StringValuePtr(buf), countc);
2465
+ return (ret < 0)?INT2NUM(ret):rb_str_resize(buf,ret);
2466
+ //if(ret < 0){buf=Qnil;}
2467
+ //return rb_ary_new_from_args(2,buf,INT2NUM(ret));
2468
+ }
2469
+ /*
2470
+ This function writes count bytes of data from buf to the SPI
2471
+ device associated with the handle.
2472
+
2473
+ . .
2474
+ pi: >=0 (as returned by [*pigpio_start*]).
2475
+ handle: >=0, as returned by a call to [*spi_open*].
2476
+ buf: the data bytes to write.
2477
+ . .
2478
+
2479
+ Returns the number of bytes transferred if OK, otherwise
2480
+ PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED.
2481
+
2482
+ :call-seq:
2483
+ spi_write(Integer pi,Integer handle, String buf) -> Integer
2484
+
2485
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#spi_write]
2486
+ */
2487
+ VALUE pigpio_rbfn_spi_write(VALUE self, VALUE pi, VALUE handle, VALUE buf){
2488
+ int ret= spi_write(NUM2INT(pi), NUM2UINT(handle), StringValuePtr(buf), RSTRING_LEN(buf));
2489
+ RB_GC_GUARD(buf);
2490
+ return INT2NUM(ret);
2491
+ }
2492
+ /*
2493
+ This function transfers count bytes of data from txBuf to the SPI
2494
+ device associated with the handle. Simultaneously count bytes of
2495
+ data are read from the device and placed in rxBuf.
2496
+
2497
+ . .
2498
+ pi: >=0 (as returned by [*pigpio_start*]).
2499
+ handle: >=0, as returned by a call to [*spi_open*].
2500
+ txBuf: the data bytes to write.
2501
+ rxBuf: the received data bytes.
2502
+ . .
2503
+
2504
+ Returns the number of bytes transferred if OK, otherwise
2505
+ PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED.
2506
+
2507
+ :call-seq:
2508
+ spi_xfer(Integer pi,Integer handle, String txBuf) -> Integer (When onError)
2509
+ spi_xfer(Integer pi,Integer handle, String txBuf) -> String rxBuf (When Success)
2510
+
2511
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#spi_xfer]
2512
+ */
2513
+ VALUE pigpio_rbfn_spi_xfer(VALUE self, VALUE pi, VALUE handle, VALUE txBuf){
2514
+ unsigned countc=RSTRING_LEN(txBuf);
2515
+ VALUE rxBuf=rb_str_new("",countc);//#<Encoding:ASCII-8BIT>;
2516
+ int ret=spi_xfer(NUM2INT(pi), NUM2UINT(handle), StringValuePtr(txBuf), StringValuePtr(rxBuf), countc);
2517
+ RB_GC_GUARD(txBuf);
2518
+ return (ret < 0)?INT2NUM(ret):rb_str_resize(rxBuf,ret);
2519
+ }
2520
+ /*
2521
+ This returns a handle for the device at address i2c_addr on bus i2c_bus.
2522
+
2523
+ . .
2524
+ pi: >=0 (as returned by [*pigpio_start*]).
2525
+ i2c_bus: >=0.
2526
+ i2c_addr: 0-0x7F.
2527
+ i2c_flags: 0.
2528
+ . .
2529
+
2530
+ No flags are currently defined. This parameter should be set to zero.
2531
+
2532
+ Physically buses 0 and 1 are available on the Pi. Higher numbered buses
2533
+ will be available if a kernel supported bus multiplexor is being used.
2534
+
2535
+ Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR,
2536
+ PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED.
2537
+
2538
+ For the SMBus commands the low level transactions are shown at the end
2539
+ of the function description. The following abbreviations are used.
2540
+
2541
+ . .
2542
+ S (1 bit) : Start bit
2543
+ P (1 bit) : Stop bit
2544
+ Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
2545
+ A, NA (1 bit) : Accept and not accept bit.
2546
+ Addr (7 bits): I2C 7 bit address.
2547
+ i2c_reg (8 bits): A byte which often selects a register.
2548
+ Data (8 bits): A data byte.
2549
+ Count (8 bits): A byte defining the length of a block operation.
2550
+
2551
+ [..]: Data sent by the device.
2552
+ . .
2553
+
2554
+ :call-seq:
2555
+ i2c_open(Integer pi,Integer i2c_bus, Integer i2c_addr, Integer i2c_flags) -> Integer
2556
+
2557
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#i2c_open]
2558
+ */
2559
+ VALUE pigpio_rbfn_i2c_open(VALUE self, VALUE pi, VALUE i2c_bus, VALUE i2c_addr, VALUE i2c_flags){
2560
+ return INT2NUM( i2c_open(NUM2INT(pi), NUM2UINT(i2c_bus), NUM2UINT(i2c_addr), NUM2UINT(i2c_flags)));
2561
+ }
2562
+ /*
2563
+ This closes the I2C device associated with the handle.
2564
+
2565
+ . .
2566
+ pi: >=0 (as returned by [*pigpio_start*]).
2567
+ handle: >=0, as returned by a call to [*i2c_open*].
2568
+ . .
2569
+
2570
+ Returns 0 if OK, otherwise PI_BAD_HANDLE.
2571
+
2572
+ :call-seq:
2573
+ i2c_close(Integer pi,Integer handle) -> Integer
2574
+
2575
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#i2c_close]
2576
+ */
2577
+ VALUE pigpio_rbfn_i2c_close(VALUE self, VALUE pi, VALUE handle){
2578
+ return INT2NUM( i2c_close(NUM2INT(pi), NUM2UINT(handle)));
2579
+ }
2580
+ /*
2581
+ This sends a single bit (in the Rd/Wr bit) to the device associated
2582
+ with handle.
2583
+
2584
+ . .
2585
+ pi: >=0 (as returned by [*pigpio_start*]).
2586
+ handle: >=0, as returned by a call to [*i2c_open*].
2587
+ bit: 0-1, the value to write.
2588
+ . .
2589
+
2590
+ Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
2591
+ PI_I2C_WRITE_FAILED.
2592
+
2593
+ Quick command. SMBus 2.0 5.5.1
2594
+ . .
2595
+ S Addr bit [A] P
2596
+ . .
2597
+
2598
+ :call-seq:
2599
+ i2c_write_quick(Integer pi,Integer handle, Integer handle, Integer bit) -> Integer
2600
+
2601
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#i2c_write_quick]
2602
+ */
2603
+ VALUE pigpio_rbfn_i2c_write_quick(VALUE self, VALUE pi, VALUE handle, VALUE bit){
2604
+ return INT2NUM( i2c_write_quick(NUM2INT(pi), NUM2UINT(handle), NUM2UINT(bit)));
2605
+ }
2606
+ /*
2607
+ This sends a single byte to the device associated with handle.
2608
+
2609
+ . .
2610
+ pi: >=0 (as returned by [*pigpio_start*]).
2611
+ handle: >=0, as returned by a call to [*i2c_open*].
2612
+ bVal: 0-0xFF, the value to write.
2613
+ . .
2614
+
2615
+ Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
2616
+ PI_I2C_WRITE_FAILED.
2617
+
2618
+ Send byte. SMBus 2.0 5.5.2
2619
+ . .
2620
+ S Addr Wr [A] bVal [A] P
2621
+ . .
2622
+
2623
+ :call-seq:
2624
+ i2c_write_byte(Integer pi,Integer handle, Integer bVal) -> Integer
2625
+
2626
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#i2c_write_byte]
2627
+ */
2628
+ VALUE pigpio_rbfn_i2c_write_byte(VALUE self, VALUE pi, VALUE handle, VALUE bVal){
2629
+ return INT2NUM( i2c_write_byte(NUM2INT(pi), NUM2UINT(handle), NUM2UINT(bVal)));
2630
+ }
2631
+ /*
2632
+ This reads a single byte from the device associated with handle.
2633
+
2634
+ . .
2635
+ pi: >=0 (as returned by [*pigpio_start*]).
2636
+ handle: >=0, as returned by a call to [*i2c_open*].
2637
+ . .
2638
+
2639
+ Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE,
2640
+ or PI_I2C_READ_FAILED.
2641
+
2642
+ Receive byte. SMBus 2.0 5.5.3
2643
+ . .
2644
+ S Addr Rd [A] [Data] NA P
2645
+ . .
2646
+
2647
+ :call-seq:
2648
+ i2c_read_byte(Integer pi,Integer handle) -> Integer
2649
+
2650
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#i2c_read_byte]
2651
+ */
2652
+ VALUE pigpio_rbfn_i2c_read_byte(VALUE self, VALUE pi, VALUE handle){
2653
+ return INT2NUM( i2c_read_byte(NUM2INT(pi), NUM2UINT(handle)));
2654
+ }
2655
+ /*
2656
+ This writes a single byte to the specified register of the device
2657
+ associated with handle.
2658
+
2659
+ . .
2660
+ pi: >=0 (as returned by [*pigpio_start*]).
2661
+ handle: >=0, as returned by a call to [*i2c_open*].
2662
+ i2c_reg: 0-255, the register to write.
2663
+ bVal: 0-0xFF, the value to write.
2664
+ . .
2665
+
2666
+ Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
2667
+ PI_I2C_WRITE_FAILED.
2668
+
2669
+ Write byte. SMBus 2.0 5.5.4
2670
+ . .
2671
+ S Addr Wr [A] i2c_reg [A] bVal [A] P
2672
+ . .
2673
+
2674
+ :call-seq:
2675
+ i2c_write_byte_data(Integer pi,Integer handle, Integer i2c_reg, Integer bVal) -> Integer
2676
+
2677
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#i2c_write_byte_data]
2678
+ */
2679
+ VALUE pigpio_rbfn_i2c_write_byte_data(VALUE self, VALUE pi, VALUE handle, VALUE i2c_reg, VALUE bVal){
2680
+ return INT2NUM( i2c_write_byte_data(NUM2INT(pi), NUM2UINT(handle), NUM2UINT(i2c_reg), NUM2UINT(bVal)));
2681
+ }
2682
+ /*
2683
+ This writes a single 16 bit word to the specified register of the device
2684
+ associated with handle.
2685
+
2686
+ . .
2687
+ pi: >=0 (as returned by [*pigpio_start*]).
2688
+ handle: >=0, as returned by a call to [*i2c_open*].
2689
+ i2c_reg: 0-255, the register to write.
2690
+ wVal: 0-0xFFFF, the value to write.
2691
+ . .
2692
+
2693
+ Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
2694
+ PI_I2C_WRITE_FAILED.
2695
+
2696
+ Write word. SMBus 2.0 5.5.4
2697
+ . .
2698
+ S Addr Wr [A] i2c_reg [A] wval_Low [A] wVal_High [A] P
2699
+ . .
2700
+
2701
+ :call-seq:
2702
+ i2c_write_word_data(Integer pi,Integer handle, Integer i2c_reg, Integer wVal) -> Integer
2703
+
2704
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#i2c_write_word_data]
2705
+ */
2706
+ VALUE pigpio_rbfn_i2c_write_word_data(VALUE self, VALUE pi, VALUE handle, VALUE i2c_reg, VALUE wVal){
2707
+ return INT2NUM( i2c_write_word_data(NUM2INT(pi), NUM2UINT(handle), NUM2UINT(i2c_reg), NUM2UINT(wVal)));
2708
+ }
2709
+ /*
2710
+ This reads a single byte from the specified register of the device
2711
+ associated with handle.
2712
+
2713
+ . .
2714
+ pi: >=0 (as returned by [*pigpio_start*]).
2715
+ handle: >=0, as returned by a call to [*i2c_open*].
2716
+ i2c_reg: 0-255, the register to read.
2717
+ . .
2718
+
2719
+ Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE,
2720
+ PI_BAD_PARAM, or PI_I2C_READ_FAILED.
2721
+
2722
+ Read byte. SMBus 2.0 5.5.5
2723
+ . .
2724
+ S Addr Wr [A] i2c_reg [A] S Addr Rd [A] [Data] NA P
2725
+ . .
2726
+
2727
+ :call-seq:
2728
+ i2c_read_byte_data(Integer pi,Integer handle, Integer i2c_reg) -> Integer
2729
+
2730
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#i2c_read_byte_data]
2731
+ */
2732
+ VALUE pigpio_rbfn_i2c_read_byte_data(VALUE self, VALUE pi, VALUE handle, VALUE i2c_reg){
2733
+ return INT2NUM( i2c_read_byte_data(NUM2INT(pi), NUM2UINT(handle), NUM2UINT(i2c_reg)));
2734
+ }
2735
+ /*
2736
+ This reads a single 16 bit word from the specified register of the device
2737
+ associated with handle.
2738
+
2739
+ . .
2740
+ pi: >=0 (as returned by [*pigpio_start*]).
2741
+ handle: >=0, as returned by a call to [*i2c_open*].
2742
+ i2c_reg: 0-255, the register to read.
2743
+ . .
2744
+
2745
+ Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE,
2746
+ PI_BAD_PARAM, or PI_I2C_READ_FAILED.
2747
+
2748
+ Read word. SMBus 2.0 5.5.5
2749
+ . .
2750
+ S Addr Wr [A] i2c_reg [A]
2751
+ S Addr Rd [A] [DataLow] A [DataHigh] NA P
2752
+ . .
2753
+
2754
+ :call-seq:
2755
+ i2c_read_word_data(Integer pi,Integer handle, Integer i2c_reg) -> Integer
2756
+
2757
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#i2c_read_word_data]
2758
+ */
2759
+ VALUE pigpio_rbfn_i2c_read_word_data(VALUE self, VALUE pi, VALUE handle, VALUE i2c_reg){
2760
+ return INT2NUM( i2c_read_word_data(NUM2INT(pi), NUM2UINT(handle), NUM2UINT(i2c_reg)));
2761
+ }
2762
+ /*
2763
+ This writes 16 bits of data to the specified register of the device
2764
+ associated with handle and and reads 16 bits of data in return.
2765
+
2766
+ . .
2767
+ pi: >=0 (as returned by [*pigpio_start*]).
2768
+ handle: >=0, as returned by a call to [*i2c_open*].
2769
+ i2c_reg: 0-255, the register to write/read.
2770
+ wVal: 0-0xFFFF, the value to write.
2771
+ . .
2772
+
2773
+ Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE,
2774
+ PI_BAD_PARAM, or PI_I2C_READ_FAILED.
2775
+
2776
+ Process call. SMBus 2.0 5.5.6
2777
+ . .
2778
+ S Addr Wr [A] i2c_reg [A] wVal_Low [A] wVal_High [A]
2779
+ S Addr Rd [A] [DataLow] A [DataHigh] NA P
2780
+ . .
2781
+
2782
+ :call-seq:
2783
+ i2c_process_call(Integer pi,Integer handle, Integer i2c_reg, Integer wVal) -> Integer
2784
+
2785
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#i2c_process_call]
2786
+ */
2787
+ VALUE pigpio_rbfn_i2c_process_call(VALUE self, VALUE pi, VALUE handle, VALUE i2c_reg, VALUE wVal){
2788
+ return INT2NUM( i2c_process_call(NUM2INT(pi), NUM2UINT(handle), NUM2UINT(i2c_reg), NUM2UINT(wVal)));
2789
+ }
2790
+ /*
2791
+ This reads a block of up to 32 bytes from the specified register of
2792
+ the device associated with handle.
2793
+
2794
+ . .
2795
+ pi: >=0 (as returned by [*pigpio_start*]).
2796
+ handle: >=0, as returned by a call to [*i2c_open*].
2797
+ i2c_reg: 0-255, the register to read.
2798
+ buf: an binary string to receive the read data.
2799
+ . .
2800
+
2801
+ The amount of returned data is set by the device.
2802
+
2803
+ Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE,
2804
+ PI_BAD_PARAM, or PI_I2C_READ_FAILED.
2805
+
2806
+ Block read. SMBus 2.0 5.5.7
2807
+ . .
2808
+ S Addr Wr [A] i2c_reg [A]
2809
+ S Addr Rd [A] [Count] A [buf0] A [buf1] A ... A [bufn] NA P
2810
+ . .
2811
+
2812
+ :call-seq:
2813
+ i2c_read_block_data(Integer pi,Integer handle, Integer i2c_reg) -> Integer (When onError)
2814
+ i2c_read_block_data(Integer pi,Integer handle, Integer i2c_reg) -> String buf (When Success)
2815
+
2816
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#i2c_read_block_data]
2817
+ */
2818
+ VALUE pigpio_rbfn_i2c_read_block_data(VALUE self, VALUE pi, VALUE handle, VALUE i2c_reg){
2819
+ char buf[32];
2820
+ int ret=i2c_read_block_data(NUM2INT(pi), NUM2UINT(handle), NUM2UINT(i2c_reg), buf);
2821
+ return (ret<0)?INT2NUM(ret):rb_str_new(buf,ret);
2822
+ }
2823
+ /*
2824
+ This reads count bytes from the specified register of the device
2825
+ associated with handle . The count may be 1-32.
2826
+
2827
+ . .
2828
+ pi: >=0 (as returned by [*pigpio_start*]).
2829
+ handle: >=0, as returned by a call to [*i2c_open*].
2830
+ i2c_reg: 0-255, the register to read.
2831
+ buf: an array to receive the read data.
2832
+ count: 1-32, the number of bytes to read.
2833
+ . .
2834
+
2835
+ Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE,
2836
+ PI_BAD_PARAM, or PI_I2C_READ_FAILED.
2837
+
2838
+ . .
2839
+ S Addr Wr [A] i2c_reg [A]
2840
+ S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P
2841
+ . .
2842
+
2843
+ :call-seq:
2844
+ i2c_read_i2c_block_data(Integer pi,Integer handle, Integer i2c_reg,Integer buf) -> Integer (When onError)
2845
+ i2c_read_i2c_block_data(Integer pi,Integer handle, Integer i2c_reg,Integer buf) -> String (When Success)
2846
+
2847
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#i2c_read_i2c_block_data]
2848
+ */
2849
+ VALUE pigpio_rbfn_i2c_read_i2c_block_data(VALUE self, VALUE pi, VALUE handle, VALUE i2c_reg, VALUE count){
2850
+ char buf[32];
2851
+ int ret=i2c_read_i2c_block_data(NUM2INT(pi), NUM2UINT(handle), NUM2UINT(i2c_reg), buf, NUM2UINT(count));
2852
+ return (ret<0)?INT2NUM(ret):rb_str_new(buf,ret);
2853
+ }
2854
+ /*
2855
+ This writes up to 32 bytes to the specified register of the device
2856
+ associated with handle.
2857
+
2858
+ . .
2859
+ pi: >=0 (as returned by [*pigpio_start*]).
2860
+ handle: >=0, as returned by a call to [*i2c_open*].
2861
+ i2c_reg: 0-255, the register to write.
2862
+ buf: an binary string with the data to send.
2863
+ . .
2864
+
2865
+ Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
2866
+ PI_I2C_WRITE_FAILED.
2867
+
2868
+ Block write. SMBus 2.0 5.5.7
2869
+ . .
2870
+ S Addr Wr [A] i2c_reg [A] count [A] buf0 [A] buf1 [A] ...
2871
+ [A] bufn [A] P
2872
+ . .
2873
+
2874
+ :call-seq:
2875
+ i2c_write_block_data(Integer pi,Integer handle, Integer i2c_reg,String buf) -> Integer
2876
+
2877
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#i2c_write_block_data]
2878
+ */
2879
+ VALUE pigpio_rbfn_i2c_write_block_data(VALUE self, VALUE pi, VALUE handle, VALUE i2c_reg, VALUE buf){
2880
+ int ret=i2c_write_block_data(NUM2INT(pi), NUM2UINT(handle), NUM2UINT(i2c_reg),StringValuePtr(buf), RSTRING_LEN(buf));
2881
+ RB_GC_GUARD(buf);
2882
+ return INT2NUM(ret);
2883
+ }
2884
+ /*
2885
+ This writes 1 to 32 bytes to the specified register of the device
2886
+ associated with handle.
2887
+
2888
+ . .
2889
+ pi: >=0 (as returned by [*pigpio_start*]).
2890
+ handle: >=0, as returned by a call to [*i2c_open*].
2891
+ i2c_reg: 0-255, the register to write.
2892
+ buf: the data to write.
2893
+ count: 1-32, the number of bytes to write.
2894
+ . .
2895
+
2896
+ Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
2897
+ PI_I2C_WRITE_FAILED.
2898
+
2899
+ . .
2900
+ S Addr Wr [A] i2c_reg [A] buf0 [A] buf1 [A] ... [A] bufn [A] P
2901
+ . .
2902
+
2903
+ :call-seq:
2904
+ i2c_write_i2c_block_data(Integer pi,Integer handle, Integer i2c_reg,String buf) -> Integer
2905
+
2906
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#i2c_write_i2c_block_data]
2907
+ */
2908
+ VALUE pigpio_rbfn_i2c_write_i2c_block_data(VALUE self, VALUE pi, VALUE handle, VALUE i2c_reg, VALUE buf){
2909
+ int ret=i2c_write_i2c_block_data(NUM2INT(pi), NUM2UINT(handle), NUM2UINT(i2c_reg),StringValuePtr(buf), RSTRING_LEN(buf));
2910
+ RB_GC_GUARD(buf);
2911
+ return INT2NUM(ret);
2912
+ }
2913
+ /*
2914
+ This writes data bytes to the specified register of the device
2915
+ associated with handle and reads a device specified number
2916
+ of bytes of data in return.
2917
+
2918
+ . .
2919
+ pi: >=0 (as returned by [*pigpio_start*]).
2920
+ handle: >=0, as returned by a call to [*i2c_open*].
2921
+ i2c_reg: 0-255, the register to write/read.
2922
+ buf: an binary string with the data to send and to receive the read data.
2923
+ . .
2924
+
2925
+
2926
+ Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE,
2927
+ PI_BAD_PARAM, or PI_I2C_READ_FAILED.
2928
+
2929
+ The smbus 2.0 documentation states that a minimum of 1 byte may be
2930
+ sent and a minimum of 1 byte may be received. The total number of
2931
+ bytes sent/received must be 32 or less.
2932
+
2933
+ Block write-block read. SMBus 2.0 5.5.8
2934
+ . .
2935
+ S Addr Wr [A] i2c_reg [A] count [A] buf0 [A] ...
2936
+ S Addr Rd [A] [Count] A [Data] ... A P
2937
+ . .
2938
+
2939
+ :call-seq:
2940
+ i2c_block_process_call(Integer pi,Integer handle, Integer i2c_reg,String buf) -> Integer
2941
+
2942
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#i2c_block_process_call]
2943
+ */
2944
+ VALUE pigpio_rbfn_i2c_block_process_call(VALUE self, VALUE pi, VALUE handle, VALUE i2c_reg, VALUE buf){
2945
+ int ret=i2c_block_process_call(NUM2INT(pi), NUM2UINT(handle), NUM2UINT(i2c_reg),StringValuePtr(buf), RSTRING_LEN(buf));
2946
+ RB_GC_GUARD(buf);
2947
+ return INT2NUM(ret);
2948
+ }
2949
+ /*
2950
+ This reads count bytes from the raw device into buf.
2951
+
2952
+ . .
2953
+ pi: >=0 (as returned by [*pigpio_start*]).
2954
+ handle: >=0, as returned by a call to [*i2c_open*].
2955
+ buf: an binary string to receive the read data bytes.
2956
+ count: >0, the number of bytes to read.
2957
+ . .
2958
+
2959
+ Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
2960
+ PI_I2C_READ_FAILED.
2961
+
2962
+ . .
2963
+ S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P
2964
+ . .
2965
+
2966
+ :call-seq:
2967
+ i2c_read_device(Integer pi,Integer handle, Integer count) -> Integer (When onError)
2968
+ i2c_read_device(Integer pi,Integer handle, Integer count) -> String buf (When Success)
2969
+
2970
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#i2c_read_device]
2971
+ */
2972
+ VALUE pigpio_rbfn_i2c_read_device(VALUE self, VALUE pi, VALUE handle, VALUE count){
2973
+ unsigned countc=NUM2UINT(count);
2974
+ VALUE buf=rb_str_new("",countc);//#<Encoding:ASCII-8BIT>;
2975
+ int ret=i2c_read_device(NUM2INT(pi), NUM2UINT(handle), StringValuePtr(buf), countc);
2976
+ return (ret<0)?INT2NUM(ret):rb_str_resize(buf,ret);
2977
+ }
2978
+ /*
2979
+ This writes count bytes from buf to the raw device.
2980
+
2981
+ . .
2982
+ pi: >=0 (as returned by [*pigpio_start*]).
2983
+ handle: >=0, as returned by a call to [*i2c_open*].
2984
+ buf: an array containing the data bytes to write.
2985
+ count: >0, the number of bytes to write.
2986
+ . .
2987
+
2988
+ Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
2989
+ PI_I2C_WRITE_FAILED.
2990
+
2991
+ . .
2992
+ S Addr Wr [A] buf0 [A] buf1 [A] ... [A] bufn [A] P
2993
+ . .
2994
+
2995
+ :call-seq:
2996
+ i2c_write_device(Integer pi,Integer handle, String buf) -> Integer
2997
+
2998
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#i2c_write_device]
2999
+ */
3000
+ VALUE pigpio_rbfn_i2c_write_device(VALUE self, VALUE pi, VALUE handle, VALUE buf){
3001
+ int ret=i2c_write_device(NUM2INT(pi), NUM2UINT(handle), StringValuePtr(buf), RSTRING_LEN(buf));
3002
+ RB_GC_GUARD(buf);
3003
+ return INT2NUM(ret);
3004
+ }
3005
+ /*
3006
+ This function executes a sequence of I2C operations. The
3007
+ operations to be performed are specified by the contents of inBuf
3008
+ which contains the concatenated command codes and associated data.
3009
+
3010
+ . .
3011
+ pi: >=0 (as returned by [*pigpio_start*]).
3012
+ handle: >=0, as returned by a call to [*i2cOpen*]
3013
+ inBuf: the concatenated I2C commands, see below
3014
+ outBuf: buffer to hold returned data
3015
+ outLen: size of output buffer
3016
+ . .
3017
+
3018
+ Returns >= 0 if OK (the number of bytes read), otherwise
3019
+ PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN.
3020
+ PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG.
3021
+
3022
+ The following command codes are supported:
3023
+
3024
+ Name @ Cmd & Data @ Meaning
3025
+ End @ 0 @ No more commands
3026
+ Escape @ 1 @ Next P is two bytes
3027
+ On @ 2 @ Switch combined flag on
3028
+ Off @ 3 @ Switch combined flag off
3029
+ Address @ 4 P @ Set I2C address to P
3030
+ Flags @ 5 lsb msb @ Set I2C flags to lsb + (msb << 8)
3031
+ Read @ 6 P @ Read P bytes of data
3032
+ Write @ 7 P ... @ Write P bytes of data
3033
+
3034
+ The address, read, and write commands take a parameter P.
3035
+ Normally P is one byte (0-255). If the command is preceded by
3036
+ the Escape command then P is two bytes (0-65535, least significant
3037
+ byte first).
3038
+
3039
+ The address defaults to that associated with the handle.
3040
+ The flags default to 0. The address and flags maintain their
3041
+ previous value until updated.
3042
+
3043
+ The returned I2C data is stored in consecutive locations of outBuf.
3044
+
3045
+ ...
3046
+ Set address 0x53, write 0x32, read 6 bytes
3047
+ Set address 0x1E, write 0x03, read 6 bytes
3048
+ Set address 0x68, write 0x1B, read 8 bytes
3049
+ End
3050
+
3051
+ 0x04 0x53 0x07 0x01 0x32 0x06 0x06
3052
+ 0x04 0x1E 0x07 0x01 0x03 0x06 0x06
3053
+ 0x04 0x68 0x07 0x01 0x1B 0x06 0x08
3054
+ 0x00
3055
+ ...
3056
+
3057
+
3058
+ :call-seq:
3059
+ i2c_zip(Integer pi,Integer handle, String inBuf, Integer outLen) -> Integer (When onError)
3060
+ i2c_zip(Integer pi,Integer handle, String inBuf, Integer outLen) -> String outBuf (When Success)
3061
+
3062
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#i2c_zip]
3063
+ */
3064
+ VALUE pigpio_rbfn_i2c_zip(VALUE self, VALUE pi, VALUE handle, VALUE inBuf, VALUE outLen_v){
3065
+ unsigned inLen=RSTRING_LEN(inBuf);
3066
+ unsigned outLen=NUM2UINT(outLen_v);
3067
+ VALUE outBuf=rb_str_new("",outLen);//#<Encoding:ASCII-8BIT>;
3068
+ int ret=i2c_zip(NUM2INT(pi), NUM2UINT(handle), StringValuePtr(inBuf), inLen, StringValuePtr(outBuf), outLen);
3069
+ RB_GC_GUARD(inBuf);
3070
+ return (ret < 0)?INT2NUM(ret):rb_str_resize(outBuf,ret);
3071
+ //if(ret < 0){outBuf=Qnil;}
3072
+ //return rb_ary_new_from_args(2,outBuf,INT2NUM(ret));
3073
+ }
3074
+ /*
3075
+ This function selects a pair of GPIO for bit banging I2C at a
3076
+ specified baud rate.
3077
+
3078
+ Bit banging I2C allows for certain operations which are not possible
3079
+ with the standard I2C driver.
3080
+
3081
+ * baud rates as low as 50
3082
+ * repeated starts
3083
+ * clock stretching
3084
+ * I2C on any pair of spare GPIO
3085
+
3086
+ . .
3087
+ pi: >=0 (as returned by [*pigpio_start*]).
3088
+ SDA: 0-31
3089
+ SCL: 0-31
3090
+ baud: 50-500000
3091
+ . .
3092
+
3093
+ Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or
3094
+ PI_GPIO_IN_USE.
3095
+
3096
+ NOTE:
3097
+
3098
+ The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As
3099
+ a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value.
3100
+
3101
+ :call-seq:
3102
+ bb_i2c_open(Integer pi,Integer SDA, Integer SCL, Integer baud) -> Integer
3103
+
3104
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#bb_i2c_open]
3105
+ */
3106
+ VALUE pigpio_rbfn_bb_i2c_open(VALUE self, VALUE pi, VALUE SDA, VALUE SCL, VALUE baud){
3107
+ return INT2NUM( bb_i2c_open(NUM2INT(pi), NUM2UINT(SDA), NUM2UINT(SCL), NUM2UINT(baud)));
3108
+ }
3109
+ /*
3110
+ This function stops bit banging I2C on a pair of GPIO previously
3111
+ opened with [*bb_i2c_open*].
3112
+
3113
+ . .
3114
+ pi: >=0 (as returned by [*pigpio_start*]).
3115
+ SDA: 0-31, the SDA GPIO used in a prior call to [*bb_i2c_open*]
3116
+ . .
3117
+
3118
+ Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO.
3119
+
3120
+ :call-seq:
3121
+ bb_i2c_close(Integer pi,Integer SDA) -> Integer
3122
+
3123
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#bb_i2c_close]
3124
+ */
3125
+ VALUE pigpio_rbfn_bb_i2c_close(VALUE self, VALUE pi, VALUE SDA){
3126
+ return INT2NUM( bb_i2c_close(NUM2INT(pi), NUM2UINT(SDA)));
3127
+ }
3128
+ /*
3129
+ This function executes a sequence of bit banged I2C operations. The
3130
+ operations to be performed are specified by the contents of inBuf
3131
+ which contains the concatenated command codes and associated data.
3132
+
3133
+ . .
3134
+ pi: >=0 (as returned by [*pigpio_start*]).
3135
+ SDA: 0-31 (as used in a prior call to [*bb_i2c_open*])
3136
+ inBuf: the concatenated I2C commands, see below
3137
+ outBuf: buffer to hold returned data
3138
+ outLen: size of output buffer
3139
+ . .
3140
+
3141
+ Returns >= 0 if OK (the number of bytes read), otherwise
3142
+ PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER,
3143
+ PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN,
3144
+ PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED.
3145
+
3146
+ The following command codes are supported:
3147
+
3148
+ Name @ Cmd & Data @ Meaning
3149
+ End @ 0 @ No more commands
3150
+ Escape @ 1 @ Next P is two bytes
3151
+ Start @ 2 @ Start condition
3152
+ Stop @ 3 @ Stop condition
3153
+ Address @ 4 P @ Set I2C address to P
3154
+ Flags @ 5 lsb msb @ Set I2C flags to lsb + (msb << 8)
3155
+ Read @ 6 P @ Read P bytes of data
3156
+ Write @ 7 P ... @ Write P bytes of data
3157
+
3158
+ The address, read, and write commands take a parameter P.
3159
+ Normally P is one byte (0-255). If the command is preceded by
3160
+ the Escape command then P is two bytes (0-65535, least significant
3161
+ byte first).
3162
+
3163
+ The address and flags default to 0. The address and flags maintain
3164
+ their previous value until updated.
3165
+
3166
+ No flags are currently defined.
3167
+
3168
+ The returned I2C data is stored in consecutive locations of outBuf.
3169
+
3170
+ ...
3171
+ Set address 0x53
3172
+ start, write 0x32, (re)start, read 6 bytes, stop
3173
+ Set address 0x1E
3174
+ start, write 0x03, (re)start, read 6 bytes, stop
3175
+ Set address 0x68
3176
+ start, write 0x1B, (re)start, read 8 bytes, stop
3177
+ End
3178
+
3179
+ 0x04 0x53
3180
+ 0x02 0x07 0x01 0x32 0x02 0x06 0x06 0x03
3181
+
3182
+ 0x04 0x1E
3183
+ 0x02 0x07 0x01 0x03 0x02 0x06 0x06 0x03
3184
+
3185
+ 0x04 0x68
3186
+ 0x02 0x07 0x01 0x1B 0x02 0x06 0x08 0x03
3187
+
3188
+ 0x00
3189
+ ...
3190
+
3191
+ :call-seq:
3192
+ bb_i2c_zip(Integer pi,Integer SDA, String inBuf, Integer outLen) -> Integer (When onError)
3193
+ bb_i2c_zip(Integer pi,Integer SDA, String inBuf, Integer outLen) -> String outBuf (When Success)
3194
+
3195
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#bb_i2c_zip]
3196
+ */
3197
+ VALUE pigpio_rbfn_bb_i2c_zip(VALUE self, VALUE pi, VALUE SDA, VALUE inBuf, VALUE outLen_v){
3198
+ unsigned outLen=NUM2UINT(outLen_v);
3199
+ VALUE outBuf=rb_str_new("",outLen);//#<Encoding:ASCII-8BIT>;
3200
+ int ret=bb_i2c_zip(NUM2INT(pi), NUM2UINT(SDA), StringValuePtr(inBuf), RSTRING_LEN(inBuf), StringValuePtr(outBuf), outLen);
3201
+ RB_GC_GUARD(inBuf);
3202
+ return (ret < 0)?INT2NUM(ret):rb_str_resize(outBuf,ret);
3203
+ //if(ret < 0){outBuf=Qnil;}
3204
+ //return rb_ary_new_from_args(2,outBuf,INT2NUM(ret));
3205
+ }
3206
+
3207
+
3208
+ /*
3209
+ This function returns the pad drive strength in mA.
3210
+
3211
+ . .
3212
+ pi: >=0 (as returned by [*pigpio_start*]).
3213
+ pad: 0-2, the pad to get.
3214
+ . .
3215
+
3216
+ Returns the pad drive strength if OK, otherwise PI_BAD_PAD.
3217
+
3218
+ Pad @ GPIO
3219
+ 0 @ 0-27
3220
+ 1 @ 28-45
3221
+ 2 @ 46-53
3222
+
3223
+ ...
3224
+ strength = get_pad_strength(pi, 0); // get pad 0 strength
3225
+ ...
3226
+
3227
+ :call-seq:
3228
+ get_pad_strength(Integer pi,Integer pad) -> Integer
3229
+
3230
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#get_pad_strength]
3231
+ */
3232
+ VALUE pigpio_rbfn_get_pad_strength(VALUE self, VALUE pi, VALUE pad){
3233
+ return INT2NUM( get_pad_strength(NUM2INT(pi), NUM2UINT(pad)));
3234
+ }
3235
+ /*
3236
+ This function sets the pad drive strength in mA.
3237
+
3238
+ . .
3239
+ pi: >=0 (as returned by [*pigpio_start*]).
3240
+ pad: 0-2, the pad to set.
3241
+ padStrength: 1-16 mA.
3242
+ . .
3243
+
3244
+ Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH.
3245
+
3246
+ Pad @ GPIO
3247
+ 0 @ 0-27
3248
+ 1 @ 28-45
3249
+ 2 @ 46-53
3250
+
3251
+ ...
3252
+ set_pad_strength(pi, 0, 10); // set pad 0 strength to 10 mA
3253
+ ...
3254
+
3255
+ :call-seq:
3256
+ set_pad_strength(Integer pi,Integer pad, Integer padStrength) -> Integer
3257
+
3258
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#set_pad_strength]
3259
+ */
3260
+ VALUE pigpio_rbfn_set_pad_strength(VALUE self, VALUE pi, VALUE pad, VALUE padStrength){
3261
+ return INT2NUM( set_pad_strength(NUM2INT(pi), NUM2UINT(pad), NUM2UINT(padStrength)));
3262
+ }
3263
+
3264
+ /*
3265
+ This function provides a low-level interface to the
3266
+ SPI/I2C Slave peripheral. This peripheral allows the
3267
+ Pi to act as a slave device on an I2C or SPI bus.
3268
+
3269
+ I can't get SPI to work properly. I tried with a
3270
+ control word of 0x303 and swapped MISO and MOSI.
3271
+
3272
+ The function sets the BSC mode, writes any data in
3273
+ the transmit buffer to the BSC transmit FIFO, and
3274
+ copies any data in the BSC receive FIFO to the
3275
+ receive buffer.
3276
+
3277
+ . .
3278
+ pi: >=0 (as returned by [*pigpio_start*]).
3279
+ bscxfer: a structure defining the transfer.
3280
+
3281
+ typedef struct
3282
+ {
3283
+ uint32_t control; // Write
3284
+ int rxCnt; // Read only
3285
+ char rxBuf[BSC_FIFO_SIZE]; // Read only
3286
+ int txCnt; // Write
3287
+ char txBuf[BSC_FIFO_SIZE]; // Write
3288
+ } bsc_xfer_t;
3289
+ . .
3290
+
3291
+ To start a transfer set control (see below) and copy the bytes to
3292
+ be sent (if any) to txBuf and set the byte count in txCnt.
3293
+
3294
+ Upon return rxCnt will be set to the number of received bytes placed
3295
+ in rxBuf.
3296
+
3297
+ The returned function value is the status of the transfer (see below).
3298
+
3299
+ If there was an error the status will be less than zero
3300
+ (and will contain the error code).
3301
+
3302
+ The most significant word of the returned status contains the number
3303
+ of bytes actually copied from txBuf to the BSC transmit FIFO (may be
3304
+ less than requested if the FIFO already contained untransmitted data).
3305
+
3306
+ Note that the control word sets the BSC mode. The BSC will stay in
3307
+ that mode until a different control word is sent.
3308
+
3309
+ The BSC peripheral uses GPIO 18 (SDA) and 19 (SCL) in I2C mode
3310
+ and GPIO 18 (MOSI), 19 (SCLK), 20 (MISO), and 21 (CE) in SPI mode. You
3311
+ need to swap MISO/MOSI between master and slave.
3312
+
3313
+ When a zero control word is received GPIO 18-21 will be reset
3314
+ to INPUT mode.
3315
+
3316
+ control consists of the following bits.
3317
+
3318
+ . .
3319
+ 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
3320
+ a a a a a a a - - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN
3321
+ . .
3322
+
3323
+ Bits 0-13 are copied unchanged to the BSC CR register. See
3324
+ pages 163-165 of the Broadcom peripherals document for full
3325
+ details.
3326
+
3327
+ aaaaaaa @ defines the I2C slave address (only relevant in I2C mode)
3328
+ IT @ invert transmit status flags
3329
+ HC @ enable host control
3330
+ TF @ enable test FIFO
3331
+ IR @ invert receive status flags
3332
+ RE @ enable receive
3333
+ TE @ enable transmit
3334
+ BK @ abort operation and clear FIFOs
3335
+ EC @ send control register as first I2C byte
3336
+ ES @ send status register as first I2C byte
3337
+ PL @ set SPI polarity high
3338
+ PH @ set SPI phase high
3339
+ I2 @ enable I2C mode
3340
+ SP @ enable SPI mode
3341
+ EN @ enable BSC peripheral
3342
+
3343
+ The returned status has the following format
3344
+
3345
+ . .
3346
+ 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
3347
+ S S S S S R R R R R T T T T T RB TE RF TF RE TB
3348
+ . .
3349
+
3350
+ Bits 0-15 are copied unchanged from the BSC FR register. See
3351
+ pages 165-166 of the Broadcom peripherals document for full
3352
+ details.
3353
+
3354
+ SSSSS @ number of bytes successfully copied to transmit FIFO
3355
+ RRRRR @ number of bytes in receieve FIFO
3356
+ TTTTT @ number of bytes in transmit FIFO
3357
+ RB @ receive busy
3358
+ TE @ transmit FIFO empty
3359
+ RF @ receive FIFO full
3360
+ TF @ transmit FIFO full
3361
+ RE @ receive FIFO empty
3362
+ TB @ transmit busy
3363
+
3364
+ :call-seq:
3365
+ bsc_xfer(Integer pi, PIGPIO::BscXfer bscxfer) -> Integer
3366
+
3367
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#bsc_xfer]
3368
+ */
3369
+ VALUE pigpio_rbfn_bsc_xfer(VALUE self, VALUE pi, VALUE bscxfer){
3370
+ bsc_xfer_t *st=TypedData_Get_Struct2(bscxfer,bsc_xfer_t,&bsc_xfer_data_type);
3371
+ int ret=bsc_xfer(NUM2INT(pi), st);
3372
+ return INT2NUM(ret);
3373
+ }
3374
+ /*
3375
+ This function allows the Pi to act as a slave I2C device.
3376
+
3377
+ The data bytes (if any) are written to the BSC transmit
3378
+ FIFO and the bytes in the BSC receive FIFO are returned.
3379
+
3380
+ . .
3381
+ pi: >=0 (as returned by [*pigpio_start*]).
3382
+ i2c_addr: 0-0x7F.
3383
+ bscxfer: a structure defining the transfer.
3384
+
3385
+ typedef struct
3386
+ {
3387
+ uint32_t control; // N/A
3388
+ int rxCnt; // Read only
3389
+ char rxBuf[BSC_FIFO_SIZE]; // Read only
3390
+ int txCnt; // Write
3391
+ char txBuf[BSC_FIFO_SIZE]; // Write
3392
+ } bsc_xfer_t;
3393
+ . .
3394
+
3395
+ txCnt is set to the number of bytes to be transmitted, possibly
3396
+ zero. The data itself should be copied to txBuf.
3397
+
3398
+ Any received data will be written to rxBuf with rxCnt set.
3399
+
3400
+ See [*bsc_xfer*] for details of the returned status value.
3401
+
3402
+ If there was an error the status will be less than zero
3403
+ (and will contain the error code).
3404
+
3405
+ Note that an i2c_address of 0 may be used to close
3406
+ the BSC device and reassign the used GPIO (18/19)
3407
+ as inputs.
3408
+
3409
+ :call-seq:
3410
+ bsc_i2c(Integer pi,Integer i2c_addr, PIGPIO::BscXfer bscxfer) -> Integer
3411
+
3412
+ See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#bsc_i2c]
3413
+ */
3414
+ VALUE pigpio_rbfn_bsc_i2c(VALUE self, VALUE pi, VALUE i2c_addr, VALUE bscxfer){
3415
+ bsc_xfer_t *st=TypedData_Get_Struct2(bscxfer,bsc_xfer_t,&bsc_xfer_data_type);
3416
+ int ret=bsc_i2c(NUM2INT(pi), NUM2INT(i2c_addr), st);
3417
+ return INT2NUM(ret);
3418
+ }
3419
+
3420
+ /*
3421
+ This class has some constances for pigpio library.
3422
+ */
3423
+ void Init_pigpio(void){
3424
+ VALUE cCTest = rb_define_class("Pigpio", rb_cObject);
3425
+ /*
3426
+ This module is a ruby binding to pigpio library.
3427
+ */
3428
+ VALUE cAPI = rb_define_module_under(cCTest, "IF");
3429
+ rb_define_singleton_method(cAPI, "pigpio_start_local",pigpio_rbfn_pigpio_start_local, 0);
3430
+ rb_define_singleton_method(cAPI, "pigpio_start", pigpio_rbfn_pigpio_start, 2);
3431
+ rb_define_singleton_method(cAPI, "pigpio_stop", pigpio_rbfn_pigpio_stop, 1);
3432
+ rb_define_singleton_method(cAPI, "set_mode", pigpio_rbfn_set_mode, 3);
3433
+ rb_define_singleton_method(cAPI, "get_mode", pigpio_rbfn_get_mode, 2);
3434
+ rb_define_singleton_method(cAPI, "set_pull_up_down", pigpio_rbfn_set_pull_up_down, 3);
3435
+ rb_define_singleton_method(cAPI, "gpio_read", pigpio_rbfn_gpio_read, 2);
3436
+ rb_define_singleton_method(cAPI, "gpio_write", pigpio_rbfn_gpio_write, 3);
3437
+ rb_define_singleton_method(cAPI, "time_time", pigpio_rbfn_time_time, 0);
3438
+ rb_define_singleton_method(cAPI, "pigpio_error", pigpio_rbfn_pigpio_error, 1);
3439
+ rb_define_singleton_method(cAPI, "pigpiod_if_version",pigpio_rbfn_pigpiod_if_version, 0);
3440
+ rb_define_singleton_method(cAPI, "set_watchdog", pigpio_rbfn_set_watchdog, 3);
3441
+ rb_define_singleton_method(cAPI, "set_glitch_filter", pigpio_rbfn_set_glitch_filter, 3);
3442
+ rb_define_singleton_method(cAPI, "set_noise_filter", pigpio_rbfn_set_noise_filter, 4);
3443
+ rb_define_singleton_method(cAPI, "get_current_tick", pigpio_rbfn_get_current_tick, 1);
3444
+ rb_define_singleton_method(cAPI, "get_hardware_revision",pigpio_rbfn_get_hardware_revision, 1);
3445
+ rb_define_singleton_method(cAPI, "get_pigpio_version", pigpio_rbfn_get_pigpio_version, 1);
3446
+ rb_define_singleton_method(cAPI, "wave_clear", pigpio_rbfn_wave_clear, 1);
3447
+ rb_define_singleton_method(cAPI, "wave_add_new", pigpio_rbfn_wave_add_new, 1);
3448
+ rb_define_singleton_method(cAPI, "wave_create", pigpio_rbfn_wave_create, 1);
3449
+ rb_define_singleton_method(cAPI, "wave_delete", pigpio_rbfn_wave_delete, 2);
3450
+ rb_define_singleton_method(cAPI, "wave_send_once", pigpio_rbfn_wave_send_once, 2);
3451
+ rb_define_singleton_method(cAPI, "wave_send_repeat", pigpio_rbfn_wave_send_repeat, 2);
3452
+ rb_define_singleton_method(cAPI, "wave_send_using_mode", pigpio_rbfn_wave_send_using_mode, 3);
3453
+ rb_define_singleton_method(cAPI, "wave_tx_at", pigpio_rbfn_wave_tx_at, 1);
3454
+ rb_define_singleton_method(cAPI, "wave_tx_busy", pigpio_rbfn_wave_tx_busy, 1);
3455
+ rb_define_singleton_method(cAPI, "wave_tx_stop", pigpio_rbfn_wave_tx_stop, 1);
3456
+ rb_define_singleton_method(cAPI, "wave_get_micros", pigpio_rbfn_wave_get_micros, 1);
3457
+ rb_define_singleton_method(cAPI, "wave_get_high_micros", pigpio_rbfn_wave_get_high_micros, 1);
3458
+ rb_define_singleton_method(cAPI, "wave_get_max_micros", pigpio_rbfn_wave_get_max_micros, 1);
3459
+ rb_define_singleton_method(cAPI, "wave_get_pulses", pigpio_rbfn_wave_get_pulses, 1);
3460
+ rb_define_singleton_method(cAPI, "wave_get_high_pulses", pigpio_rbfn_wave_get_high_pulses, 1);
3461
+ rb_define_singleton_method(cAPI, "wave_get_max_pulses", pigpio_rbfn_wave_get_max_pulses, 1);
3462
+ rb_define_singleton_method(cAPI, "wave_get_cbs", pigpio_rbfn_wave_get_cbs, 1);
3463
+ rb_define_singleton_method(cAPI, "wave_get_high_cbs", pigpio_rbfn_wave_get_high_cbs, 1);
3464
+ rb_define_singleton_method(cAPI, "wave_get_max_cbs", pigpio_rbfn_wave_get_max_cbs, 1);
3465
+ rb_define_singleton_method(cAPI, "gpio_trigger", pigpio_rbfn_gpio_trigger, 4);
3466
+ rb_define_singleton_method(cAPI, "set_PWM_dutycycle", pigpio_rbfn_set_PWM_dutycycle, 3);
3467
+ rb_define_singleton_method(cAPI, "get_PWM_dutycycle", pigpio_rbfn_get_PWM_dutycycle, 2);
3468
+ rb_define_singleton_method(cAPI, "set_PWM_range", pigpio_rbfn_set_PWM_range, 3);
3469
+ rb_define_singleton_method(cAPI, "get_PWM_range", pigpio_rbfn_get_PWM_range, 2);
3470
+ rb_define_singleton_method(cAPI, "get_PWM_real_range", pigpio_rbfn_get_PWM_real_range, 2);
3471
+ rb_define_singleton_method(cAPI, "set_PWM_frequency", pigpio_rbfn_set_PWM_frequency, 3);
3472
+ rb_define_singleton_method(cAPI, "get_PWM_frequency", pigpio_rbfn_get_PWM_frequency, 2);
3473
+ rb_define_singleton_method(cAPI, "set_servo_pulsewidth", pigpio_rbfn_set_servo_pulsewidth, 3);
3474
+ rb_define_singleton_method(cAPI, "get_servo_pulsewidth", pigpio_rbfn_get_servo_pulsewidth, 2);
3475
+ rb_define_singleton_method(cAPI, "notify_open", pigpio_rbfn_notify_open, 1);
3476
+ rb_define_singleton_method(cAPI, "notify_begin", pigpio_rbfn_notify_begin, 3);
3477
+ rb_define_singleton_method(cAPI, "notify_pause", pigpio_rbfn_notify_pause, 2);
3478
+ rb_define_singleton_method(cAPI, "notify_close", pigpio_rbfn_notify_close, 2);
3479
+ rb_define_singleton_method(cAPI, "read_bank_1", pigpio_rbfn_read_bank_1, 1);
3480
+ rb_define_singleton_method(cAPI, "read_bank_2", pigpio_rbfn_read_bank_2, 1);
3481
+ rb_define_singleton_method(cAPI, "clear_bank_1", pigpio_rbfn_clear_bank_1, 2);
3482
+ rb_define_singleton_method(cAPI, "clear_bank_2", pigpio_rbfn_clear_bank_2, 2);
3483
+ rb_define_singleton_method(cAPI, "set_bank_1", pigpio_rbfn_set_bank_1, 2);
3484
+ rb_define_singleton_method(cAPI, "set_bank_2", pigpio_rbfn_set_bank_2, 2);
3485
+ rb_define_singleton_method(cAPI, "hardware_clock", pigpio_rbfn_hardware_clock, 3);
3486
+ rb_define_singleton_method(cAPI, "hardware_PWM", pigpio_rbfn_hardware_PWM, 4);
3487
+ rb_define_singleton_method(cAPI, "wave_add_generic", pigpio_rbfn_wave_add_generic, 2);
3488
+ rb_define_singleton_method(cAPI, "wave_add_serial", pigpio_rbfn_wave_add_serial, 7);
3489
+ rb_define_singleton_method(cAPI, "wave_chain", pigpio_rbfn_wave_chain, 2);
3490
+ rb_define_singleton_method(cAPI, "callback", pigpio_rbfn_callback, -1);
3491
+ rb_define_singleton_method(cAPI, "callback_cancel", pigpio_rbfn_callback_cancel, 1);
3492
+ rb_define_singleton_method(cAPI, "wait_for_edge", pigpio_rbfn_wait_for_edge, 4);
3493
+ rb_define_singleton_method(cAPI, "event_callback", pigpio_rbfn_event_callback, -1);
3494
+ rb_define_singleton_method(cAPI, "event_callback_cancel", pigpio_rbfn_event_callback_cancel, 1);
3495
+ rb_define_singleton_method(cAPI, "wait_for_event", pigpio_rbfn_wait_for_event, 3);
3496
+ rb_define_singleton_method(cAPI, "event_trigger", pigpio_rbfn_event_trigger, 2);
3497
+ rb_define_singleton_method(cAPI, "serial_open", pigpio_rbfn_serial_open, 4);
3498
+ rb_define_singleton_method(cAPI, "serial_close", pigpio_rbfn_serial_close, 2);
3499
+ rb_define_singleton_method(cAPI, "serial_write_byte", pigpio_rbfn_serial_write_byte, 3);
3500
+ rb_define_singleton_method(cAPI, "serial_read_byte", pigpio_rbfn_serial_read_byte, 2);
3501
+ rb_define_singleton_method(cAPI, "serial_write", pigpio_rbfn_serial_write, 3);
3502
+ rb_define_singleton_method(cAPI, "serial_read", pigpio_rbfn_serial_read, 3);
3503
+ rb_define_singleton_method(cAPI, "serial_data_available", pigpio_rbfn_serial_data_available, 2);
3504
+ rb_define_singleton_method(cAPI, "bb_serial_read_open", pigpio_rbfn_bb_serial_read_open, 4);
3505
+ rb_define_singleton_method(cAPI, "bb_serial_read", pigpio_rbfn_bb_serial_read, 3);
3506
+ rb_define_singleton_method(cAPI, "bb_serial_read_close", pigpio_rbfn_bb_serial_read_close, 2);
3507
+ rb_define_singleton_method(cAPI, "bb_serial_invert", pigpio_rbfn_bb_serial_invert, 3);
3508
+ rb_define_singleton_method(cAPI, "bb_spi_open", pigpio_rbfn_bb_spi_open, 7);
3509
+ rb_define_singleton_method(cAPI, "bb_spi_close", pigpio_rbfn_bb_spi_close, 2);
3510
+ rb_define_singleton_method(cAPI, "bb_spi_xfer", pigpio_rbfn_bb_spi_xfer, 3);
3511
+ rb_define_singleton_method(cAPI, "spi_open", pigpio_rbfn_spi_open, 4);
3512
+ rb_define_singleton_method(cAPI, "spi_close", pigpio_rbfn_spi_close, 2);
3513
+ rb_define_singleton_method(cAPI, "spi_read", pigpio_rbfn_spi_read, 3);
3514
+ rb_define_singleton_method(cAPI, "spi_write", pigpio_rbfn_spi_write, 3);
3515
+ rb_define_singleton_method(cAPI, "spi_xfer", pigpio_rbfn_spi_xfer, 3);
3516
+ rb_define_singleton_method(cAPI, "i2c_open", pigpio_rbfn_i2c_open, 4);
3517
+ rb_define_singleton_method(cAPI, "i2c_close", pigpio_rbfn_i2c_close, 2);
3518
+ rb_define_singleton_method(cAPI, "i2c_write_quick", pigpio_rbfn_i2c_write_quick, 3);
3519
+ rb_define_singleton_method(cAPI, "i2c_write_byte", pigpio_rbfn_i2c_write_byte, 3);
3520
+ rb_define_singleton_method(cAPI, "i2c_read_byte", pigpio_rbfn_i2c_read_byte, 2);
3521
+ rb_define_singleton_method(cAPI, "i2c_write_byte_data", pigpio_rbfn_i2c_write_byte_data, 4);
3522
+ rb_define_singleton_method(cAPI, "i2c_write_word_data", pigpio_rbfn_i2c_write_word_data, 4);
3523
+ rb_define_singleton_method(cAPI, "i2c_read_byte_data", pigpio_rbfn_i2c_read_byte_data, 3);
3524
+ rb_define_singleton_method(cAPI, "i2c_read_word_data", pigpio_rbfn_i2c_read_word_data, 3);
3525
+ rb_define_singleton_method(cAPI, "i2c_process_call", pigpio_rbfn_i2c_process_call, 4);
3526
+ rb_define_singleton_method(cAPI, "i2c_read_block_data", pigpio_rbfn_i2c_read_block_data, 3);
3527
+ rb_define_singleton_method(cAPI, "i2c_read_i2c_block_data", pigpio_rbfn_i2c_read_i2c_block_data, 4);
3528
+ rb_define_singleton_method(cAPI, "i2c_write_block_data", pigpio_rbfn_i2c_write_block_data, 4);
3529
+ rb_define_singleton_method(cAPI, "i2c_write_i2c_block_data",pigpio_rbfn_i2c_write_i2c_block_data, 4);
3530
+ rb_define_singleton_method(cAPI, "i2c_block_process_call", pigpio_rbfn_i2c_block_process_call, 4);
3531
+ rb_define_singleton_method(cAPI, "i2c_read_device", pigpio_rbfn_i2c_read_device, 3);
3532
+ rb_define_singleton_method(cAPI, "i2c_write_device", pigpio_rbfn_i2c_write_device, 3);
3533
+ rb_define_singleton_method(cAPI, "i2c_zip", pigpio_rbfn_i2c_zip, 4);
3534
+ rb_define_singleton_method(cAPI, "bb_i2c_open", pigpio_rbfn_bb_i2c_open, 4);
3535
+ rb_define_singleton_method(cAPI, "bb_i2c_close", pigpio_rbfn_bb_i2c_close, 2);
3536
+ rb_define_singleton_method(cAPI, "bb_i2c_zip", pigpio_rbfn_bb_i2c_zip, 4);
3537
+ rb_define_singleton_method(cAPI, "store_script", pigpio_rbfn_store_script, 2);
3538
+ rb_define_singleton_method(cAPI, "run_script", pigpio_rbfn_run_script, 3);
3539
+ rb_define_singleton_method(cAPI, "script_status", pigpio_rbfn_script_status, 2);
3540
+ rb_define_singleton_method(cAPI, "stop_script", pigpio_rbfn_stop_script, 2);
3541
+ rb_define_singleton_method(cAPI, "delete_script", pigpio_rbfn_delete_script, 2);
3542
+ rb_define_singleton_method(cAPI, "bsc_xfer", pigpio_rbfn_bsc_xfer, 2);
3543
+ rb_define_singleton_method(cAPI, "bsc_i2c", pigpio_rbfn_bsc_i2c, 3);
3544
+ rb_define_singleton_method(cAPI, "get_pad_strength", pigpio_rbfn_get_pad_strength, 2);
3545
+ rb_define_singleton_method(cAPI, "set_pad_strength", pigpio_rbfn_set_pad_strength, 3);
3546
+ //rb_define_singleton_method(cAPI, "time_time",pigpio_rbfn_, 0);
3547
+ }