Module: I2C::Drivers
- Defined in:
- lib/i2c/drivers/mcp230xx.rb
Defined Under Namespace
Modules: MCP230xx
Class Method Summary collapse
-
.define_mcp230xx_chip(name, parameters) ⇒ Object
Defines a class for a chip implementation.
Instance Method Summary collapse
-
#gpio(no) ⇒ Integer
Returns the address of the GPIO register for an IO port.
-
#iodir(no) ⇒ Object
Returns the address of the IO direction register for an IO port.
-
#max_pin_no ⇒ Integer
Returns the highest pin index.
-
#max_port_no ⇒ Integer
Returns the highest port index.
-
#pin_count ⇒ Integer
Returns the number of pins in the io expander.
-
#port_count ⇒ Integer
Returns the number of ports in the io expander.
Class Method Details
.define_mcp230xx_chip(name, parameters) ⇒ Object
Defines a class for a chip implementation.
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/i2c/drivers/mcp230xx.rb', line 213 def self.define_mcp230xx_chip(name, parameters) raise ArgumentError, "Expecting options hash." unless parameters.kind_of? Hash [ [ :pin_count, Integer ], [ :port_count, Integer ], [ :iodir, Array ], [ :gpio, Array ] ].each do |expected_key| raise ArgumentError, "Missing option #{expected_key[0]}" unless parameters.has_key? expected_key[0] raise ArgumentError, "Option #{expected_key[0]} expected to be a #{expected_key[1]}" unless parameters[expected_key[0]].kind_of? expected_key[1] end chip_class = self.const_set(name.to_sym, Class.new) chip_class.instance_eval do include MCP230xx parameters.each do |method_name, return_value| #puts "Defining #{name}##{method_name.to_sym}" define_method method_name.to_sym do return_value end end define_method :max_pin_no do parameters[:pin_count] - 1 end define_method :max_port_no do parameters[:port_count] - 1 end end chip_class end |
Instance Method Details
#gpio(no) ⇒ Integer
Returns the address of the GPIO register for an IO port.
|
# File 'lib/i2c/drivers/mcp230xx.rb', line 181
|
#iodir(no) ⇒ Object
Returns the address of the IO direction register for an IO port.
|
# File 'lib/i2c/drivers/mcp230xx.rb', line 173
|
#max_pin_no ⇒ Integer
Returns the highest pin index. Usually #pin_count - 1.
|
# File 'lib/i2c/drivers/mcp230xx.rb', line 194
|
#max_port_no ⇒ Integer
Returns the highest port index. Usually #port_count - 1.
|
# File 'lib/i2c/drivers/mcp230xx.rb', line 204
|
#pin_count ⇒ Integer
Returns the number of pins in the io expander.
|
# File 'lib/i2c/drivers/mcp230xx.rb', line 189
|
#port_count ⇒ Integer
Returns the number of ports in the io expander.
|
# File 'lib/i2c/drivers/mcp230xx.rb', line 199
|