mruby-sysfs-gpio 0.9.2 → 1.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 +4 -4
- data/README.md +9 -0
- data/lib/mruby/gpio/sysfs/gpio_sysfs.rb +19 -32
- data/lib/mruby/gpio/sysfs/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb917e12cce816c2b697c373998159c1aa65837452fa232ba484f6cc1fe0560e
|
4
|
+
data.tar.gz: 46ed16bba8561ad357c5f17c2e007356986211ad56a9cf0fa60399eef28c44ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: faf269900edb889f54e7b540cc20bf447deb1f23429938bce58a92304cc63940fe7db41ec583f6b252b2877cd022ba879cf21c94d3a6070381c5eb0ece137223
|
7
|
+
data.tar.gz: 3e9effd008df980a8f3ffd69958618a3a9d24ebc78d02df90f25099a55f5304fb5199ba3859491a116e13d86fdf4eb9d56244f877544ae715f1c66aec8c062a5
|
data/README.md
CHANGED
@@ -7,6 +7,9 @@
|
|
7
7
|
This is an implementation of the GPIO class library for Linux.
|
8
8
|
Follows [mruby, mruby/c common I/O API guidelines.](https://github.com/mruby/microcontroller-peripheral-interface-guide)
|
9
9
|
|
10
|
+
This library uses the Linux sysfs.
|
11
|
+
Works well on 32-bit and 64-bit OS.
|
12
|
+
|
10
13
|
|
11
14
|
## Installation
|
12
15
|
|
@@ -19,6 +22,12 @@ Follows [mruby, mruby/c common I/O API guidelines.](https://github.com/mruby/mic
|
|
19
22
|
* Has an extension that allows you to define code to be executed when the input changes.
|
20
23
|
|
21
24
|
|
25
|
+
## Operation check target
|
26
|
+
|
27
|
+
* [Raspberry Pi 4](https://www.raspberrypi.com/products/raspberry-pi-4-model-b/)
|
28
|
+
* [Armadillo-IoT G3](https://armadillo.atmark-techno.com/armadillo-iot-g3)
|
29
|
+
|
30
|
+
|
22
31
|
## Usage
|
23
32
|
|
24
33
|
about RaspberryPi...
|
@@ -16,6 +16,7 @@ class GPIO
|
|
16
16
|
DRIVER = "sysfs"
|
17
17
|
|
18
18
|
# Constants
|
19
|
+
UNUSED = 0b0000_0000 # option
|
19
20
|
IN = 0b0000_0001
|
20
21
|
OUT = 0b0000_0010
|
21
22
|
HIGH_Z = 0b0000_0100
|
@@ -23,11 +24,8 @@ class GPIO
|
|
23
24
|
PULL_DOWN = 0b0001_0000
|
24
25
|
OPEN_DRAIN = 0b0010_0000
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
FALLING = 0b1000_0000
|
29
|
-
BOTH = 0b1100_0000
|
30
|
-
UNUSED = 0b0000_0000
|
27
|
+
EDGE_RISE = 0b0001_0000_0000
|
28
|
+
EDGE_FALL = 0b0010_0000_0000
|
31
29
|
|
32
30
|
PATH_SYSFS = "/sys/class/gpio"
|
33
31
|
|
@@ -183,7 +181,7 @@ class GPIO
|
|
183
181
|
# constructor
|
184
182
|
#
|
185
183
|
#@param [Integer] pin pin number
|
186
|
-
#@param [Constant] params modes
|
184
|
+
#@param [Constant] params modes (GPIO::IN or GPIO::OUT)
|
187
185
|
#
|
188
186
|
def initialize( pin, params )
|
189
187
|
@pin = pin
|
@@ -199,7 +197,7 @@ class GPIO
|
|
199
197
|
#
|
200
198
|
def read()
|
201
199
|
@value.sysseek( 0 )
|
202
|
-
return @value.sysread(
|
200
|
+
return @value.sysread(10).to_i
|
203
201
|
end
|
204
202
|
|
205
203
|
|
@@ -254,27 +252,23 @@ class GPIO
|
|
254
252
|
|
255
253
|
|
256
254
|
##
|
257
|
-
#
|
258
|
-
# (extend)
|
255
|
+
# (option) IRQ event handling
|
259
256
|
#
|
260
|
-
#@param [Constant]
|
261
|
-
#@param [Integer] bounce_ms bounce time
|
262
|
-
#@return [
|
257
|
+
#@param [Constant] cond EDGE_RISE or EDGE_FALL
|
258
|
+
#@param [Integer] bounce_ms bounce time in milliseconds.
|
259
|
+
#@return [void]
|
263
260
|
#
|
264
261
|
#@example
|
265
|
-
# gpio.
|
262
|
+
# gpio.irq( GPIO::EDGE_RISE ) {|reason| puts "Rising UP." }
|
266
263
|
#
|
267
|
-
def
|
268
|
-
if !@
|
264
|
+
def irq( cond, bounce_ms:50, &block )
|
265
|
+
if !@irq_thread
|
269
266
|
File.binwrite("#{PATH_SYSFS}/gpio#{@pin}/edge", "both")
|
270
267
|
@bounce_time = bounce_ms / 1000.0
|
271
|
-
@events_rising = []
|
272
|
-
@events_falling = []
|
273
|
-
|
274
268
|
@value.sysseek( 0 )
|
275
|
-
v1 = @value.sysread(
|
269
|
+
v1 = @value.sysread(10).to_i
|
276
270
|
|
277
|
-
@
|
271
|
+
@irq_thread = Thread.new {
|
278
272
|
while true
|
279
273
|
@value.sysseek(0)
|
280
274
|
rs,ws,es = IO.select(nil, nil, [@value], 1)
|
@@ -283,9 +277,9 @@ class GPIO
|
|
283
277
|
v2 = @value.sysread(10).to_i
|
284
278
|
|
285
279
|
if v1 == 0 && v2 == 1
|
286
|
-
@
|
280
|
+
@handler_rise && @handler_rise.call( EDGE_RISE )
|
287
281
|
elsif v1 == 1 && v2 == 0
|
288
|
-
@
|
282
|
+
@handler_fall && @handler_fall.call( EDGE_FALL )
|
289
283
|
end
|
290
284
|
|
291
285
|
v1 = v2
|
@@ -293,17 +287,10 @@ class GPIO
|
|
293
287
|
}
|
294
288
|
end
|
295
289
|
|
296
|
-
|
297
|
-
|
298
|
-
@events_rising << block
|
299
|
-
when FALLING
|
300
|
-
@events_falling << block
|
301
|
-
when BOTH
|
302
|
-
@events_rising << block
|
303
|
-
@events_falling << block
|
304
|
-
end
|
290
|
+
@handler_rise = block if (cond & EDGE_RISE) != 0
|
291
|
+
@handler_fall = block if (cond & EDGE_FALL) != 0
|
305
292
|
|
306
|
-
return
|
293
|
+
return nil
|
307
294
|
end
|
308
295
|
|
309
296
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mruby-sysfs-gpio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HirohitoHigashi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -28,8 +28,8 @@ licenses:
|
|
28
28
|
- BSD 3-CLAUSE
|
29
29
|
metadata:
|
30
30
|
homepage_uri: https://github.com/HirohitoHigashi/mruby-mio/
|
31
|
-
source_code_uri: https://github.com/HirohitoHigashi/mruby-mio/tree/
|
32
|
-
documentation_uri: https://www.rubydoc.info/gems/mruby-sysfs-gpio
|
31
|
+
source_code_uri: https://github.com/HirohitoHigashi/mruby-mio/tree/v1.0.0/mruby-sysfs-gpio
|
32
|
+
documentation_uri: https://www.rubydoc.info/gems/mruby-sysfs-gpio/1.0.0/
|
33
33
|
post_install_message:
|
34
34
|
rdoc_options: []
|
35
35
|
require_paths:
|
@@ -38,7 +38,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
38
38
|
requirements:
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: 2.
|
41
|
+
version: 2.5.0
|
42
42
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - ">="
|