Class: UChip::MCP2221::ChipSettings
- Inherits:
-
Object
- Object
- UChip::MCP2221::ChipSettings
- Defined in:
- lib/uchip/mcp2221.rb
Constant Summary collapse
- BIT_FIELDS =
[]
Instance Attribute Summary collapse
-
#bytes ⇒ Object
readonly
Returns the value of attribute bytes.
Class Method Summary collapse
- .bit_attr_accesor(name, index, offset, mask) ⇒ Object
- .bool_attr_accessor(name, index, offset) ⇒ Object
Instance Method Summary collapse
- #decode(bytes) ⇒ Object
-
#initialize(bytes) ⇒ ChipSettings
constructor
A new instance of ChipSettings.
- #inspect ⇒ Object
Constructor Details
#initialize(bytes) ⇒ ChipSettings
Returns a new instance of ChipSettings.
43 44 45 |
# File 'lib/uchip/mcp2221.rb', line 43 def initialize bytes @bytes = bytes end |
Instance Attribute Details
#bytes ⇒ Object (readonly)
Returns the value of attribute bytes.
94 95 96 |
# File 'lib/uchip/mcp2221.rb', line 94 def bytes @bytes end |
Class Method Details
.bit_attr_accesor(name, index, offset, mask) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/uchip/mcp2221.rb', line 56 def self.bit_attr_accesor name, index, offset, mask BIT_FIELDS << name define_method(name) do (bytes[index] >> offset) & mask end define_method(:"#{name}=") do |v| bytes[index] &= ~(mask << offset) bytes[index] |= ((mask & v) << offset) end end |
.bool_attr_accessor(name, index, offset) ⇒ Object
52 53 54 |
# File 'lib/uchip/mcp2221.rb', line 52 def self.bool_attr_accessor name, index, offset bit_attr_accesor name, index, offset, 0x1 end |
Instance Method Details
#decode(bytes) ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/uchip/mcp2221.rb', line 85 def decode bytes BIT_FIELDS.each_with_object({}) { |n, o| o[n] = send n }.merge({ :vid => bytes[4] + (bytes[5] << 8), :pid => bytes[6] + (bytes[7] << 8), :usb_power_attributes => bytes[8], :usb_requested_mas => bytes[9], }) end |
#inspect ⇒ Object
47 48 49 |
# File 'lib/uchip/mcp2221.rb', line 47 def inspect to_s.sub(/>$/, " #{decode(@bytes).inspect}>") end |