Class: Elemac::Output::Default

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

Direct Known Subclasses

Output::Power, Output::Pwm, Output::Ttl

Constant Summary collapse

OFFSET =
2048
DATA_SIZE =
1
TYPE =
0
MODE =
256
DAY_1_START =
25
DAY_1_STOP =
281
DAY_2_START =
100
DAY_2_STOP =
356
DAY_3_START =
175
DAY_3_STOP =
431
WORK =
512
PAUSE =
587
TIMER =
662
POWER_FLAG =
1
VOLTAGE_FLAG =

bits 1110

14
DIMMABLE_FLAG =
16
NEGATIVE_FLAG =
32
TIMER_ON_FLAG =
64
PRESENT_FLAG =
128

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Default.



25
26
27
28
29
30
31
# File 'lib/elemac/output/default.rb', line 25

def initialize(device:, index: 0)
	@device = device
	@index = index
	@voltage = 0
	@dimmable = false
	@dim_value = 0
end

Instance Method Details

#board_dimmableObject



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

def board_dimmable
	type & DIMMABLE_FLAG != 0
end

#board_presentObject



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

def board_present
	type & 128 != 0
end

#board_voltageObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/elemac/output/default.rb', line 59

def board_voltage
	val = (type & VOLTAGE_FLAG) >> 1
	case(val)
	when 0
		230
	when 1
		12
	when 2
		5
	when 3
		3
	else
		0
	end
end

#dimmableObject



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

def dimmable
	@dimmable
end

#get_offsetObject



33
34
35
36
# File 'lib/elemac/output/default.rb', line 33

def get_offset
	throw "Bad offset. Can be only 0..25. #{@index} given." unless (0..25).cover?(@index)
	OFFSET + (@index * DATA_SIZE)
end

#inspectObject



87
88
89
90
91
92
93
94
95
96
# File 'lib/elemac/output/default.rb', line 87

def inspect
	puts "NAME:\t\t#{name}"
	puts "TYPE:\t\t#{type}"
	puts "POWERED:\t#{powered}"
	puts "TIMER:\t\t#{timer_on}"
	puts "NEGATIVE:\t#{negative}"
	puts "BRD_PRESENT:\t#{board_present}"
	puts "BRD_VOLTAGE:\t#{board_voltage}"
	puts "BRD_DIMMABLE:\t#{board_dimmable}"		
end

#nameObject



38
39
40
# File 'lib/elemac/output/default.rb', line 38

def name
	(@index + 'A'.ord).chr
end

#negativeObject



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

def negative
	type & NEGATIVE_FLAG != 0
end

#poweredObject



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

def powered
	type & POWER_FLAG != 0
end

#timer_onObject



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

def timer_on
	type & TIMER_ON_FLAG != 0
end

#typeObject



42
43
44
45
# File 'lib/elemac/output/default.rb', line 42

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