Class: Elemac::Sensor::Default

Inherits:
Object
  • Object
show all
Defined in:
lib/elemac/sensor/default.rb

Direct Known Subclasses

Temperature, Sensor::Ph, Sensor::Redox

Constant Summary collapse

FLAGS =
0
MEASURMENT =
2
HYSTERESIS =
10
DAY_HIGH =
6
NIGHT_HIGH =
8
DAY_LOW =
13
NIGHT_LOW =
11
ALARM_HIGH =
4
ALARM_LOW =
15
DATA_SIZE =
17
FLAG_PRESENT =
1
FLAG_RISE =
2
FLAG_LOWER =
4
FLAG_ALARM_HIGH =
8
FLAG_ALARM_LOW =
16
OFFSET =
1864

Instance Method Summary collapse

Constructor Details

#initialize(device:, index: 0, divider: 1.0) ⇒ Default

Returns a new instance of Default.



23
24
25
26
27
28
29
# File 'lib/elemac/sensor/default.rb', line 23

def initialize(device:, index: 0, divider: 1.0)
	throw 'Index has to be in range 0-5' if !(0..5).cover?(index)
	@device = device
	@index = index
	@offset = get_offset
	@divider = divider
end

Instance Method Details

#alarm_highObject



59
60
61
62
# File 'lib/elemac/sensor/default.rb', line 59

def alarm_high
	prop = Property.new(offset: get_offset, address: ALARM_HIGH, type: :short)
	get_data(prop.to_s) / @divider
end

#alarm_lowObject



63
64
65
66
# File 'lib/elemac/sensor/default.rb', line 63

def alarm_low
	prop = Property.new(offset: get_offset, address: ALARM_LOW, type: :short)
	get_data(prop.to_s) / @divider
end

#day_highObject



43
44
45
46
# File 'lib/elemac/sensor/default.rb', line 43

def day_high
	prop = Property.new(offset: get_offset, address: DAY_HIGH, type: :short)
	get_data(prop.to_s) / @divider
end

#day_lowObject



47
48
49
50
# File 'lib/elemac/sensor/default.rb', line 47

def day_low
	prop = Property.new(offset: get_offset, address: DAY_LOW, type: :short)
	get_data(prop.to_s) / @divider
end

#flag_alarm_highObject



82
83
84
85
# File 'lib/elemac/sensor/default.rb', line 82

def flag_alarm_high
	return false unless flag_present
	flags & FLAG_ALARM_HIGH != 0
end

#flag_alarm_lowObject



86
87
88
89
# File 'lib/elemac/sensor/default.rb', line 86

def flag_alarm_low
	return false unless flag_present
	flags & FLAG_ALARM_LOW != 0
end

#flag_lowerObject



78
79
80
81
# File 'lib/elemac/sensor/default.rb', line 78

def flag_lower
	return false unless flag_present
	flags & FLAG_LOWER != 0
end

#flag_presentObject



71
72
73
# File 'lib/elemac/sensor/default.rb', line 71

def flag_present
	flags & FLAG_PRESENT != 0
end

#flag_riseObject



74
75
76
77
# File 'lib/elemac/sensor/default.rb', line 74

def flag_rise
	return false unless flag_present
	flags & FLAG_RISE != 0
end

#flagsObject



67
68
69
70
# File 'lib/elemac/sensor/default.rb', line 67

def flags
	prop = Property.new(offset: get_offset, address: FLAGS, type: :short)
	get_data(prop.to_s)
end

#get_offsetObject



30
31
32
33
34
# File 'lib/elemac/sensor/default.rb', line 30

def get_offset
	# this does not include rh sensor yet
	throw "Bad offset. Can be only 0,1,2,3 for TEMP or 4,5 for PH. #{@index} given." unless (0..5).cover?(@index)
	OFFSET + (@index * DATA_SIZE)
end

#hysteresisObject



39
40
41
42
# File 'lib/elemac/sensor/default.rb', line 39

def hysteresis
	prop = Property.new(offset: get_offset, address: HYSTERESIS, type: :char)
	get_data(prop.to_s) / @divider
end

#inspectObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/elemac/sensor/default.rb', line 91

def inspect
	puts "MEASURMENT\t#{value}"
	puts "HYSTERESIS\t#{hysteresis}"
	puts "DAY LOW\t\t#{day_low}"
	puts "DAY HIGH\t#{day_high}"
	puts "NIGHT LOW\t#{night_low}"
	puts "NIGHT HIGH\t#{night_high}"
	puts "ALARM LOW\t#{alarm_low}"
	puts "ALARM HIGH\t#{alarm_high}"
	puts "FLAGS:\t\t#{flags} (#{flags.to_s(2)})"
	puts "F_PRESENT:\t#{flag_present}"
	puts "F_RISE:\t\t#{flag_rise}"
	puts "F_LOWER:\t#{flag_lower}"
	puts "F_ALARM_H:\t#{flag_alarm_high}"
	puts "F_ALARM_L:\t#{flag_alarm_low}"
end

#night_highObject



51
52
53
54
# File 'lib/elemac/sensor/default.rb', line 51

def night_high
	prop = Property.new(offset: get_offset, address: NIGHT_HIGH, type: :short)
	get_data(prop.to_s) / @divider
end

#night_lowObject



55
56
57
58
# File 'lib/elemac/sensor/default.rb', line 55

def night_low
	prop = Property.new(offset: get_offset, address: NIGHT_LOW, type: :short)
	get_data(prop.to_s) / @divider
end

#valueObject



35
36
37
38
# File 'lib/elemac/sensor/default.rb', line 35

def value
	prop = Property.new(offset: get_offset, address: MEASURMENT, type: :short)
	get_data(prop.to_s) / @divider
end