dbrady-switchy 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +77 -139
- data/bin/sparcumber +5 -0
- data/lib/sparky.rb +3 -1
- data/lib/sparky_cucumber.rb +29 -0
- data/lib/sparky_progress_formatter.rb +5 -0
- data/res/spec.sparky.opts +1 -1
- metadata +5 -2
data/README.rdoc
CHANGED
@@ -4,159 +4,104 @@ Ruby Application to switch AC loads (e.g. turn a lamp on and off).
|
|
4
4
|
|
5
5
|
= Example
|
6
6
|
|
7
|
-
== Command-line
|
8
|
-
|
9
|
-
TODO: This documentation is prescriptive, not descriptive. Update this
|
10
|
-
when it's finally implemented.
|
11
|
-
|
12
|
-
$ switchy 1 status
|
13
|
-
Light 1 is: OFF
|
14
|
-
$ switchy 1 on
|
15
|
-
Light 1 switched on.
|
16
|
-
$ switchy 1 status
|
17
|
-
Light 1 is: ON
|
18
|
-
$ switchy 1 off
|
19
|
-
Light 1 switched off.
|
20
|
-
$ switchy 1 on
|
21
|
-
Light 1 switched on.
|
7
|
+
== Command-line Apps
|
22
8
|
|
23
|
-
|
9
|
+
=== Switchy
|
24
10
|
|
25
|
-
|
26
|
-
when it's finally implemented.
|
11
|
+
Switchy gives you control of each light individually.
|
27
12
|
|
28
|
-
|
29
|
-
#
|
30
|
-
# Light 1 starts out off.
|
31
|
-
s = Switchy.new
|
32
|
-
s.light1
|
33
|
-
# => false # light 1 is off
|
34
|
-
s.light1 = true
|
35
|
-
# => false # previous state returned; light1 was off, now on
|
36
|
-
s.light1
|
37
|
-
# => true
|
38
|
-
s.light1 = false
|
39
|
-
# => true # previous state again; light1 was on, now off
|
40
|
-
|
41
|
-
# Access to lights array
|
42
|
-
# ----------------------------------------
|
43
|
-
s.lights
|
44
|
-
# => [false, false, false, false, false, false]
|
45
|
-
s.lights[2]
|
46
|
-
# => false
|
47
|
-
s.lights[2] = true
|
48
|
-
# => false
|
49
|
-
s.lights[2]
|
50
|
-
# => true
|
51
|
-
s.lights[2] = false
|
52
|
-
# => true
|
53
|
-
s.lights[2]
|
54
|
-
# => false
|
13
|
+
$ switchy 1 1 2 0 10 1 8 1
|
14
|
+
# => Lights 1, 8, 10 turn on; light 2 turns off
|
55
15
|
|
16
|
+
DANGER: This is wildly incompatible with the original design of
|
17
|
+
switchy. The original design is intended to drive a single external
|
18
|
+
device from a single pin through a relay.
|
56
19
|
|
57
|
-
|
20
|
+
The prototype design, however, ended up getting optimizing for low
|
21
|
+
part count, and in fact I just soldered LEDs directly to the logic
|
22
|
+
board (and there ARE no other parts). This means that each LED is
|
23
|
+
soldered across TWO pins.
|
58
24
|
|
59
|
-
|
25
|
+
Turning on light 1, for instance, involves driving pin C4 high and
|
26
|
+
driving pin C5 low.
|
60
27
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
- switching circuit
|
66
|
-
- modified power strip
|
28
|
+
Remember that when discussing lights, we turn them on or off, but when
|
29
|
+
discussing the logic pins we drive them high or low, because when you
|
30
|
+
drive a pin low you are actually establishing a connection between
|
31
|
+
that pin and ground, allowing current to "sink".
|
67
32
|
|
68
|
-
|
33
|
+
=== Sparky
|
69
34
|
|
70
|
-
|
71
|
-
|
72
|
-
Example Commands
|
73
|
-
B0? Read Port B, pin 0
|
74
|
-
C2=0 Write Port C, pin 1 LOW
|
75
|
-
D6=1 Write Port D, pin 6 HIGH (D6 is LED pin)
|
76
|
-
|
77
|
-
>
|
35
|
+
A wrapper on top of switchy that gives you pass/pending/fail
|
36
|
+
semantics.
|
78
37
|
|
79
|
-
|
38
|
+
$ sparky (run|pass|pending|fail)
|
39
|
+
# => turns on running|green|yellow|red lights
|
40
|
+
|
41
|
+
$ sparky <system command> [<command options>]
|
42
|
+
|
43
|
+
# => Turns on run lights and executise shell command. If the exit
|
44
|
+
# code is 0, turns green. Any other exit code and it turns red.
|
45
|
+
|
46
|
+
=== Sparcumber
|
47
|
+
|
48
|
+
Sparcumber is a cucumber wrapper. It hooks into Cucumber's
|
49
|
+
AST::Visitor class. Use it like you would use Cucumber:
|
50
|
+
|
51
|
+
$ sparcumber -r features features/
|
52
|
+
|
53
|
+
One additional bit of cleverness: While running, each step that
|
54
|
+
passes/pends/fails will turn on ONE light of the appropriate color. If
|
55
|
+
another step exits in the same condition, that color light will
|
56
|
+
advance (E.g. the currently lit green light will go out and the next
|
57
|
+
one will turn on). This provides the visual effect of animating the
|
58
|
+
feature output. Note that it is thus possible to 5 leds lit at once:
|
59
|
+
the 2 running lights plus one each of red, yellow and green.
|
60
|
+
|
61
|
+
== Ruby Library
|
62
|
+
|
63
|
+
TODO: The ruby lib is pretty messed up. Here's what currently works:
|
64
|
+
|
65
|
+
s = Switchy.new
|
66
|
+
s.set_pin Switchy::PINS::D6, 0
|
67
|
+
# Drives pin D6 low (which turns on the on-board LED)
|
68
|
+
s.set_pin Switchy::PINS::B3, 1
|
69
|
+
# Drives pin B3 high
|
70
|
+
|
71
|
+
= The Hardware
|
80
72
|
|
73
|
+
...is currently very much in flux.
|
81
74
|
|
82
|
-
|
83
|
-
outputs.
|
75
|
+
TODO: Write me!
|
84
76
|
|
85
|
-
|
86
|
-
a flasher register and timing/counters. For starters, just set it to
|
87
|
-
blink a hard-coded rate when "2" is sent, e.g "switchy 1 2" would
|
88
|
-
blink light 1 at some rate. Later we can attach different blink
|
89
|
-
rates and/or patterns to other numbers. For example, 3 might blink
|
90
|
-
at the same rate as 2 but out of phase, so "switchy 1 2 2 3" would
|
91
|
-
oscillate lights 1 and 2.
|
77
|
+
= TODO
|
92
78
|
|
93
|
-
|
79
|
+
- There's an enable line on the 74ls244 driver chip. Use it. Device
|
94
80
|
should boot disabled. Once everything's had a chance to settle
|
95
81
|
(10-100ms or so), enable the driver chip.
|
96
82
|
|
97
|
-
|
83
|
+
- Add circuit schematics to the project.
|
98
84
|
|
99
|
-
|
100
|
-
and no 120VAC switching. (Trust me. The little LEDs are VERY
|
85
|
+
- [DONE] Fork the circuit, make a version with just a little LED light
|
86
|
+
bar and no 120VAC switching. (Trust me. The little LEDs are VERY
|
101
87
|
compelling!)
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
* 1-LED Version. Single RGB LED.
|
117
|
-
* Blinking (ooh, or throbbing) Blue/White: Specs running
|
118
|
-
* Green: Passed
|
119
|
-
* Yellow: Pending
|
120
|
-
* Red: Failed
|
121
|
-
* 1-LED Version. Single Bi-color. Same as RGB. Will need to
|
122
|
-
oscillate because red/green = orange.
|
123
|
-
* Blinking: Running
|
124
|
-
* Green: Passed
|
125
|
-
* Orange: Pending
|
126
|
-
* Red: Failed
|
127
|
-
|
128
|
-
* Expand the switch control logic. Need static on/off, Timers, and
|
129
|
-
blinkers. Note: if the board can handle infinite vs. countdown, then
|
130
|
-
implementing one-shot timers is easy: just set countdown to 1.
|
131
|
-
* Static on/off: Sit pin state and forget about it.
|
132
|
-
SET C4 1
|
133
|
-
* Blinker: set pin state for n milliseconds, toggle to other state
|
134
|
-
for m milliseconds. Repeat x times. (0 = infinite)
|
135
|
-
TMR C7 1 500 250 10
|
136
|
-
* Timer: set pin state for n milliseconds, then toggle it to other
|
137
|
-
state.
|
138
|
-
TMR C6 0 60000 250 1 # alarm timer, flashes C6 once for 250ms
|
139
|
-
after 60s
|
140
|
-
|
141
|
-
* Given the above switch control logic, the ruby app should now be
|
142
|
-
able to programmatically define compound events like:
|
143
|
-
* When program starts, turn off siren, green, yellow and red lights.
|
144
|
-
* When test runs, turn off siren, yellow and red lights, and blink
|
145
|
-
green light at 2Hz.
|
146
|
-
* If a spec is pending and green light is blinking, turn off green
|
147
|
-
link and blink yellow light at 2Hz.
|
148
|
-
* If a spec fails and red light is off, turn off green and yellow
|
149
|
-
lights, honk siren for 250ms, and blink red light at 2Hz.
|
150
|
-
* When specs all pass, turn on green light for 10 seconds.
|
151
|
-
* When specs fail, "blink" siren for 1 second every 60 seconds, turn
|
152
|
-
on red light and leave it on.
|
153
|
-
* Blink RGB yellow by seting Red and Green to blink. (Need to build
|
154
|
-
the system to permit synchronous blink rates.)
|
155
|
-
|
156
|
-
* 2009-04-20: Review previous TODOs in light of first finished
|
88
|
+
|
89
|
+
- [ABANDONED] Add duty cycling/blinking to the board. (Tabled for now.
|
90
|
+
The USB serial port driver that comes with the Teensy board appears
|
91
|
+
to use blocking methods. The code libraries are poorly documented
|
92
|
+
and will require a significantly higher amount of expertise with AVR
|
93
|
+
programming than I currently have before I can port it to a
|
94
|
+
non-blocking form.)
|
95
|
+
|
96
|
+
- Write a simulator for the 6.3E+06-1 people on the planet who do not
|
97
|
+
have the only existing prototype. I think a little MacRuby
|
98
|
+
Red/Green/Refactor applet would be spiffy all by itself--and would
|
99
|
+
make debugging/testing driver and linking apps much easier.
|
100
|
+
|
101
|
+
- [DONE] 2009-04-20: Review previous TODOs in light of first finished
|
157
102
|
prototype.
|
158
103
|
|
159
|
-
|
104
|
+
- [DONE] Change progress formatter lights, and light up only one
|
160
105
|
pass/fail/pending LED as specs run. As each example completes,
|
161
106
|
animate the display by moving the the one led to another spot. So if
|
162
107
|
all your specs are passing, you'll see the green light move 1 -> 2
|
@@ -164,11 +109,4 @@ TODO: Write me!
|
|
164
109
|
light up 1 -> 2 -> 1 -> 2 etc. When the test finishes, light up all
|
165
110
|
the status lights of the appropriate color.
|
166
111
|
|
167
|
-
* As a potential addition, light up one of EACH status color as they
|
168
|
-
occur. So you might have Pass light 3, Pending light 2, and Fail
|
169
|
-
light 1 lit. As each example completes, animate the status light for
|
170
|
-
that example's color. Then, when it's finished, turn on all status
|
171
|
-
lights for the final pass/pend/fail status and turn off all other
|
172
|
-
lights.
|
173
|
-
|
174
112
|
|
data/bin/sparcumber
ADDED
data/lib/sparky.rb
CHANGED
@@ -49,14 +49,16 @@ class Sparky
|
|
49
49
|
def pass
|
50
50
|
set_pins @@pass_pins
|
51
51
|
end
|
52
|
+
alias :passed :pass
|
52
53
|
|
53
54
|
def clear_pass
|
54
55
|
clear_pins @@pass_pins
|
55
56
|
end
|
56
57
|
|
57
|
-
def
|
58
|
+
def fail
|
58
59
|
set_pins @@fail_pins
|
59
60
|
end
|
61
|
+
alias :failed :fail
|
60
62
|
|
61
63
|
def clear_failed
|
62
64
|
clear_pins @@fail_pins
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'cucumber', '>= 0.3.0'
|
3
|
+
|
4
|
+
require 'sparky'
|
5
|
+
|
6
|
+
module Cucumber
|
7
|
+
module Ast
|
8
|
+
class Visitor
|
9
|
+
|
10
|
+
alias :orig_visit_step_result :visit_step_result
|
11
|
+
alias :orig_visit_features :visit_features
|
12
|
+
|
13
|
+
def visit_features(features)
|
14
|
+
begin
|
15
|
+
@sparky = Sparky.new
|
16
|
+
@sparky.start_run
|
17
|
+
orig_visit_features(features)
|
18
|
+
ensure
|
19
|
+
@sparky.finish_run
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def visit_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background)
|
24
|
+
@sparky.send "example_#{status}" if [:passed, :failed, :pending].include?(status)
|
25
|
+
orig_visit_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -3,6 +3,11 @@ require 'spec/runner/formatter/progress_bar_formatter'
|
|
3
3
|
$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
4
|
require 'sparky'
|
5
5
|
|
6
|
+
# TODO: rewire this to just patch the base class like I did in
|
7
|
+
# sparky_cucumber.rb. May be problematic as the child classes here
|
8
|
+
# ain't so good at calling super, so I may just need to patch the key
|
9
|
+
# formatters I normally use like ProgressBar and Html.
|
10
|
+
|
6
11
|
module Spec
|
7
12
|
module Runner
|
8
13
|
module Formatter
|
data/res/spec.sparky.opts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
--colour
|
2
|
-
--require /Library/Ruby/Gems/1.8/gems/switchy-0.1.
|
2
|
+
--require /Library/Ruby/Gems/1.8/gems/switchy-0.1.2/lib/sparky_progress_formatter.rb
|
3
3
|
--format Spec::Runner::Formatter::SparkyProgressFormatter
|
4
4
|
--loadby mtime
|
5
5
|
--reverse
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbrady-switchy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Brady
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-05-12 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -27,6 +27,7 @@ email: github@shinybit.com
|
|
27
27
|
executables:
|
28
28
|
- switchy
|
29
29
|
- sparky
|
30
|
+
- sparcumber
|
30
31
|
extensions: []
|
31
32
|
|
32
33
|
extra_rdoc_files:
|
@@ -35,7 +36,9 @@ extra_rdoc_files:
|
|
35
36
|
files:
|
36
37
|
- bin/sparky
|
37
38
|
- bin/switchy
|
39
|
+
- bin/sparcumber
|
38
40
|
- lib/sparky.rb
|
41
|
+
- lib/sparky_cucumber.rb
|
39
42
|
- lib/sparky_progress_formatter.rb
|
40
43
|
- res/spec.sparky.opts
|
41
44
|
- lib/switchy.rb
|