Class: Denko::OneWire::Peripheral

Inherits:
Object
  • Object
show all
Includes:
Behaviors::BusPeripheralAddressed, Behaviors::Poller, Constants
Defined in:
lib/denko/one_wire/peripheral.rb

Direct Known Subclasses

Sensor::DS18B20

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 Behaviors::Reader

Behaviors::Reader::READ_WAIT_TIME

Constants included from Behaviors::Lifecycle

Behaviors::Lifecycle::CALLBACK_METHODS

Instance Attribute Summary

Attributes included from Behaviors::Threaded

#interrupts_enabled, #thread

Attributes included from Behaviors::State

#state

Attributes included from Behaviors::Component

#board, #params

Instance Method Summary collapse

Methods included from Behaviors::Poller

#poll, #poll_using, #stop

Methods included from Behaviors::Threaded

#enable_interrupts, included, #mruby_thread_check, #stop, #stop_thread, #threaded, #threaded_loop

Methods included from Behaviors::Reader

#_read, #read, #read_busy?, #read_nb, #read_raw, #read_using, #update

Methods included from Behaviors::Callbacks

#add_callback, #callbacks, #pre_callback_filter, #remove_callback, #update

Methods included from Behaviors::State

#update_state

Methods included from Behaviors::Lifecycle

included

Methods included from Behaviors::BusPeripheralAddressed

#address

Methods included from Behaviors::BusPeripheral

#atomically

Methods included from Behaviors::Component

#initialize, #micro_delay

Instance Method Details

#address_bytesObject



44
45
46
# File 'lib/denko/one_wire/peripheral.rb', line 44

def address_bytes
  Helper.address_to_bytes(self.address)
end

#copy_scratchObject



25
26
27
28
29
30
31
32
# File 'lib/denko/one_wire/peripheral.rb', line 25

def copy_scratch
  atomically do
    match
    bus.write(COPY_SCRATCH)
    sleep 0.05
    bus.reset if bus.parasite_power
  end
end

#extract_serialObject



52
53
54
55
56
# File 'lib/denko/one_wire/peripheral.rb', line 52

def extract_serial
  # Remove CRC & family code.
  serial = (@address & 0x00FFFFFFFFFFFFFF) >> 8
  serial.to_s(16).rjust(12, "0")
end

#matchObject



34
35
36
37
38
39
40
41
42
# File 'lib/denko/one_wire/peripheral.rb', line 34

def match
  bus.reset
  if bus.found_devices.count < 2
    bus.write(SKIP_ROM)
  else
    bus.write(MATCH_ROM)
    bus.write(address_bytes)
  end
end

#read_scratch(num_bytes, &block) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/denko/one_wire/peripheral.rb', line 8

def read_scratch(num_bytes, &block)
  atomically do
    bus.add_callback(:read, &block) if block_given?
    match
    bus.write(READ_SCRATCH)
    bus.read(num_bytes)
  end
end

#serial_numberObject



48
49
50
# File 'lib/denko/one_wire/peripheral.rb', line 48

def serial_number
  @serial_number ||= extract_serial
end

#write_scratch(*bytes) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/denko/one_wire/peripheral.rb', line 17

def write_scratch(*bytes)
  atomically do
    match
    bus.write(WRITE_SCRATCH)
    bus.write(*bytes)
  end
end