ffi-wiring_pi 0.1.6 → 0.2.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.
- checksums.yaml +4 -4
- data/ChangeLog.md +2 -0
- data/Gemfile.lock +2 -1
- data/README.md +14 -1
- data/gemspec.yml +2 -1
- data/lib/ffi/wiring_pi/gpio.rb +43 -0
- data/spec/ffi/wiring_pi/gpio_spec.rb +18 -0
- data/spec/spec_helper.rb +1 -4
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96d67497059bd425b34843259199031c0945ffa4ea239af8c7a5a4dd61ab23e6
|
4
|
+
data.tar.gz: e85e81abfca1d648175cde24b841f9a1be6e25df7ff6b99ef5a575ab6db3dd4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d0381b71c738cf6342da8bcde90403d9dc7c2a3485dbfd7ee284e706b9f94c79e55cc723e220ed955934c6269085e058d238a0614dd271b42664963b4f1895a
|
7
|
+
data.tar.gz: 693a22b26b22d46b4c4229e95c6f2b3981a47436eb01b5007e4d495292e661ad89dc6774c7d727ea83d679658ebebf749841d926ed36f269fef532f14b0d7adc
|
data/ChangeLog.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# ffi-wiring-pi
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/ffi-wiring_pi)[](https://travis-ci.org/vimutter/ffi-wiring_pi)
|
4
|
+
|
3
5
|
* [Source](https://github.com/vimutter/ffi-wiring_pi/)
|
4
6
|
* [Issues](https://github.com/vimutter/ffi-wiring_pi/issues)
|
5
7
|
|
@@ -27,6 +29,17 @@ Setup GPIO:
|
|
27
29
|
pin = FFI::WiringPi::GPIO.get(0)
|
28
30
|
pin.up!
|
29
31
|
|
32
|
+
# Or
|
33
|
+
|
34
|
+
extend FFI::WiringPi::GPIO
|
35
|
+
|
36
|
+
setup
|
37
|
+
pin = get 0
|
38
|
+
pin.up!
|
39
|
+
|
40
|
+
pin2 = get 1, INPUT
|
41
|
+
p pin2.value
|
42
|
+
|
30
43
|
## Requirements
|
31
44
|
|
32
45
|
* [Ruby](http://ruby-lang.org/) >= 2.6.1 or
|
@@ -41,4 +54,4 @@ Setup GPIO:
|
|
41
54
|
|
42
55
|
Copyright (c) 2019 Mark Huk
|
43
56
|
|
44
|
-
See
|
57
|
+
See [Licence](LICENSE.txt) for license information.
|
data/gemspec.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
name: ffi-wiring_pi
|
2
|
-
version: 0.
|
2
|
+
version: 0.2.0
|
3
3
|
summary: FFI bindings for wiringPi
|
4
4
|
description: Ruby FFI bindings for the wiringPi library.
|
5
5
|
license: MIT
|
@@ -16,3 +16,4 @@ dependencies:
|
|
16
16
|
development_dependencies:
|
17
17
|
rspec: ~> 3.8
|
18
18
|
yard: ~> 0.9.1
|
19
|
+
bundler: ~> 2.0
|
data/lib/ffi/wiring_pi/gpio.rb
CHANGED
@@ -105,6 +105,44 @@ module FFI::WiringPi::GPIO
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
+
# @param pin [Integer] pin position (depends on setup mode)
|
109
|
+
# @param value [Integer] 0-1023
|
110
|
+
attach_function :pwm_write, :pwmWrite, [:int, :int], :void
|
111
|
+
|
112
|
+
# This writes the 8-bit byte supplied to the first 8 GPIO pins.
|
113
|
+
# It’s the fastest way to set all 8 bits at once to a particular value,
|
114
|
+
# although it still takes two write operations to the Pi’s GPIO hardware.
|
115
|
+
# @param pin [Integer] pin position (depends on setup mode)
|
116
|
+
# @param value [Integer] 0-1023
|
117
|
+
attach_function :digital_write_byte, :digitalWriteByte, [:int], :void
|
118
|
+
|
119
|
+
def self.batch_write(boolean_array)
|
120
|
+
digital_write_byte boolean_array.each_with_index.sum { |bit, i| (bit ? 1 : 0 ) << i }
|
121
|
+
end
|
122
|
+
|
123
|
+
# The PWM generator can run in 2 modes – :balanced and :mark_space
|
124
|
+
# The :mark_space mode is traditional, however the default mode in the Pi is :balanced.
|
125
|
+
# @param value [Integer] PWM_MODE_BAL or PWM_MODE_MS
|
126
|
+
attach_function :pwm_set_mode, :pwmSetMode, [:int], :void
|
127
|
+
|
128
|
+
def self.pwm_mode(mode = :balanced)
|
129
|
+
raise ArgumentError("mode is invalid: #{mode.inspect}") unless mode.in?([:balanced, :mark_space])
|
130
|
+
pwm_set_mode mode == :balanced ? PWM_MODE_BAL : PWM_MODE_MS
|
131
|
+
end
|
132
|
+
|
133
|
+
# This sets the range register in the PWM generator. The default is 1024.
|
134
|
+
# @param value [Integer]
|
135
|
+
attach_function :pwm_set_range, :pwmSetRange, [:uint], :void
|
136
|
+
|
137
|
+
def self.pwm_range(range = 1024)
|
138
|
+
raise ArgumentError("range is invalid: #{range.inspect}") unless range.is_a?(Integer) && range >= 0
|
139
|
+
pwm_set_range range
|
140
|
+
end
|
141
|
+
|
142
|
+
# This sets the divisor for the PWM clock.
|
143
|
+
# @param value [Integer]
|
144
|
+
attach_function :pwm_set_clock, :pwmSetClock, [:int], :void
|
145
|
+
|
108
146
|
class Pin
|
109
147
|
def initialize(position, mode)
|
110
148
|
@position = position
|
@@ -120,5 +158,10 @@ module FFI::WiringPi::GPIO
|
|
120
158
|
raise ArgumentError('Can only set in OUTPUT mode') && return unless @mode == FFI::WiringPi::GPIO::OUTPUT
|
121
159
|
FFI::WiringPi::GPIO.down(@position)
|
122
160
|
end
|
161
|
+
|
162
|
+
def value
|
163
|
+
raise ArgumentError('Can only set in INPUT mode') && return unless @mode == FFI::WiringPi::GPIO::INPUT
|
164
|
+
FFI::WiringPi::GPIO.read(@position)
|
165
|
+
end
|
123
166
|
end
|
124
167
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe FFI::WiringPi::GPIO do
|
4
|
+
|
5
|
+
describe '.batch_write' do
|
6
|
+
shared_examples_for 'byte converter' do |byte, array|
|
7
|
+
it 'converts boolean array to byte' do
|
8
|
+
expect(described_class).to receive(:digital_write_byte).with(byte)
|
9
|
+
described_class.batch_write array
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it_behaves_like 'byte converter', 1, [true, false, false, false, false, false, false, false]
|
14
|
+
it_behaves_like 'byte converter', 2, [false, true, false, false, false, false, false, false]
|
15
|
+
it_behaves_like 'byte converter', 3, [true, true, false, false, false, false, false, false]
|
16
|
+
it_behaves_like 'byte converter', 17, [true, false, false, false, true, false, false, false]
|
17
|
+
end
|
18
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi-wiring_pi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Huk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.9.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
55
69
|
description: Ruby FFI bindings for the wiringPi library.
|
56
70
|
email: mark.guk.e@gmail.com
|
57
71
|
executables: []
|
@@ -75,6 +89,7 @@ files:
|
|
75
89
|
- gemspec.yml
|
76
90
|
- lib/ffi/wiring_pi.rb
|
77
91
|
- lib/ffi/wiring_pi/gpio.rb
|
92
|
+
- spec/ffi/wiring_pi/gpio_spec.rb
|
78
93
|
- spec/spec_helper.rb
|
79
94
|
homepage: https://github.com/vimutter/ffi-wiring_pi
|
80
95
|
licenses:
|
@@ -100,4 +115,5 @@ rubygems_version: 3.0.1
|
|
100
115
|
signing_key:
|
101
116
|
specification_version: 4
|
102
117
|
summary: FFI bindings for wiringPi
|
103
|
-
test_files:
|
118
|
+
test_files:
|
119
|
+
- spec/ffi/wiring_pi/gpio_spec.rb
|