pi_wire 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +75 -0
- data/Rakefile +12 -0
- data/ext/pi_wire/extconf.rb +30 -0
- data/ext/pi_wire/pi_wire.c +29 -0
- data/ext/pi_wire/pi_wire.h +17 -0
- data/ext/pi_wire/pi_wire_output_pin.c +19 -0
- data/ext/pi_wire/pi_wire_output_pin.h +9 -0
- data/ext/pi_wire/pi_wire_pin.c +19 -0
- data/ext/pi_wire/pi_wire_pin.h +11 -0
- data/ext/pi_wire/pi_wire_pwm_pin.c +13 -0
- data/ext/pi_wire/pi_wire_pwm_pin.h +9 -0
- data/ext/pi_wire/pi_wire_serial.c +72 -0
- data/ext/pi_wire/pi_wire_serial.h +8 -0
- data/lib/pi_wire/output_pin.rb +28 -0
- data/lib/pi_wire/pin.rb +5 -0
- data/lib/pi_wire/pwm_pin.rb +8 -0
- data/lib/pi_wire/serial.rb +16 -0
- data/lib/pi_wire/version.rb +3 -0
- data/lib/pi_wire.rb +11 -0
- data/pi_wire.gemspec +26 -0
- data/spec/output_pin_spec.rb +120 -0
- data/spec/pi_wire_spec.rb +10 -0
- data/spec/pwm_pin_spec.rb +8 -0
- data/spec/spec_helper.rb +17 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fc5b6d6abcb49e1e5acc56711ad043f6bccd38c0
|
4
|
+
data.tar.gz: ab15e75cf0f06d57b8b4be0acb993f2454c2254c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 697f5d880a9163ec71e5630b033224868f28c0a34196d9f9e21bf7b4fabafa3f4216a008902dc1d99b6b2e97bc13b8b747fe05358010bcf843d14717d9a5cbd6
|
7
|
+
data.tar.gz: 040dc0268bc21657ef512cdd1dfe8e4997091eb351a76b19cec0af823ffbc5f8f7b8d2f8b909a15d6a3298d469f31abd72c5a458613a1bc580d4109b06cb4b51
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# PiWire
|
2
|
+
|
3
|
+
PiWire is a ruby wrapper around the [wiringPi](http://wiringpi.com) C library.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
PiWire requires the wiringPi library be installed to work, make sure you have succesfully installed wiringPi _before_ trying to install PiWire.
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'pi_wire'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install pi_wire
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
As with wiringPi you must initialize PiWire before you start using it.
|
24
|
+
|
25
|
+
PiWire.init
|
26
|
+
|
27
|
+
If you don't do this then at best things wont work, and at worst your program will crash.
|
28
|
+
|
29
|
+
### LED Blink
|
30
|
+
|
31
|
+
This is effectively the hello world program of electronics:
|
32
|
+
|
33
|
+
require 'pi_wire'
|
34
|
+
|
35
|
+
PiWire.init
|
36
|
+
|
37
|
+
pin = PiWire::OutputPin.new(1)
|
38
|
+
|
39
|
+
loop do
|
40
|
+
pin.toggle!
|
41
|
+
sleep 0.5
|
42
|
+
end
|
43
|
+
|
44
|
+
### Output Pin
|
45
|
+
|
46
|
+
A new output pin can be created, specifiying the wiringPi pin number to use:
|
47
|
+
|
48
|
+
pin = PiWire::OutputPin.new(0)
|
49
|
+
|
50
|
+
You can now read and write from this pin:
|
51
|
+
|
52
|
+
pin.read # will return PiWire::LOW (0) or PiWire::HIGH (1)
|
53
|
+
pin.write PiWire::HIGH
|
54
|
+
|
55
|
+
### PWM Pin
|
56
|
+
|
57
|
+
A new PWM pin can be created, this will use pin number 1 by default.
|
58
|
+
|
59
|
+
pin = PiWire::PWMPin.new
|
60
|
+
|
61
|
+
You can write to this pin, by default the range is from 0 to 1023
|
62
|
+
|
63
|
+
pin.write 512
|
64
|
+
|
65
|
+
## Tests
|
66
|
+
|
67
|
+
Run the tests with `rake`, these must be run as a superuser.
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
1. Fork it
|
72
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
73
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
74
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
75
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/extensiontask"
|
3
|
+
require "rspec/core/rake_task"
|
4
|
+
|
5
|
+
spec = Gem::Specification.load("pi_wire.gemspec")
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
Rake::ExtensionTask.new("pi_wire", spec) do |ext|
|
9
|
+
ext.lib_dir = File.join("lib", "pi_wire")
|
10
|
+
end
|
11
|
+
|
12
|
+
task default: :spec
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
LIBDIR = RbConfig::CONFIG['libdir']
|
4
|
+
INCLUDEDIR = RbConfig::CONFIG['includedir']
|
5
|
+
|
6
|
+
HEADER_DIRS = [
|
7
|
+
'/opt/local/include',
|
8
|
+
'/usr/local/include',
|
9
|
+
INCLUDEDIR,
|
10
|
+
'/usr/include'
|
11
|
+
]
|
12
|
+
|
13
|
+
LIB_DIRS = [
|
14
|
+
'/opt/local/lib',
|
15
|
+
'/usr/local/lib',
|
16
|
+
LIBDIR,
|
17
|
+
'/usr/lib'
|
18
|
+
]
|
19
|
+
|
20
|
+
dir_config('wiringPi', HEADER_DIRS, LIB_DIRS)
|
21
|
+
|
22
|
+
unless find_header('wiringPi.h', *HEADER_DIRS)
|
23
|
+
abort 'wiringPi is missing, please install wiringPi'
|
24
|
+
end
|
25
|
+
|
26
|
+
unless find_library('wiringPi', nil, *LIB_DIRS)
|
27
|
+
abort 'wiringPi is missing, please install wiringPi'
|
28
|
+
end
|
29
|
+
|
30
|
+
create_makefile('pi_wire/pi_wire')
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#include <pi_wire.h>
|
2
|
+
|
3
|
+
VALUE mPiWire;
|
4
|
+
|
5
|
+
static VALUE hello_world(VALUE klass) {
|
6
|
+
return rb_str_new2("Hello, World!");
|
7
|
+
}
|
8
|
+
|
9
|
+
static VALUE init_wiring_pi(VALUE klass) {
|
10
|
+
wiringPiSetup();
|
11
|
+
return Qtrue;
|
12
|
+
}
|
13
|
+
|
14
|
+
void Init_pi_wire() {
|
15
|
+
mPiWire = rb_define_module("PiWire");
|
16
|
+
rb_define_module_function(mPiWire, "hello_world", hello_world, 0);
|
17
|
+
rb_define_module_function(mPiWire, "init", init_wiring_pi, 0);
|
18
|
+
|
19
|
+
rb_define_const(mPiWire, "OUTPUT_MODE", INT2FIX(OUTPUT));
|
20
|
+
rb_define_const(mPiWire, "PWM_MODE", INT2FIX(PWM_OUTPUT));
|
21
|
+
|
22
|
+
rb_define_const(mPiWire, "LOW", INT2FIX(LOW));
|
23
|
+
rb_define_const(mPiWire, "HIGH", INT2FIX(HIGH));
|
24
|
+
|
25
|
+
Init_pi_wire_pin();
|
26
|
+
Init_pi_wire_output_pin();
|
27
|
+
Init_pi_wire_pwm_pin();
|
28
|
+
Init_pi_wire_serial();
|
29
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#ifndef PI_WIRE
|
2
|
+
#define PI_WIRE
|
3
|
+
|
4
|
+
#include <ruby.h>
|
5
|
+
#include <wiringPi.h>
|
6
|
+
#include <wiringSerial.h>
|
7
|
+
|
8
|
+
extern VALUE mPiWire;
|
9
|
+
|
10
|
+
void Init_pi_wire();
|
11
|
+
|
12
|
+
#include <pi_wire_pin.h>
|
13
|
+
#include <pi_wire_output_pin.h>
|
14
|
+
#include <pi_wire_pwm_pin.h>
|
15
|
+
#include <pi_wire_serial.h>
|
16
|
+
|
17
|
+
#endif
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#include <pi_wire_output_pin.h>
|
2
|
+
|
3
|
+
static VALUE read(VALUE self) {
|
4
|
+
int pin_value = digitalRead(pin_number(self));
|
5
|
+
return INT2FIX(pin_value);
|
6
|
+
}
|
7
|
+
|
8
|
+
static VALUE write(VALUE self, VALUE rb_int) {
|
9
|
+
digitalWrite(pin_number(self), NUM2INT(rb_int));
|
10
|
+
return Qtrue;
|
11
|
+
}
|
12
|
+
|
13
|
+
void Init_pi_wire_output_pin() {
|
14
|
+
VALUE cPiWireOutputPin = rb_define_class_under(mPiWire, "OutputPin", cPiWirePin);
|
15
|
+
|
16
|
+
rb_define_method(cPiWireOutputPin, "read", read, 0);
|
17
|
+
rb_define_method(cPiWireOutputPin, "write", write, 1);
|
18
|
+
rb_define_alias(cPiWireOutputPin, "<<", "write");
|
19
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#include <pi_wire_pin.h>
|
2
|
+
|
3
|
+
VALUE cPiWirePin;
|
4
|
+
|
5
|
+
int pin_number(VALUE self) {
|
6
|
+
VALUE pin_number = rb_ivar_get(self, rb_intern("@number"));
|
7
|
+
return NUM2INT(pin_number);
|
8
|
+
}
|
9
|
+
|
10
|
+
static VALUE set_mode(VALUE self, VALUE rb_int) {
|
11
|
+
pinMode(pin_number(self), NUM2INT(rb_int));
|
12
|
+
return Qtrue;
|
13
|
+
}
|
14
|
+
|
15
|
+
void Init_pi_wire_pin() {
|
16
|
+
cPiWirePin = rb_define_class_under(mPiWire, "Pin", rb_cObject);
|
17
|
+
|
18
|
+
rb_define_private_method(cPiWirePin, "mode=", set_mode, 1);
|
19
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#include <pi_wire_pwm_pin.h>
|
2
|
+
|
3
|
+
static VALUE write(VALUE self, VALUE rb_int) {
|
4
|
+
pwmWrite(pin_number(self), NUM2INT(rb_int));
|
5
|
+
return Qtrue;
|
6
|
+
}
|
7
|
+
|
8
|
+
void Init_pi_wire_pwm_pin() {
|
9
|
+
VALUE cPiWirePWMPin = rb_define_class_under(mPiWire, "PWMPin", cPiWirePin);
|
10
|
+
|
11
|
+
rb_define_method(cPiWirePWMPin, "write", write, 1);
|
12
|
+
rb_define_alias(cPiWirePWMPin, "<<", "write");
|
13
|
+
}
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#include <pi_wire_serial.h>
|
2
|
+
|
3
|
+
static char *get_file_name(VALUE self) {
|
4
|
+
VALUE rb_file_name = rb_ivar_get(self, rb_intern("@name"));
|
5
|
+
return StringValueCStr(rb_file_name);
|
6
|
+
}
|
7
|
+
|
8
|
+
static int get_baud_rate(VALUE self) {
|
9
|
+
VALUE rb_baud_rate = rb_ivar_get(self, rb_intern("@baud_rate"));
|
10
|
+
return NUM2INT(rb_baud_rate);
|
11
|
+
}
|
12
|
+
|
13
|
+
static int get_fd(VALUE self) {
|
14
|
+
VALUE rb_fd = rb_ivar_get(self, rb_intern("@fd"));
|
15
|
+
return NUM2INT(rb_fd);
|
16
|
+
}
|
17
|
+
|
18
|
+
static VALUE open_serial_file(VALUE self) {
|
19
|
+
char *file_name = get_file_name(self);
|
20
|
+
int baud_rate = get_baud_rate(self);
|
21
|
+
int fd = serialOpen(file_name, baud_rate);
|
22
|
+
|
23
|
+
if (fd == -1) {
|
24
|
+
rb_raise(rb_eRuntimeError, "Couldn't open %s", file_name);
|
25
|
+
}
|
26
|
+
|
27
|
+
rb_ivar_set(self, rb_intern("@fd"), INT2NUM(fd));
|
28
|
+
return Qnil;
|
29
|
+
}
|
30
|
+
|
31
|
+
static VALUE serial_write(VALUE self, VALUE str) {
|
32
|
+
int fd = get_fd(self);
|
33
|
+
char *s = StringValueCStr(str);
|
34
|
+
serialPuts(fd, s);
|
35
|
+
return Qtrue;
|
36
|
+
}
|
37
|
+
|
38
|
+
static VALUE serial_read(VALUE self) {
|
39
|
+
int fd = get_fd(self);
|
40
|
+
int chars_available = serialDataAvail(fd);
|
41
|
+
int i;
|
42
|
+
char *str = malloc(chars_available + 2);
|
43
|
+
|
44
|
+
if (chars_available == -1) {
|
45
|
+
rb_raise(rb_eRuntimeError, "No data to read");
|
46
|
+
return Qnil;
|
47
|
+
}
|
48
|
+
|
49
|
+
for (i = 0; i < chars_available; i++) {
|
50
|
+
str[i] = serialGetchar(fd);
|
51
|
+
}
|
52
|
+
|
53
|
+
str[chars_available +1] = '\0';
|
54
|
+
|
55
|
+
return rb_str_new2(str);
|
56
|
+
}
|
57
|
+
|
58
|
+
static VALUE serial_close(VALUE self) {
|
59
|
+
int fd = get_fd(self);
|
60
|
+
serialClose(fd);
|
61
|
+
return Qtrue;
|
62
|
+
}
|
63
|
+
|
64
|
+
void Init_pi_wire_serial() {
|
65
|
+
VALUE cPiWireSerial = rb_define_class_under(mPiWire, "Serial", rb_cObject);
|
66
|
+
|
67
|
+
rb_define_method(cPiWireSerial, "write", serial_write, 1);
|
68
|
+
rb_define_method(cPiWireSerial, "read", serial_read, 0);
|
69
|
+
rb_define_method(cPiWireSerial, "close", serial_close, 0);
|
70
|
+
|
71
|
+
rb_define_private_method(cPiWireSerial, "open", open_serial_file, 0);
|
72
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module PiWire
|
2
|
+
class OutputPin < Pin
|
3
|
+
def initialize(number)
|
4
|
+
@number = number
|
5
|
+
self.mode = PiWire::OUTPUT_MODE
|
6
|
+
end
|
7
|
+
|
8
|
+
def low?
|
9
|
+
read == PiWire::LOW
|
10
|
+
end
|
11
|
+
|
12
|
+
def high?
|
13
|
+
read == PiWire::HIGH
|
14
|
+
end
|
15
|
+
|
16
|
+
def low!
|
17
|
+
write PiWire::LOW
|
18
|
+
end
|
19
|
+
|
20
|
+
def high!
|
21
|
+
write PiWire::HIGH
|
22
|
+
end
|
23
|
+
|
24
|
+
def toggle!
|
25
|
+
low? ? high! : low!
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/pi_wire/pin.rb
ADDED
data/lib/pi_wire.rb
ADDED
data/pi_wire.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pi_wire/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pi_wire"
|
8
|
+
spec.version = PiWire::VERSION
|
9
|
+
spec.authors = ["Oliver Nightingale"]
|
10
|
+
spec.email = ["oliver.nightingale1@gmail.com"]
|
11
|
+
spec.description = %q{Ruby bindings to WiringPi}
|
12
|
+
spec.summary = %q{Ruby bindings to WiringPi}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
spec.extensions << "ext/pi_wire/extconf.rb"
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rake-compiler"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PiWire::OutputPin do
|
4
|
+
describe "#initialise" do
|
5
|
+
subject(:pin) { PiWire::OutputPin.new(1) }
|
6
|
+
its(:number) { should == 1 }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#low?" do
|
10
|
+
let(:pin) { PiWire::OutputPin.new(1) }
|
11
|
+
|
12
|
+
subject { pin.low? }
|
13
|
+
|
14
|
+
context "yes" do
|
15
|
+
before { pin.stub(:read).and_return(PiWire::LOW) }
|
16
|
+
it { should be_true }
|
17
|
+
end
|
18
|
+
|
19
|
+
context "no" do
|
20
|
+
before { pin.stub(:read).and_return(PiWire::HIGH) }
|
21
|
+
it { should be_false }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#high?" do
|
26
|
+
let(:pin) { PiWire::OutputPin.new(1) }
|
27
|
+
|
28
|
+
subject { pin.high? }
|
29
|
+
|
30
|
+
context "yes" do
|
31
|
+
before { pin.stub(:read).and_return(PiWire::HIGH) }
|
32
|
+
it { should be_true }
|
33
|
+
end
|
34
|
+
|
35
|
+
context "no" do
|
36
|
+
before { pin.stub(:read).and_return(PiWire::LOW) }
|
37
|
+
it { should be_false }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#read" do
|
42
|
+
subject(:pin) { PiWire::OutputPin.new(1) }
|
43
|
+
|
44
|
+
context "high" do
|
45
|
+
before { pin << PiWire::HIGH }
|
46
|
+
it { should be_high }
|
47
|
+
end
|
48
|
+
|
49
|
+
context "low" do
|
50
|
+
before { pin << PiWire::LOW }
|
51
|
+
it { should be_low }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#high!" do
|
56
|
+
subject(:pin) { PiWire::OutputPin.new(1) }
|
57
|
+
|
58
|
+
context "currently high" do
|
59
|
+
before { pin << PiWire::HIGH }
|
60
|
+
|
61
|
+
it "sets the pin high" do
|
62
|
+
pin.high!
|
63
|
+
pin.should be_high
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "currently low" do
|
68
|
+
before { pin << PiWire::LOW }
|
69
|
+
|
70
|
+
it "sets the pin high" do
|
71
|
+
pin.high!
|
72
|
+
pin.should be_high
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#low!" do
|
78
|
+
subject(:pin) { PiWire::OutputPin.new(1) }
|
79
|
+
|
80
|
+
context "currently high" do
|
81
|
+
before { pin << PiWire::HIGH }
|
82
|
+
|
83
|
+
it "sets the pin low" do
|
84
|
+
pin.low!
|
85
|
+
pin.should be_low
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "currently low" do
|
90
|
+
before { pin << PiWire::LOW }
|
91
|
+
|
92
|
+
it "sets the pin low" do
|
93
|
+
pin.low!
|
94
|
+
pin.should be_low
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "toggle!" do
|
100
|
+
subject(:pin) { PiWire::OutputPin.new(1) }
|
101
|
+
|
102
|
+
context "currently high" do
|
103
|
+
before { pin << PiWire::HIGH }
|
104
|
+
|
105
|
+
it "sets the pin low" do
|
106
|
+
pin.toggle!
|
107
|
+
pin.should be_low
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "currently low" do
|
112
|
+
before { pin << PiWire::LOW }
|
113
|
+
|
114
|
+
it "sets the pin high" do
|
115
|
+
pin.toggle!
|
116
|
+
pin.should be_high
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'pi_wire'
|
3
|
+
|
4
|
+
# needed to setup the RaspberryPi GPIO hardware.
|
5
|
+
PiWire.init
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pi_wire
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oliver Nightingale
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake-compiler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Ruby bindings to WiringPi
|
70
|
+
email:
|
71
|
+
- oliver.nightingale1@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions:
|
74
|
+
- ext/pi_wire/extconf.rb
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- ext/pi_wire/extconf.rb
|
83
|
+
- ext/pi_wire/pi_wire.c
|
84
|
+
- ext/pi_wire/pi_wire.h
|
85
|
+
- ext/pi_wire/pi_wire_output_pin.c
|
86
|
+
- ext/pi_wire/pi_wire_output_pin.h
|
87
|
+
- ext/pi_wire/pi_wire_pin.c
|
88
|
+
- ext/pi_wire/pi_wire_pin.h
|
89
|
+
- ext/pi_wire/pi_wire_pwm_pin.c
|
90
|
+
- ext/pi_wire/pi_wire_pwm_pin.h
|
91
|
+
- ext/pi_wire/pi_wire_serial.c
|
92
|
+
- ext/pi_wire/pi_wire_serial.h
|
93
|
+
- lib/pi_wire.rb
|
94
|
+
- lib/pi_wire/output_pin.rb
|
95
|
+
- lib/pi_wire/pin.rb
|
96
|
+
- lib/pi_wire/pwm_pin.rb
|
97
|
+
- lib/pi_wire/serial.rb
|
98
|
+
- lib/pi_wire/version.rb
|
99
|
+
- pi_wire.gemspec
|
100
|
+
- spec/output_pin_spec.rb
|
101
|
+
- spec/pi_wire_spec.rb
|
102
|
+
- spec/pwm_pin_spec.rb
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
homepage: ''
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.0.3
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Ruby bindings to WiringPi
|
128
|
+
test_files:
|
129
|
+
- spec/output_pin_spec.rb
|
130
|
+
- spec/pi_wire_spec.rb
|
131
|
+
- spec/pwm_pin_spec.rb
|
132
|
+
- spec/spec_helper.rb
|