ffi-wiring_pi 0.2.0 → 0.3.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: 96d67497059bd425b34843259199031c0945ffa4ea239af8c7a5a4dd61ab23e6
4
- data.tar.gz: e85e81abfca1d648175cde24b841f9a1be6e25df7ff6b99ef5a575ab6db3dd4c
3
+ metadata.gz: e2d098355a7b9f55120d935e27114a215ac7c3aac2e0dfe3ec2a09bf5c7e8909
4
+ data.tar.gz: ca6b7da382e795cf235125ed0f06ec4352cdd212b6643b8afdc209d707725b5b
5
5
  SHA512:
6
- metadata.gz: 6d0381b71c738cf6342da8bcde90403d9dc7c2a3485dbfd7ee284e706b9f94c79e55cc723e220ed955934c6269085e058d238a0614dd271b42664963b4f1895a
7
- data.tar.gz: 693a22b26b22d46b4c4229e95c6f2b3981a47436eb01b5007e4d495292e661ad89dc6774c7d727ea83d679658ebebf749841d926ed36f269fef532f14b0d7adc
6
+ metadata.gz: d441d40e6fa144d1a02633691d2883cd90a6fcc4c20e7cec270bbb33b7d8fa928934f38d284470b7d226d0d0aa8814e73b7cc8117e038e927221589c879b6990
7
+ data.tar.gz: 934367bebb0e49ae9e62ad4da043d623cb10629c97425709b5c9608bf49ded08fd66728d9cd687e19544e10e713511e1d28dd9a539323a6401f7d1b2f3a1c36f
data/.gitignore CHANGED
@@ -48,3 +48,4 @@ build-iPhoneSimulator/
48
48
 
49
49
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
50
  .rvmrc
51
+ build
@@ -4,6 +4,7 @@ before_install:
4
4
  - cd wiringPi
5
5
  - ./build
6
6
  - gem install ffi
7
+ - gem install bundler:2.0.1
7
8
  rvm:
8
9
  - 2.6.1
9
10
  script: rake test
@@ -1,2 +1,3 @@
1
+ # 0.3.0 Added Software PWM, added instructions for libws281x, but not enabled
1
2
  # 0.2.0 Added PWM pin control functions
2
3
  # 0.1.0 Added GPIO basic functions: read and write
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ffi-wiring_pi (0.1.6)
4
+ ffi-wiring_pi (0.3.0)
5
5
  ffi (~> 1.0)
6
6
 
7
7
  GEM
@@ -0,0 +1,86 @@
1
+ VERSION=$(shell cat version)
2
+ DESTDIR?=/usr
3
+ PREFIX?=/local
4
+
5
+ LDCONFIG?=ldconfig
6
+
7
+ ifneq ($V,1)
8
+ Q ?= @
9
+ endif
10
+
11
+ STATIC=libws281x.a
12
+ DYNAMIC=libws281x.so.$(VERSION)
13
+
14
+ #DEBUG = -g -O0
15
+ DEBUG = -O2
16
+ CC = gcc
17
+ INCLUDE = -I.
18
+ DEFS = -D_GNU_SOURCE
19
+ CFLAGS = $(DEBUG) $(DEFS) -Wformat=2 -Wall -Wextra -Winline $(INCLUDE) -pipe -fPIC
20
+ #CFLAGS = $(DEBUG) $(DEFS) -Wformat=2 -Wall -Wextra -Wconversion -Winline $(INCLUDE) -pipe -fPIC
21
+
22
+ LIBS = -lm -lpthread -lrt -lcrypt
23
+
24
+ ###############################################################################
25
+
26
+ SRC = ws2811.c \
27
+ pwm.c \
28
+ pcm.c \
29
+ dma.c \
30
+ rpihw.c \
31
+ mailbox.c
32
+
33
+
34
+ HEADERS = $(shell ls *.h)
35
+
36
+ OBJ = $(SRC:.c=.o)
37
+
38
+ all: $(DYNAMIC)
39
+
40
+ .PHONY: static
41
+ static:
42
+ $Q cat noMoreStatic
43
+
44
+ $(DYNAMIC): $(OBJ)
45
+ $Q echo "[Link (Dynamic)]"
46
+ $Q $(CC) -shared -Wl,-soname,libws281x.so -o libws281x.so.$(VERSION) $(LIBS) $(OBJ)
47
+
48
+ .c.o:
49
+ $Q echo [Compile] $<
50
+ $Q $(CC) -c $(CFLAGS) $< -o $@
51
+
52
+
53
+ .PHONY: clean
54
+ clean:
55
+ $Q echo "[Clean]"
56
+ $Q rm -f $(OBJ) $(OBJ_I2C) *~ core tags Makefile.bak libws281x.*
57
+
58
+ .PHONY: tags
59
+ tags: $(SRC)
60
+ $Q echo [ctags]
61
+ $Q ctags $(SRC)
62
+
63
+
64
+ .PHONY: install
65
+ install: $(DYNAMIC)
66
+ $Q echo "[Install Headers]"
67
+ $Q install -m 0755 -d $(DESTDIR)$(PREFIX)/include
68
+ $Q install -m 0644 $(HEADERS) $(DESTDIR)$(PREFIX)/include
69
+ $Q echo "[Install Dynamic Lib]"
70
+ $Q install -m 0755 -d $(DESTDIR)$(PREFIX)/lib
71
+ $Q install -m 0755 libws281x.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib/libws281x.so.$(VERSION)
72
+ $Q ln -sf $(DESTDIR)$(PREFIX)/lib/libws281x.so.$(VERSION) $(DESTDIR)/lib/libws281x.so
73
+ $Q $(LDCONFIG)
74
+
75
+ .PHONY: uninstall
76
+ uninstall:
77
+ $Q echo "[UnInstall]"
78
+ $Q cd $(DESTDIR)$(PREFIX)/include/ && rm -f $(HEADERS)
79
+ $Q cd $(DESTDIR)$(PREFIX)/lib/ && rm -f libws281x.*
80
+ $Q $(LDCONFIG)
81
+
82
+
83
+ .PHONY: depend
84
+ depend:
85
+ makedepend -Y $(SRC) $(SRC_I2C)
86
+
data/README.md CHANGED
@@ -12,6 +12,7 @@ Ruby FFI bindings for the [wiringPi](http://wiringpi.com) library.
12
12
  ## Features
13
13
 
14
14
  * Can setup and work with GPIO
15
+ * In progress: bindings to rpi_ws281x library to work with NeoPixel (ws2811 & ws2812) LED strips
15
16
 
16
17
  ## Examples
17
18
 
@@ -45,6 +46,7 @@ Setup GPIO:
45
46
  * [Ruby](http://ruby-lang.org/) >= 2.6.1 or
46
47
  * [wiringPi](http://wiringpi.com/download-and-install/) >= 2.46
47
48
  * [ffi](http://github.com/ffi/ffi) ~> 1.0
49
+ * [rpi_ws281x](https://github.com/jgarff/rpi_ws281x)
48
50
 
49
51
  ## Install
50
52
 
@@ -0,0 +1,103 @@
1
+ #!/bin/bash
2
+
3
+ # ---------------------------------------------------------------------------------------------------------------------
4
+ # Compiles shared libraries required for interfacing with Raspberry Pi GPIO hardware from Java, using JNI.
5
+ # ---------------------------------------------------------------------------------------------------------------------
6
+ # Author(s): limpygnome <limpygnome@gmail.com>, mbelling <matthew.bellinger@gmail.com>
7
+ # ---------------------------------------------------------------------------------------------------------------------
8
+
9
+ # *********************************************************************************************************************
10
+ # Configuration
11
+ # *********************************************************************************************************************
12
+
13
+
14
+ # Relative dir names for input/output
15
+ BASE_DIR="$(dirname "$0")/"
16
+ OUTPUT="${BASE_DIR}/build"
17
+
18
+ NATIVE_SRC="${OUTPUT}/ws281x"
19
+ NATIVE_OUT="${NATIVE_SRC}/output"
20
+ NATIVE_LIB_NAME="ws281x.so"
21
+ LIB_BASE_NAME="libws281x"
22
+ WRAPPER_LIB_NAME="${LIB_BASE_NAME}.so"
23
+
24
+
25
+ # *********************************************************************************************************************
26
+ # Functions
27
+ # *********************************************************************************************************************
28
+
29
+ function compileSrc
30
+ {
31
+ SRC="${1}"
32
+ OUT="${2}"
33
+
34
+ gcc -shared -fPIC -w -o "${OUT}" -c "${SRC}" -I./
35
+ }
36
+
37
+ function programInstalled
38
+ (
39
+ CMD="${1}"
40
+ EXPECTED="${2}"
41
+ ERROR="${3}"
42
+ SUCCESS="${4}"
43
+
44
+ OUTPUT=$(eval ${CMD} || echo "fail")
45
+ if [[ "${OUTPUT}" != *"${EXPECTED}"* ]]; then
46
+ echo "${ERROR}"
47
+ exit 1
48
+ else
49
+ echo "${SUCCESS}"
50
+ fi
51
+ )
52
+
53
+ # *********************************************************************************************************************
54
+ # Main
55
+ # *********************************************************************************************************************
56
+
57
+ echo "NeoPixel ws281x Library Compiler"
58
+ echo "****************************************************"
59
+
60
+ # Check dependencies installed
61
+ set -e
62
+ programInstalled "gcc --version" "free software" "Error - GCC is not installed, cannot continue!" "Check - GCC installed..."
63
+ programInstalled "git --version" "git version" "Error - git is not installed, cannot continue!" "Check - git installed..."
64
+ set +e
65
+
66
+ # Clean workspace
67
+ echo "Deleting build directory to start clean..."
68
+ rm -rf build
69
+
70
+ # Retrieve rpi_ws281x repository
71
+ echo "Cloning rpi_ws281x repository..."
72
+ git clone https://github.com/jgarff/rpi_ws281x.git ${NATIVE_SRC}
73
+
74
+ # # At the time of this writing this repository does not tag versions, so checking out at a specific commit so we build a consistent library
75
+ # echo "Checking out specific revision..."
76
+ # pushd ${NATIVE_SRC}
77
+ # git checkout master
78
+ # popd
79
+
80
+ # Create all the required dirs
81
+ echo "Creating required dirs..."
82
+ mkdir -p "${NATIVE_OUT}"
83
+ mkdir -p "${OUTPUT}/nativeLib"
84
+
85
+ # Compile library objects
86
+ echo "Compiling ws281x library objects..."
87
+
88
+ compileSrc "${NATIVE_SRC}/ws2811.c" "${NATIVE_OUT}/ws2811.o"
89
+ compileSrc "${NATIVE_SRC}/pwm.c" "${NATIVE_OUT}/pwm.o"
90
+ compileSrc "${NATIVE_SRC}/pcm.c" "${NATIVE_OUT}/pcm.o"
91
+ compileSrc "${NATIVE_SRC}/dma.c" "${NATIVE_OUT}/dma.o"
92
+ compileSrc "${NATIVE_SRC}/rpihw.c" "${NATIVE_OUT}/rpihw.o"
93
+ compileSrc "${NATIVE_SRC}/mailbox.c" "${NATIVE_OUT}/mailbox.o"
94
+
95
+
96
+ # Compile library
97
+ echo "Compiling ws281x library..."
98
+ gcc -shared -o "${OUTPUT}/${NATIVE_LIB_NAME}" "${NATIVE_OUT}/ws2811.o" "${NATIVE_OUT}/pwm.o" "${NATIVE_OUT}/pcm.o" "${NATIVE_OUT}/dma.o" "${NATIVE_OUT}/rpihw.o" "${NATIVE_OUT}/mailbox.o"
99
+
100
+ cp "Makefile.template" "${NATIVE_SRC}/Makefile"
101
+ cd $NATIVE_SRC && make
102
+ sudo make install
103
+ echo "Done!"
@@ -1,5 +1,5 @@
1
1
  name: ffi-wiring_pi
2
- version: 0.2.0
2
+ version: 0.3.0
3
3
  summary: FFI bindings for wiringPi
4
4
  description: Ruby FFI bindings for the wiringPi library.
5
5
  license: MIT
@@ -11,3 +11,4 @@ module FFI
11
11
  end
12
12
 
13
13
  require 'ffi/wiring_pi/gpio'
14
+ require 'ffi/wiring_pi/soft_pwm'
@@ -0,0 +1,15 @@
1
+ #frozen_string_literal: true
2
+
3
+ module FFI::WiringPi::Neopixel
4
+ extend FFI::Library
5
+
6
+ ffi_lib 'libws281x'
7
+ # ws2811_return_t ws2811_init(ws2811_t *ws2811); //< Initialize buffers/hardware
8
+ # void ws2811_fini(ws2811_t *ws2811); //< Tear it all down
9
+ # ws2811_return_t ws2811_render(ws2811_t *ws2811); //< Send LEDs off to hardware
10
+ # ws2811_return_t ws2811_wait(ws2811_t *ws2811); //< Wait for DMA completion
11
+ # const char * ws2811_get_return_t_str(const ws2811_return_t state); //< Get string representation of the given return state
12
+
13
+ # attach_function :setup, :wiringPiSetup, [], :int
14
+
15
+ end
@@ -0,0 +1,26 @@
1
+ #frozen_string_literal: true
2
+
3
+ module FFI::WiringPi::SoftPwm
4
+ extend FFI::Library
5
+
6
+ ffi_lib 'wiringPi'
7
+
8
+ attach_function :soft_pwm_create, :softPwmCreate, [:int, :int, :int], :int
9
+ attach_function :soft_pwm_write, :softPwmWrite, [:int, :int], :void
10
+
11
+ class Pin
12
+ def initialize(pin, initial_state = 0, range = 100)
13
+ raise ArgumentError, 'Range should be Integer > 0' unless range.is_a?(Integer) && range > 0
14
+ raise ArgumentError, 'State should be within the range' unless initial_state.is_a?(Integer) && (0..range).cover?(initial_state)
15
+ @pin = pin
16
+ @range = range
17
+ FFI::WiringPi::SoftPwm.soft_pwm_create pin, initial_state, range
18
+ end
19
+
20
+ def write(value)
21
+ raise ArgumentError, 'Value should be within the range' unless value.is_a?(Integer) && (0..@range).cover?(value)
22
+ FFI::WiringPi::SoftPwm.soft_pwm_write @pin, value
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe FFI::WiringPi::SoftPwm do
4
+
5
+ before :each do
6
+ allow(FFI::WiringPi::SoftPwm).to receive(:soft_pwm_create)
7
+ end
8
+
9
+ describe '::Pin' do
10
+ it 'raises error when range is negative' do
11
+ expect { described_class::Pin.new 0, 0, -1 }.to raise_error('Range should be Integer > 0')
12
+ end
13
+
14
+ it 'raises error when initial state is negative' do
15
+ expect { described_class::Pin.new 0, -1, 100 }.to raise_error('State should be within the range')
16
+ end
17
+
18
+ it 'raises error when initial state is out of range' do
19
+ expect { described_class::Pin.new 0, 101, 100 }.to raise_error('State should be within the range')
20
+ end
21
+
22
+ describe '#write' do
23
+ subject do
24
+ described_class::Pin.new 0, 0, 100
25
+ end
26
+
27
+ it 'raises error when value is out of range', :aggregate_failures do
28
+ expect { subject.write(-1) }.to raise_error('Value should be within the range')
29
+ expect { subject.write(101) }.to raise_error('Value should be within the range')
30
+ end
31
+ end
32
+ end
33
+ 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.2.0
4
+ version: 0.3.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-16 00:00:00.000000000 Z
11
+ date: 2019-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -83,13 +83,18 @@ files:
83
83
  - Gemfile
84
84
  - Gemfile.lock
85
85
  - LICENSE.txt
86
+ - Makefile.template
86
87
  - README.md
87
88
  - Rakefile
89
+ - build_rpi_ws281x.sh
88
90
  - ffi-wiring_pi.gemspec
89
91
  - gemspec.yml
90
92
  - lib/ffi/wiring_pi.rb
91
93
  - lib/ffi/wiring_pi/gpio.rb
94
+ - lib/ffi/wiring_pi/neopixel.rb
95
+ - lib/ffi/wiring_pi/soft_pwm.rb
92
96
  - spec/ffi/wiring_pi/gpio_spec.rb
97
+ - spec/ffi/wiring_pi/soft_pwm_spec.rb
93
98
  - spec/spec_helper.rb
94
99
  homepage: https://github.com/vimutter/ffi-wiring_pi
95
100
  licenses:
@@ -117,3 +122,4 @@ specification_version: 4
117
122
  summary: FFI bindings for wiringPi
118
123
  test_files:
119
124
  - spec/ffi/wiring_pi/gpio_spec.rb
125
+ - spec/ffi/wiring_pi/soft_pwm_spec.rb