class UChip::MCP2221::GPSettings
Attributes
bytes[R]
Public Class Methods
new(bytes)
click to toggle source
# File lib/uchip/mcp2221.rb, line 125 def initialize bytes @bytes = bytes end
Public Instance Methods
decode(bytes)
click to toggle source
# File lib/uchip/mcp2221.rb, line 167 def decode bytes 4.times.each_with_object({}) { |i, o| o[:"gp#{i}_output_value"] = output_value_at(i) o[:"gp#{i}_direction"] = direction_at(i) o[:"gp#{i}_designation"] = designation_at(i) } end
designation_at(i)
click to toggle source
# File lib/uchip/mcp2221.rb, line 151 def designation_at i (bytes[i] >> 0) & 0x3 end
direction_at(i)
click to toggle source
# File lib/uchip/mcp2221.rb, line 142 def direction_at i (bytes[i] >> 3) & 0x1 end
inspect()
click to toggle source
# File lib/uchip/mcp2221.rb, line 129 def inspect to_s.sub(/>$/, " #{decode(@bytes).inspect}>") end
output_value_at(i)
click to toggle source
# File lib/uchip/mcp2221.rb, line 133 def output_value_at i (bytes[i] >> 4) & 0x1 end
set_designation_at(i, v)
click to toggle source
# File lib/uchip/mcp2221.rb, line 155 def set_designation_at i, v bytes[i] &= ~(0x3 << 0) bytes[i] |= (0x3 & v) << 0 end
set_direction_at(i, v)
click to toggle source
# File lib/uchip/mcp2221.rb, line 146 def set_direction_at i, v bytes[i] &= ~(1 << 3) bytes[i] |= (1 & v) << 3 end
set_output_value_at(i, v)
click to toggle source
# File lib/uchip/mcp2221.rb, line 137 def set_output_value_at i, v bytes[i] &= ~(1 << 4) bytes[i] |= (1 & v) << 4 end