Class: UChip::MCP2221::GPSettings
- Inherits:
-
Object
- Object
- UChip::MCP2221::GPSettings
- Defined in:
- lib/uchip/mcp2221.rb
Instance Attribute Summary collapse
-
#bytes ⇒ Object
readonly
Returns the value of attribute bytes.
Instance Method Summary collapse
- #decode(bytes) ⇒ Object
- #designation_at(i) ⇒ Object
- #direction_at(i) ⇒ Object
-
#initialize(bytes) ⇒ GPSettings
constructor
A new instance of GPSettings.
- #inspect ⇒ Object
- #output_value_at(i) ⇒ Object
- #set_designation_at(i, v) ⇒ Object
- #set_direction_at(i, v) ⇒ Object
- #set_output_value_at(i, v) ⇒ Object
Constructor Details
#initialize(bytes) ⇒ GPSettings
Returns a new instance of GPSettings.
125 126 127 |
# File 'lib/uchip/mcp2221.rb', line 125 def initialize bytes @bytes = bytes end |
Instance Attribute Details
#bytes ⇒ Object (readonly)
Returns the value of attribute bytes.
123 124 125 |
# File 'lib/uchip/mcp2221.rb', line 123 def bytes @bytes end |
Instance Method Details
#decode(bytes) ⇒ Object
167 168 169 170 171 172 173 |
# 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) ⇒ Object
151 152 153 |
# File 'lib/uchip/mcp2221.rb', line 151 def designation_at i (bytes[i] >> 0) & 0x3 end |
#direction_at(i) ⇒ Object
142 143 144 |
# File 'lib/uchip/mcp2221.rb', line 142 def direction_at i (bytes[i] >> 3) & 0x1 end |
#inspect ⇒ Object
129 130 131 |
# File 'lib/uchip/mcp2221.rb', line 129 def inspect to_s.sub(/>$/, " #{decode(@bytes).inspect}>") end |
#output_value_at(i) ⇒ Object
133 134 135 |
# File 'lib/uchip/mcp2221.rb', line 133 def output_value_at i (bytes[i] >> 4) & 0x1 end |
#set_designation_at(i, v) ⇒ Object
155 156 157 158 |
# 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) ⇒ Object
146 147 148 149 |
# 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) ⇒ Object
137 138 139 140 |
# File 'lib/uchip/mcp2221.rb', line 137 def set_output_value_at i, v bytes[i] &= ~(1 << 4) bytes[i] |= (1 & v) << 4 end |