Class: Denko::OneWire::Bus
- Inherits:
-
Object
- Object
- Denko::OneWire::Bus
- Includes:
- Behaviors::BusControllerAddressed, Behaviors::Reader, Behaviors::SinglePin, BusEnumerator, Constants
- Defined in:
- lib/denko/one_wire/bus.rb
Constant Summary
Constants included from Constants
Constants::ALARM_SEARCH, Constants::CONVERT_T, Constants::COPY_SCRATCH, Constants::MATCH_ROM, Constants::READ_POWER_SUPPLY, Constants::READ_ROM, Constants::READ_SCRATCH, Constants::RECALL_EEPROM, Constants::SEARCH_ROM, Constants::SKIP_ROM, Constants::WRITE_SCRATCH
Constants included from BusEnumerator
Denko::OneWire::BusEnumerator::PERIPHERAL_CLASSES
Instance Attribute Summary collapse
-
#parasite_power ⇒ Object
readonly
Returns the value of attribute parasite_power.
Attributes included from Behaviors::Callbacks
Attributes included from Behaviors::SinglePin
Attributes included from Behaviors::Component
Instance Method Summary collapse
- #_read(num_bytes) ⇒ Object
- #after_initialize(options = {}) ⇒ Object
- #device_present ⇒ Object (also: #device_present?)
- #pre_callback_filter(bytes) ⇒ Object
- #read_power_supply ⇒ Object
- #reset(get_presence = 0) ⇒ Object
- #write(*bytes) ⇒ Object
Methods included from BusEnumerator
#_search, #family_lookup, #found_devices, #parse_search_result, #search, #split_search_result
Methods included from Behaviors::Reader
#read, #read_using, #wait_for_read
Methods included from Behaviors::Callbacks
#add_callback, #callbacks, #initialize, #remove_callback, #update
Methods included from Behaviors::State
Methods included from Behaviors::BusControllerAddressed
Methods included from Behaviors::BusController
Methods included from Behaviors::Subcomponents
#add_component, #components, #remove_component, #single_pin_components
Methods included from Behaviors::Component
Instance Attribute Details
#parasite_power ⇒ Object (readonly)
Returns the value of attribute parasite_power.
10 11 12 |
# File 'lib/denko/one_wire/bus.rb', line 10 def parasite_power @parasite_power end |
Instance Method Details
#_read(num_bytes) ⇒ Object
45 46 47 |
# File 'lib/denko/one_wire/bus.rb', line 45 def _read(num_bytes) board.one_wire_read(pin, num_bytes) end |
#after_initialize(options = {}) ⇒ Object
12 13 14 15 |
# File 'lib/denko/one_wire/bus.rb', line 12 def after_initialize( = {}) super() read_power_supply end |
#device_present ⇒ Object Also known as: device_present?
33 34 35 36 37 38 |
# File 'lib/denko/one_wire/bus.rb', line 33 def device_present mutex.synchronize do byte = read_using -> { reset(1) } (byte == 0) ? true : false end end |
#pre_callback_filter(bytes) ⇒ Object
55 56 57 58 |
# File 'lib/denko/one_wire/bus.rb', line 55 def pre_callback_filter(bytes) bytes = bytes.split(",").map(&:to_i) bytes.length > 1 ? bytes : bytes[0] end |
#read_power_supply ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/denko/one_wire/bus.rb', line 17 def read_power_supply mutex.synchronize do # Without driving low first, results are inconsistent. board.set_pin_mode(self.pin, :output) board.digital_write(self.pin, board.low) sleep 0.1 reset write(SKIP_ROM, READ_POWER_SUPPLY) # Only LSBIT matters, but we can only read whole bytes. byte = read(1) @parasite_power = (byte[0] == 0) ? true : false end end |
#reset(get_presence = 0) ⇒ Object
41 42 43 |
# File 'lib/denko/one_wire/bus.rb', line 41 def reset(get_presence=0) board.one_wire_reset(pin, get_presence) end |
#write(*bytes) ⇒ Object
49 50 51 52 53 |
# File 'lib/denko/one_wire/bus.rb', line 49 def write(*bytes) bytes.flatten! pp = parasite_power && [CONVERT_T, COPY_SCRATCH].include?(bytes.last) board.one_wire_write(pin, pp, bytes) end |