raspi-gpio 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/raspi-gpio.rb +69 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0ad59ed3ff2152b5b518c09e5a1c174aa345645fe28a59e46e10c4a1b9d02830
|
4
|
+
data.tar.gz: fb9f1fbac3770add6a2100e947c07657913444ea8c35a85806e276c7a0c78f4d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dbc135c394dd882cfca0169856a2f6994628bc129f38f6d4af0ff03e235a2e4ed113a052fef3c772584bded10b4f238c3972dd80cc37ad11256fdede336380e0
|
7
|
+
data.tar.gz: 2120f9206a0ba4236a0280252ac4c4f1b33a4d66f88bfd19ca218ba9a3d7e2c5866136781dba9e06f9b309d1c95354ed7e8b8102891a2e1acf28b785520714b8
|
data/lib/raspi-gpio.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# GPIO core library path
|
2
|
+
LIB_PATH = '/sys/class/gpio'
|
3
|
+
|
4
|
+
# Shortcuts for pin values
|
5
|
+
LOW = 0
|
6
|
+
HIGH = 1
|
7
|
+
|
8
|
+
IN = 'in'
|
9
|
+
OUT = 'out'
|
10
|
+
|
11
|
+
# Exception to handle unknown pin mode (not 'in' or 'out')
|
12
|
+
class UnknownMode < StandardError
|
13
|
+
end
|
14
|
+
|
15
|
+
class NotOutMode < StandardError
|
16
|
+
end
|
17
|
+
|
18
|
+
# Exception to handle bad pin value (not 0 or 1)
|
19
|
+
class BadValue < StandardError
|
20
|
+
end
|
21
|
+
|
22
|
+
# GPIO class
|
23
|
+
class GPIO
|
24
|
+
|
25
|
+
# Initialize the GPIO pin
|
26
|
+
#
|
27
|
+
# @param pin [Integer] GPIO pin to use
|
28
|
+
# @param mode [String, nil] pin mode ('in' or 'out')
|
29
|
+
def initialize(pin, mode = OUT)
|
30
|
+
@pin = pin
|
31
|
+
begin
|
32
|
+
File.open("#{LIB_PATH}/export", 'w') do |file|
|
33
|
+
file.write(@pin)
|
34
|
+
end
|
35
|
+
rescue Errno::EBUSY
|
36
|
+
# -
|
37
|
+
end
|
38
|
+
@mode = mode
|
39
|
+
end
|
40
|
+
|
41
|
+
# Set the pin mode
|
42
|
+
#
|
43
|
+
# @param mode [String] pin mode ('in' or 'out')
|
44
|
+
def set_mode(mode)
|
45
|
+
raise UnknownMode, "gpio error : unknown mode #{mode}" unless mode == IN or mode == OUT
|
46
|
+
File.open("#{LIB_PATH}/gpio#{@pin}/direction", 'w') do |file|
|
47
|
+
file.write(mode)
|
48
|
+
end
|
49
|
+
@mode = mode
|
50
|
+
end
|
51
|
+
|
52
|
+
# Read the value of the pin
|
53
|
+
#
|
54
|
+
# @return [Boolean]
|
55
|
+
def get_value
|
56
|
+
File.open("#{LIB_PATH}/gpio#{@pin}/value", 'r').read
|
57
|
+
end
|
58
|
+
|
59
|
+
# Set a value to the pin
|
60
|
+
#
|
61
|
+
# @param v [Integer] the value (0 or 1)
|
62
|
+
def set_value(v)
|
63
|
+
raise NotOutMode, "error : mode isn't OUT" unless @mode == OUT
|
64
|
+
raise BadValue, "error : bad pin value" unless v.between? 0,1
|
65
|
+
File.open("#{LIB_PATH}/gpio#{@pin}/value", 'w') do |file|
|
66
|
+
file.write(v)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: raspi-gpio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Exybore
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-02-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple and light interface to interact with GPIO pins of the Raspberry
|
14
|
+
Pi.
|
15
|
+
email: exybore@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/raspi-gpio.rb
|
21
|
+
homepage: https://github.com/exybore/raspi-gpio-rb
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata:
|
25
|
+
source_code_uri: https://github.com/exybore/raspi-gpio-rb
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubygems_version: 3.0.1
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Simple & light Raspberry Pi GPIO interface.
|
45
|
+
test_files: []
|