switchy 0.2.2
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.
- data/MIT-LICENSE +22 -0
- data/README.rdoc +150 -0
- data/bin/sparcumber +5 -0
- data/bin/sparky +79 -0
- data/bin/switchy +65 -0
- data/lib/sparky.rb +130 -0
- data/lib/sparky_cucumber.rb +29 -0
- data/lib/sparky_progress_formatter.rb +48 -0
- data/lib/switchy.rb +143 -0
- data/res/spec.sparky.opts +6 -0
- metadata +81 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2008-2009 David Brady github@shinybit.com
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
= Switchy
|
2
|
+
|
3
|
+
Ruby Application to switch AC loads (e.g. turn a lamp on and off).
|
4
|
+
|
5
|
+
Update 2009-09-26: This has actually become something of a
|
6
|
+
unit-testing light dongle for me. The basic switching hardware was
|
7
|
+
finished quite early, so the only thing left to do was to add a Killer
|
8
|
+
Demo App(TM). The basic switching app is just called "switchy", and it
|
9
|
+
controls individual pins 1 through 10 on the board.
|
10
|
+
|
11
|
+
The Killer Demo, then, would be Sparky, Sparcumber, and Autospark.
|
12
|
+
Each of these has a "christmas tree" LED arrangement: Five LEDs on
|
13
|
+
each side of the device are wired for run, fail, warning, and pass.
|
14
|
+
There are two green LEDs for pass on each side, so the pinouts are:
|
15
|
+
|
16
|
+
Pins 1-5 (left side): blue, red, yellow, green, green
|
17
|
+
Pins 10-6 (right side, note reverse order because pin numbering continues
|
18
|
+
clockwise around the board): blue, red, yellow, green, green
|
19
|
+
|
20
|
+
Sparky provides an RSpec progress formatter, so that it gets updated
|
21
|
+
as each spec runs. While running it animates the LEDs to show the
|
22
|
+
current overall progress. As each spec finishes an LED of the
|
23
|
+
appropriate color lights up.
|
24
|
+
|
25
|
+
Sparky also has a generic mode. If you run "sparky foo", sparky will
|
26
|
+
turn on the running lights, then run the foo command. When foo
|
27
|
+
finishes, its exit status will be used to turn on either the red or
|
28
|
+
green lights.
|
29
|
+
|
30
|
+
Sparcumber does for Cucumber what Sparky does for RSpec. Get Cucumber
|
31
|
+
configured so you can type "cucumber" from the root of your project,
|
32
|
+
then type "sparcumber" instead. Sparcumber will light up the board as
|
33
|
+
Cucumber runs.
|
34
|
+
|
35
|
+
Autospark is currently vaporware. All it should do is hook sparky into
|
36
|
+
autospec. Patches are welcome. There is a spec.sparky.opts file in the
|
37
|
+
res folder, however, that will achieve this for now, but it does cause
|
38
|
+
your project to take a dependency on sparky, which in turn requires
|
39
|
+
having the hardware dongle connected to run your specs, which is less
|
40
|
+
than agile.
|
41
|
+
|
42
|
+
|
43
|
+
= Example
|
44
|
+
|
45
|
+
== Command-line Apps
|
46
|
+
|
47
|
+
=== Switchy
|
48
|
+
|
49
|
+
Switchy gives you control of each light individually.
|
50
|
+
|
51
|
+
$ switchy 1 1 2 0 10 1 8 1
|
52
|
+
# => Lights 1, 8, 10 turn on; light 2 turns off
|
53
|
+
|
54
|
+
DANGER: This is wildly incompatible with the original design of
|
55
|
+
switchy. The original design is intended to drive a single external
|
56
|
+
device from a single pin through a relay.
|
57
|
+
|
58
|
+
The prototype design, however, ended up getting optimizing for low
|
59
|
+
part count, and in fact I just soldered LEDs directly to the logic
|
60
|
+
board (and there ARE no other parts). This means that each LED is
|
61
|
+
soldered across TWO pins.
|
62
|
+
|
63
|
+
Turning on light 1, for instance, involves driving pin C4 high and
|
64
|
+
driving pin C5 low.
|
65
|
+
|
66
|
+
Remember that when discussing lights, we turn them on or off, but when
|
67
|
+
discussing the logic pins we drive them high or low, because when you
|
68
|
+
drive a pin low you are actually establishing a connection between
|
69
|
+
that pin and ground, allowing current to "sink".
|
70
|
+
|
71
|
+
=== Sparky
|
72
|
+
|
73
|
+
A wrapper on top of switchy that gives you pass/pending/fail
|
74
|
+
semantics.
|
75
|
+
|
76
|
+
$ sparky (run|pass|pending|fail)
|
77
|
+
# => turns on running|green|yellow|red lights
|
78
|
+
|
79
|
+
$ sparky <system command> [<command options>]
|
80
|
+
|
81
|
+
# => Turns on run lights and executise shell command. If the exit
|
82
|
+
# code is 0, turns green. Any other exit code and it turns red.
|
83
|
+
|
84
|
+
=== Sparcumber
|
85
|
+
|
86
|
+
Sparcumber is a cucumber wrapper. It hooks into Cucumber's
|
87
|
+
AST::Visitor class. Use it like you would use Cucumber:
|
88
|
+
|
89
|
+
$ sparcumber -r features features/
|
90
|
+
|
91
|
+
One additional bit of cleverness: While running, each step that
|
92
|
+
passes/pends/fails will turn on ONE light of the appropriate color. If
|
93
|
+
another step exits in the same condition, that color light will
|
94
|
+
advance (E.g. the currently lit green light will go out and the next
|
95
|
+
one will turn on). This provides the visual effect of animating the
|
96
|
+
feature output. Note that it is thus possible to 5 leds lit at once:
|
97
|
+
the 2 running lights plus one each of red, yellow and green.
|
98
|
+
|
99
|
+
== Ruby Library
|
100
|
+
|
101
|
+
TODO: The ruby lib is pretty messed up. Here's what currently works:
|
102
|
+
|
103
|
+
s = Switchy.new
|
104
|
+
s.set_pin Switchy::PINS::D6, 0
|
105
|
+
# Drives pin D6 low (which turns on the on-board LED)
|
106
|
+
s.set_pin Switchy::PINS::B3, 1
|
107
|
+
# Drives pin B3 high
|
108
|
+
|
109
|
+
= The Hardware
|
110
|
+
|
111
|
+
...is currently very much in flux.
|
112
|
+
|
113
|
+
TODO: Write me!
|
114
|
+
|
115
|
+
= TODO
|
116
|
+
|
117
|
+
- There's an enable line on the 74ls244 driver chip. Use it. Device
|
118
|
+
should boot disabled. Once everything's had a chance to settle
|
119
|
+
(10-100ms or so), enable the driver chip.
|
120
|
+
|
121
|
+
- Add circuit schematics to the project.
|
122
|
+
|
123
|
+
- [DONE] Fork the circuit, make a version with just a little LED light
|
124
|
+
bar and no 120VAC switching. (Trust me. The little LEDs are VERY
|
125
|
+
compelling!)
|
126
|
+
|
127
|
+
- [ABANDONED] Add duty cycling/blinking to the board. (Tabled for now.
|
128
|
+
The USB serial port driver that comes with the Teensy board appears
|
129
|
+
to use blocking methods. The code libraries are poorly documented
|
130
|
+
and will require a significantly higher amount of expertise with AVR
|
131
|
+
programming than I currently have before I can port it to a
|
132
|
+
non-blocking form.)
|
133
|
+
|
134
|
+
- Write a simulator for the 6.3E+06-1 people on the planet who do not
|
135
|
+
have the only existing prototype. I think a little MacRuby
|
136
|
+
Red/Green/Refactor applet would be spiffy all by itself--and would
|
137
|
+
make debugging/testing driver and linking apps much easier.
|
138
|
+
|
139
|
+
- [DONE] 2009-04-20: Review previous TODOs in light of first finished
|
140
|
+
prototype.
|
141
|
+
|
142
|
+
- [DONE] Change progress formatter lights, and light up only one
|
143
|
+
pass/fail/pending LED as specs run. As each example completes,
|
144
|
+
animate the display by moving the the one led to another spot. So if
|
145
|
+
all your specs are passing, you'll see the green light move 1 -> 2
|
146
|
+
-> 3 -> 4 -> 1 -> 2 etc. If you have any pending specs, they will
|
147
|
+
light up 1 -> 2 -> 1 -> 2 etc. When the test finishes, light up all
|
148
|
+
the status lights of the appropriate color.
|
149
|
+
|
150
|
+
|
data/bin/sparcumber
ADDED
data/bin/sparky
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
class Sparky
|
4
|
+
def show_run
|
5
|
+
# system "switchy 1 0 2 1 3 1 4 1"
|
6
|
+
system "switchy 1 1 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 1"
|
7
|
+
end
|
8
|
+
|
9
|
+
def show_fail
|
10
|
+
system "switchy 1 0 2 1 3 0 4 0 5 0 6 0 7 0 8 0 9 1 10 0"
|
11
|
+
end
|
12
|
+
|
13
|
+
def show_pending
|
14
|
+
system "switchy 1 0 2 0 3 1 4 0 5 0 6 0 7 0 8 1 9 0 10 0"
|
15
|
+
end
|
16
|
+
|
17
|
+
def show_pass
|
18
|
+
system "switchy 1 0 2 0 3 0 4 1 5 1 6 1 7 1 8 0 9 0 10 0"
|
19
|
+
end
|
20
|
+
|
21
|
+
def show_reset
|
22
|
+
system "switchy 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0"
|
23
|
+
end
|
24
|
+
|
25
|
+
def show_all
|
26
|
+
system "switchy 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1"
|
27
|
+
end
|
28
|
+
|
29
|
+
def show_selftest
|
30
|
+
show_reset
|
31
|
+
|
32
|
+
show_all
|
33
|
+
sleep 1.0
|
34
|
+
show_reset
|
35
|
+
|
36
|
+
1.upto(10) do |i|
|
37
|
+
system "switchy #{i} 1"
|
38
|
+
system "switchy #{i} 0"
|
39
|
+
end
|
40
|
+
|
41
|
+
%w(run fail pending pass).each do |msg|
|
42
|
+
send "show_#{msg}"
|
43
|
+
sleep 0.5
|
44
|
+
end
|
45
|
+
sleep 0.5
|
46
|
+
show_reset
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
if __FILE__==$0
|
51
|
+
s = Sparky.new
|
52
|
+
|
53
|
+
case ARGV[0].downcase
|
54
|
+
when "reset" then s.show_reset
|
55
|
+
when "pending" then s.show_pending
|
56
|
+
when "fail" then s.show_fail
|
57
|
+
when "pass" then s.show_pass
|
58
|
+
when "run" then s.show_run
|
59
|
+
when "test" then s.show_test
|
60
|
+
when "selftest" then s.show_selftest
|
61
|
+
when "spec"
|
62
|
+
lib_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'sparky_progress_formatter.rb'))
|
63
|
+
args = ARGV[1..-1].dup.map {|a| '"' + a.gsub(/"/, '\"') + '"' } * ' '
|
64
|
+
cmd = "spec --require #{lib_path} --format Spec::Runner::Formatter::SparkyProgressFormatter #{args}"
|
65
|
+
system(cmd)
|
66
|
+
else
|
67
|
+
# TODO: If spec or rake spec:*, bind formatter
|
68
|
+
# TODO: If autospec, bind formatter
|
69
|
+
s.show_run
|
70
|
+
|
71
|
+
cmd = ARGV.map {|a| '"' + a.gsub(/"/, '\"') + '"' } * ' '
|
72
|
+
|
73
|
+
if system(cmd)
|
74
|
+
s.show_pass
|
75
|
+
else
|
76
|
+
s.show_fail
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/bin/switchy
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
|
5
|
+
def usage
|
6
|
+
u = <<USAGE
|
7
|
+
switchy - turn external lights on/off
|
8
|
+
switchy <light> <0|1> [<light2> <0|1> [...]]
|
9
|
+
|
10
|
+
light:
|
11
|
+
0 - Onboard LED (reversed: 0 = on, 1 = off)
|
12
|
+
1-4 External Switches (1 = on)
|
13
|
+
|
14
|
+
example: Turn off onboard LED, turn on lights 2 and 4, turn off light 3, leave light 1 alone:
|
15
|
+
switchy 0 1 2 1 4 1 3 0
|
16
|
+
USAGE
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'switchy'
|
20
|
+
|
21
|
+
args = ARGV.dup
|
22
|
+
|
23
|
+
s = Switchy.new
|
24
|
+
# The serial port is a bit tetchy. Give it a few cycles to settle.
|
25
|
+
sleep 0.05
|
26
|
+
|
27
|
+
|
28
|
+
# lights by number => pair of pins, one to set high, the other low
|
29
|
+
# TODO: change these into on/off arrays so we can set multiple lights with a single command
|
30
|
+
# TODO: consider dropping this altogether and doing "switchy C4 1 C5 0" etc?
|
31
|
+
lights = {
|
32
|
+
0 => [nil, Switchy::PINS::D6 ],
|
33
|
+
1 => [Switchy::PINS::C4, Switchy::PINS::C5 ],
|
34
|
+
2 => [Switchy::PINS::C6, Switchy::PINS::C7 ],
|
35
|
+
3 => [Switchy::PINS::B7, Switchy::PINS::B6 ],
|
36
|
+
4 => [Switchy::PINS::B5, Switchy::PINS::B4 ],
|
37
|
+
5 => [Switchy::PINS::B3, Switchy::PINS::B2 ],
|
38
|
+
6 => [Switchy::PINS::D7, Switchy::PINS::B0 ],
|
39
|
+
7 => [Switchy::PINS::D5, Switchy::PINS::D6 ],
|
40
|
+
8 => [Switchy::PINS::D3, Switchy::PINS::D4 ],
|
41
|
+
9 => [Switchy::PINS::D1, Switchy::PINS::D2 ],
|
42
|
+
10 => [Switchy::PINS::C2, Switchy::PINS::D0 ],
|
43
|
+
}
|
44
|
+
|
45
|
+
until args.empty?
|
46
|
+
light = args.shift.to_i
|
47
|
+
command = args.shift.to_i
|
48
|
+
|
49
|
+
unless light >= 0 && light <= 10
|
50
|
+
puts usage
|
51
|
+
raise "ERROR: ARGV[1] must be between 0 and 10"
|
52
|
+
end
|
53
|
+
|
54
|
+
unless command >= 0 && command <= 1
|
55
|
+
puts usage
|
56
|
+
raise "ERROR: ARGV[2] must be one of on/off/status"
|
57
|
+
end
|
58
|
+
|
59
|
+
raise "ERROR: status not yet implemented" if command == 'status'
|
60
|
+
|
61
|
+
s.set_pin(lights[light][0], command) if lights[light][0]
|
62
|
+
s.set_pin(lights[light][1], 1-command) if lights[light][1]
|
63
|
+
end
|
64
|
+
|
65
|
+
|
data/lib/sparky.rb
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
dir = File.expand_path(File.dirname(__FILE__))
|
3
|
+
$: << dir unless $:.include?(dir)
|
4
|
+
require 'switchy'
|
5
|
+
|
6
|
+
class Sparky
|
7
|
+
attr_accessor :passed, :failed, :pending
|
8
|
+
|
9
|
+
@@run_pins = [[Switchy::PINS::C4, Switchy::PINS::C2], [Switchy::PINS::C5, Switchy::PINS::D0 ]]
|
10
|
+
@@fail_pins = [[Switchy::PINS::C6, Switchy::PINS::D1], [Switchy::PINS::C7, Switchy::PINS::D2]]
|
11
|
+
@@pending_pins = [[Switchy::PINS::B7, Switchy::PINS::D3], [Switchy::PINS::B6, Switchy::PINS::D4]]
|
12
|
+
@@pass_pins = [[Switchy::PINS::B3, Switchy::PINS::D7, Switchy::PINS::B5, Switchy::PINS::D5],
|
13
|
+
[Switchy::PINS::B2, Switchy::PINS::B0, Switchy::PINS::B4, Switchy::PINS::D6]]
|
14
|
+
|
15
|
+
@@reset_pins = [[Switchy::PINS::C4, Switchy::PINS::C2,
|
16
|
+
Switchy::PINS::C6, Switchy::PINS::D1,
|
17
|
+
Switchy::PINS::B7, Switchy::PINS::D3,
|
18
|
+
Switchy::PINS::B5, Switchy::PINS::B3,
|
19
|
+
Switchy::PINS::D7, Switchy::PINS::D5]]
|
20
|
+
def initialize
|
21
|
+
@passed, @failed, @pending = -1, -1, -1
|
22
|
+
@switchy = Switchy.new
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_pins(pins)
|
26
|
+
pins.first.each do |pin|
|
27
|
+
@switchy.set_pin pin, 1
|
28
|
+
end
|
29
|
+
pins.last.each do |pin|
|
30
|
+
@switchy.set_pin pin, 0
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def set_pin(pin)
|
35
|
+
@switchy.set_pin pin.first, 1
|
36
|
+
@switchy.set_pin pin.last, 0
|
37
|
+
end
|
38
|
+
|
39
|
+
def clear_pin(pin)
|
40
|
+
@switchy.set_pin pin.first, 0
|
41
|
+
end
|
42
|
+
|
43
|
+
def clear_pins(pins)
|
44
|
+
pins.first.each do |pin|
|
45
|
+
@switchy.set_pin pin, 0
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def pass
|
50
|
+
set_pins @@pass_pins
|
51
|
+
end
|
52
|
+
alias :passed :pass
|
53
|
+
|
54
|
+
def clear_pass
|
55
|
+
clear_pins @@pass_pins
|
56
|
+
end
|
57
|
+
|
58
|
+
def fail
|
59
|
+
set_pins @@fail_pins
|
60
|
+
end
|
61
|
+
alias :failed :fail
|
62
|
+
|
63
|
+
def clear_failed
|
64
|
+
clear_pins @@fail_pins
|
65
|
+
end
|
66
|
+
|
67
|
+
def pending
|
68
|
+
set_pins @@pending_pins
|
69
|
+
end
|
70
|
+
|
71
|
+
def clear_pending
|
72
|
+
clear_pins @@pending_pins
|
73
|
+
end
|
74
|
+
|
75
|
+
def run
|
76
|
+
set_pins @@run_pins
|
77
|
+
end
|
78
|
+
|
79
|
+
def clear_run
|
80
|
+
clear_pins @@run_pins
|
81
|
+
end
|
82
|
+
|
83
|
+
def reset
|
84
|
+
clear_pins @@reset_pins
|
85
|
+
end
|
86
|
+
|
87
|
+
def start_run
|
88
|
+
reset
|
89
|
+
run
|
90
|
+
end
|
91
|
+
|
92
|
+
def finish_run
|
93
|
+
reset
|
94
|
+
if @failed > -1
|
95
|
+
failed
|
96
|
+
elsif @pending > -1
|
97
|
+
pending
|
98
|
+
else
|
99
|
+
pass
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def example_passed
|
104
|
+
clear_pin pin(:passed, @passed % 4) if @passed >= 0
|
105
|
+
@passed += 1
|
106
|
+
set_pin pin(:passed, @passed % 4)
|
107
|
+
end
|
108
|
+
|
109
|
+
def example_failed
|
110
|
+
clear_pin pin(:failed, @failed % 2) if @failed >= 0
|
111
|
+
@failed += 1
|
112
|
+
set_pin pin(:failed, @failed % 2)
|
113
|
+
end
|
114
|
+
|
115
|
+
def example_pending
|
116
|
+
clear_pin pin(:pending, @pending % 2) if @pending >= 0
|
117
|
+
@pending += 1
|
118
|
+
set_pin pin(:pending, @pending % 2)
|
119
|
+
end
|
120
|
+
|
121
|
+
def pin(set, idx)
|
122
|
+
pins = case set
|
123
|
+
when :passed then @@pass_pins
|
124
|
+
when :failed then @@fail_pins
|
125
|
+
when :pending then @@pending_pins
|
126
|
+
end
|
127
|
+
[ pins.first[idx], pins.last[idx] ]
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
@@ -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
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec/runner/formatter/progress_bar_formatter'
|
3
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
require 'sparky'
|
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
|
+
|
11
|
+
module Spec
|
12
|
+
module Runner
|
13
|
+
module Formatter
|
14
|
+
class SparkyProgressFormatter < ProgressBarFormatter
|
15
|
+
@@anything_failed_ever = false
|
16
|
+
@@anything_pended_ever = false
|
17
|
+
|
18
|
+
def initialize(a,b)
|
19
|
+
super
|
20
|
+
@sparky = Sparky.new
|
21
|
+
@sparky.start_run
|
22
|
+
end
|
23
|
+
|
24
|
+
def start_dump
|
25
|
+
@sparky.finish_run
|
26
|
+
super
|
27
|
+
end
|
28
|
+
|
29
|
+
def example_passed(example)
|
30
|
+
@sparky.example_passed
|
31
|
+
super
|
32
|
+
end
|
33
|
+
|
34
|
+
def example_failed(example, counter, failure)
|
35
|
+
@@anything_failed_ever = true
|
36
|
+
@sparky.example_failed
|
37
|
+
super
|
38
|
+
end
|
39
|
+
|
40
|
+
def example_pending(example, message)
|
41
|
+
@@anything_pended_ever = true
|
42
|
+
@sparky.example_pending
|
43
|
+
super
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/switchy.rb
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "serialport"
|
4
|
+
|
5
|
+
class Switchy
|
6
|
+
module PINS
|
7
|
+
B0 = "B0"
|
8
|
+
B1 = "B1"
|
9
|
+
B2 = "B2"
|
10
|
+
B3 = "B3"
|
11
|
+
B4 = "B4"
|
12
|
+
B5 = "B5"
|
13
|
+
B6 = "B6"
|
14
|
+
B7 = "B7"
|
15
|
+
|
16
|
+
C2 = "C2"
|
17
|
+
C4 = "C4"
|
18
|
+
C5 = "C5"
|
19
|
+
C6 = "C6"
|
20
|
+
C7 = "C7"
|
21
|
+
|
22
|
+
D0 = "D0"
|
23
|
+
D1 = "D1"
|
24
|
+
D2 = "D2"
|
25
|
+
D3 = "D3"
|
26
|
+
D4 = "D4"
|
27
|
+
D5 = "D5"
|
28
|
+
D6 = "D6"
|
29
|
+
D7 = "D7"
|
30
|
+
|
31
|
+
OC1B = "C5"
|
32
|
+
|
33
|
+
OC1A = "C6"
|
34
|
+
|
35
|
+
ICP1 = "C7"
|
36
|
+
INT4 = "C7"
|
37
|
+
|
38
|
+
OC1C = "B7"
|
39
|
+
|
40
|
+
T1 = "B4"
|
41
|
+
|
42
|
+
M1S0 = "B3"
|
43
|
+
|
44
|
+
M0S1 = "B2"
|
45
|
+
|
46
|
+
SCLK = "B1"
|
47
|
+
|
48
|
+
SS = "B0"
|
49
|
+
|
50
|
+
INT7 = "D7"
|
51
|
+
HWB = "D7"
|
52
|
+
CTS = "D7"
|
53
|
+
T0 = "D7"
|
54
|
+
|
55
|
+
INT6 = "D6"
|
56
|
+
RTS = "D6"
|
57
|
+
LED = "D6"
|
58
|
+
|
59
|
+
XCK = "D5"
|
60
|
+
|
61
|
+
INT5 = "D4"
|
62
|
+
|
63
|
+
INT3 = "D3"
|
64
|
+
TXD1 = "D3"
|
65
|
+
TXD = "D3"
|
66
|
+
|
67
|
+
INT2 = "D2"
|
68
|
+
AIN1 = "D2"
|
69
|
+
RXD1 = "D2"
|
70
|
+
RXD = "D2"
|
71
|
+
|
72
|
+
INT1 = "D1"
|
73
|
+
AIN0 = "D1"
|
74
|
+
|
75
|
+
INT0 = "D0"
|
76
|
+
OC0B = "D0"
|
77
|
+
|
78
|
+
PD0 = "D0"
|
79
|
+
PD1 = "D1"
|
80
|
+
PD2 = "D2"
|
81
|
+
PD3 = "D3"
|
82
|
+
PD4 = "D4"
|
83
|
+
PD5 = "D5"
|
84
|
+
PD6 = "D6"
|
85
|
+
PD7 = "D7"
|
86
|
+
end
|
87
|
+
|
88
|
+
attr_accessor :modem, :baud
|
89
|
+
attr_accessor :borked # true when the device was not found at startup. Makes switchy-inclusive apps noncrashy when they find themselves unexpectedly switchy-excluded
|
90
|
+
def borked?; @borked; end
|
91
|
+
|
92
|
+
def initialize(modem = '/dev/tty.usbmodem12341', baud=38400)
|
93
|
+
@borked = !File.exists?(modem)
|
94
|
+
puts "**** Could not find Switchy device on #{modem}" if borked?
|
95
|
+
@modem, @baud = modem, baud
|
96
|
+
connect
|
97
|
+
end
|
98
|
+
|
99
|
+
def connect
|
100
|
+
return if borked?
|
101
|
+
@sp = SerialPort.new @modem, @baud
|
102
|
+
end
|
103
|
+
|
104
|
+
def disconnect
|
105
|
+
return if borked?
|
106
|
+
# ???
|
107
|
+
end
|
108
|
+
|
109
|
+
# Set pin "b4", 1 # turn on pin b4
|
110
|
+
def set_pin(p, v)
|
111
|
+
return if borked?
|
112
|
+
cmd = "#{p.upcase}=#{v}\r\n"
|
113
|
+
@sp.write cmd
|
114
|
+
end
|
115
|
+
|
116
|
+
def set_light(l, v)
|
117
|
+
return if borked?
|
118
|
+
cmd = "C#{l+3}=#{v}\r\n"
|
119
|
+
@sp.write cmd
|
120
|
+
end
|
121
|
+
|
122
|
+
def light1=(v)
|
123
|
+
return if borked?
|
124
|
+
set_light 1, v
|
125
|
+
end
|
126
|
+
|
127
|
+
def light2=(v)
|
128
|
+
return if borked?
|
129
|
+
set_light 2, v
|
130
|
+
end
|
131
|
+
|
132
|
+
def light3=(v)
|
133
|
+
return if borked?
|
134
|
+
set_light 3, v
|
135
|
+
end
|
136
|
+
|
137
|
+
def light4=(v)
|
138
|
+
return if borked?
|
139
|
+
set_light 4, v
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: switchy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Brady
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-09 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: ruby-serialport
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: Switchy USB serial load switcher
|
26
|
+
email: github@shinybit.com
|
27
|
+
executables:
|
28
|
+
- switchy
|
29
|
+
- sparky
|
30
|
+
- sparcumber
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files:
|
34
|
+
- README.rdoc
|
35
|
+
- MIT-LICENSE
|
36
|
+
files:
|
37
|
+
- bin/sparky
|
38
|
+
- bin/switchy
|
39
|
+
- bin/sparcumber
|
40
|
+
- lib/sparky.rb
|
41
|
+
- lib/sparky_cucumber.rb
|
42
|
+
- lib/sparky_progress_formatter.rb
|
43
|
+
- res/spec.sparky.opts
|
44
|
+
- lib/switchy.rb
|
45
|
+
- README.rdoc
|
46
|
+
- MIT-LICENSE
|
47
|
+
has_rdoc: true
|
48
|
+
homepage: http://github.com/dbrady/switchy
|
49
|
+
licenses: []
|
50
|
+
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- --line-numbers
|
54
|
+
- --inline-source
|
55
|
+
- --main
|
56
|
+
- README.rdoc
|
57
|
+
- --title
|
58
|
+
- Switchy - USB serial load switcher
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
version:
|
73
|
+
requirements: []
|
74
|
+
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 1.3.5
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: Switchy USB serial load switcher
|
80
|
+
test_files: []
|
81
|
+
|