Class: Player::AIO

Inherits:
Device show all
Includes:
Enumerable
Defined in:
lib/ruby-player/aio.rb

Overview

The aio interface provides access to an analog I/O device.

Instance Attribute Summary collapse

Attributes inherited from Device

#addr

Instance Method Summary collapse

Methods inherited from Device

#handle_response, #send_message

Constructor Details

#initialize(dev, client) ⇒ AIO

Returns a new instance of AIO.



22
23
24
25
# File 'lib/ruby-player/aio.rb', line 22

def initialize(dev, client)
  super
  @state = { voltages: [] }
end

Instance Attribute Details

#stateObject (readonly)

Returns the value of attribute state.



20
21
22
# File 'lib/ruby-player/aio.rb', line 20

def state
  @state
end

Instance Method Details

#[](id) ⇒ Float

Get single sample [V]

Returns:

  • (Float)


53
54
55
# File 'lib/ruby-player/aio.rb', line 53

def [](id)
  state[:voltages][id] 
end

#[]=(id, voltage) ⇒ Object

See Also:



58
59
60
# File 'lib/ruby-player/aio.rb', line 58

def []=(id, voltage)
  set_voltage(id, voltage) 
end

#eachObject



62
63
64
# File 'lib/ruby-player/aio.rb', line 62

def each
  state[:voltages].each { |v| yield v }  
end

#fill(hdr, msg) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/ruby-player/aio.rb', line 42

def fill(hdr, msg)
  case hdr.subtype
  when PLAYER_AIO_DATA_STATE
    read_state(msg)
  else
    unexpected_message hdr
  end
end

#set_voltage(id, voltage) ⇒ AIO

The aio interface allows for the voltage level on one output to be set

Parameters:

  • id (Integer)

    which I/O output to command.

  • voltage (Float)

    voltage level to set.

Returns:

  • (AIO)

    self



37
38
39
40
# File 'lib/ruby-player/aio.rb', line 37

def set_voltage(id, voltage)
  send_message(PLAYER_MSGTYPE_CMD, PLAYER_AIO_CMD_STATE, [id, voltage].pack("Ng"))
  self
end

#voltagesObject

The samples [V]



29
30
31
# File 'lib/ruby-player/aio.rb', line 29

def voltages
  state[:voltages]
end