Class: Denko::OneWire::Bus

Inherits:
DigitalIO::CBitBang show all
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

Attributes included from Behaviors::State

#state

Attributes included from Behaviors::Component

#board, #params

Attributes included from Behaviors::SinglePin

#mode, #pin

Instance Method Summary collapse

Methods included from BusEnumerator

#_search, #family_lookup, #found_devices, #parse_search_result, #peripheral_classes, #search, #split_search_result

Methods included from Behaviors::Lifecycle

included

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

#update_state

Methods included from Behaviors::BusControllerAddressed

#add_component

Methods included from Behaviors::BusController

#mutex

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

#initialize, #micro_delay

Methods included from Behaviors::SinglePin

#convert_pins, #initialize_pins

Instance Attribute Details

#parasite_powerObject (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_presentObject 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_supplyObject



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