wiringpi-ruby 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/wiringpi/spi.rb CHANGED
@@ -1,15 +1,18 @@
1
1
  module WiringPi
2
2
  class SPI
3
- @channel = 0
4
- def initialize(channel,speed)
5
- @channel = channel
6
- Wiringpi.wiringPiSPISetup(channel,speed)
7
- end
8
- def wiringPiSPIGetFd()
9
- return Wiringpi.wiringPiSPIGetFd(@channel)
10
- end
11
- def wiringPiSPIDataRW(data)
12
- return Wiringpi.wiringPiSPIDataRW(@channel,data)
13
- end
3
+ attr_reader :channel
4
+
5
+ def initialize(channel, speed)
6
+ @channel = channel
7
+ Wiringpi.wiringPiSPISetup(channel, speed)
8
+ end
9
+
10
+ def wiringPiSPIGetFd
11
+ Wiringpi.wiringPiSPIGetFd(@channel)
12
+ end
13
+
14
+ def wiringPiSPIDataRW(data)
15
+ Wiringpi.wiringPiSPIDataRW(@channel, data)
16
+ end
14
17
  end
15
18
  end
@@ -0,0 +1,24 @@
1
+ module WiringPi
2
+ class GPIO
3
+ def watch(pin, *states, &block)
4
+ raise 'block is required' unless block_given?
5
+
6
+ unless states.include?(WiringPi::FALLING) || states.include?(WiringPi::RISING)
7
+ raise 'states must WiringPi::FALLING or WiringPi::RISING or both'
8
+ end
9
+
10
+ Thread.new do
11
+ last_value = digital_read(pin)
12
+ loop do
13
+ new_value = digital_read(pin)
14
+ if new_value != last_value
15
+ state = WiringPi::FALLING if new_value == 0
16
+ state = WiringPi::RISING if new_value == 1
17
+ block.call new_value if states.include?(state)
18
+ last_value = new_value
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wiringpi-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rifqi
@@ -177,17 +177,19 @@ files:
177
177
  - ext/wiringpi/extconf.rb
178
178
  - ext/wiringpi/wiringpi_wrap.c
179
179
  - lib/wiringpi.rb
180
- - lib/wiringpi/event.rb
181
180
  - lib/wiringpi/gpio.rb
182
181
  - lib/wiringpi/i2c.rb
183
- - lib/wiringpi/mcp23x17.rb
182
+ - lib/wiringpi/modules/mcp23017.rb
183
+ - lib/wiringpi/modules/mcp23s17.rb
184
184
  - lib/wiringpi/scrollphat.rb
185
185
  - lib/wiringpi/serial.rb
186
186
  - lib/wiringpi/spi.rb
187
+ - lib/wiringpi/watch.rb
187
188
  homepage: http://rubygems.org/gems/wiringpi-ruby
188
189
  licenses:
189
190
  - GNU Lesser General Public License v3
190
- metadata: {}
191
+ metadata:
192
+ source_code_uri: https://gitlab.com/ikirifqi/WiringPi-Ruby
191
193
  post_install_message:
192
194
  rdoc_options: []
193
195
  require_paths:
@@ -1,21 +0,0 @@
1
- module WiringPi
2
- class GPIO
3
- def interrupt(pin, edge, &block)
4
- Thread.new do
5
- @value = digital_read(pin)
6
- @last_value = value
7
- loop do
8
- @last_value = @value
9
- @value = digital_read(pin)
10
-
11
- if @value != @last_value
12
- next if @value == 0 and edge == :falling_edge
13
- next if @value == 1 and edge == :rising_edge
14
- break
15
- end
16
- block.call @value
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,31 +0,0 @@
1
- module WiringPi
2
- class Modules
3
- class Mcp23017 < ModuleBase
4
-
5
- @i2c_address = 0x0
6
-
7
- def initialize(pin_base, i2c_address)
8
- @pin_base = pin_base
9
- @pin_count = 16
10
- @i2c_address = i2c_address
11
- Wiringpi.mcp23017Setup( pin_base, i2c_address )
12
- super()
13
- end
14
- end
15
- class Mcp23s17 < ModuleBase
16
-
17
- @spi_port = 0
18
- @device_id = 0
19
-
20
- def initialize(pin_base, spi_port, device_id)
21
- @pin_base = pin_base
22
- @pin_count = 16
23
- @spi_port = spi_port
24
- @device_id = device_id
25
- Wiringpi.mcp23s17Setup( pin_base, spi_port, device_id )
26
- super()
27
- end
28
-
29
- end
30
- end
31
- end