pigpio 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 030a9cfb8449fc59b223cd96371aa249dbc86876
4
- data.tar.gz: 8e6aabca541f968cacfa06a08f79739bbc1807a2
2
+ SHA256:
3
+ metadata.gz: ea48e2455183f291ab01d01923f98291d1fc3cbdac8237e0bfb47c6918f1b94d
4
+ data.tar.gz: 4734cdafc9f127194a972f6fbe366a5c7be1554837d6bd4829ea9ce5ecf56b0f
5
5
  SHA512:
6
- metadata.gz: e79ff833f0475fc2e817f56250def1d4a8d474fce3015ba9a77cb8412f707968e9720825aa686d54dfd2a7db004a0ad1d1fa74c7d55e6ca1a883bd7b1663dd19
7
- data.tar.gz: e07c2ce1196b00ea32be4fcfc5fe420f10b5a18b3c13b4ed92044c12ae2401904f581d1efebc0b5f670c75454a2a1d7f96d759d94404e24001ad2014a6ac6e9e
6
+ metadata.gz: 86aba3d72fe106c69facc776e655fb6237cbeb2ccb63ee00de8a4e7f5678f14f1dbdd3727b3d48539f6c75e06d61083a2711854d642d6799edf03d82155e3717
7
+ data.tar.gz: 19750b1ea68bd3fabbe2036fcba8924aded9edcf2e46c0a2fd3bf654d4920006729cdd051ed5cd6886c5affeeea433454968c7b774a6bd4eaba4a437020f7f02
@@ -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
@@ -65,7 +65,7 @@ More sample for this circuit. : [Hare](./example/simple/readme.md)
65
65
 
66
66
  More sample for other circuit. : [Hare](./example/readme.md)
67
67
 
68
- More document : [GitHub Pages](https://nak1114.github.io/ruby-extension-pigpio/)
68
+ More document : [GitHub Pages](https://nak1114.github.io/ruby-extension-pigpio/Pigpio/IF.html)
69
69
 
70
70
  ## Development
71
71
 
data/Rakefile CHANGED
@@ -9,10 +9,9 @@ end
9
9
 
10
10
  RSpec::Core::RakeTask.new(:spec)
11
11
 
12
- task :default => :spec
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
@@ -1,5 +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
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
@@ -3829,13 +3829,15 @@ void Init_pigpio(void){
3829
3829
  /*
3830
3830
  This class wrap gpioPulse_t.
3831
3831
  */
3832
- cPulse = rb_define_class_under(cPigpio,"Pulse", rb_cData);
3832
+ cPulse = rb_define_class_under(cPigpio,"Pulse", rb_cObject);
3833
+ rb_undef_alloc_func(cPulse);
3833
3834
  rb_define_singleton_method(cPulse, "make", pigpio_rbst_gpioPulse_make, 3);
3834
3835
 
3835
3836
  /*
3836
3837
  This class wrap bsc_xfer_t.
3837
3838
  */
3838
- cBscXfer = rb_define_class_under(cPigpio,"BscXfer", rb_cData);
3839
+ cBscXfer = rb_define_class_under(cPigpio,"BscXfer", rb_cObject);
3840
+ rb_undef_alloc_func(cBscXfer);
3839
3841
  rb_define_singleton_method(cBscXfer, "make", pigpio_rbst_bsc_xfer_make, 0);
3840
3842
  rb_define_method(cBscXfer, "control=", pigpio_rbst_bsc_xfer_w_control, 1);
3841
3843
  rb_define_method(cBscXfer, "control", pigpio_rbst_bsc_xfer_r_control, 0);
@@ -3847,13 +3849,15 @@ void Init_pigpio(void){
3847
3849
  /*
3848
3850
  The class of native queue.
3849
3851
  */
3850
- cNativeQueue = rb_define_class_under(cAPI,"NativeQueue", rb_cData);
3852
+ cNativeQueue = rb_define_class_under(cAPI,"NativeQueue", rb_cObject);
3853
+ rb_undef_alloc_func(cNativeQueue);
3851
3854
  rb_gc_register_address(&cNativeQueue);
3852
3855
 
3853
3856
  /*
3854
3857
  The class of callback.
3855
3858
  */
3856
- cCallbackID = rb_define_class_under(cPigpio,"Callback", rb_cData);
3859
+ cCallbackID = rb_define_class_under(cPigpio,"Callback", rb_cObject);
3860
+ rb_undef_alloc_func(cCallbackID);
3857
3861
  rb_define_method(cCallbackID, "id", pigpio_rbst_callback_id_r_id, 0);
3858
3862
  rb_define_method(cCallbackID, "cancel", pigpio_rbst_callback_id_cancel, 0);
3859
3863
  rb_gc_register_address(&cCallbackID);
@@ -3862,11 +3866,13 @@ void Init_pigpio(void){
3862
3866
  The class of callback error.
3863
3867
  */
3864
3868
  cCallbackError = rb_define_class_under(cPigpio,"CallbackError", rb_eException);
3869
+ rb_undef_alloc_func(cCallbackError);
3865
3870
  rb_gc_register_address(&cCallbackError);
3866
3871
 
3867
3872
  /*
3868
3873
  The class of Rx buffer.
3869
3874
  */
3870
3875
  cBuffer = rb_define_class_under(cPigpio,"Buffer", rb_cString);
3876
+ rb_undef_alloc_func(cBuffer);
3871
3877
  rb_gc_register_address(&cBuffer);
3872
3878
  }
data/lib/pigpio/bank.rb CHANGED
@@ -1,22 +1,25 @@
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
- def read
13
- IF.send(Set[:read][@num],@pi)
14
- end
15
- def clear(bits)
16
- IF.send(Set[:clear][@num],@pi,bits)
17
- end
18
- def set(bits)
19
- IF.send(Set[:set][@num],@pi,bits)
20
- end
21
- end
22
- end
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=:none)
8
- super(tx,baud,data_bits,stop_bits)
9
- @rx=BitBangSerialRx.new(rx,baud,data_bits)
10
- end
11
- def close
12
- super
13
- @rx.close
14
- end
15
- def read(bufsize=1)
16
- @rx.read(bufsize)
17
- end
18
- end
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
- class BitBangSerialRx
3
- attr_reader :rx
4
- def initialize(rx,baud=9600,data_bits=8)
5
- @rx=rx
6
- IF.bb_serial_read_open(@rx.pi,@rx.gpio,baud,data_bits)
7
- IF.bb_serial_invert(@rx.pi,@rx.gpio,0)
8
- end
9
- def close
10
- IF.bb_serial_read_close(@rx.pi,@rx.gpio)
11
- end
12
- def read(bufsize=1)
13
- IF.bb_serial_read(@rx.pi,@rx.gpio,bufsize)
14
- end
15
- def invert(invert=1)
16
- IF.bb_serial_invert(@rx.pi,@rx.gpio,invert)
17
- end
18
- end
19
- end
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
- def close
11
- IF.wave_tx_stop(@tx.pi) if busy?
12
- IF.wave_clear(@tx.pi)
13
- end
14
- def write(buf)
15
- IF.wave_clear(@tx.pi)
16
- IF.wave_add_new(@tx.pi)
17
- ret=IF.wave_add_serial(@tx.pi,@tx.gpio,@baud,@data_bits,@stop_half_bits,0,buf)
18
- return ret if ret < 0
19
- wid=IF.wave_create(@tx.pi)
20
- return wid if wid < 0
21
- IF.wave_send_once(@tx.pi,wid)
22
- end
23
- def sync
24
- while busy?
25
- sleep 0.1
26
- end
27
- end
28
- def write_sync(buf)
29
- ret=write(buf)
30
- return ret if ret < 0
31
- sync
32
- IF.wave_clear(@tx.pi)
33
- end
34
- def busy?
35
- IF.wave_tx_busy(@tx.pi)
36
- end
37
- def stop
38
- IF.wave_tx_stop(@tx.pi)
39
- end
40
- end
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
data/lib/pigpio/buffer.rb CHANGED
@@ -1,12 +1,13 @@
1
- class Pigpio
2
- class Buffer < String
3
- attr_reader :ret_code
4
- def initialize(ret_code,str=nil)
5
- super(str)
6
- @ret_code=ret_code
7
- end
8
- def valid?
9
- @ret_code>=0
10
- end
11
- end
12
- end
1
+ class Pigpio
2
+ class Buffer < String
3
+ attr_reader :ret_code
4
+ def initialize(ret_code, str = nil)
5
+ super(str)
6
+ @ret_code = ret_code
7
+ end
8
+
9
+ def valid?
10
+ @ret_code >= 0
11
+ end
12
+ end
13
+ end