Class: I2CDevice::ADT7410

Inherits:
I2CDevice show all
Defined in:
lib/i2c/device/adt7410.rb

Overview

Constant Summary collapse

OPERATION_MODE =

:nodoc:

{ # :nodoc:
	0b00 => :continuous_conversion,
	0b01 => :one_shot,
	0b10 => :one_sps_mode,
	0b11 => :shutdown,
}
INT_CT_MODE =

:nodoc:

{ # :nodoc:
	0 => :interrupt_mode,  
	1 => :comparator_mode,
}
RESOLUTION =

:nodoc:

{ # :nodoc:
	0 => 13,
	1 => 16,
}

Constants inherited from I2CDevice

VERSION

Instance Attribute Summary collapse

Attributes inherited from I2CDevice

#address

Instance Method Summary collapse

Methods inherited from I2CDevice

#i2cget, #i2cset

Constructor Details

#initialize(args) ⇒ ADT7410

Returns a new instance of ADT7410.


28
29
30
31
# File 'lib/i2c/device/adt7410.rb', line 28

def initialize(args)
	super
	configuration({})
end

Instance Attribute Details

#configuration(args) ⇒ Object (readonly)

Returns the value of attribute configuration


26
27
28
# File 'lib/i2c/device/adt7410.rb', line 26

def configuration
  @configuration
end

Instance Method Details

#calculate_temperatureObject


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/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_configurationObject


113
114
115
116
117
118
119
120
121
122
123
# File 'lib/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_idObject


78
79
80
81
82
83
84
# File 'lib/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_statusObject


68
69
70
71
72
73
74
75
76
# File 'lib/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) ⇒ Object


133
134
135
# File 'lib/i2c/device/adt7410.rb', line 133

def set_T_crit(value)
	set_point(0x08, value)
end

#set_T_high(value) ⇒ Object


125
126
127
# File 'lib/i2c/device/adt7410.rb', line 125

def set_T_high(value)
	set_point(0x04, value)
end

#set_T_hyst(value) ⇒ Object


137
138
139
# File 'lib/i2c/device/adt7410.rb', line 137

def set_T_hyst(value)
	i2cset(0x0a, value)
end

#set_T_low(value) ⇒ Object


129
130
131
# File 'lib/i2c/device/adt7410.rb', line 129

def set_T_low(value)
	set_point(0x06, value)
end

#software_resetObject


86
87
88
# File 'lib/i2c/device/adt7410.rb', line 86

def software_reset
	i2cset(0x2f, 0x01)
end