Class: PiDriver::Device::MCP23017::HardwareAddress

Inherits:
Object
  • Object
show all
Defined in:
lib/pi_driver/device/mcp23017/hardware_address.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ HardwareAddress

Returns a new instance of HardwareAddress.



7
8
9
10
11
12
13
14
15
# File 'lib/pi_driver/device/mcp23017/hardware_address.rb', line 7

def initialize(options)
  @argument_helper = Utils::ArgumentHelper.new prefix: 'MCP23017::HardwareAddress'

  @observer = options.delete :observer

  @a0 = Utils::State::LOW
  @a1 = Utils::State::LOW
  @a2 = Utils::State::LOW
end

Instance Attribute Details

#a0Object (readonly)

Returns the value of attribute a0.



5
6
7
# File 'lib/pi_driver/device/mcp23017/hardware_address.rb', line 5

def a0
  @a0
end

#a1Object (readonly)

Returns the value of attribute a1.



5
6
7
# File 'lib/pi_driver/device/mcp23017/hardware_address.rb', line 5

def a1
  @a1
end

#a2Object (readonly)

Returns the value of attribute a2.



5
6
7
# File 'lib/pi_driver/device/mcp23017/hardware_address.rb', line 5

def a2
  @a2
end

Class Method Details

.address_writer(*addresses) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pi_driver/device/mcp23017/hardware_address.rb', line 17

def self.address_writer(*addresses)
  addresses.each do |address|
    setter_symbol = "#{address}=".to_sym
    getter_instance = "@#{address}"

    define_method setter_symbol do |value|
      @argument_helper.check(:hardware_address, value, Utils::State::VALID_STATES)
      instance_variable_set(getter_instance, value)
      @observer.update_opcodes
      instance_variable_get getter_instance
    end
  end
end