mruby-sysfs-gpio 0.9.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c433286a8efee3dc6f6b616e8325d414212377c692effdd9fb3f454e4255cafa
4
- data.tar.gz: 99958321f531066575f299feb83f0518713e7a553f863bda0af8e5c5806a476c
3
+ metadata.gz: eb917e12cce816c2b697c373998159c1aa65837452fa232ba484f6cc1fe0560e
4
+ data.tar.gz: 46ed16bba8561ad357c5f17c2e007356986211ad56a9cf0fa60399eef28c44ef
5
5
  SHA512:
6
- metadata.gz: a9be8d6f361203b23cbc3602d6f2e6d824209c0b1acf38aba71f33b6a62d2794ae551a203445cef1be57a0731078c5ff920a64559ebe41924c848e462c8d04f6
7
- data.tar.gz: f191b94e683ecf83bda73b418c51181aa2b08f89023549cab56d8363d5351a009d55de6d0585ad4a2d4325dfd83961e9596be06a6e2ec628c7c23f3ed8d170ce
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
- # extend
27
- RISING = 0b0100_0000
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
 
@@ -254,27 +252,23 @@ class GPIO
254
252
 
255
253
 
256
254
  ##
257
- # rising/falling edge event
258
- # (extend)
255
+ # (option) IRQ event handling
259
256
  #
260
- #@param [Constant] edge GPIO::RISING, GPIO::FALLING or GPIO::BOTH
257
+ #@param [Constant] cond EDGE_RISE or EDGE_FALL
261
258
  #@param [Integer] bounce_ms bounce time in milliseconds.
262
- #@return [Thread] event thread.
259
+ #@return [void]
263
260
  #
264
261
  #@example
265
- # gpio.event( GPIO::RISING ) { puts "Rising UP." }
262
+ # gpio.irq( GPIO::EDGE_RISE ) {|reason| puts "Rising UP." }
266
263
  #
267
- def event( edge, bounce_ms:50, &block )
268
- if !@event_thread
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
269
  v1 = @value.sysread(10).to_i
276
270
 
277
- @event_thread = Thread.new {
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
- @events_rising.each {|event| event.call( v2 ) }
280
+ @handler_rise && @handler_rise.call( EDGE_RISE )
287
281
  elsif v1 == 1 && v2 == 0
288
- @events_falling.each {|event| event.call( v2 ) }
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
- case edge
297
- when RISING
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 @event_thread
293
+ return nil
307
294
  end
308
295
 
309
296
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class GPIO
4
- VERSION = "0.9.3"
4
+ VERSION = "1.0.0"
5
5
  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.9.3
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-10-14 00:00:00.000000000 Z
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/main/mruby-sysfs-gpio
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.6.0
41
+ version: 2.5.0
42
42
  required_rubygems_version: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - ">="