Module: PCF8591::Assertions

Extended by:
DefaultAssertions::ClassMethods
Includes:
DefaultAssertions, Constants
Included in:
PCF8591
Defined in:
app/models/pcf8591.rb

Constant Summary

Constants included from Constants

Constants::CB_Mask, Constants::Default_control_byte, Constants::MAX_OSC_WARM_UP

Instance Method Summary collapse

Instance Method Details

#assert_constant(control_byte = Default_control_byte, samples = 64, expected_value = nil) ⇒ Object

assert_pre_conditions


90
91
92
93
94
95
96
97
# File 'app/models/pcf8591.rb', line 90

def assert_constant(control_byte=Default_control_byte, samples=64, expected_value=nil)
	scan=adc_read(control_byte, samples, 0)
	unique_values=scan.uniq
	assert_equal(1, unique_values.size,message)
	if !expected_value.nil? then
		assert_equal(expected_value, unique_values[0], message)
	end #if
end

#assert_disconnected(control_byte = Default_control_byte, samples = 64) ⇒ Object

assert_range


107
108
109
110
111
112
113
114
115
116
117
# File 'app/models/pcf8591.rb', line 107

def assert_disconnected(control_byte=Default_control_byte, samples=64)
	scan=adc_read(control_byte, samples, 0)
	message="\ncontrol_byte=#{control_byte}\n#{self.inspect} #{scan.inspect}\ndecay=#{@read_behind.to_f/scan[0].to_f}\n#{caller_lines}"
	assert_operator(@read_behind/4.0, :<=, scan[0], "under "+message)
	scan[1..-1].each do |value|
		assert_operator(value, :<=, 4, "byte "+message)
	end #each
	if @read_behind>8 then
		assert_operator((@read_behind-4)/2.0, :>=, scan[0], "over "+message)
	end #if
end

#assert_loopback(input_control_byte, output_value = 0) ⇒ Object

assert_disconnected


118
119
120
121
122
123
# File 'app/models/pcf8591.rb', line 118

def assert_loopback(input_control_byte, output_value=0)
	256.times do |i|
		dac_set(i)
		assert_range(input_control_byte, Examples::BURST_LENGTH, i, i+1, 2)
	end #times
end

#assert_pre_conditionsObject


87
88
89
# File 'app/models/pcf8591.rb', line 87

def assert_pre_conditions
	assert_instance_of(Class, self)
end

#assert_range(control_byte = Default_control_byte, samples = 64, min = 0, max = 255, max_range = nil) ⇒ Object

assert_constant


98
99
100
101
102
103
104
105
106
# File 'app/models/pcf8591.rb', line 98

def assert_range(control_byte=Default_control_byte, samples=64, min=0, max=255, max_range=nil)
	scan=adc_read(control_byte, samples, 0)
	message="\ncontrol_byte=#{control_byte}\n#{self.inspect} #{scan.inspect}\ndecay=#{@read_behind.to_f/scan[0].to_f}\n#{caller_lines}"
	assert_operator(min, :<=, scan.min, message)
	assert_operator(max, :>=, scan.max, message)
	if !max_range.nil? then
		assert_operator(max_range, :>=, scan.max-scan.min, message)
	end #if
end