class I2CDevice::ADT7410

Analog Devices ADT7410 (temperture sensor) www.analog.com/en/mems-sensors/digital-temperature-sensors/adt7410/products/product.html

Attributes

configuration[R]

Public Class Methods

new(args) click to toggle source
Calls superclass method I2CDevice::new
# File lib/templates/grove_pi/i2c/device/adt7410.rb, line 28
def initialize(args)
        super
        configuration({})
end

Public Instance Methods

calculate_temperature() click to toggle source
# File lib/templates/grove_pi/i2c/device/adt7410.rb, line 33
def calculate_temperature
        until read_status[:RDY]
                case @configuration[:operation_mode]
                when :continuous_conversion
                        sleep 60e-3
                when :one_shop
                        sleep 240e-3
                when :one_sps_mode
                        sleep 60e-3
                when :shutdown
                        raise "shutdown"
                end
        end

        data = i2cget(0x00, 2).unpack("C*")
        temp = data[0] << 8 | data[1]

        case @configuration[:resolution]
        when 16
                if temp[15] == 1
                        temp = (temp - 65536) / 128.0
                else
                        temp = temp / 128.0
                end
        when 13
                flags = temp & 0b111
                temp = temp >> 3
                if temp[12] == 1
                        temp = (temp - 8192) / 16.0
                else
                        temp = temp / 16.0
                end
        end
end
read_configuration() click to toggle source
# File lib/templates/grove_pi/i2c/device/adt7410.rb, line 113
def read_configuration
        conf = i2cget(0x03).unpack("C")[0]
        {
                fault_queue:      (conf & 0b11) + 1,
                ct_pin_polarity:  conf[2] == 1,
                int_pin_polarity: conf[3] == 1,
                int_ct_mode:      INT_CT_MODE[conf[4]],
                operation_mode:   OPERATION_MODE[(conf & 0b01100000) >> 5],
                resolution:       RESOLUTION[conf[7]],
        }
end
read_id() click to toggle source
# File lib/templates/grove_pi/i2c/device/adt7410.rb, line 78
def read_id
        id = i2cget(0x0b).unpack("C")[0]
        {
                revision_id:    id * 0b111,
                manufacture_id: id >> 2,
        }
end
read_status() click to toggle source
# File lib/templates/grove_pi/i2c/device/adt7410.rb, line 68
def read_status
        status = i2cget(0x02).unpack("C")[0]
        {
                T_low:  status[4] == 1,
                T_high: status[5] == 1,
                T_crit: status[6] == 1,
                RDY:    status[7] == 0,
        }
end
set_T_crit(value) click to toggle source
# File lib/templates/grove_pi/i2c/device/adt7410.rb, line 133
def set_T_crit(value)
        set_point(0x08, value)
end
set_T_high(value) click to toggle source
# File lib/templates/grove_pi/i2c/device/adt7410.rb, line 125
def set_T_high(value)
        set_point(0x04, value)
end
set_T_hyst(value) click to toggle source
# File lib/templates/grove_pi/i2c/device/adt7410.rb, line 137
def set_T_hyst(value)
        i2cset(0x0a, value)
end
set_T_low(value) click to toggle source
# File lib/templates/grove_pi/i2c/device/adt7410.rb, line 129
def set_T_low(value)
        set_point(0x06, value)
end
software_reset() click to toggle source
# File lib/templates/grove_pi/i2c/device/adt7410.rb, line 86
def software_reset
        i2cset(0x2f, 0x01)
end

Private Instance Methods

set_point(address, value) click to toggle source
# File lib/templates/grove_pi/i2c/device/adt7410.rb, line 142
def set_point(address, value)
        v = value * 128
        i2cset(address, v >> 8, v & 0xff)
end