ffi-wiring_pi 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2d098355a7b9f55120d935e27114a215ac7c3aac2e0dfe3ec2a09bf5c7e8909
4
- data.tar.gz: ca6b7da382e795cf235125ed0f06ec4352cdd212b6643b8afdc209d707725b5b
3
+ metadata.gz: 19e1117a25b8972026d0855e55c76dfc0264f3102efe8eb658c33f039af3628a
4
+ data.tar.gz: 32c9523cd1c4b605127760a87f0840efcc82e65fcb7ad657b4bc2bf54c7b7dd9
5
5
  SHA512:
6
- metadata.gz: d441d40e6fa144d1a02633691d2883cd90a6fcc4c20e7cec270bbb33b7d8fa928934f38d284470b7d226d0d0aa8814e73b7cc8117e038e927221589c879b6990
7
- data.tar.gz: 934367bebb0e49ae9e62ad4da043d623cb10629c97425709b5c9608bf49ded08fd66728d9cd687e19544e10e713511e1d28dd9a539323a6401f7d1b2f3a1c36f
6
+ metadata.gz: bd6b2ab6e7f04a9288f5344e3d43a8b2b88bfa7dbe1b74a62a62349adef0bc6bc83f7100c6a7a826ee298b5b0662f56e886009da21e371d07575ef7ac9925d5f
7
+ data.tar.gz: d713437e2a39be14dedcbc0297b713fd20997e34b9a2bd41a968879b3e007d9b4a0c34f05f52192928c634ccb796b233600aeb865b529e5c2000e7b04cdd074c
@@ -1,3 +1,4 @@
1
+ # 0.4.0 Added Software Tone PWM functions wrappers
1
2
  # 0.3.0 Added Software PWM, added instructions for libws281x, but not enabled
2
3
  # 0.2.0 Added PWM pin control functions
3
4
  # 0.1.0 Added GPIO basic functions: read and write
@@ -1,5 +1,5 @@
1
1
  name: ffi-wiring_pi
2
- version: 0.3.0
2
+ version: 0.4.0
3
3
  summary: FFI bindings for wiringPi
4
4
  description: Ruby FFI bindings for the wiringPi library.
5
5
  license: MIT
@@ -12,3 +12,4 @@ end
12
12
 
13
13
  require 'ffi/wiring_pi/gpio'
14
14
  require 'ffi/wiring_pi/soft_pwm'
15
+ require 'ffi/wiring_pi/soft_tone'
@@ -0,0 +1,26 @@
1
+ #frozen_string_literal: true
2
+
3
+ module FFI::WiringPi::SoftTone
4
+ extend FFI::Library
5
+
6
+ ffi_lib 'wiringPi'
7
+
8
+ attach_function :soft_tone_create, :softToneCreate, [:int], :int
9
+ attach_function :soft_tone_write, :softToneWrite , [:int, :int], :void
10
+
11
+ class Pin
12
+ def initialize(pin)
13
+ @pin = pin
14
+ status = FFI::WiringPi::SoftTone.soft_tone_create pin
15
+ raise "Something went wrong: Errno:#{FFI::LastError.error}" unless status == 0
16
+ end
17
+
18
+ # Sets the frequency of software PWM in tone mode (50%)
19
+ # @param frequecy [Integer] if 0 - disable output, if less than 5000 usually
20
+ # produces sound (if connected to devise)
21
+ def write(frequecy)
22
+ FFI::WiringPi::SoftTone.soft_tone_write @pin, frequecy
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe FFI::WiringPi::SoftTone do
4
+
5
+ before :each do
6
+ allow(FFI::WiringPi::SoftTone).to receive(:soft_tone_create).and_return 0
7
+ end
8
+
9
+ describe '::Pin' do
10
+ it 'raises error when soft_tone_create returns non-zero' do
11
+ allow(FFI::WiringPi::SoftTone).to receive(:soft_tone_create).and_return 1
12
+ expect { described_class::Pin.new 0 }.to raise_error('Something went wrong: Errno:0')
13
+ end
14
+
15
+ describe '#write' do
16
+ subject do
17
+ described_class::Pin.new 0
18
+ end
19
+
20
+ it 'calls soft_tone_write', :aggregate_failures do
21
+ expect(FFI::WiringPi::SoftTone).to receive(:soft_tone_write).with(0, 100)
22
+ subject.write(100)
23
+ end
24
+ end
25
+ end
26
+ end
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.3.0
4
+ version: 0.4.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-20 00:00:00.000000000 Z
11
+ date: 2019-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -93,8 +93,10 @@ files:
93
93
  - lib/ffi/wiring_pi/gpio.rb
94
94
  - lib/ffi/wiring_pi/neopixel.rb
95
95
  - lib/ffi/wiring_pi/soft_pwm.rb
96
+ - lib/ffi/wiring_pi/soft_tone.rb
96
97
  - spec/ffi/wiring_pi/gpio_spec.rb
97
98
  - spec/ffi/wiring_pi/soft_pwm_spec.rb
99
+ - spec/ffi/wiring_pi/soft_tone_spec.rb
98
100
  - spec/spec_helper.rb
99
101
  homepage: https://github.com/vimutter/ffi-wiring_pi
100
102
  licenses:
@@ -123,3 +125,4 @@ summary: FFI bindings for wiringPi
123
125
  test_files:
124
126
  - spec/ffi/wiring_pi/gpio_spec.rb
125
127
  - spec/ffi/wiring_pi/soft_pwm_spec.rb
128
+ - spec/ffi/wiring_pi/soft_tone_spec.rb