c_gpio 0.0.5 → 0.0.6

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +134 -0
  3. data/lib/c_gpio.rb +33 -0
  4. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5cd82e4b29799d13c1a63c6ec7dbcf7b3c96e869
4
- data.tar.gz: 39a6cf9317d22980a076c39a64f2a30e17473199
3
+ metadata.gz: 7ccafeaa0502815b135c4bc830c182bbf0824c79
4
+ data.tar.gz: 0c8dd4659fe70110185f72f5252a5a9d3ac8976d
5
5
  SHA512:
6
- metadata.gz: c51a22897cf2414ef0774bd989edd69c5981230cc0710f2ace3cee2369f644641f7418d2d28e339474bc0f174586280a27a5e9e5f2dab886677f1ce7420fad92
7
- data.tar.gz: 3c89cf81a22997184a86aeda24fc2e82d33332d722354c53913544327c8561c353553e6995d91d9ca4b80d9bdebf53754f066a51e387f443a59c3f81304b5246
6
+ metadata.gz: effcf66a43487ad13acce3b6036e32dd127ab46a743a3c8b62cba7c36d3aeea37e08a7e227a226d0d39f9176cc303a48ef864b6223734f66565e3ff36b6975bf
7
+ data.tar.gz: 8b4a5010ea9211373be756ff74cee6962301e764651ab623c7d234dc9492e5c5bb39a2cf8f004b5e508192b89231db1b115999ac7d84d7e363a48cae9528833f
@@ -0,0 +1,134 @@
1
+ # c_GPIO
2
+
3
+ c_GPIO is a rubygem for controlling GPIO Ports of raspberry PIs out of ruby.
4
+
5
+ It provides an easy to use interface for accessing the GPIO feature. c_GPIO is written in C to be as close as possible to the system.
6
+
7
+ I also wrote this as ruby c extension to learn a bit about C.
8
+
9
+ c_GPIO provides predefined classes for
10
+
11
+ - LED
12
+ - Buttons
13
+
14
+ There is a base class available as well which provides manual setting of direction (IN / OUT) and value (HIGH / LOW).
15
+
16
+ ## Usage / Examples
17
+
18
+ Here you will find various examples for this gem.
19
+
20
+ #### Turning a LED on and off
21
+
22
+ require 'c_gpio'
23
+
24
+ led = GPIO::Led.new(2) # Initialize a LED connected to PIN 2
25
+
26
+ led.turn_on! # Turn on the LED
27
+
28
+ sleep(1) # Wait a second
29
+
30
+ led.turn_off! # Turn off the LED
31
+
32
+ #### Connect a button to GPIO
33
+
34
+ require 'c_gpio'
35
+
36
+ button = GPIO::Button.new(2) # Initialize a button connected to PIN 2
37
+
38
+ # pressed? will return true, if the button is being pressed,
39
+ # otherwise it will return false
40
+ if(button.pressed?) {
41
+ puts "The button is currently pressed"
42
+ }
43
+
44
+ # If you want to get notified, once a button is pressed or released,
45
+ # You can easily use one (or both) of the following callbacks
46
+
47
+ button.on_press do
48
+ puts "You pressed da button"
49
+ end
50
+
51
+ button.on_release do
52
+ puts "ou stopped pressing the button"
53
+ end
54
+
55
+ #### Controlling a PWM Engine
56
+
57
+ Please note that this is experimental. This gem will create a PWM signal using the CPU which might not be that accurate.
58
+ You can still try it and you are welcome to have a look at the implementation if. Give feedback an collaborate in optimizing it.
59
+
60
+ require 'c_gpio'
61
+
62
+ stepper = GPIO::Pwm.new(2) # Initialize a stepping motor connected to PIN 2
63
+
64
+ # Move the stepper to the one side (0 is the lowest value you can submit)
65
+ stepper.move_to(0)
66
+
67
+ # Move the stepper to the middle position
68
+ stepper.move_to(100)
69
+
70
+ # Move the stepper to the other side (200 is the highest value you can submit)
71
+ stepper.move_to(200)
72
+
73
+ Because of the CPU of a PI being unprecise, this class stopps sending a PWM signal after ~1400ms.
74
+ Your stepper will have to reach it's final position after this time. I decided to stop the PWM signal after 1400ms because otherwise, the stepper will start jittering. The reason for this that generating a PWM signal from the CPU is not that accurate as from an arduino. If you know a more precise implementation of PWM signals, feel free to contact me.
75
+
76
+ #### Using the Base class for reading custom parts
77
+
78
+ require 'c_gpio'
79
+
80
+ io = GPIO::Base.new(2) # We want to read from PIN 2
81
+
82
+ io.direction = :in # Setting the direction to "in", so we can read
83
+
84
+ io.value # will return :high or :low depending on what your sensor says
85
+
86
+ #### Using the Base class for writing custom parts
87
+
88
+ require 'c_gpio'
89
+
90
+ io = GPIO::Base.new(2) # We want to write to PIN 2
91
+
92
+ io.direction = :out # Setting the direction to "out", so we can write
93
+
94
+ io.value = :high # will power the connected part on
95
+
96
+ io.value = :low # will power the connected part off
97
+
98
+ #### Using callbacks of the Base class
99
+
100
+ Those callbacks can be used for both directions, "IN" and "OUT".
101
+ Using them you can observe, if your peripheral device changed the signal from HIGH to LOW or from LOW to HIGH.
102
+ If the direction is set to "OUT", you also can observe, if someone is changing the outgoing signal.
103
+
104
+ require 'c_gpio'
105
+
106
+ io = GPIO::Base.new(2) # We want to write to PIN 2
107
+
108
+ io.direction = :in
109
+
110
+ io.on_high do
111
+ puts "signal changed to HIGH"
112
+ end
113
+
114
+ io.on_low do
115
+ puts "signal changed to low"
116
+ end
117
+
118
+
119
+
120
+ License
121
+ ----
122
+
123
+ MIT
124
+
125
+
126
+ **Free Software, Hell Yeah!**
127
+
128
+ Finally
129
+ ----
130
+
131
+ I wrote this as my fist c program and my first c extension.
132
+ I have to Idea if this code is looking pretty or optimized.
133
+
134
+ But I am open to everyone who wants to give feedback or collaborate in this.
@@ -0,0 +1,33 @@
1
+ module GPIO
2
+ VERSION = '0.0.5'
3
+ end
4
+
5
+ require 'c_gpio/gpio'
6
+
7
+ class GPIO::Base
8
+ def on_high(&block)
9
+ Thread.new do
10
+ wait_for_high(block)
11
+ end
12
+ end
13
+
14
+ def on_low(&block)
15
+ Thread.new do
16
+ wait_for_low(block)
17
+ end
18
+ end
19
+ end
20
+
21
+ class GPIO::Button
22
+ def on_press(&block)
23
+ Thread.new do
24
+ wait_for_low(block)
25
+ end
26
+ end
27
+
28
+ def on_release(&block)
29
+ Thread.new do
30
+ wait_for_high(block)
31
+ end
32
+ end
33
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: c_gpio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - hujiko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-22 00:00:00.000000000 Z
11
+ date: 2018-06-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby gem to control GPIO ports of a raspberry PI
14
14
  email:
@@ -17,7 +17,9 @@ extensions:
17
17
  - ext/c_gpio/extconf.rb
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - README.md
20
21
  - ext/c_gpio/extconf.rb
22
+ - lib/c_gpio.rb
21
23
  homepage: https://github.com/hujiko/c_GPIO
22
24
  licenses:
23
25
  - MIT
@@ -38,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
38
40
  version: '0'
39
41
  requirements: []
40
42
  rubyforge_project:
41
- rubygems_version: 2.2.0
43
+ rubygems_version: 2.6.10
42
44
  signing_key:
43
45
  specification_version: 4
44
46
  summary: Ruby gem to control GPIO ports of a raspberry PI