ffi-wiring_pi 0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2b093eca499d179c3e519ff1538646aa14f9c5857ad81594407cbf9571a15669
4
+ data.tar.gz: 19775a22037d0c3af959a33d0550ea4cf38c5f3e566a23b901e179a79373e40e
5
+ SHA512:
6
+ metadata.gz: 1768ba1ccd52dedf96527da90a2613249f18b0918aef34cd6bf1a7546ee17cf02c32e9d41687ab45b0f34700c42de328fb211a3b9c94490dd361a63fddf0d665
7
+ data.tar.gz: 05eb09d62cac5c272e0bc6cff217006891e6075c2d2db16af7d8064956c5d278261256099ddef9bcf6b13fc3d856a4e5977ade4c3ad6b601f43f075f98c41cde
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/.rake_tasks~ ADDED
File without changes
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ before_install:
3
+ - git clone git://git.drogon.net/wiringPi
4
+ - cd wiringPi
5
+ - ./build
6
+ - gem install ffi
7
+ rvm:
8
+ - 2.6.1
9
+ script: rake test
data/ChangeLog.md ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ffi-wiring_pi (0.1.0)
5
+ ffi (~> 1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ ffi (1.10.0)
12
+ rspec (3.8.0)
13
+ rspec-core (~> 3.8.0)
14
+ rspec-expectations (~> 3.8.0)
15
+ rspec-mocks (~> 3.8.0)
16
+ rspec-core (3.8.0)
17
+ rspec-support (~> 3.8.0)
18
+ rspec-expectations (3.8.2)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.8.0)
21
+ rspec-mocks (3.8.0)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-support (3.8.0)
25
+ yard (0.9.18)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ ffi-wiring_pi!
32
+ rspec (~> 3.8)
33
+ yard (~> 0.9.1)
34
+
35
+ BUNDLED WITH
36
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2019 Mark Huk
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ 'Software'), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # ffi-wiring-pi
2
+
3
+ * [Source](https://github.com/vimutter/ffi-wiring_pi/)
4
+ * [Issues](https://github.com/vimutter/ffi-wiring_pi/issues)
5
+
6
+ ## Description
7
+
8
+ Ruby FFI bindings for the [wiringPi](http://wiringpi.com) library.
9
+
10
+ ## Features
11
+
12
+ * Can setup and work with GPIO
13
+
14
+ ## Examples
15
+
16
+ Setup GPIO:
17
+
18
+ require 'ffi/wiring_pi'
19
+
20
+ # Will setup with wiringPi pin numbering scheme
21
+ FFI::WiringPi::GPIO.setup
22
+ FFI::WiringPi::GPIO.set_pin_mode(0, FFI::WiringPi::GPIO::OUTPUT)
23
+ FFI::WiringPi::GPIO.write(0, true)
24
+ # Or
25
+ FFI::WiringPi::GPIO.up(0)
26
+ # Or
27
+ pin = FFI::WiringPi::GPIO.get(0)
28
+ pin.up!
29
+
30
+ ## Requirements
31
+
32
+ * [Ruby](http://ruby-lang.org/) >= 2.6.1 or
33
+ * [wiringPi](http://wiringpi.com/download-and-install/) >= 2.46
34
+ * [ffi](http://github.com/ffi/ffi) ~> 1.0
35
+
36
+ ## Install
37
+
38
+ $ gem install ffi-wiring_pi
39
+
40
+ ## License
41
+
42
+ Copyright (c) 2019 Mark Huk
43
+
44
+ See {file:LICENSE.txt} for license information.
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ gem 'rspec'
6
+ require 'rspec/core/rake_task'
7
+
8
+ RSpec::Core::RakeTask.new
9
+ rescue LoadError => e
10
+ task :spec do
11
+ abort "Please run `gem install rspec` to install RSpec."
12
+ end
13
+ end
14
+ task :test => :spec
15
+ task :default => :spec
16
+
17
+ begin
18
+ gem 'yard', '~> 0.9.18'
19
+ require 'yard'
20
+
21
+ YARD::Rake::YardocTask.new
22
+ rescue LoadError => e
23
+ task :yard do
24
+ abort "Please run `gem install yard` to install YARD."
25
+ end
26
+ end
@@ -0,0 +1,127 @@
1
+ # encoding: utf-8
2
+
3
+ require 'yaml'
4
+
5
+ Gem::Specification.new do |gemspec|
6
+ files = if File.directory?('.git')
7
+ `git ls-files`.split($/)
8
+ elsif File.directory?('.hg')
9
+ `hg manifest`.split($/)
10
+ elsif File.directory?('.svn')
11
+ `svn ls -R`.split($/).select { |path| File.file?(path) }
12
+ else
13
+ Dir['{**/}{.*,*}'].select { |path| File.file?(path) }
14
+ end
15
+
16
+ filter_files = lambda { |paths|
17
+ case paths
18
+ when Array
19
+ (files & paths)
20
+ when String
21
+ (files & Dir[paths])
22
+ end
23
+ }
24
+
25
+ version = {
26
+ :file => 'lib/ffi/wiring_pi/version.rb',
27
+ :constant => 'FFI::WiringPi::VERSION'
28
+ }
29
+
30
+ defaults = {
31
+ 'name' => File.basename(File.dirname(__FILE__)),
32
+ 'files' => files,
33
+ 'executables' => filter_files['bin/*'].map { |path| File.basename(path) },
34
+ 'test_files' => filter_files['{test/{**/}*_test.rb,spec/{**/}*_spec.rb}'],
35
+ 'extra_doc_files' => filter_files['*.{txt,rdoc,md,markdown,tt,textile}'],
36
+ }
37
+
38
+ metadata = defaults.merge(YAML.load_file('gemspec.yml'))
39
+
40
+ gemspec.name = metadata.fetch('name',defaults[:name])
41
+ gemspec.version = if metadata['version']
42
+ metadata['version']
43
+ elsif File.file?(version[:file])
44
+ require File.join('.',version[:file])
45
+ eval(version[:constant])
46
+ end
47
+
48
+ gemspec.summary = metadata.fetch('summary',metadata['description'])
49
+ gemspec.description = metadata.fetch('description',metadata['summary'])
50
+
51
+ case metadata['license']
52
+ when Array
53
+ gemspec.licenses = metadata['license']
54
+ when String
55
+ gemspec.license = metadata['license']
56
+ end
57
+
58
+ case metadata['authors']
59
+ when Array
60
+ gemspec.authors = metadata['authors']
61
+ when String
62
+ gemspec.author = metadata['authors']
63
+ end
64
+
65
+ gemspec.email = metadata['email']
66
+ gemspec.homepage = metadata['homepage']
67
+
68
+ case metadata['require_paths']
69
+ when Array
70
+ gemspec.require_paths = metadata['require_paths']
71
+ when String
72
+ gemspec.require_path = metadata['require_paths']
73
+ end
74
+
75
+ gemspec.files = filter_files[metadata['files']]
76
+
77
+ gemspec.executables = metadata['executables']
78
+ gemspec.extensions = metadata['extensions']
79
+
80
+ if Gem::VERSION < '1.7.'
81
+ gemspec.default_executable = gemspec.executables.first
82
+ end
83
+
84
+ gemspec.test_files = filter_files[metadata['test_files']]
85
+
86
+ unless gemspec.files.include?('.document')
87
+ gemspec.extra_rdoc_files = metadata['extra_doc_files']
88
+ end
89
+
90
+ gemspec.post_install_message = metadata['post_install_message']
91
+ gemspec.requirements = metadata['requirements']
92
+
93
+ if gemspec.respond_to?(:required_ruby_version=)
94
+ gemspec.required_ruby_version = metadata['required_ruby_version']
95
+ end
96
+
97
+ if gemspec.respond_to?(:required_rubygems_version=)
98
+ gemspec.required_rubygems_version = metadata['required_ruby_version']
99
+ end
100
+
101
+ parse_versions = lambda { |versions|
102
+ case versions
103
+ when Array
104
+ versions.map { |v| v.to_s }
105
+ when String
106
+ versions.split(/,\s*/)
107
+ end
108
+ }
109
+
110
+ if metadata['dependencies']
111
+ metadata['dependencies'].each do |name,versions|
112
+ gemspec.add_dependency(name,parse_versions[versions])
113
+ end
114
+ end
115
+
116
+ if metadata['runtime_dependencies']
117
+ metadata['runtime_dependencies'].each do |name,versions|
118
+ gemspec.add_runtime_dependency(name,parse_versions[versions])
119
+ end
120
+ end
121
+
122
+ if metadata['development_dependencies']
123
+ metadata['development_dependencies'].each do |name,versions|
124
+ gemspec.add_development_dependency(name,parse_versions[versions])
125
+ end
126
+ end
127
+ end
data/gemspec.yml ADDED
@@ -0,0 +1,18 @@
1
+ name: ffi-wiring_pi
2
+ version: 0.1.0
3
+ summary: FFI bindings for wiringPi
4
+ description: Ruby FFI bindings for the wiringPi library.
5
+ license: MIT
6
+ authors: Mark Huk
7
+ email: mark.guk.e@gmail.com
8
+ homepage: https://github.com/vimutter/ffi-wiring_pi
9
+ has_yard: true
10
+
11
+ requirements: wiringPi >= 2.46
12
+
13
+ dependencies:
14
+ ffi: ~> 1.0
15
+
16
+ development_dependencies:
17
+ rspec: ~> 3.8
18
+ yard: ~> 0.9.1
@@ -0,0 +1,3 @@
1
+ #frozen_string_literal: true
2
+
3
+ require 'ffi/wiring_pi'
@@ -0,0 +1,124 @@
1
+ #frozen_string_literal: true
2
+
3
+ module FFI::WiringPi::GPIO
4
+ extend FFI::Library
5
+
6
+ INPUT = 0
7
+ OUTPUT = 1
8
+ PWM_OUTPUT = 2
9
+ GPIO_CLOCK = 3
10
+ SOFT_PWM_OUTPUT = 4
11
+ SOFT_TONE_OUTPUT = 5
12
+ PWM_TONE_OUTPUT = 6
13
+
14
+ LOW = 0
15
+ HIGH = 1
16
+
17
+ PUD_OFF = 0
18
+ PUD_DOWN = 1
19
+ PUD_UP = 2
20
+
21
+ PWM_MODE_MS = 0
22
+ PWM_MODE_BAL = 1
23
+
24
+
25
+ ffi_lib 'wiringPi'
26
+
27
+ attach_function :setup, :wiringPiSetup, [], :int
28
+ attach_function :setup_as_gpio, :wiringPiSetupGpio, [], :int
29
+ attach_function :setup_as_physical, :wiringPiSetupPhys, [], :int
30
+
31
+ # This initialises wiringPi but uses the /sys/class/gpio interface rather
32
+ # than accessing the hardware directly. This can be called as a non-root user
33
+ # provided the GPIO pins have been exported before-hand using the gpio program.
34
+ # Pin numbering in this mode is the native Broadcom GPIO numbers – the same as
35
+ # wiringPiSetupGpio() above, so be aware of the differences between Rev 1 and Rev 2 boards.
36
+ # Note: In this mode you can only use the pins which have been exported via the /sys/class/gpio
37
+ # interface before you run your program. You can do this in a separate shell-script, or by
38
+ # using the system() function from inside your program to call the gpio program.
39
+ # Also note that some functions have no effect when using this mode as they’re
40
+ # not currently possible to action unless called with root privileges.
41
+ # (although you can use system() to call gpio to set/change modes if needed)
42
+ #
43
+ # @see http://wiringpi.com/reference/setup/
44
+ attach_function :setup_system_mode, :wiringPiSetupSys, [], :int
45
+
46
+ #
47
+ # @param pin [Integer] pin position (depends on setup mode)
48
+ # @param mode [Integer] `FFI::WiringPi::GPIO::INPUT`, `FFI::WiringPi::GPIO::OUTPUT`,
49
+ # `FFI::WiringPi::GPIO::PWM_OUTPUT` or `FFI::WiringPi::GPIO::GPIO_CLOCK`
50
+ attach_function :set_pin_mode, :pinMode, [:int, :int], :void
51
+
52
+ def get(pin, mode = FFI::WiringPi::GPIO::OUTPUT)
53
+ set_pin_mode(pin, mode)
54
+ Pin.new(pin, mode)
55
+ end
56
+
57
+ # @param pin [Integer] pin position (depends on setup mode)
58
+ # @param mode [Integer] `FFI::WiringPi::GPIO::LOW` or `FFI::WiringPi::GPIO::HIGH`
59
+ attach_function :digital_write, :digitalWrite, [:int, :int], :void
60
+
61
+ # Write pin state (aka digital_write)
62
+ #
63
+ # @param pin [Integer] pin position (depends on setup mode)
64
+ # @param state [Boolean] `true` to set to HIGH, `false` to set to LOW
65
+ #
66
+ def write(pin, state)
67
+ digital_write(state ? HIGH : LOW)
68
+ end
69
+
70
+ # Sets pin to HIGH state
71
+ #
72
+ # @param pin [Integer] pin position (depends on setup mode)
73
+ #
74
+ def up(pin)
75
+ write(pin, true)
76
+ end
77
+
78
+ # Sets pin to LOW state
79
+ #
80
+ # @param pin [Integer] pin position (depends on setup mode)
81
+ #
82
+ def down(pin)
83
+ write(pin, false)
84
+ end
85
+
86
+ # @param pin [Integer] pin position (depends on setup mode)
87
+ #
88
+ # @returns [Integer] `FFI::WiringPi::GPIO::LOW` or `FFI::WiringPi::GPIO::HIGH`
89
+ attach_function :digital_read, :digitalRead, [:int], :int
90
+
91
+ # Read pin state (aka digital_read)
92
+ #
93
+ # @param pin [Integer] pin position (depends on setup mode)
94
+ # @returns [Boolean] `true` if pin is in high state, `false` if in low
95
+ #
96
+ def read(pin)
97
+ result = digital_read(pin)
98
+ case result
99
+ when LOW
100
+ false
101
+ when HIGH
102
+ true
103
+ else
104
+ raise "Unknown result: #{result.inspect}"
105
+ end
106
+ end
107
+
108
+ class Pin
109
+ def initialize(position, mode)
110
+ @position = position
111
+ @mode = mode
112
+ end
113
+
114
+ def up!
115
+ raise ArgumentError('Can only set in OUTPUT mode') && return unless @mode == OUTPUT
116
+ GPIO.up(@position)
117
+ end
118
+
119
+ def down!
120
+ raise ArgumentError('Can only set in OUTPUT mode') && return unless @mode == OUTPUT
121
+ GPIO.down(@position)
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,10 @@
1
+ #frozen_string_literal: true
2
+
3
+ require 'ffi'
4
+ require 'ffi/wiring_pi/gpio'
5
+
6
+ module FFI
7
+ module WiringPi
8
+ extend FFI::Library
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ gem 'rspec', '~> 2.4'
2
+ require 'rspec'
3
+
4
+ require 'ffi'
5
+ include FFI
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ffi-wiring_pi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mark Huk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-02-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ffi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: yard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.1
55
+ description: Ruby FFI bindings for the wiringPi library.
56
+ email: mark.guk.e@gmail.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files:
60
+ - ChangeLog.md
61
+ - LICENSE.txt
62
+ - README.md
63
+ files:
64
+ - ".gitignore"
65
+ - ".rake_tasks~"
66
+ - ".rspec"
67
+ - ".travis.yml"
68
+ - ChangeLog.md
69
+ - Gemfile
70
+ - Gemfile.lock
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - ffi-wiring_pi.gemspec
75
+ - gemspec.yml
76
+ - lib/ffi/wiring_pi.rb
77
+ - lib/ffi/wiring_pi/gpio.rb
78
+ - lib/ffi/wiring_pi/wiring_pi.rb
79
+ - spec/spec_helper.rb
80
+ homepage: https://github.com/vimutter/ffi-wiring_pi
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements:
99
+ - wiringPi >= 2.46
100
+ rubygems_version: 3.0.1
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: FFI bindings for wiringPi
104
+ test_files: []