Class: Switchy
- Inherits:
-
Object
- Object
- Switchy
- Defined in:
- lib/switchy.rb
Defined Under Namespace
Modules: PINS
Instance Attribute Summary collapse
-
#baud ⇒ Object
Returns the value of attribute baud.
-
#borked ⇒ Object
true when the device was not found at startup.
-
#modem ⇒ Object
Returns the value of attribute modem.
Instance Method Summary collapse
- #borked? ⇒ Boolean
- #connect ⇒ Object
- #disconnect ⇒ Object
-
#initialize(modem = '/dev/tty.usbmodem12341', baud = 38400) ⇒ Switchy
constructor
A new instance of Switchy.
- #light1=(v) ⇒ Object
- #light2=(v) ⇒ Object
- #light3=(v) ⇒ Object
- #light4=(v) ⇒ Object
- #set_light(l, v) ⇒ Object
-
#set_pin(p, v) ⇒ Object
Set pin “b4”, 1 # turn on pin b4.
Constructor Details
#initialize(modem = '/dev/tty.usbmodem12341', baud = 38400) ⇒ Switchy
Returns a new instance of Switchy.
92 93 94 95 96 97 |
# File 'lib/switchy.rb', line 92 def initialize(modem = '/dev/tty.usbmodem12341', baud=38400) @borked = !File.exists?(modem) puts "**** Could not find Switchy device on #{modem}" if borked? @modem, @baud = modem, baud connect end |
Instance Attribute Details
#baud ⇒ Object
Returns the value of attribute baud.
88 89 90 |
# File 'lib/switchy.rb', line 88 def baud @baud end |
#borked ⇒ Object
true when the device was not found at startup. Makes switchy-inclusive apps noncrashy when they find themselves unexpectedly switchy-excluded
89 90 91 |
# File 'lib/switchy.rb', line 89 def borked @borked end |
#modem ⇒ Object
Returns the value of attribute modem.
88 89 90 |
# File 'lib/switchy.rb', line 88 def modem @modem end |
Instance Method Details
#borked? ⇒ Boolean
90 |
# File 'lib/switchy.rb', line 90 def borked?; @borked; end |
#connect ⇒ Object
99 100 101 102 |
# File 'lib/switchy.rb', line 99 def connect return if borked? @sp = SerialPort.new @modem, @baud end |
#disconnect ⇒ Object
104 105 106 107 |
# File 'lib/switchy.rb', line 104 def disconnect return if borked? # ??? end |
#light1=(v) ⇒ Object
122 123 124 125 |
# File 'lib/switchy.rb', line 122 def light1=(v) return if borked? set_light 1, v end |
#light2=(v) ⇒ Object
127 128 129 130 |
# File 'lib/switchy.rb', line 127 def light2=(v) return if borked? set_light 2, v end |
#light3=(v) ⇒ Object
132 133 134 135 |
# File 'lib/switchy.rb', line 132 def light3=(v) return if borked? set_light 3, v end |
#light4=(v) ⇒ Object
137 138 139 140 |
# File 'lib/switchy.rb', line 137 def light4=(v) return if borked? set_light 4, v end |
#set_light(l, v) ⇒ Object
116 117 118 119 120 |
# File 'lib/switchy.rb', line 116 def set_light(l, v) return if borked? cmd = "C#{l+3}=#{v}\r\n" @sp.write cmd end |
#set_pin(p, v) ⇒ Object
Set pin “b4”, 1 # turn on pin b4
110 111 112 113 114 |
# File 'lib/switchy.rb', line 110 def set_pin(p, v) return if borked? cmd = "#{p.upcase}=#{v}\r\n" @sp.write cmd end |