Class: Denko::OneWire::Bus
- Inherits:
-
DigitalIO::CBitBang
- Object
- DigitalIO::CBitBang
- Denko::OneWire::Bus
- Includes:
- Behaviors::BusControllerAddressed, Behaviors::Lifecycle, Behaviors::Reader, 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
Constants included from Behaviors::Lifecycle
Behaviors::Lifecycle::CALLBACK_METHODS
Constants included from Behaviors::Reader
Behaviors::Reader::READ_WAIT_TIME
Instance Attribute Summary collapse
-
#parasite_power ⇒ Object
readonly
Returns the value of attribute parasite_power.
Attributes included from Behaviors::State
Attributes included from Behaviors::Component
Attributes included from Behaviors::SinglePin
Instance Method Summary collapse
- #_read(num_bytes) ⇒ Object
- #device_present ⇒ Object (also: #device_present?)
- #pre_callback_filter(bytes) ⇒ Object
- #read_power_supply ⇒ Object
- #reset(get_presence = false) ⇒ Object
- #write(*bytes) ⇒ Object
Methods included from BusEnumerator
#_search, #family_lookup, #found_devices, #parse_search_result, #peripheral_classes, #search, #split_search_result
Methods included from Behaviors::Lifecycle
Methods included from Behaviors::Reader
#read, #read_busy?, #read_nb, #read_raw, #read_using, #update
Methods included from Behaviors::Callbacks
#add_callback, #callbacks, #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, #add_hw_i2c, #add_hw_spi, #add_single_pin, #components, #hw_i2c_comps, #hw_spi_comps, #remove_component, #remove_hw_i2c, #remove_hw_spi, #remove_single_pin, #single_pin_components
Methods included from Behaviors::Component
Methods included from Behaviors::SinglePin
#convert_pins, #initialize_pins
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
48 49 50 |
# File 'lib/denko/one_wire/bus.rb', line 48 def _read(num_bytes) board.one_wire_read(pin, num_bytes) end |
#device_present ⇒ Object Also known as: device_present?
35 36 37 38 39 40 41 |
# File 'lib/denko/one_wire/bus.rb', line 35 def device_present mutex.lock byte = read_using -> { reset(true) } presence = (byte == 0) ? true : false mutex.unlock presence end |
#pre_callback_filter(bytes) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/denko/one_wire/bus.rb', line 58 def pre_callback_filter(bytes) # C extensions respond with Ruby array # External Board responds with comma delimited String unless bytes.class == Array bytes = bytes.split(",").map(&:to_i) end bytes.length > 1 ? bytes : bytes[0] end |
#read_power_supply ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/denko/one_wire/bus.rb', line 16 def read_power_supply mutex.lock # 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 & 0b1 == 0) ? true : false mutex.unlock @parasite_power end |
#reset(get_presence = false) ⇒ Object
44 45 46 |
# File 'lib/denko/one_wire/bus.rb', line 44 def reset(get_presence=false) board.one_wire_reset(pin, get_presence) end |
#write(*bytes) ⇒ Object
52 53 54 55 56 |
# File 'lib/denko/one_wire/bus.rb', line 52 def write(*bytes) bytes.flatten! pp = parasite_power && [CONVERT_T, COPY_SCRATCH].include?(bytes.last) board.one_wire_write(pin, pp, bytes) end |