class UChip::MCP2221::ChipSettings
Constants
- BIT_FIELDS
Attributes
bytes[R]
Public Class Methods
bit_attr_accesor(name, index, offset, mask)
click to toggle source
# 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)
click to toggle source
# File lib/uchip/mcp2221.rb, line 52 def self.bool_attr_accessor name, index, offset bit_attr_accesor name, index, offset, 0x1 end
new(bytes)
click to toggle source
# File lib/uchip/mcp2221.rb, line 43 def initialize bytes @bytes = bytes end
Public Instance Methods
decode(bytes)
click to toggle source
# 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()
click to toggle source
# File lib/uchip/mcp2221.rb, line 47 def inspect to_s.sub(/>$/, " #{decode(@bytes).inspect}>") end