class Wifly::Control
Attributes
connection[RW]
Public Class Methods
new(address, port, connection=nil)
click to toggle source
address - the hostname or IP address port - defaults to 2000 connection - the object to use for talking to the wifly. Responds to “send_command.”
Defaults to Wifly::Connection.
# File lib/wifly/control.rb, line 13 def initialize(address, port, connection=nil) self.connection = connection || Connection.new(address, port) end
Public Instance Methods
close()
click to toggle source
Close the connection.
# File lib/wifly/control.rb, line 57 def close connection.close end
high_pins()
click to toggle source
Return an array of all the pins which are currently high
# File lib/wifly/control.rb, line 50 def high_pins parse_io(read_io) end
lites()
click to toggle source
Toggle the blinking lights on the device
# File lib/wifly/control.rb, line 20 def lites connection.send_command("lites") end
read_pin(pin)
click to toggle source
given a pin number, return 1 if high or 0 if low
# File lib/wifly/control.rb, line 43 def read_pin(pin) high_pins.include?(pin) ? 1 : 0 end
set_high(pin)
click to toggle source
set a pin high
# File lib/wifly/control.rb, line 27 def set_high(pin) hex = pin_to_hex(pin) connection.send_command "set sys output #{hex} #{hex}" end
set_low(pin)
click to toggle source
set a pin low
# File lib/wifly/control.rb, line 35 def set_low(pin) hex = pin_to_hex(pin) connection.send_command "set sys output 0x00 #{hex}" end
Private Instance Methods
read_io()
click to toggle source
Gets the status of all IO pins on wifly. Returns a hex string.
# File lib/wifly/control.rb, line 66 def read_io cmd = "show io\r" # result is something like 'show io\r\r\n8d08' str = connection.send_command "show io" # Return only the middle part, which is the io state str.gsub(cmd,'').strip end