gpio_sysfs 0.1.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/lib/gpio_sysfs/pin.rb +70 -0
- data/lib/gpio_sysfs/version.rb +5 -0
- data/lib/gpio_sysfs.rb +9 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c58723e1cb1ff2747eacc0fd4d1dcf56cb11dc142963a4ab4f1be175751b0c8a
|
4
|
+
data.tar.gz: f100e7f8a23e466e36941ee2e77e718f5ded62e3977a0a873a0162152a13c0bb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 713be4e4e64bc75df922d302117a6e904f6cc87c19e120f2aec6bb2fed3ccb9c9f5c3c480ce27480c568561cb14818e0bebaa37a95b8175b7eb67de12214c54c
|
7
|
+
data.tar.gz: 31a0bad9e4b269d054ccac0a1e6435f4846759884b07e7424e22971bf70fb4c0830db61e3dd00df97ace5fc8be392edc538f8f0ea8510c47ad56e45484536ded
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GpioSysfs
|
4
|
+
class Pin
|
5
|
+
attr_accessor :pin
|
6
|
+
|
7
|
+
def initialize(pin)
|
8
|
+
@pin = pin
|
9
|
+
end
|
10
|
+
|
11
|
+
def export
|
12
|
+
return if exported?
|
13
|
+
|
14
|
+
File.write(EXPORT_PATH, pin)
|
15
|
+
end
|
16
|
+
|
17
|
+
def exported?
|
18
|
+
File.exist?(pin_path)
|
19
|
+
end
|
20
|
+
|
21
|
+
def direction
|
22
|
+
export
|
23
|
+
|
24
|
+
File.read(direction_path).chomp
|
25
|
+
end
|
26
|
+
|
27
|
+
def direction=(direction)
|
28
|
+
export
|
29
|
+
|
30
|
+
File.write(direction_path, direction)
|
31
|
+
end
|
32
|
+
|
33
|
+
def value
|
34
|
+
export
|
35
|
+
|
36
|
+
File.read(value_path).to_i.positive?
|
37
|
+
end
|
38
|
+
|
39
|
+
def value=(value)
|
40
|
+
self.direction = "out"
|
41
|
+
|
42
|
+
File.write(value_path, normalized_value(value))
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def pin_path
|
48
|
+
@pin_path ||= File.join(SYS_PATH, "gpio#{pin}")
|
49
|
+
end
|
50
|
+
|
51
|
+
def direction_path
|
52
|
+
@direction_path ||= File.join(pin_path, "direction")
|
53
|
+
end
|
54
|
+
|
55
|
+
def value_path
|
56
|
+
@value_path ||= File.join(pin_path, "value")
|
57
|
+
end
|
58
|
+
|
59
|
+
def normalized_value(value)
|
60
|
+
case value
|
61
|
+
when true
|
62
|
+
1
|
63
|
+
when false
|
64
|
+
0
|
65
|
+
else
|
66
|
+
value
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/gpio_sysfs.rb
ADDED
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gpio_sysfs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maxwell Pray
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-11-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.10.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.10.0
|
27
|
+
description:
|
28
|
+
email: synthead@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/gpio_sysfs.rb
|
34
|
+
- lib/gpio_sysfs/pin.rb
|
35
|
+
- lib/gpio_sysfs/version.rb
|
36
|
+
homepage: https://github.com/synthead/gpio_sysfs
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata: {}
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubygems_version: 3.1.4
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: Portable sysfs-driven GPIO library for Ruby
|
59
|
+
test_files: []
|