Class: Sparky
- Inherits:
-
Object
- Object
- Sparky
- Defined in:
- lib/sparky.rb
Constant Summary collapse
- @@run_pins =
[[Switchy::PINS::C4, Switchy::PINS::C2], [Switchy::PINS::C5, Switchy::PINS::D0 ]]
- @@fail_pins =
[[Switchy::PINS::C6, Switchy::PINS::D1], [Switchy::PINS::C7, Switchy::PINS::D2]]
- @@pending_pins =
[[Switchy::PINS::B7, Switchy::PINS::D3], [Switchy::PINS::B6, Switchy::PINS::D4]]
- @@pass_pins =
[[Switchy::PINS::B3, Switchy::PINS::D7, Switchy::PINS::B5, Switchy::PINS::D5], [Switchy::PINS::B2, Switchy::PINS::B0, Switchy::PINS::B4, Switchy::PINS::D6]]
- @@reset_pins =
[[Switchy::PINS::C4, Switchy::PINS::C2, Switchy::PINS::C6, Switchy::PINS::D1, Switchy::PINS::B7, Switchy::PINS::D3, Switchy::PINS::B5, Switchy::PINS::B3, Switchy::PINS::D7, Switchy::PINS::D5]]
Instance Attribute Summary collapse
-
#failed ⇒ Object
Returns the value of attribute failed.
-
#passed ⇒ Object
Returns the value of attribute passed.
-
#pending ⇒ Object
Returns the value of attribute pending.
Instance Method Summary collapse
- #clear_failed ⇒ Object
- #clear_pass ⇒ Object
- #clear_pending ⇒ Object
- #clear_pin(pin) ⇒ Object
- #clear_pins(pins) ⇒ Object
- #clear_run ⇒ Object
- #example_failed ⇒ Object
- #example_passed ⇒ Object
- #example_pending ⇒ Object
- #finish_run ⇒ Object
-
#initialize ⇒ Sparky
constructor
A new instance of Sparky.
- #pass ⇒ Object
- #pin(set, idx) ⇒ Object
- #reset ⇒ Object
- #run ⇒ Object
- #set_pin(pin) ⇒ Object
- #set_pins(pins) ⇒ Object
- #start_run ⇒ Object
Constructor Details
Instance Attribute Details
#failed ⇒ Object
Returns the value of attribute failed.
7 8 9 |
# File 'lib/sparky.rb', line 7 def failed @failed end |
#passed ⇒ Object
Returns the value of attribute passed.
7 8 9 |
# File 'lib/sparky.rb', line 7 def passed @passed end |
#pending ⇒ Object
Returns the value of attribute pending.
7 8 9 |
# File 'lib/sparky.rb', line 7 def pending @pending end |
Instance Method Details
#clear_failed ⇒ Object
61 62 63 |
# File 'lib/sparky.rb', line 61 def clear_failed clear_pins @@fail_pins end |
#clear_pass ⇒ Object
53 54 55 |
# File 'lib/sparky.rb', line 53 def clear_pass clear_pins @@pass_pins end |
#clear_pending ⇒ Object
69 70 71 |
# File 'lib/sparky.rb', line 69 def clear_pending clear_pins @@pending_pins end |
#clear_pin(pin) ⇒ Object
39 40 41 |
# File 'lib/sparky.rb', line 39 def clear_pin(pin) @switchy.set_pin pin.first, 0 end |
#clear_pins(pins) ⇒ Object
43 44 45 46 47 |
# File 'lib/sparky.rb', line 43 def clear_pins(pins) pins.first.each do |pin| @switchy.set_pin pin, 0 end end |
#clear_run ⇒ Object
77 78 79 |
# File 'lib/sparky.rb', line 77 def clear_run clear_pins @@run_pins end |
#example_failed ⇒ Object
107 108 109 110 111 |
# File 'lib/sparky.rb', line 107 def example_failed clear_pin pin(:failed, @failed % 2) if @failed >= 0 @failed += 1 set_pin pin(:failed, @failed % 2) end |
#example_passed ⇒ Object
101 102 103 104 105 |
# File 'lib/sparky.rb', line 101 def example_passed clear_pin pin(:passed, @passed % 4) if @passed >= 0 @passed += 1 set_pin pin(:passed, @passed % 4) end |
#example_pending ⇒ Object
113 114 115 116 117 |
# File 'lib/sparky.rb', line 113 def example_pending clear_pin pin(:pending, @pending % 2) if @pending >= 0 @pending += 1 set_pin pin(:pending, @pending % 2) end |
#finish_run ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/sparky.rb', line 90 def finish_run reset if @failed > -1 failed elsif @pending > -1 pending else pass end end |
#pass ⇒ Object
49 50 51 |
# File 'lib/sparky.rb', line 49 def pass set_pins @@pass_pins end |
#pin(set, idx) ⇒ Object
119 120 121 122 123 124 125 126 |
# File 'lib/sparky.rb', line 119 def pin(set, idx) pins = case set when :passed then @@pass_pins when :failed then @@fail_pins when :pending then @@pending_pins end [ pins.first[idx], pins.last[idx] ] end |
#reset ⇒ Object
81 82 83 |
# File 'lib/sparky.rb', line 81 def reset clear_pins @@reset_pins end |
#run ⇒ Object
73 74 75 |
# File 'lib/sparky.rb', line 73 def run set_pins @@run_pins end |
#set_pin(pin) ⇒ Object
34 35 36 37 |
# File 'lib/sparky.rb', line 34 def set_pin(pin) @switchy.set_pin pin.first, 1 @switchy.set_pin pin.last, 0 end |
#set_pins(pins) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/sparky.rb', line 25 def set_pins(pins) pins.first.each do |pin| @switchy.set_pin pin, 1 end pins.last.each do |pin| @switchy.set_pin pin, 0 end end |
#start_run ⇒ Object
85 86 87 88 |
# File 'lib/sparky.rb', line 85 def start_run reset run end |