Class: Denko::AnalogIO::ADS1118

Inherits:
Object
  • Object
show all
Includes:
ADS111X, Behaviors::Lifecycle, SPI::Peripheral
Defined in:
lib/denko/analog_io/ads1118.rb

Constant Summary collapse

CONFIG_STARTUP =

Config register values on startup. MSB-first. Matches datasheet. Same as: [0x05, 0x8B] or [5, 139]

[0b00000101, 0b10001011]
BASE_MSB =

Base config bytes to mask settings into. Not same as default. MSB bits 0 and 7 set to enable single-shot mode. LSB bit 3 set to enable pullup resistor on MISO pin. LSB bit 1 set to flag valid data in the NOP bits.

0b10000001
BASE_LSB =
0b00001010

Constants included from ADS111X

Denko::AnalogIO::ADS111X::MUX_SETTINGS, Denko::AnalogIO::ADS111X::PGA_RANGE, Denko::AnalogIO::ADS111X::PGA_SETTINGS, Denko::AnalogIO::ADS111X::SAMPLE_RATE_RANGE, Denko::AnalogIO::ADS111X::SAMPLE_TIMES, Denko::AnalogIO::ADS111X::WAIT_TIMES

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 ADS111X

#active_gain, #active_pin, #config_register

Attributes included from Behaviors::State

#state

Attributes included from SPI::Peripheral

#spi_bit_order, #spi_frequency

Attributes included from Behaviors::Component

#board, #params

Attributes included from Behaviors::MultiPin

#pin, #pins, #proxies

Instance Method Summary collapse

Methods included from ADS111X

#analog_listen, #analog_read, #enable_proxy, #mutex, #pins_to_mux_bits, #pre_callback_filter, #stop_listener

Methods included from Behaviors::BoardProxy

#analog_read_high, #analog_write_high, #convert_pin, #high, #low, #set_pin_mode, #start_read

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

#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 SPI::Peripheral

#ensure_byte_array, #initialize_pins, #proxy_pin, #spi_listen, #spi_read, #spi_stop, #spi_transfer, #spi_write, #update

Methods included from Behaviors::BusPeripheral

#atomically

Methods included from Behaviors::Component

#initialize, #micro_delay

Methods included from Behaviors::MultiPin

#convert_pins, #proxy_pin, #proxy_states, #require_pin, #require_pins

Instance Method Details

#_read(config) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/denko/analog_io/ads1118.rb', line 28

def _read(config)
  # Write config register to start reading.
  spi_write(config)

  # Sleep the right amount of time for conversion, based on sample rate bits.
  sleep WAIT_TIMES[config[1] >> 5]

  # Read the result, triggering callbacks.
  spi_read(2)
end

#_temperature_readObject



39
40
41
42
43
44
# File 'lib/denko/analog_io/ads1118.rb', line 39

def _temperature_read
  # Don't interfere with subcomponent reads.
  mutex.lock
  _read([0b10000001, 0b10011011])
  mutex.unlock
end

#spi_modeObject



19
20
21
# File 'lib/denko/analog_io/ads1118.rb', line 19

def spi_mode
  @spi_mode ||= params[:spi_mode] || 1
end

#temperature_read(&block) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/denko/analog_io/ads1118.rb', line 46

def temperature_read(&block)
  reading = read_using -> { _temperature_read }

  # Temperature is shifted 2 bits left, and is 0.03125 degrees C per bit.
  temperature = (reading / 4) * 0.03125

  block.call(temperature) if block_given?
  return temperature
end