artoo-gpio 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -2
- data/Gemfile.lock +14 -13
- data/README.md +17 -7
- data/artoo-gpio.gemspec +1 -1
- data/docs/commands_analog_sensor.md +49 -0
- data/docs/commands_button.md +13 -0
- data/docs/commands_continuous_servo.md +37 -0
- data/docs/commands_led.md +73 -0
- data/docs/commands_makey_button.md +13 -0
- data/docs/commands_maxbotix.md +25 -0
- data/docs/commands_motor.md +157 -0
- data/docs/commands_servo.md +61 -0
- data/docs/events_analog_sensor.md +15 -0
- data/docs/events_button.md +14 -0
- data/docs/events_makey_button.md +14 -0
- data/docs/events_maxbotix.md +11 -0
- data/lib/artoo/drivers/continuous_servo.rb +30 -0
- data/lib/artoo/drivers/makey_button.rb +59 -0
- data/lib/artoo-gpio/version.rb +1 -1
- data/test/drivers/continuous_servo_test.rb +34 -0
- data/test/drivers/makey_button_test.rb +55 -0
- metadata +21 -6
- data/.rvmrc +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ddb4de7935782db58aa0534bc5af242e42ff778
|
4
|
+
data.tar.gz: fe10fef77bc40ee9c51feef00ca9db38e91086fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 212993e748a5f316c3ad7171aa78456b9ce01cd6c4c8f5d9ab07ef5052edf243d3a16c0b220f6f6d4d20640acfed90f7e351e99b03e096446d0c818a8b853e72
|
7
|
+
data.tar.gz: da012ef5b062b3309a4c44dca277bdd2373b5ed0b2b4222fa796ee91095d52cadc6617bd37f106d725709f68344b83197f053cde46e18a0941792789ec1b3256
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,53 +1,54 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
artoo-gpio (0.
|
5
|
-
artoo (>= 1.
|
4
|
+
artoo-gpio (0.4.0)
|
5
|
+
artoo (>= 1.6.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
-
artoo (1.
|
10
|
+
artoo (1.6.0)
|
11
11
|
celluloid (~> 0.15.0)
|
12
12
|
celluloid-io (~> 0.15.0)
|
13
13
|
multi_json (~> 1.6)
|
14
14
|
pry (~> 0.9)
|
15
15
|
rake
|
16
16
|
reel (~> 0.4.0)
|
17
|
+
robeaux (~> 0.0.3)
|
17
18
|
thor (~> 0.18.1)
|
18
19
|
celluloid (0.15.2)
|
19
20
|
timers (~> 1.1.0)
|
20
21
|
celluloid-io (0.15.0)
|
21
22
|
celluloid (>= 0.15.0)
|
22
23
|
nio4r (>= 0.5.0)
|
23
|
-
coderay (1.0
|
24
|
+
coderay (1.1.0)
|
24
25
|
http (0.5.0)
|
25
26
|
http_parser.rb
|
26
|
-
http_parser.rb (0.6.0
|
27
|
+
http_parser.rb (0.6.0)
|
27
28
|
metaclass (0.0.1)
|
28
29
|
method_source (0.8.2)
|
29
30
|
minitest (5.0.7)
|
30
31
|
minitest-happy (1.0.0)
|
31
32
|
mocha (0.14.0)
|
32
33
|
metaclass (~> 0.0.1)
|
33
|
-
multi_json (1.8.
|
34
|
-
nio4r (0.
|
35
|
-
pry (0.9.12.
|
36
|
-
coderay (~> 1.0
|
34
|
+
multi_json (1.8.4)
|
35
|
+
nio4r (1.0.0)
|
36
|
+
pry (0.9.12.6)
|
37
|
+
coderay (~> 1.0)
|
37
38
|
method_source (~> 0.8)
|
38
39
|
slop (~> 3.4)
|
39
|
-
rake (10.1.
|
40
|
+
rake (10.1.1)
|
40
41
|
reel (0.4.0)
|
41
42
|
celluloid (>= 0.15.1)
|
42
43
|
celluloid-io (>= 0.15.0)
|
43
44
|
http (>= 0.5.0)
|
44
45
|
http_parser.rb (>= 0.6.0.beta.2)
|
45
46
|
websocket_parser (>= 0.1.4)
|
46
|
-
|
47
|
+
robeaux (0.0.3)
|
48
|
+
slop (3.4.7)
|
47
49
|
thor (0.18.1)
|
48
50
|
timers (1.1.0)
|
49
|
-
websocket_parser (0.1.
|
50
|
-
http
|
51
|
+
websocket_parser (0.1.6)
|
51
52
|
|
52
53
|
PLATFORMS
|
53
54
|
ruby
|
data/README.md
CHANGED
@@ -51,18 +51,28 @@ end
|
|
51
51
|
## Devices supported
|
52
52
|
|
53
53
|
The following GPIO hardware devices have Artoo driver support:
|
54
|
+
- Analog sensor
|
54
55
|
- Button
|
56
|
+
- Continuous Servo
|
55
57
|
- LED
|
58
|
+
- MakeyButton (high-resistance switch influenced by the MakeyMakey ([http://makeymakey.com](http://makeymakey.com)))
|
56
59
|
- Maxbotix ultrasonic range finder
|
57
|
-
- Analog sensor
|
58
60
|
- Motor (DC)
|
59
61
|
- Servo
|
60
62
|
|
61
|
-
|
62
63
|
## Contributing
|
63
64
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
65
|
+
* All patches must be provided under the Apache 2.0 License
|
66
|
+
* Please use the -s option in git to "sign off" that the commit is your work and you are providing it under the Apache 2.0 License
|
67
|
+
* Submit a Github Pull Request to the appropriate branch and ideally discuss the changes with us in IRC.
|
68
|
+
* We will look at the patch, test it out, and give you feedback.
|
69
|
+
* Avoid doing minor whitespace changes, renamings, etc. along with merged content. These will be done by the maintainers from time to time but they can complicate merges and should be done seperately.
|
70
|
+
* Take care to maintain the existing coding style.
|
71
|
+
* Add unit tests for any new or changed functionality.
|
72
|
+
* All pull requests should be "fast forward"
|
73
|
+
* If there are commits after yours use “git rebase -i <new_head_branch>”
|
74
|
+
* If you have local changes you may need to use “git stash”
|
75
|
+
* For git help see [progit](http://git-scm.com/book) which is an awesome (and free) book on git
|
76
|
+
|
77
|
+
|
78
|
+
(c) 2012-2014 The Hybrid Group
|
data/artoo-gpio.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
21
|
s.require_paths = ["lib"]
|
22
22
|
|
23
|
-
s.add_runtime_dependency 'artoo', '>= 1.
|
23
|
+
s.add_runtime_dependency 'artoo', '>= 1.6.0'
|
24
24
|
s.add_development_dependency 'minitest', '>= 5.0'
|
25
25
|
s.add_development_dependency 'minitest-happy'
|
26
26
|
s.add_development_dependency 'mocha', '>= 0.14.0'
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# Commands
|
2
|
+
|
3
|
+
## pin
|
4
|
+
|
5
|
+
Returns the pin number set up when creating the sensor.
|
6
|
+
|
7
|
+
##### Params
|
8
|
+
|
9
|
+
`no params`
|
10
|
+
|
11
|
+
##### Returns
|
12
|
+
|
13
|
+
`integer`
|
14
|
+
|
15
|
+
## upper
|
16
|
+
|
17
|
+
Returns the upper limit set up when creating the sensor.
|
18
|
+
|
19
|
+
##### Params
|
20
|
+
|
21
|
+
`no params`
|
22
|
+
|
23
|
+
##### Returns
|
24
|
+
|
25
|
+
`integer`
|
26
|
+
|
27
|
+
## lower
|
28
|
+
|
29
|
+
Returns the lower limit set up when creating the sensor.
|
30
|
+
|
31
|
+
##### Params
|
32
|
+
|
33
|
+
`no params`
|
34
|
+
|
35
|
+
##### Returns
|
36
|
+
|
37
|
+
`integer`
|
38
|
+
|
39
|
+
## analog_read(pin_number)
|
40
|
+
|
41
|
+
Returns an integer value that represents the analog read from the sensor, the value goes from `0` to `1027`.
|
42
|
+
|
43
|
+
##### Params
|
44
|
+
|
45
|
+
- **pin_number** - params, the pin value
|
46
|
+
|
47
|
+
##### Returns
|
48
|
+
|
49
|
+
`integer (from 0 to 1027)`
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# Commands
|
2
|
+
|
3
|
+
## clockwise
|
4
|
+
|
5
|
+
Turns the servo to go clockwise, if the driver is continuous.
|
6
|
+
|
7
|
+
##### Params
|
8
|
+
|
9
|
+
`no params`
|
10
|
+
|
11
|
+
##### Returns
|
12
|
+
|
13
|
+
`nil`
|
14
|
+
|
15
|
+
## counter_clockwise
|
16
|
+
|
17
|
+
Turns the servo to go counter clockwise, if the driver is continuous.
|
18
|
+
|
19
|
+
##### Params
|
20
|
+
|
21
|
+
`no params`
|
22
|
+
|
23
|
+
##### Returns
|
24
|
+
|
25
|
+
`nil`
|
26
|
+
|
27
|
+
## stop
|
28
|
+
|
29
|
+
Stops the driver.
|
30
|
+
|
31
|
+
##### Params
|
32
|
+
|
33
|
+
`no params`
|
34
|
+
|
35
|
+
##### Returns
|
36
|
+
|
37
|
+
`nil`
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# Commands
|
2
|
+
|
3
|
+
## on
|
4
|
+
|
5
|
+
Turns LED on.
|
6
|
+
|
7
|
+
##### Params
|
8
|
+
|
9
|
+
`no params`
|
10
|
+
|
11
|
+
##### Returns
|
12
|
+
|
13
|
+
`true or nil`
|
14
|
+
|
15
|
+
## off
|
16
|
+
|
17
|
+
Turns LED off.
|
18
|
+
|
19
|
+
##### Params
|
20
|
+
|
21
|
+
`no params`
|
22
|
+
|
23
|
+
##### Returns
|
24
|
+
|
25
|
+
`true or nil`
|
26
|
+
|
27
|
+
## on?
|
28
|
+
|
29
|
+
Returns true if LED is on, otherwise returns false.
|
30
|
+
|
31
|
+
##### Params
|
32
|
+
|
33
|
+
`no params`
|
34
|
+
|
35
|
+
##### Returns
|
36
|
+
|
37
|
+
`true or false`
|
38
|
+
|
39
|
+
## off?
|
40
|
+
|
41
|
+
Returns true if LED is off, otherwise returns false.
|
42
|
+
|
43
|
+
##### Params
|
44
|
+
|
45
|
+
`no params`
|
46
|
+
|
47
|
+
##### Returns
|
48
|
+
|
49
|
+
`true or false`
|
50
|
+
|
51
|
+
## toggle
|
52
|
+
|
53
|
+
Turns the LED on, or off, depending on if it is already off, or on, respectively.
|
54
|
+
|
55
|
+
##### Params
|
56
|
+
|
57
|
+
`no params`
|
58
|
+
|
59
|
+
##### Returns
|
60
|
+
|
61
|
+
`true or nil`
|
62
|
+
|
63
|
+
## brightness(brightness_int)
|
64
|
+
|
65
|
+
Sets brightness of the led to the specified brightness value passed to brightness(brightness_int) using PWM, brightness can be any integer value between `0` and `255`.
|
66
|
+
|
67
|
+
##### Params
|
68
|
+
|
69
|
+
- **brightness_int** - params , the brightness value
|
70
|
+
|
71
|
+
##### Returns
|
72
|
+
|
73
|
+
`true or nil`
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Commands
|
2
|
+
|
3
|
+
## range
|
4
|
+
|
5
|
+
Returns the distance measured by the sonar in inches.
|
6
|
+
|
7
|
+
##### Params
|
8
|
+
|
9
|
+
`no params`
|
10
|
+
|
11
|
+
##### Returns
|
12
|
+
|
13
|
+
`distance_in_inches(float)`
|
14
|
+
|
15
|
+
## range_cm
|
16
|
+
|
17
|
+
Returns the distance measured by the sonar in cm.
|
18
|
+
|
19
|
+
##### Params
|
20
|
+
|
21
|
+
`no params`
|
22
|
+
|
23
|
+
##### Returns
|
24
|
+
|
25
|
+
`distance_in_cm(float)`
|
@@ -0,0 +1,157 @@
|
|
1
|
+
# Commands
|
2
|
+
|
3
|
+
## stop
|
4
|
+
|
5
|
+
Stops the motor.
|
6
|
+
|
7
|
+
##### Params
|
8
|
+
|
9
|
+
`no params`
|
10
|
+
|
11
|
+
##### Returns
|
12
|
+
|
13
|
+
`true or nil`
|
14
|
+
|
15
|
+
## start
|
16
|
+
|
17
|
+
Starts the motor.
|
18
|
+
|
19
|
+
##### Params
|
20
|
+
|
21
|
+
`no params`
|
22
|
+
|
23
|
+
##### Returns
|
24
|
+
|
25
|
+
`true or nil`
|
26
|
+
|
27
|
+
## on?
|
28
|
+
|
29
|
+
Returns true if the motor is on, otherwise returns false.
|
30
|
+
|
31
|
+
##### Params
|
32
|
+
|
33
|
+
`no params`
|
34
|
+
|
35
|
+
##### Returns
|
36
|
+
|
37
|
+
`true or false`
|
38
|
+
|
39
|
+
## off?
|
40
|
+
|
41
|
+
Returns true if the motor is off, otherwise returns false.
|
42
|
+
|
43
|
+
##### Params
|
44
|
+
|
45
|
+
`no params`
|
46
|
+
|
47
|
+
##### Returns
|
48
|
+
|
49
|
+
`true or false`
|
50
|
+
|
51
|
+
## toggle
|
52
|
+
|
53
|
+
Sets the state of the motor to the oposite of the current state, if motor is on then sets it to off.
|
54
|
+
|
55
|
+
##### Params
|
56
|
+
|
57
|
+
`no params`
|
58
|
+
|
59
|
+
##### Returns
|
60
|
+
|
61
|
+
`true or nil`
|
62
|
+
|
63
|
+
## speed(speed_value)
|
64
|
+
|
65
|
+
Sets the speed of the motor to the value provided in the speed param, speed value must be an integer between `0` and `255`.
|
66
|
+
|
67
|
+
##### Params
|
68
|
+
|
69
|
+
- **speed_value** - params, the speed value
|
70
|
+
|
71
|
+
##### Returns
|
72
|
+
|
73
|
+
`true or nil`
|
74
|
+
|
75
|
+
## min
|
76
|
+
|
77
|
+
Stops the motor, sets the speed to `0`.
|
78
|
+
|
79
|
+
##### Params
|
80
|
+
|
81
|
+
`no params`
|
82
|
+
|
83
|
+
##### Returns
|
84
|
+
|
85
|
+
`true or nil`
|
86
|
+
|
87
|
+
## max
|
88
|
+
|
89
|
+
Starts the motor at max speed, sets the speed to `255`.
|
90
|
+
|
91
|
+
##### Params
|
92
|
+
|
93
|
+
`no params`
|
94
|
+
|
95
|
+
##### Returns
|
96
|
+
|
97
|
+
`true or nil`
|
98
|
+
|
99
|
+
## forward(speed)
|
100
|
+
|
101
|
+
Starts the motor in forward direction at the provided speed.
|
102
|
+
|
103
|
+
##### Params
|
104
|
+
|
105
|
+
- **speed** - params, the speed value
|
106
|
+
|
107
|
+
##### Returns
|
108
|
+
|
109
|
+
`true or nil`
|
110
|
+
|
111
|
+
## backward(speed)
|
112
|
+
|
113
|
+
Starts the motor in backward direction at the provided speed.
|
114
|
+
|
115
|
+
##### Params
|
116
|
+
|
117
|
+
- **speed** - params, the speed value
|
118
|
+
|
119
|
+
##### Returns
|
120
|
+
|
121
|
+
`true or nil`
|
122
|
+
|
123
|
+
## forward?
|
124
|
+
|
125
|
+
Returns true if the motor is direction is set to forward, otherwise false.
|
126
|
+
|
127
|
+
##### Params
|
128
|
+
|
129
|
+
`no params`
|
130
|
+
|
131
|
+
##### Returns
|
132
|
+
|
133
|
+
`true or false`
|
134
|
+
|
135
|
+
## backward?
|
136
|
+
|
137
|
+
Returns true if the motor is direction is set to backward, otherwise false.
|
138
|
+
|
139
|
+
##### Params
|
140
|
+
|
141
|
+
`no params`
|
142
|
+
|
143
|
+
##### Returns
|
144
|
+
|
145
|
+
`true or false`
|
146
|
+
|
147
|
+
## current_speed
|
148
|
+
|
149
|
+
Returns the current speed of the motor as an integer between `0` and `255`.
|
150
|
+
|
151
|
+
##### Params
|
152
|
+
|
153
|
+
`no params`
|
154
|
+
|
155
|
+
##### Returns
|
156
|
+
|
157
|
+
`speed`
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Commands
|
2
|
+
|
3
|
+
## move(angle)
|
4
|
+
|
5
|
+
Moves the servo to the specified angle, angle must be an integer value between `0` and `180`.
|
6
|
+
|
7
|
+
##### Params
|
8
|
+
|
9
|
+
- ** angle ** - params
|
10
|
+
|
11
|
+
##### Returns
|
12
|
+
|
13
|
+
`true or nil`
|
14
|
+
|
15
|
+
## min
|
16
|
+
|
17
|
+
Moves the servo to the angle = `0` position.
|
18
|
+
|
19
|
+
##### Params
|
20
|
+
|
21
|
+
`no params`
|
22
|
+
|
23
|
+
##### Returns
|
24
|
+
|
25
|
+
`nil`
|
26
|
+
|
27
|
+
## max
|
28
|
+
|
29
|
+
Moves the servo to the angle = `180` position.
|
30
|
+
|
31
|
+
##### Params
|
32
|
+
|
33
|
+
`no params`
|
34
|
+
|
35
|
+
##### Returns
|
36
|
+
|
37
|
+
`nil`
|
38
|
+
|
39
|
+
## center
|
40
|
+
|
41
|
+
Moves the servo to the angle = `90` position.
|
42
|
+
|
43
|
+
##### Params
|
44
|
+
|
45
|
+
`no params`
|
46
|
+
|
47
|
+
##### Returns
|
48
|
+
|
49
|
+
`nil`
|
50
|
+
|
51
|
+
## current_angle
|
52
|
+
|
53
|
+
Returns the current angle of the servo, an integer value between `0` and `180`.
|
54
|
+
|
55
|
+
##### Params
|
56
|
+
|
57
|
+
`no params`
|
58
|
+
|
59
|
+
##### Returns
|
60
|
+
|
61
|
+
`integer (0 - 180)`
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Events
|
2
|
+
|
3
|
+
The limits that trigger the events are setup when creating the sensor (see above in the section titled "How to stablish a connection and driver" ), there are `:upper` and `:lower` limits, as well as an `:interval` param that defines how often the sensor should be read; when the specified amount of time passes the sensor is read, if one of the limits stablished is reached the corresponging event will be triggered.
|
4
|
+
|
5
|
+
## start_driver
|
6
|
+
|
7
|
+
Starts the driver.
|
8
|
+
|
9
|
+
## :upper
|
10
|
+
|
11
|
+
Gets triggered if the value read by the sensor is greater or equal to `:upper` (value passed when setting up the sensor).
|
12
|
+
|
13
|
+
## :lower
|
14
|
+
|
15
|
+
Gets triggered if the value read by the sensor is less or equal to `:lower` (value passed when setting up the sensor).
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Events
|
2
|
+
|
3
|
+
## start_driver
|
4
|
+
|
5
|
+
Starts the driver.
|
6
|
+
|
7
|
+
## :push
|
8
|
+
|
9
|
+
This event gets triggered when the button changes state from released to pushed.
|
10
|
+
|
11
|
+
## :release
|
12
|
+
|
13
|
+
This event gets triggered when the button changes state from pushed to released.
|
14
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Events
|
2
|
+
|
3
|
+
## start_driver
|
4
|
+
|
5
|
+
Starts the driver.
|
6
|
+
|
7
|
+
## :push
|
8
|
+
|
9
|
+
This event gets triggered when the button changes state from released to pushed.
|
10
|
+
|
11
|
+
## :release
|
12
|
+
|
13
|
+
This event gets triggered when the button changes state from pushed to released.
|
14
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# Events
|
2
|
+
|
3
|
+
The events will be triggered when the amount of time specified by the param `:interval`, when setting up the driver, passes.
|
4
|
+
|
5
|
+
## start_driver
|
6
|
+
|
7
|
+
Starts the driver.
|
8
|
+
|
9
|
+
## :range
|
10
|
+
|
11
|
+
Gets triggered after `:interval` amount of time passes, everytime the range will be read and the event triggered.
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'artoo/drivers/driver'
|
2
|
+
|
3
|
+
module Artoo
|
4
|
+
module Drivers
|
5
|
+
# ContinuousServo behaviors for Firmata
|
6
|
+
class ContinuousServo < Driver
|
7
|
+
COMMANDS = [:clockwise, :counter_clockwise, :stop].freeze
|
8
|
+
|
9
|
+
# Create new ContinuousServo
|
10
|
+
def initialize(params={})
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
# Stops the driver
|
15
|
+
def stop
|
16
|
+
connection.servo_write(pin, 90)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Turns the servo clockwise
|
20
|
+
def clockwise
|
21
|
+
connection.servo_write(pin, 180)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Turns the servo counter clockwise
|
25
|
+
def counter_clockwise
|
26
|
+
connection.servo_write(pin, 89)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'artoo/drivers/driver'
|
2
|
+
|
3
|
+
module Artoo
|
4
|
+
module Drivers
|
5
|
+
# MakeyButton driver behaviors
|
6
|
+
class MakeyButton < Driver
|
7
|
+
COMMANDS = [:is_pressed?].freeze
|
8
|
+
|
9
|
+
DOWN = 1
|
10
|
+
UP = 0
|
11
|
+
|
12
|
+
attr_accessor :data
|
13
|
+
|
14
|
+
def initialize(params={})
|
15
|
+
super
|
16
|
+
|
17
|
+
@data = []
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [Boolean] True if pressed
|
21
|
+
def is_pressed?
|
22
|
+
(@pressed_val == 1) ? true : false
|
23
|
+
end
|
24
|
+
|
25
|
+
def start_driver
|
26
|
+
@pressed_val = 0
|
27
|
+
|
28
|
+
every(100) do
|
29
|
+
new_value = connection.digital_read(pin)
|
30
|
+
@data << new_value
|
31
|
+
@data.shift
|
32
|
+
update(new_value) if !new_value.nil? && new_value != is_pressed?
|
33
|
+
end
|
34
|
+
|
35
|
+
super
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
# Publishes events according to the button feedback
|
40
|
+
def update
|
41
|
+
if average_data > 0.5 and not is_pressed?
|
42
|
+
@pressed_val = 1
|
43
|
+
publish(event_topic_name("update"), "push", new_val)
|
44
|
+
publish(event_topic_name("push"), new_val)
|
45
|
+
elsif average_data <= 0.5 and is_pressed?
|
46
|
+
@pressed_val = 0
|
47
|
+
publish(event_topic_name("update"), "release", new_val)
|
48
|
+
publish(event_topic_name("release"), new_val)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
#Averages data received
|
53
|
+
def average_data
|
54
|
+
return 0 unless @data.any?
|
55
|
+
@data.inject(:+) / @data.size.to_f
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/artoo-gpio/version.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
2
|
+
require 'artoo/drivers/continuous_servo'
|
3
|
+
|
4
|
+
describe Artoo::Drivers::ContinuousServo do
|
5
|
+
before do
|
6
|
+
@device = mock('device')
|
7
|
+
@device.stubs(:pin).returns(3)
|
8
|
+
@servo = Artoo::Drivers::ContinuousServo.new(:parent => @device)
|
9
|
+
|
10
|
+
@connection = mock('connection')
|
11
|
+
@device.stubs(:connection).returns(@connection)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'ContinuousServo#stop' do
|
15
|
+
it 'stops the driver' do
|
16
|
+
@connection.expects(:servo_write).with(3, 90)
|
17
|
+
@servo.stop
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'ContinuousServo#clockwise' do
|
22
|
+
it 'turns the servo clockwise' do
|
23
|
+
@connection.expects(:servo_write).with(3, 180)
|
24
|
+
@servo.clockwise
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'ContinuousServo#counter_clockwise' do
|
29
|
+
it 'turns the servo counter clockwise' do
|
30
|
+
@connection.expects(:servo_write).with(3, 89)
|
31
|
+
@servo.counter_clockwise
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
2
|
+
require 'artoo/drivers/makey_button'
|
3
|
+
|
4
|
+
describe Artoo::Drivers::MakeyButton do
|
5
|
+
before do
|
6
|
+
@device = mock('device')
|
7
|
+
@pin = 0
|
8
|
+
@device.stubs(:pin).returns(@pin)
|
9
|
+
@makey = Artoo::Drivers::MakeyButton.new(:parent => @device)
|
10
|
+
@connection = mock('connection')
|
11
|
+
@device.stubs(:connection).returns(@connection)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'MakeyButton#is_pressed?' do
|
15
|
+
it 'should return true when pressed' do
|
16
|
+
@makey.instance_variable_set(:@pressed_val, 1)
|
17
|
+
@makey.is_pressed?.must_equal true
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should return false when not pressed' do
|
21
|
+
@makey.instance_variable_set(:@pressed_val, 0)
|
22
|
+
@makey.is_pressed?.must_equal false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'MakeyButton#average_data' do
|
27
|
+
it 'returns 0 if no data' do
|
28
|
+
@makey.instance_variable_set(:@data, [])
|
29
|
+
@makey.send(:average_data).must_equal 0
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns average if data present' do
|
33
|
+
@makey.instance_variable_set(:@data, [1,2,3])
|
34
|
+
@makey.send(:average_data).must_equal 2.0
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'MakeyButton#update' do
|
39
|
+
it 'publishes a push when pushed' do
|
40
|
+
@makey.stubs(:average_data).returns(0.6)
|
41
|
+
@makey.stubs(:is_pressed?).returns(false)
|
42
|
+
@device.expects(:event_topic_name).with('update')
|
43
|
+
@device.expects(:event_topic_name).with('push')
|
44
|
+
@makey.send(:update)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'publishes a release when released' do
|
48
|
+
@makey.stubs(:average_data).returns(0.4)
|
49
|
+
@makey.stubs(:is_pressed?).returns(true)
|
50
|
+
@device.expects(:event_topic_name).with('update')
|
51
|
+
@device.expects(:event_topic_name).with('release')
|
52
|
+
@makey.send(:update)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: artoo-gpio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ron Evans
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2014-02-06 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: artoo
|
@@ -19,14 +19,14 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - '>='
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1.
|
22
|
+
version: 1.6.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.
|
29
|
+
version: 1.6.0
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: minitest
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,7 +77,6 @@ executables: []
|
|
77
77
|
extensions: []
|
78
78
|
extra_rdoc_files: []
|
79
79
|
files:
|
80
|
-
- .rvmrc
|
81
80
|
- .travis.yml
|
82
81
|
- Gemfile
|
83
82
|
- Gemfile.lock
|
@@ -85,15 +84,31 @@ files:
|
|
85
84
|
- README.md
|
86
85
|
- Rakefile
|
87
86
|
- artoo-gpio.gemspec
|
87
|
+
- docs/commands_analog_sensor.md
|
88
|
+
- docs/commands_button.md
|
89
|
+
- docs/commands_continuous_servo.md
|
90
|
+
- docs/commands_led.md
|
91
|
+
- docs/commands_makey_button.md
|
92
|
+
- docs/commands_maxbotix.md
|
93
|
+
- docs/commands_motor.md
|
94
|
+
- docs/commands_servo.md
|
95
|
+
- docs/events_analog_sensor.md
|
96
|
+
- docs/events_button.md
|
97
|
+
- docs/events_makey_button.md
|
98
|
+
- docs/events_maxbotix.md
|
88
99
|
- lib/artoo-gpio.rb
|
89
100
|
- lib/artoo-gpio/version.rb
|
90
101
|
- lib/artoo/drivers/analog_sensor.rb
|
91
102
|
- lib/artoo/drivers/button.rb
|
103
|
+
- lib/artoo/drivers/continuous_servo.rb
|
92
104
|
- lib/artoo/drivers/led.rb
|
105
|
+
- lib/artoo/drivers/makey_button.rb
|
93
106
|
- lib/artoo/drivers/maxbotix.rb
|
94
107
|
- lib/artoo/drivers/motor.rb
|
95
108
|
- lib/artoo/drivers/servo.rb
|
109
|
+
- test/drivers/continuous_servo_test.rb
|
96
110
|
- test/drivers/led_test.rb
|
111
|
+
- test/drivers/makey_button_test.rb
|
97
112
|
- test/drivers/maxbotix_test.rb
|
98
113
|
- test/drivers/motor_test.rb
|
99
114
|
- test/drivers/servo_test.rb
|
@@ -118,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
133
|
version: '0'
|
119
134
|
requirements: []
|
120
135
|
rubyforge_project: artoo-gpio
|
121
|
-
rubygems_version: 2.
|
136
|
+
rubygems_version: 2.2.1
|
122
137
|
signing_key:
|
123
138
|
specification_version: 4
|
124
139
|
summary: Artoo standard drivers for GPIO devices
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm use 1.9.3@artoo-gpio --create
|