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.
-
#modem ⇒ Object
Returns the value of attribute modem.
Instance Method Summary collapse
- #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.
90 91 92 93 |
# File 'lib/switchy.rb', line 90 def initialize(modem = '/dev/tty.usbmodem12341', baud=38400) @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 |
#modem ⇒ Object
Returns the value of attribute modem.
88 89 90 |
# File 'lib/switchy.rb', line 88 def modem @modem end |
Instance Method Details
#connect ⇒ Object
95 96 97 |
# File 'lib/switchy.rb', line 95 def connect @sp = SerialPort.new @modem, @baud end |
#disconnect ⇒ Object
99 100 101 |
# File 'lib/switchy.rb', line 99 def disconnect # ??? end |
#light1=(v) ⇒ Object
114 115 116 |
# File 'lib/switchy.rb', line 114 def light1=(v) set_light 1, v end |
#light2=(v) ⇒ Object
118 119 120 |
# File 'lib/switchy.rb', line 118 def light2=(v) set_light 2, v end |
#light3=(v) ⇒ Object
122 123 124 |
# File 'lib/switchy.rb', line 122 def light3=(v) set_light 3, v end |
#light4=(v) ⇒ Object
126 127 128 |
# File 'lib/switchy.rb', line 126 def light4=(v) set_light 4, v end |
#set_light(l, v) ⇒ Object
109 110 111 112 |
# File 'lib/switchy.rb', line 109 def set_light(l, v) cmd = "C#{l+3}=#{v}\r\n" @sp.write cmd end |
#set_pin(p, v) ⇒ Object
Set pin “b4”, 1 # turn on pin b4
104 105 106 107 |
# File 'lib/switchy.rb', line 104 def set_pin(p, v) cmd = "#{p.upcase}=#{v}\r\n" @sp.write cmd end |