raspi-gpio 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/raspi-gpio.rb +31 -12
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ad59ed3ff2152b5b518c09e5a1c174aa345645fe28a59e46e10c4a1b9d02830
4
- data.tar.gz: fb9f1fbac3770add6a2100e947c07657913444ea8c35a85806e276c7a0c78f4d
3
+ metadata.gz: 4090a815424c69468a90e4967471b31fdad4b546101146c1defda003400a8faa
4
+ data.tar.gz: 6d90479e68bec065740ab4ffcd18e065ce21e0ba98db2b868620ae5ee6cb1efa
5
5
  SHA512:
6
- metadata.gz: dbc135c394dd882cfca0169856a2f6994628bc129f38f6d4af0ff03e235a2e4ed113a052fef3c772584bded10b4f238c3972dd80cc37ad11256fdede336380e0
7
- data.tar.gz: 2120f9206a0ba4236a0280252ac4c4f1b33a4d66f88bfd19ca218ba9a3d7e2c5866136781dba9e06f9b309d1c95354ed7e8b8102891a2e1acf28b785520714b8
6
+ metadata.gz: 85656902aa5de465d735d7bba0954164ae5f9d8e736957f1b14688f4ff0387550b570f37a30ebe78f3228334290a0f40c9dc7ca1ef37a0e98a336bd8fc62ec79
7
+ data.tar.gz: 26ce7953054d037975ef57780af70f1162677e9f824f67bfdc7ce4552104122944c0f2355d71563ef5b20ae985de67806eb67867f1d3631fdee63fb2617cb522
@@ -1,46 +1,62 @@
1
+ # raspi-gpio - A simple and light interface to interact with GPIO pins of the Raspberry Pi.
2
+ # Guide and source code : https://github.com/exybore/raspi-gpio-rb
3
+ # Documentation : https://rubydoc.info/gems/raspi-gpio
4
+ #
5
+ # @author exybore
6
+
1
7
  # GPIO core library path
2
8
  LIB_PATH = '/sys/class/gpio'
3
9
 
4
- # Shortcuts for pin values
10
+ # Shortcut for low pin value (0)
5
11
  LOW = 0
12
+
13
+ # Shortcut for high pin value (1)
6
14
  HIGH = 1
7
15
 
16
+ # Shortcut for 'in' pin mode
8
17
  IN = 'in'
18
+
19
+ # Shortcut for 'out' pin mode
9
20
  OUT = 'out'
10
21
 
11
- # Exception to handle unknown pin mode (not 'in' or 'out')
22
+ # Exception to handle unknown pin mode (not IN or OUT)
12
23
  class UnknownMode < StandardError
13
24
  end
14
25
 
26
+ # Exception to handle pin writing when not in OUT mode
15
27
  class NotOutMode < StandardError
16
28
  end
17
29
 
18
- # Exception to handle bad pin value (not 0 or 1)
30
+ # Exception to handle bad pin value (not LOW or HIGH)
19
31
  class BadValue < StandardError
20
32
  end
21
33
 
22
- # GPIO class
34
+ # Main class, to manage GPIO pins
23
35
  class GPIO
24
36
 
25
37
  # Initialize the GPIO pin
26
38
  #
27
- # @param pin [Integer] GPIO pin to use
28
- # @param mode [String, nil] pin mode ('in' or 'out')
39
+ # @param pin [Integer] GPIO pin number to use
40
+ # @param mode [String] pin mode : IN or OUT
29
41
  def initialize(pin, mode = OUT)
30
42
  @pin = pin
31
43
  begin
32
- File.open("#{LIB_PATH}/export", 'w') do |file|
44
+ File.open("#{LIB_PATH}/unexport", 'w') do |file|
33
45
  file.write(@pin)
34
46
  end
35
- rescue Errno::EBUSY
36
- # -
47
+ rescue Errno::EINVAL
48
+ # Do nothing - the pin is already unexported
49
+ end
50
+ File.open("#{LIB_PATH}/export", 'w') do |file|
51
+ file.write(@pin)
37
52
  end
38
53
  @mode = mode
39
54
  end
40
55
 
41
56
  # Set the pin mode
42
57
  #
43
- # @param mode [String] pin mode ('in' or 'out')
58
+ # @param mode [String] pin mode : IN or OUT
59
+ # @raise [UnknownMode] if the mode isn't IN or OUT
44
60
  def set_mode(mode)
45
61
  raise UnknownMode, "gpio error : unknown mode #{mode}" unless mode == IN or mode == OUT
46
62
  File.open("#{LIB_PATH}/gpio#{@pin}/direction", 'w') do |file|
@@ -51,14 +67,17 @@ class GPIO
51
67
 
52
68
  # Read the value of the pin
53
69
  #
54
- # @return [Boolean]
70
+ # @return [Integer] pin's value : 0 or 1
55
71
  def get_value
56
72
  File.open("#{LIB_PATH}/gpio#{@pin}/value", 'r').read
57
73
  end
58
74
 
59
75
  # Set a value to the pin
76
+ # This method can only be used when the pin is in OUT mode
60
77
  #
61
- # @param v [Integer] the value (0 or 1)
78
+ # @param v [Integer] the value : LOW or HIGH
79
+ # @raise [NotOutMode] if the pin isn't in OUT mode
80
+ # @raise [BadValue] if the provided value isn't LOW or HIGH
62
81
  def set_value(v)
63
82
  raise NotOutMode, "error : mode isn't OUT" unless @mode == OUT
64
83
  raise BadValue, "error : bad pin value" unless v.between? 0,1
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raspi-gpio
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Exybore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-20 00:00:00.000000000 Z
11
+ date: 2019-02-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple and light interface to interact with GPIO pins of the Raspberry
14
14
  Pi.
@@ -41,5 +41,5 @@ requirements: []
41
41
  rubygems_version: 3.0.1
42
42
  signing_key:
43
43
  specification_version: 4
44
- summary: Simple & light Raspberry Pi GPIO interface.
44
+ summary: "\U0001F50C Simple & light Raspberry Pi GPIO interface."
45
45
  test_files: []