wiringpi 0.0.1-armv6l-linux
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/wiringpi/extconf.rb +2 -0
- data/ext/wiringpi/wiringpi.c +587 -0
- data/ext/wiringpi/wiringpi.h +63 -0
- data/ext/wiringpi/wiringpi_wrap.c +2346 -0
- data/lib/wiringpi.rb +111 -0
- metadata +54 -0
data/lib/wiringpi.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'wiringpi/wiringpi'
|
2
|
+
|
3
|
+
WPI_MODE_PINS = 0
|
4
|
+
WPI_MODE_GPIO = 1
|
5
|
+
|
6
|
+
INPUT = 0
|
7
|
+
OUTPUT = 1
|
8
|
+
PWM_OUTPUT = 2
|
9
|
+
|
10
|
+
HIGH = 1
|
11
|
+
LOW = 0
|
12
|
+
|
13
|
+
PUD_OFF = 0
|
14
|
+
PUD_DOWN = 1
|
15
|
+
PUD_UP = 2
|
16
|
+
|
17
|
+
class WiringPi
|
18
|
+
|
19
|
+
@@gpioPins = [
|
20
|
+
0,1,4,7,8,9,10,11,14,15,17,18,21,22,23,24,25 # seemingly random indeed!
|
21
|
+
]
|
22
|
+
|
23
|
+
@@pins = [
|
24
|
+
0,1,2,3,4,5,6,7, # basic IO pins
|
25
|
+
8,9, # i2c with 1k8 pull up resistor
|
26
|
+
10,11,12,13,14, # SPI pins, can also be used for IO
|
27
|
+
15,16,17
|
28
|
+
]
|
29
|
+
|
30
|
+
@@mode = WPI_MODE_PINS
|
31
|
+
@@init = false
|
32
|
+
|
33
|
+
def self.readAll
|
34
|
+
|
35
|
+
self.wiringPiSetup unless @@init
|
36
|
+
|
37
|
+
pinValues = Hash.new
|
38
|
+
|
39
|
+
@@pins.each do |pin|
|
40
|
+
|
41
|
+
pinValues[pin] = self.read(pin)
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
pinValues
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.wiringPiMode( mode )
|
50
|
+
|
51
|
+
@@mode = mode
|
52
|
+
Wiringpi.wiringPiGpioMode( @@mode )
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.wiringPiSetup
|
57
|
+
|
58
|
+
begin
|
59
|
+
Wiringpi.wiringPiSetup
|
60
|
+
rescue Exception=>e
|
61
|
+
raise e
|
62
|
+
end
|
63
|
+
|
64
|
+
Wiringpi.wiringPiGpioMode( @@mode )
|
65
|
+
@@init = true
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.read(pin)
|
70
|
+
|
71
|
+
self.wiringPiSetup unless @@init
|
72
|
+
|
73
|
+
raise ArgumentError, "invalid pin, available gpio pins: #{@@pins}" unless ( @@mode = WPI_MODE_PINS and @@pins.include?(pin) ) or ( @@mode = WPI_MODE_GPIO and @@gpioPins.include?(pin) )
|
74
|
+
|
75
|
+
Wiringpi.digitalRead(pin)
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.pwmWrite(pin,value)
|
80
|
+
|
81
|
+
self.wiringPiSetup unless @@init
|
82
|
+
|
83
|
+
raise ArgumentError, "invalid pin, available gpio pins: #{@@pins}" unless ( @@mode = WPI_MODE_PINS and @@pins.include?(pin) ) or ( @@mode = WPI_MODE_GPIO and @@gpioPins.include?(pin) )
|
84
|
+
|
85
|
+
Wiringpi.pwmWrite(pin,value)
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.write(pin,value)
|
90
|
+
|
91
|
+
self.wiringPiSetup unless @@init
|
92
|
+
|
93
|
+
raise ArgumentError, "invalid pin, available gpio pins: #{@@pins}" unless ( @@mode = WPI_MODE_PINS and @@pins.include?(pin) ) or ( @@mode = WPI_MODE_GPIO and @@gpioPins.include?(pin) )
|
94
|
+
raise ArgumentError, 'invalid value' unless [0,1].include?(value)
|
95
|
+
|
96
|
+
Wiringpi.digitalWrite(pin,value)
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.mode(pin,mode)
|
101
|
+
|
102
|
+
self.wiringPiSetup unless @@init
|
103
|
+
|
104
|
+
raise ArgumentError, "invalid pin, available gpio pins: #{@@pins}" unless ( @@mode = WPI_MODE_PINS and @@pins.include?(pin) ) or ( @@mode = WPI_MODE_GPIO and @@gpioPins.include?(pin) )
|
105
|
+
raise ArgumentError, "invalid mode" unless [INPUT,OUTPUT,PWM_OUTPUT].include?(mode)
|
106
|
+
|
107
|
+
Wiringpi.pinMode(pin, mode)
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wiringpi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: armv6l-linux
|
7
|
+
authors:
|
8
|
+
- Gordon
|
9
|
+
- Phil
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-06-22 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
15
|
+
description: ! 'Alpha version of the WiringPi library wrapper. WiringPi can be found
|
16
|
+
here: http://projects.drogon.net/raspberry-pi/wiringpi/'
|
17
|
+
email: phil@gadgetoid.com
|
18
|
+
executables: []
|
19
|
+
extensions:
|
20
|
+
- ext/wiringpi/extconf.rb
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- lib/wiringpi.rb
|
24
|
+
- ext/wiringpi/wiringpi.c
|
25
|
+
- ext/wiringpi/wiringpi_wrap.c
|
26
|
+
- ext/wiringpi/wiringpi.h
|
27
|
+
- ext/wiringpi/extconf.rb
|
28
|
+
homepage: http://rubygems.org/gems/wiringpi
|
29
|
+
licenses:
|
30
|
+
- GNU General Public License
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 1.8.24
|
50
|
+
signing_key:
|
51
|
+
specification_version: 3
|
52
|
+
summary: Arduino wiring-like library for Raspberry Pi GPIO. Will only work on a Pi.
|
53
|
+
Alpha version.
|
54
|
+
test_files: []
|