Class: Wifly::Control

Inherits:
Object
  • Object
show all
Includes:
Calculations
Defined in:
lib/wifly/control.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Calculations

#parse_io, #pin_to_hex

Constructor Details

#initialize(address, port, connection = nil) ⇒ Control

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.


13
14
15
# File 'lib/wifly/control.rb', line 13

def initialize(address, port, connection=nil)
  self.connection   = connection || Connection.new(address, port)
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



5
6
7
# File 'lib/wifly/control.rb', line 5

def connection
  @connection
end

Instance Method Details

#closeObject

Close the connection.



57
58
59
# File 'lib/wifly/control.rb', line 57

def close
  connection.close
end

#high_pinsObject

Return an array of all the pins which are currently high



50
51
52
# File 'lib/wifly/control.rb', line 50

def high_pins
  parse_io(read_io)
end

#litesObject

Toggle the blinking lights on the device



20
21
22
# File 'lib/wifly/control.rb', line 20

def lites
  connection.send_command("lites")
end

#read_pin(pin) ⇒ Object

given a pin number, return 1 if high or 0 if low



43
44
45
# File 'lib/wifly/control.rb', line 43

def read_pin(pin)
  high_pins.include?(pin) ? 1 : 0
end

#set_high(pin) ⇒ Object

set a pin high



27
28
29
30
# 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) ⇒ Object

set a pin low



35
36
37
38
# 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