pigpio 0.1.10 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.standard_todo.yml +51 -0
- data/README.md +3 -1
- data/Rakefile +3 -4
- data/ext/pigpio/extconf.rb +5 -5
- data/ext/pigpio/pigpio.c +29 -18
- data/lib/pigpio/bank.rb +25 -22
- data/lib/pigpio/bit_bang_serial.rb +21 -19
- data/lib/pigpio/bit_bang_serial_rx.rb +70 -19
- data/lib/pigpio/bit_bang_serial_tx.rb +47 -41
- data/lib/pigpio/buffer.rb +13 -0
- data/lib/pigpio/constant.rb +745 -748
- data/lib/pigpio/gpio.rb +37 -30
- data/lib/pigpio/i2c.rb +77 -60
- data/lib/pigpio/pwm.rb +48 -38
- data/lib/pigpio/serial.rb +35 -29
- data/lib/pigpio/spi.rb +37 -33
- data/lib/pigpio/user_gpio.rb +33 -27
- data/lib/pigpio/version.rb +1 -1
- data/lib/pigpio/wave.rb +100 -78
- data/lib/pigpio.rb +29 -18
- data/pigpio.gemspec +16 -17
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ea48e2455183f291ab01d01923f98291d1fc3cbdac8237e0bfb47c6918f1b94d
|
4
|
+
data.tar.gz: 4734cdafc9f127194a972f6fbe366a5c7be1554837d6bd4829ea9ce5ecf56b0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86aba3d72fe106c69facc776e655fb6237cbeb2ccb63ee00de8a4e7f5678f14f1dbdd3727b3d48539f6c75e06d61083a2711854d642d6799edf03d82155e3717
|
7
|
+
data.tar.gz: 19750b1ea68bd3fabbe2036fcba8924aded9edcf2e46c0a2fd3bf654d4920006729cdd051ed5cd6886c5affeeea433454968c7b774a6bd4eaba4a437020f7f02
|
data/.standard_todo.yml
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Auto generated files with errors to ignore.
|
2
|
+
# Remove from this list as you refactor files.
|
3
|
+
---
|
4
|
+
ignore:
|
5
|
+
- example/e-paper_spi/epd2in13b.rb:
|
6
|
+
- Style/MixinUsage
|
7
|
+
- example/loopback/spi.rb:
|
8
|
+
- Style/MixinUsage
|
9
|
+
- Lint/UselessAssignment
|
10
|
+
- example/loopback/uart.rb:
|
11
|
+
- Style/MixinUsage
|
12
|
+
- Lint/UselessAssignment
|
13
|
+
- example/sharp_memory_display/ls013b7dn05.rb:
|
14
|
+
- Lint/UselessAssignment
|
15
|
+
- Style/SafeNavigation
|
16
|
+
- Style/MixinUsage
|
17
|
+
- example/simple/callback.rb:
|
18
|
+
- Style/MixinUsage
|
19
|
+
- example/simple/led.rb:
|
20
|
+
- Style/MixinUsage
|
21
|
+
- example/simple/pwm.rb:
|
22
|
+
- Style/MixinUsage
|
23
|
+
- Style/InfiniteLoop
|
24
|
+
- example/simple/wave.rb:
|
25
|
+
- Style/MixinUsage
|
26
|
+
- example/ssd1306_i2c/ssd1306.rb:
|
27
|
+
- Style/MixinUsage
|
28
|
+
- lib/pigpio.rb:
|
29
|
+
- Naming/VariableName
|
30
|
+
- lib/pigpio/bank.rb:
|
31
|
+
- Naming/ConstantName
|
32
|
+
- lib/pigpio/constant.rb:
|
33
|
+
- Naming/ConstantName
|
34
|
+
- lib/pigpio/gpio.rb:
|
35
|
+
- Lint/UselessAssignment
|
36
|
+
- Naming/VariableName
|
37
|
+
- lib/pigpio/i2c.rb:
|
38
|
+
- Naming/VariableName
|
39
|
+
- lib/pigpio/pwm.rb:
|
40
|
+
- Lint/UselessAssignment
|
41
|
+
- lib/pigpio/serial.rb:
|
42
|
+
- Naming/ConstantName
|
43
|
+
- Lint/UselessAssignment
|
44
|
+
- Naming/VariableName
|
45
|
+
- lib/pigpio/spi.rb:
|
46
|
+
- Naming/VariableName
|
47
|
+
- lib/pigpio/user_gpio.rb:
|
48
|
+
- Lint/UselessAssignment
|
49
|
+
- Naming/VariableName
|
50
|
+
- spec/ext/extconf.rb:
|
51
|
+
- Style/GlobalVars
|
data/README.md
CHANGED
@@ -63,7 +63,9 @@ $ ruby example_led.rb
|
|
63
63
|
|
64
64
|
More sample for this circuit. : [Hare](./example/simple/readme.md)
|
65
65
|
|
66
|
-
More
|
66
|
+
More sample for other circuit. : [Hare](./example/readme.md)
|
67
|
+
|
68
|
+
More document : [GitHub Pages](https://nak1114.github.io/ruby-extension-pigpio/Pigpio/IF.html)
|
67
69
|
|
68
70
|
## Development
|
69
71
|
|
data/Rakefile
CHANGED
@@ -9,10 +9,9 @@ end
|
|
9
9
|
|
10
10
|
RSpec::Core::RakeTask.new(:spec)
|
11
11
|
|
12
|
-
task :
|
12
|
+
task default: :spec
|
13
13
|
|
14
|
-
|
15
|
-
RDOC_FILES = FileList["ext/pigpio/pigpio.c","lib/**/*.rb"]
|
14
|
+
RDOC_FILES = FileList["ext/pigpio/pigpio.c", "lib/**/*.rb"]
|
16
15
|
|
17
16
|
Rake::RDocTask.new do |rd|
|
18
17
|
rd.main = "pigpio.c"
|
@@ -33,4 +32,4 @@ end
|
|
33
32
|
task :reset do
|
34
33
|
sh "git fetch origin"
|
35
34
|
sh "git reset --hard origin/master"
|
36
|
-
end
|
35
|
+
end
|
data/ext/pigpio/extconf.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
dir_config(
|
3
|
-
if find_header(
|
4
|
-
create_makefile(
|
5
|
-
end
|
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
|
data/ext/pigpio/pigpio.c
CHANGED
@@ -7,6 +7,7 @@
|
|
7
7
|
static VALUE cCallbackID;
|
8
8
|
static VALUE cNativeQueue;
|
9
9
|
static VALUE cCallbackError;
|
10
|
+
static VALUE cBuffer;
|
10
11
|
|
11
12
|
typedef struct{
|
12
13
|
uint32_t tick;
|
@@ -2359,18 +2360,16 @@ associated with handle and writes them to buf.
|
|
2359
2360
|
. .
|
2360
2361
|
pi: >=0 (as returned by [*pigpio_start*]).
|
2361
2362
|
handle: >=0, as returned by a call to [*serial_open*].
|
2362
|
-
buf: an array to receive the read data.
|
2363
2363
|
count: the maximum number of bytes to read.
|
2364
2364
|
. .
|
2365
2365
|
|
2366
|
-
Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE,
|
2366
|
+
Returns to buf.ret_code attribute the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE,
|
2367
2367
|
PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED.
|
2368
2368
|
|
2369
|
-
|
2369
|
+
The received data is get by the buf.to_s method.
|
2370
2370
|
|
2371
2371
|
:call-seq:
|
2372
|
-
serial_read(Integer pi,Integer handle, Integer count) ->
|
2373
|
-
serial_read(Integer pi,Integer handle, Integer count) -> String buf (When Success)
|
2372
|
+
serial_read(Integer pi,Integer handle, Integer count) -> Pigpio::Buffer buf
|
2374
2373
|
|
2375
2374
|
See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#serial_read]
|
2376
2375
|
*/
|
@@ -2378,7 +2377,9 @@ VALUE pigpio_rbfn_serial_read(VALUE self, VALUE pi, VALUE handle, VALUE count){
|
|
2378
2377
|
unsigned countc=NUM2UINT(count);
|
2379
2378
|
VALUE buf=rb_str_new("",countc);//#<Encoding:ASCII-8BIT>;
|
2380
2379
|
int ret=serial_read(NUM2INT(pi), NUM2UINT(handle), (void*)StringValuePtr(buf), countc);
|
2381
|
-
return (
|
2380
|
+
return rb_funcall((VALUE)cBuffer, rb_intern("new"), 2,INT2NUM(ret),rb_str_resize(buf,ret));
|
2381
|
+
|
2382
|
+
//return (ret < 0)?INT2NUM(ret):rb_str_resize(buf,ret);
|
2382
2383
|
//if(ret < 0){buf=Qnil;}
|
2383
2384
|
//return rb_ary_new_from_args(2,buf,INT2NUM(ret));
|
2384
2385
|
}
|
@@ -2436,13 +2437,14 @@ bit bang serial cyclic buffer to the buffer starting at buf.
|
|
2436
2437
|
. .
|
2437
2438
|
pi: >=0 (as returned by [*pigpio_start*]).
|
2438
2439
|
user_gpio: 0-31, previously opened with [*bb_serial_read_open*].
|
2439
|
-
buf: an array to receive the read bytes.
|
2440
2440
|
bufSize: >=0
|
2441
2441
|
. .
|
2442
2442
|
|
2443
|
-
Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO
|
2443
|
+
Returns to buf.ret_code attribute the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO
|
2444
2444
|
or PI_NOT_SERIAL_GPIO.
|
2445
2445
|
|
2446
|
+
The received data is get by the buf.to_s method.
|
2447
|
+
|
2446
2448
|
The bytes returned for each character depend upon the number of
|
2447
2449
|
data bits [*data_bits*] specified in the [*bb_serial_read_open*] command.
|
2448
2450
|
|
@@ -2451,8 +2453,7 @@ data bits [*data_bits*] specified in the [*bb_serial_read_open*] command.
|
|
2451
2453
|
* For [*data_bits*] 17-32 there will be four bytes per character.
|
2452
2454
|
|
2453
2455
|
:call-seq:
|
2454
|
-
bb_serial_read(Integer pi,Integer user_gpio, Integer bufSize) ->
|
2455
|
-
bb_serial_read(Integer pi,Integer user_gpio, Integer bufSize) -> String (When Success)
|
2456
|
+
bb_serial_read(Integer pi,Integer user_gpio, Integer bufSize) -> Pigpio::Buffer buf
|
2456
2457
|
|
2457
2458
|
See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#bb_serial_read]
|
2458
2459
|
*/
|
@@ -2460,7 +2461,8 @@ VALUE pigpio_rbfn_bb_serial_read(VALUE self, VALUE pi, VALUE user_gpio, VALUE bu
|
|
2460
2461
|
size_t countc=NUM2SIZET(bufSize);
|
2461
2462
|
VALUE buf=rb_str_new("",countc);//#<Encoding:ASCII-8BIT>;
|
2462
2463
|
int ret=bb_serial_read(NUM2INT(pi), NUM2UINT(user_gpio), (void*)StringValuePtr(buf), countc);
|
2463
|
-
return (
|
2464
|
+
return rb_funcall((VALUE)cBuffer, rb_intern("new"), 2,INT2NUM(ret),rb_str_resize(buf,ret));
|
2465
|
+
//return (ret < 0)?INT2NUM(ret):rb_str_resize(buf,ret);
|
2464
2466
|
//if(ret < 0){buf=Qnil;}
|
2465
2467
|
//return rb_ary_new_from_args(2,buf,INT2NUM(ret));
|
2466
2468
|
}
|
@@ -3702,9 +3704,6 @@ This class has some constances for pigpio library.
|
|
3702
3704
|
*/
|
3703
3705
|
void Init_pigpio(void){
|
3704
3706
|
VALUE cPulse,cBscXfer,cNativeQueue;
|
3705
|
-
/*
|
3706
|
-
This class has some constances for pigpio library.
|
3707
|
-
*/
|
3708
3707
|
VALUE cPigpio = rb_define_class("Pigpio", rb_cObject);
|
3709
3708
|
/*
|
3710
3709
|
This module is a ruby binding to pigpio library.
|
@@ -3830,13 +3829,15 @@ This class has some constances for pigpio library.
|
|
3830
3829
|
/*
|
3831
3830
|
This class wrap gpioPulse_t.
|
3832
3831
|
*/
|
3833
|
-
cPulse = rb_define_class_under(cPigpio,"Pulse",
|
3832
|
+
cPulse = rb_define_class_under(cPigpio,"Pulse", rb_cObject);
|
3833
|
+
rb_undef_alloc_func(cPulse);
|
3834
3834
|
rb_define_singleton_method(cPulse, "make", pigpio_rbst_gpioPulse_make, 3);
|
3835
3835
|
|
3836
3836
|
/*
|
3837
3837
|
This class wrap bsc_xfer_t.
|
3838
3838
|
*/
|
3839
|
-
cBscXfer = rb_define_class_under(cPigpio,"BscXfer",
|
3839
|
+
cBscXfer = rb_define_class_under(cPigpio,"BscXfer", rb_cObject);
|
3840
|
+
rb_undef_alloc_func(cBscXfer);
|
3840
3841
|
rb_define_singleton_method(cBscXfer, "make", pigpio_rbst_bsc_xfer_make, 0);
|
3841
3842
|
rb_define_method(cBscXfer, "control=", pigpio_rbst_bsc_xfer_w_control, 1);
|
3842
3843
|
rb_define_method(cBscXfer, "control", pigpio_rbst_bsc_xfer_r_control, 0);
|
@@ -3848,13 +3849,15 @@ This class has some constances for pigpio library.
|
|
3848
3849
|
/*
|
3849
3850
|
The class of native queue.
|
3850
3851
|
*/
|
3851
|
-
cNativeQueue = rb_define_class_under(cAPI,"NativeQueue",
|
3852
|
+
cNativeQueue = rb_define_class_under(cAPI,"NativeQueue", rb_cObject);
|
3853
|
+
rb_undef_alloc_func(cNativeQueue);
|
3852
3854
|
rb_gc_register_address(&cNativeQueue);
|
3853
3855
|
|
3854
3856
|
/*
|
3855
3857
|
The class of callback.
|
3856
3858
|
*/
|
3857
|
-
cCallbackID = rb_define_class_under(cPigpio,"Callback",
|
3859
|
+
cCallbackID = rb_define_class_under(cPigpio,"Callback", rb_cObject);
|
3860
|
+
rb_undef_alloc_func(cCallbackID);
|
3858
3861
|
rb_define_method(cCallbackID, "id", pigpio_rbst_callback_id_r_id, 0);
|
3859
3862
|
rb_define_method(cCallbackID, "cancel", pigpio_rbst_callback_id_cancel, 0);
|
3860
3863
|
rb_gc_register_address(&cCallbackID);
|
@@ -3863,5 +3866,13 @@ This class has some constances for pigpio library.
|
|
3863
3866
|
The class of callback error.
|
3864
3867
|
*/
|
3865
3868
|
cCallbackError = rb_define_class_under(cPigpio,"CallbackError", rb_eException);
|
3869
|
+
rb_undef_alloc_func(cCallbackError);
|
3866
3870
|
rb_gc_register_address(&cCallbackError);
|
3871
|
+
|
3872
|
+
/*
|
3873
|
+
The class of Rx buffer.
|
3874
|
+
*/
|
3875
|
+
cBuffer = rb_define_class_under(cPigpio,"Buffer", rb_cString);
|
3876
|
+
rb_undef_alloc_func(cBuffer);
|
3877
|
+
rb_gc_register_address(&cBuffer);
|
3867
3878
|
}
|
data/lib/pigpio/bank.rb
CHANGED
@@ -1,22 +1,25 @@
|
|
1
|
-
class Pigpio
|
2
|
-
class Bank
|
3
|
-
Set={
|
4
|
-
read:
|
5
|
-
clear: [:clear_bank_1
|
6
|
-
set:
|
7
|
-
}
|
8
|
-
def initialize(pi,num)
|
9
|
-
@pi=pi
|
10
|
-
@num=num
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
1
|
+
class Pigpio
|
2
|
+
class Bank
|
3
|
+
Set = {
|
4
|
+
read: [:read_bank_1, :read_bank_2],
|
5
|
+
clear: [:clear_bank_1, :clear_bank_2],
|
6
|
+
set: [:set_bank_1, :set_bank_2]
|
7
|
+
}
|
8
|
+
def initialize(pi, num)
|
9
|
+
@pi = pi
|
10
|
+
@num = num
|
11
|
+
end
|
12
|
+
|
13
|
+
def read
|
14
|
+
IF.send(Set[:read][@num], @pi)
|
15
|
+
end
|
16
|
+
|
17
|
+
def clear(bits)
|
18
|
+
IF.send(Set[:clear][@num], @pi, bits)
|
19
|
+
end
|
20
|
+
|
21
|
+
def set(bits)
|
22
|
+
IF.send(Set[:set][@num], @pi, bits)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,19 +1,21 @@
|
|
1
|
-
require_relative "./bit_bang_serial_rx"
|
2
|
-
require_relative "./bit_bang_serial_tx"
|
3
|
-
|
4
|
-
class Pigpio
|
5
|
-
class BitBangSerial < BitBangSerialTx
|
6
|
-
attr_reader :rx
|
7
|
-
def initialize(rx,tx,baud=9600,data_bits=8,stop_bits=1,parity_type
|
8
|
-
super(tx,baud,data_bits,stop_bits)
|
9
|
-
@rx=BitBangSerialRx.new(rx,baud,data_bits)
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
1
|
+
require_relative "./bit_bang_serial_rx"
|
2
|
+
require_relative "./bit_bang_serial_tx"
|
3
|
+
|
4
|
+
class Pigpio
|
5
|
+
class BitBangSerial < BitBangSerialTx
|
6
|
+
attr_reader :rx
|
7
|
+
def initialize(rx, tx, baud = 9600, data_bits = 8, stop_bits = 1, parity_type = :none)
|
8
|
+
super(tx, baud, data_bits, stop_bits)
|
9
|
+
@rx = BitBangSerialRx.new(rx, baud, data_bits)
|
10
|
+
end
|
11
|
+
|
12
|
+
def close
|
13
|
+
super
|
14
|
+
@rx.close
|
15
|
+
end
|
16
|
+
|
17
|
+
def read(bufsize = 1)
|
18
|
+
@rx.read(bufsize)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,19 +1,70 @@
|
|
1
|
-
class Pigpio
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
1
|
+
class Pigpio
|
2
|
+
# Set a UserGPIO pin as a serial Rx.
|
3
|
+
class BitBangSerialRx
|
4
|
+
# UserGPIO#.
|
5
|
+
#
|
6
|
+
# This attribute is set at the time of ::new.
|
7
|
+
attr_reader :rx
|
8
|
+
|
9
|
+
# Set 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_GPIO_IN_USE, PI_NOT_SERIAL_GPIO or PI_BAD_SER_INVERT.
|
10
|
+
#
|
11
|
+
# This attribute is set at the time of ::new.
|
12
|
+
attr_reader :valid
|
13
|
+
|
14
|
+
# Set a UserGPIO pin as a serial Rx.
|
15
|
+
#
|
16
|
+
# The serial data recieves in a internal cyclic buffer and is read using #read method.
|
17
|
+
# It is the caller's responsibility to read data from the cyclic buffer in a timely fashion.
|
18
|
+
#
|
19
|
+
# [Parameter]
|
20
|
+
# [rx [ Pigpio::UserGPIO ]] Set This pgio as a serial Rx.
|
21
|
+
# [baud [ Integer ]] 50-250000 [bps]. default 9600.
|
22
|
+
# [data_bits [ Integer ]] 1-32 [bit/word]. default 8.
|
23
|
+
#
|
24
|
+
# See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#bb_serial_read_open]
|
25
|
+
def initialize(rx, baud = 9600, data_bits = 8)
|
26
|
+
@rx = rx
|
27
|
+
@valid = IF.bb_serial_read_open(@rx.pi, @rx.gpio, baud, data_bits)
|
28
|
+
if @valid == 0
|
29
|
+
@valid = IF.bb_serial_invert(@rx.pi, @rx.gpio, 0)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# This method closes a GPIO for bit bang reading of serial data.
|
34
|
+
#
|
35
|
+
# [Return] [Integer] Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO.
|
36
|
+
#
|
37
|
+
# See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#bb_serial_read_close]
|
38
|
+
def close
|
39
|
+
IF.bb_serial_read_close(@rx.pi, @rx.gpio)
|
40
|
+
end
|
41
|
+
|
42
|
+
# This method copies up to bufSize bytes of data read from the bit bang serial cyclic buffer to the buffer starting at returned value.
|
43
|
+
#
|
44
|
+
# [Parameter] [bufSize [ Integer ]] How many bytes receive.
|
45
|
+
# [Return] [ Pigpio::Buffer ] A copied buffer and status.
|
46
|
+
#
|
47
|
+
# The details of the returned status is the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERIAL_GPIO.
|
48
|
+
#
|
49
|
+
# The bytes returned for each character depend upon the number of data bits +data_bits+ specified in the ::new method.
|
50
|
+
#
|
51
|
+
# * For +data_bits+ 1-8 there will be one byte per character.
|
52
|
+
# * For +data_bits+ 9-16 there will be two bytes per character.
|
53
|
+
# * For +data_bits+ 17-32 there will be four bytes per character.
|
54
|
+
#
|
55
|
+
# See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#bb_serial_read]
|
56
|
+
def read(bufsize = 1)
|
57
|
+
IF.bb_serial_read(@rx.pi, @rx.gpio, bufsize)
|
58
|
+
end
|
59
|
+
|
60
|
+
# This method inverts serial logic for big bang serial reads.
|
61
|
+
#
|
62
|
+
# [Parameter] [Integer] invert 0-1.1 invert, 0 normal.
|
63
|
+
# [Return] [Integer] Returns 0 if OK, otherwise PI_NOT_SERIAL_GPIO or PI_BAD_SER_INVERT.
|
64
|
+
#
|
65
|
+
# See also: {pigpio site}[http://abyz.me.uk/rpi/pigpio/pdif2.html#bb_serial_invert]
|
66
|
+
def invert(invert = 1)
|
67
|
+
IF.bb_serial_invert(@rx.pi, @rx.gpio, invert)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -1,41 +1,47 @@
|
|
1
|
-
class Pigpio
|
2
|
-
class BitBangSerialTx
|
3
|
-
attr_reader :tx
|
4
|
-
def initialize(tx,baud=9600,data_bits=8,stop_bits=1)
|
5
|
-
@tx=tx
|
6
|
-
@baud=baud
|
7
|
-
@data_bits=data_bits
|
8
|
-
@stop_half_bits=(stop_bits*2).round.to_i
|
9
|
-
end
|
10
|
-
|
11
|
-
|
12
|
-
IF.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
return
|
21
|
-
IF.
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
1
|
+
class Pigpio
|
2
|
+
class BitBangSerialTx
|
3
|
+
attr_reader :tx
|
4
|
+
def initialize(tx, baud = 9600, data_bits = 8, stop_bits = 1)
|
5
|
+
@tx = tx
|
6
|
+
@baud = baud
|
7
|
+
@data_bits = data_bits
|
8
|
+
@stop_half_bits = (stop_bits * 2).round.to_i
|
9
|
+
end
|
10
|
+
|
11
|
+
def close
|
12
|
+
IF.wave_tx_stop(@tx.pi) if busy?
|
13
|
+
IF.wave_clear(@tx.pi)
|
14
|
+
end
|
15
|
+
|
16
|
+
def write(buf)
|
17
|
+
IF.wave_clear(@tx.pi)
|
18
|
+
IF.wave_add_new(@tx.pi)
|
19
|
+
ret = IF.wave_add_serial(@tx.pi, @tx.gpio, @baud, @data_bits, @stop_half_bits, 0, buf)
|
20
|
+
return ret if ret < 0
|
21
|
+
wid = IF.wave_create(@tx.pi)
|
22
|
+
return wid if wid < 0
|
23
|
+
IF.wave_send_once(@tx.pi, wid)
|
24
|
+
end
|
25
|
+
|
26
|
+
def sync
|
27
|
+
while busy?
|
28
|
+
sleep 0.1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def write_sync(buf)
|
33
|
+
ret = write(buf)
|
34
|
+
return ret if ret < 0
|
35
|
+
sync
|
36
|
+
IF.wave_clear(@tx.pi)
|
37
|
+
end
|
38
|
+
|
39
|
+
def busy?
|
40
|
+
IF.wave_tx_busy(@tx.pi)
|
41
|
+
end
|
42
|
+
|
43
|
+
def stop
|
44
|
+
IF.wave_tx_stop(@tx.pi)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|