wiringpi-ruby 2.0.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 +7 -0
- data/ext/wiringpi/extconf.rb +32 -0
- data/ext/wiringpi/wiringpi_wrap.c +6872 -0
- data/lib/wiringpi.rb +42 -0
- data/lib/wiringpi/event.rb +21 -0
- data/lib/wiringpi/gpio.rb +139 -0
- data/lib/wiringpi/i2c.rb +26 -0
- data/lib/wiringpi/mcp23x17.rb +31 -0
- data/lib/wiringpi/scrollphat.rb +51 -0
- data/lib/wiringpi/serial.rb +49 -0
- data/lib/wiringpi/spi.rb +15 -0
- metadata +56 -0
data/lib/wiringpi.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'wiringpi/wiringpi'
|
2
|
+
module WiringPi
|
3
|
+
extend self
|
4
|
+
|
5
|
+
HIGH = 1
|
6
|
+
LOW = 0
|
7
|
+
|
8
|
+
INPUT = 0
|
9
|
+
OUTPUT = 1
|
10
|
+
PWM_OUTPUT = 1
|
11
|
+
|
12
|
+
PUD_OFF = 0
|
13
|
+
PUD_DOWN = 1
|
14
|
+
PUD_UP = 2
|
15
|
+
|
16
|
+
LSPFIRST = 0
|
17
|
+
MSBFIRST = 1
|
18
|
+
|
19
|
+
class Modules
|
20
|
+
class ModuleBase
|
21
|
+
|
22
|
+
@name = 'Unknown'
|
23
|
+
@pin_base = 0
|
24
|
+
@pin_count = 0
|
25
|
+
@pin_end = 0
|
26
|
+
|
27
|
+
attr_reader :name, :pin_base, :pin_count, :pin_end
|
28
|
+
|
29
|
+
def new
|
30
|
+
@pin_end = @pin_base + @pin_count
|
31
|
+
updateName
|
32
|
+
end
|
33
|
+
|
34
|
+
def updateName
|
35
|
+
@name = ' at offset ' + @pin_base.to_s
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
Dir[File.dirname(__FILE__) + '/wiringpi/*.rb'].each {|file| require file }
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module WiringPi
|
2
|
+
class GPIO
|
3
|
+
def interrupt(pin, edge, &block)
|
4
|
+
Thread.new do
|
5
|
+
@value = digital_read(pin)
|
6
|
+
@last_value = value
|
7
|
+
loop do
|
8
|
+
@last_value = @value
|
9
|
+
@value = digital_read(pin)
|
10
|
+
|
11
|
+
if @value != @last_value
|
12
|
+
next if @value == 0 and edge == :falling_edge
|
13
|
+
next if @value == 1 and edge == :rising_edge
|
14
|
+
break
|
15
|
+
end
|
16
|
+
block.call @value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
module WiringPi
|
2
|
+
class GPIO
|
3
|
+
|
4
|
+
@modules = Array.new
|
5
|
+
@pins = Array.new
|
6
|
+
|
7
|
+
attr_reader :modules, :pins
|
8
|
+
|
9
|
+
def initialize(&block)
|
10
|
+
Wiringpi.wiringPiSetup
|
11
|
+
@pins = Array.new
|
12
|
+
instance_eval &block if block_given?
|
13
|
+
end
|
14
|
+
|
15
|
+
def read_byte(starting_pin)
|
16
|
+
bits = Array.new
|
17
|
+
8.times do |time|
|
18
|
+
bits << Wiringpi.digitalRead(starting_pin + time)
|
19
|
+
end
|
20
|
+
bits.join
|
21
|
+
end
|
22
|
+
|
23
|
+
def write_byte(starting_pin, byte)
|
24
|
+
byte = byte.to_s(2) unless byte.length = 8
|
25
|
+
offset = starting_pin
|
26
|
+
byte.each_char do |bit|
|
27
|
+
Wiringpi.digitalWrite(offset, bit)
|
28
|
+
offset += 1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def digital_read(pin)
|
33
|
+
if pin.respond_to?(:each)
|
34
|
+
pin.collect do |pin|
|
35
|
+
Wiringpi.digitalRead(pin)
|
36
|
+
end
|
37
|
+
else
|
38
|
+
Wiringpi.digitalRead(pin)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def digital_write(pin, value)
|
43
|
+
if pin.respond_to?(:each)
|
44
|
+
pin.each do |pin|
|
45
|
+
Wiringpi.digitalWrite(pin, value)
|
46
|
+
end
|
47
|
+
else
|
48
|
+
Wiringpi.digitalWrite(pin, value)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def pin_mode(pin, mode)
|
53
|
+
Wiringpi.pinMode(pin, mode)
|
54
|
+
end
|
55
|
+
|
56
|
+
def pull_up_dn_control(pin,mode)
|
57
|
+
Wiringpi.pullUpDnControl(pin, mode)
|
58
|
+
end
|
59
|
+
|
60
|
+
def delay(ms)
|
61
|
+
Wiringpi.delay(ms)
|
62
|
+
end
|
63
|
+
|
64
|
+
def delay_microseconds(ms)
|
65
|
+
Wiringpi.delayMicroseconds(ms)
|
66
|
+
end
|
67
|
+
|
68
|
+
def millis()
|
69
|
+
return Wiringpi.millis()
|
70
|
+
end
|
71
|
+
|
72
|
+
def micros()
|
73
|
+
return Wiringpi.micros()
|
74
|
+
end
|
75
|
+
|
76
|
+
def pi_board_rev()
|
77
|
+
return Wiringpi.piBoardRev()
|
78
|
+
end
|
79
|
+
|
80
|
+
def wpi_pin_to_gpio(pin)
|
81
|
+
return Wiringpi.wpiPinToGpio(pin)
|
82
|
+
end
|
83
|
+
|
84
|
+
def phys_pin_to_gpio(pin)
|
85
|
+
return Wiringpi.physPinToGpio(pin)
|
86
|
+
end
|
87
|
+
|
88
|
+
def pwm_set_mode(mode)
|
89
|
+
return Wiringpi.pwmSetMode(mode)
|
90
|
+
end
|
91
|
+
|
92
|
+
def pwm_set_range(range)
|
93
|
+
return Wiringpi.pwmSetRange(range)
|
94
|
+
end
|
95
|
+
|
96
|
+
def pwm_set_clock(divisor)
|
97
|
+
return Wiringpi.pwmSetClock(divisor)
|
98
|
+
end
|
99
|
+
|
100
|
+
def soft_pwm_create(pin, initial_value, pwm_range)
|
101
|
+
return Wiringpi.softPwmCreate(pin, initial_value, pwm_range)
|
102
|
+
end
|
103
|
+
|
104
|
+
def soft_pwm_write(pin, value)
|
105
|
+
Wiringpi.softPwmWrite(pin, value)
|
106
|
+
end
|
107
|
+
|
108
|
+
def gpio_clock_set(pin, freq)
|
109
|
+
return Wiringpi.gpioClockSet(pin, freq)
|
110
|
+
end
|
111
|
+
|
112
|
+
def wait_for_interrupt(pin, ms)
|
113
|
+
Wiringpi.waitForInterrupt(pin, ms)
|
114
|
+
end
|
115
|
+
|
116
|
+
def wiringpi_isr(pin, mode, fn)
|
117
|
+
Wiringpi.wiringPiISR(pin, mode, fn)
|
118
|
+
end
|
119
|
+
|
120
|
+
def shift_out(dpin, cpin, order, val )
|
121
|
+
Wiringpi.shiftOut(dpin,cpin,order,val)
|
122
|
+
end
|
123
|
+
|
124
|
+
def shift_in(dpin, cpin, order)
|
125
|
+
Wiringpi.shiftIn(dpin,cpin,order)
|
126
|
+
end
|
127
|
+
|
128
|
+
def add_module(module_instance)
|
129
|
+
@modules = Array.new if @modules.nil?
|
130
|
+
|
131
|
+
@modules << module_instance
|
132
|
+
puts 'Added module ' + module_instance.name.to_s
|
133
|
+
|
134
|
+
module_instance.pin_count.times do |offset|
|
135
|
+
@pins[offset + module_instance.pin_base] = 'ENABLED'
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
data/lib/wiringpi/i2c.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module WiringPi
|
2
|
+
class I2C
|
3
|
+
@device_id = 0
|
4
|
+
def initialize(device_address)
|
5
|
+
@device_id = Wiringpi.wiringPiI2CSetup(device_address)
|
6
|
+
end
|
7
|
+
def read()
|
8
|
+
return Wiringpi.wiringPiI2CRead(@device_id)
|
9
|
+
end
|
10
|
+
def write(data)
|
11
|
+
return Wiringpi.wiringPiI2CWrite(@device_id,data)
|
12
|
+
end
|
13
|
+
def read_reg_8(reg)
|
14
|
+
return Wiringpi.wiringPiI2CReadReg8(@device_id,reg)
|
15
|
+
end
|
16
|
+
def write_reg_8(reg,data)
|
17
|
+
return Wiringpi.wiringPiI2CWriteReg8(@device_id,reg,data)
|
18
|
+
end
|
19
|
+
def read_reg_16(reg)
|
20
|
+
return Wiringpi.wiringPiI2CReadReg16(@device_id,reg)
|
21
|
+
end
|
22
|
+
def write_reg_16(reg,data)
|
23
|
+
return Wiringpi.wiringPiI2CWriteReg16(@device_id,reg,data)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module WiringPi
|
2
|
+
class Modules
|
3
|
+
class Mcp23017 < ModuleBase
|
4
|
+
|
5
|
+
@i2c_address = 0x0
|
6
|
+
|
7
|
+
def initialize(pin_base, i2c_address)
|
8
|
+
@pin_base = pin_base
|
9
|
+
@pin_count = 16
|
10
|
+
@i2c_address = i2c_address
|
11
|
+
Wiringpi.mcp23017Setup( pin_base, i2c_address )
|
12
|
+
super()
|
13
|
+
end
|
14
|
+
end
|
15
|
+
class Mcp23s17 < ModuleBase
|
16
|
+
|
17
|
+
@spi_port = 0
|
18
|
+
@device_id = 0
|
19
|
+
|
20
|
+
def initialize(pin_base, spi_port, device_id)
|
21
|
+
@pin_base = pin_base
|
22
|
+
@pin_count = 16
|
23
|
+
@spi_port = spi_port
|
24
|
+
@device_id = device_id
|
25
|
+
Wiringpi.mcp23s17Setup( pin_base, spi_port, device_id )
|
26
|
+
super()
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module WiringPi
|
2
|
+
class ScrollPhat
|
3
|
+
def initialize()
|
4
|
+
Wiringpi.scrollPhatSetup()
|
5
|
+
end
|
6
|
+
|
7
|
+
def printf(text)
|
8
|
+
Wiringpi.scrollPhatPrintf(text)
|
9
|
+
end
|
10
|
+
|
11
|
+
def point(x, y, colour)
|
12
|
+
Wiringpi.scrollPhatPoint(x, y, colour)
|
13
|
+
end
|
14
|
+
|
15
|
+
def line(x0, y0, x1, y1, colour)
|
16
|
+
Wiringpi.scrollPhatLine(x0, y0, x1, y1, colour)
|
17
|
+
end
|
18
|
+
|
19
|
+
def lineTo(x, y, colour)
|
20
|
+
Wiringpi.scrollPhatLineTo(x, y, colour)
|
21
|
+
end
|
22
|
+
|
23
|
+
def rectangle(x1, y1, x2, y2, colour)
|
24
|
+
Wiringpi.scrollPhatRectangle(x1, y1, x2, y2, colour)
|
25
|
+
end
|
26
|
+
|
27
|
+
def update()
|
28
|
+
Wiringpi.scrollPhatUpdate()
|
29
|
+
end
|
30
|
+
|
31
|
+
def clear()
|
32
|
+
Wiringpi.scrollPhatClear()
|
33
|
+
end
|
34
|
+
|
35
|
+
def putChar(char)
|
36
|
+
Wiringpi.scrollPhatPutchar(char)
|
37
|
+
end
|
38
|
+
|
39
|
+
def puts(str)
|
40
|
+
Wiringpi.scrollPhatPuts(str)
|
41
|
+
end
|
42
|
+
|
43
|
+
def printSpeed(cps10)
|
44
|
+
Wiringpi.scrollPhatPrintSpeed(cps10)
|
45
|
+
end
|
46
|
+
|
47
|
+
def intensity(percent)
|
48
|
+
Wiringpi.scrollPhatIntensity(percent)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module WiringPi
|
2
|
+
class Serial
|
3
|
+
|
4
|
+
@id = 0
|
5
|
+
@device = '/dev/ttyAMA0'
|
6
|
+
@baud = 9600
|
7
|
+
|
8
|
+
def initialize(device='/dev/ttyAMA0', baud=9600)
|
9
|
+
|
10
|
+
@device = device
|
11
|
+
@baud = baud
|
12
|
+
|
13
|
+
@id = Wiringpi.serialOpen(@device, @baud)
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def serial_close
|
18
|
+
|
19
|
+
Wiringpi.serialClose(@id)
|
20
|
+
@id = 0
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def serial_put_char(char)
|
25
|
+
|
26
|
+
Wiringpi.serialPutchar(@id, char)
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def serial_puts(string)
|
31
|
+
|
32
|
+
Wiringpi.serialPuts(@id, string)
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def serial_data_avail
|
37
|
+
|
38
|
+
Wiringpi.serialDataAvail(@id)
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def serial_get_char
|
43
|
+
|
44
|
+
Wiringpi.serialGetchar(@id)
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
data/lib/wiringpi/spi.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module WiringPi
|
2
|
+
class SPI
|
3
|
+
@channel = 0
|
4
|
+
def initialize(channel,speed)
|
5
|
+
@channel = channel
|
6
|
+
Wiringpi.wiringPiSPISetup(channel,speed)
|
7
|
+
end
|
8
|
+
def wiringPiSPIGetFd()
|
9
|
+
return Wiringpi.wiringPiSPIGetFd(@channel)
|
10
|
+
end
|
11
|
+
def wiringPiSPIDataRW(data)
|
12
|
+
return Wiringpi.wiringPiSPIDataRW(@channel,data)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wiringpi-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rifqi
|
8
|
+
- Fauzi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2021-06-30 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: 'WiringPi library wrapper for the Raspberry Pi. Wraps up version 2.x
|
15
|
+
of the Arduino wiring-like WiringPi library into a convinient Ruby gem. Credit to
|
16
|
+
Gordon for the WiringPi library, which can be found here: http://www.wiringpi.com'
|
17
|
+
email: no-reply@gmail.com
|
18
|
+
executables: []
|
19
|
+
extensions:
|
20
|
+
- ext/wiringpi/extconf.rb
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- ext/wiringpi/extconf.rb
|
24
|
+
- ext/wiringpi/wiringpi_wrap.c
|
25
|
+
- lib/wiringpi.rb
|
26
|
+
- lib/wiringpi/event.rb
|
27
|
+
- lib/wiringpi/gpio.rb
|
28
|
+
- lib/wiringpi/i2c.rb
|
29
|
+
- lib/wiringpi/mcp23x17.rb
|
30
|
+
- lib/wiringpi/scrollphat.rb
|
31
|
+
- lib/wiringpi/serial.rb
|
32
|
+
- lib/wiringpi/spi.rb
|
33
|
+
homepage: http://rubygems.org/gems/wiringpi-ruby
|
34
|
+
licenses:
|
35
|
+
- GNU Lesser General Public License v3
|
36
|
+
metadata: {}
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubygems_version: 3.2.15
|
53
|
+
signing_key:
|
54
|
+
specification_version: 4
|
55
|
+
summary: Forked from WiringPi-Ruby.
|
56
|
+
test_files: []
|