aca-device-modules 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,249 +5,249 @@ module Epson::Projector; end
5
5
  # Port: 3629
6
6
  #
7
7
  class Epson::Projector::EscVp21
8
- include ::Orchestrator::Constants
8
+ include ::Orchestrator::Constants
9
9
  include ::Orchestrator::Transcoder
10
10
 
11
- def on_load
12
- #config({
13
- # tokenize: true,
14
- # delimiter: ":"
15
- #})
11
+ def on_load
12
+ #config({
13
+ # tokenize: true,
14
+ # delimiter: ":"
15
+ #})
16
16
 
17
- self[:volume_min] = 0
17
+ self[:volume_min] = 0
18
18
  self[:volume_max] = 255
19
19
 
20
- self[:power] = false
21
- self[:stable_state] = true # Stable by default (allows manual on and off)
22
-
23
- # Meta data for inquiring interfaces
24
- self[:type] = :projector
25
- end
26
-
27
- def on_update
28
-
29
- end
30
-
31
- def connected
32
- # Have to init comms
33
- send("ESC/VP.net\x10\x03\x00\x00\x00\x00")
34
- do_poll
35
- @polling_timer = schedule.every('52s', method(:do_poll))
36
- end
37
-
38
- def disconnected
39
- self[:power] = false
40
- @polling_timer.cancel unless @polling_timer.nil?
20
+ self[:power] = false
21
+ self[:stable_state] = true # Stable by default (allows manual on and off)
22
+
23
+ # Meta data for inquiring interfaces
24
+ self[:type] = :projector
25
+ end
26
+
27
+ def on_update
28
+
29
+ end
30
+
31
+ def connected
32
+ # Have to init comms
33
+ send("ESC/VP.net\x10\x03\x00\x00\x00\x00")
34
+ do_poll
35
+ @polling_timer = schedule.every('52s', method(:do_poll))
36
+ end
37
+
38
+ def disconnected
39
+ self[:power] = false
40
+ @polling_timer.cancel unless @polling_timer.nil?
41
41
  @polling_timer = nil
42
- end
43
-
44
-
45
-
46
- #
47
- # Power commands
48
- #
49
- def power(state, opt = nil)
50
- self[:stable_state] = false
51
- if is_affirmative?(state)
52
- self[:power_target] = On
53
- do_send(:PWR, :ON, {:timeout => 40000, :name => :power})
54
- logger.debug "-- epson Proj, requested to power on"
55
- do_send(:PWR, :name => :power_state)
56
- else
57
- self[:power_target] = Off
58
- do_send(:PWR, :OFF, {:timeout => 10000, :name => :power})
59
- logger.debug "-- epson Proj, requested to power off"
60
- do_send(:PWR, :name => :power_state)
61
- end
62
- end
63
-
64
- def power?(options = {}, &block)
65
- options[:emit] = block if block_given?
66
- options[:name] = :power_state
67
- do_send(:PWR, options)
68
- end
69
-
70
-
71
-
72
- #
73
- # Input selection
74
- #
75
- INPUTS = {
76
- :hdmi => 0x30 # TODO:: Might need to have a setting for configuring this
77
- }
78
- INPUTS.merge!(INPUTS.invert)
79
-
80
-
81
- def switch_to(input)
82
- input = input.to_sym
83
- return unless INPUTS.has_key? input
84
-
85
- do_send(:SOURCE, INPUTS[input].to_s(16), {:name => :inpt_source})
86
- do_send(:SOURCE, {:name => :inpt_query})
87
-
88
- logger.debug "-- epson LCD, requested to switch to: #{input}"
89
-
90
- self[:input] = input # for a responsive UI
91
- self[:mute] = false
92
- end
93
-
94
-
95
-
96
- #
97
- # Volume commands are sent using the inpt command
98
- #
99
- def volume(vol, options = {})
42
+ end
43
+
44
+
45
+
46
+ #
47
+ # Power commands
48
+ #
49
+ def power(state, opt = nil)
50
+ self[:stable_state] = false
51
+ if is_affirmative?(state)
52
+ self[:power_target] = On
53
+ do_send(:PWR, :ON, {:timeout => 40000, :name => :power})
54
+ logger.debug "-- epson Proj, requested to power on"
55
+ do_send(:PWR, :name => :power_state)
56
+ else
57
+ self[:power_target] = Off
58
+ do_send(:PWR, :OFF, {:timeout => 10000, :name => :power})
59
+ logger.debug "-- epson Proj, requested to power off"
60
+ do_send(:PWR, :name => :power_state)
61
+ end
62
+ end
63
+
64
+ def power?(options = {}, &block)
65
+ options[:emit] = block if block_given?
66
+ options[:name] = :power_state
67
+ do_send(:PWR, options)
68
+ end
69
+
70
+
71
+
72
+ #
73
+ # Input selection
74
+ #
75
+ INPUTS = {
76
+ :hdmi => 0x30 # TODO:: Might need to have a setting for configuring this
77
+ }
78
+ INPUTS.merge!(INPUTS.invert)
79
+
80
+
81
+ def switch_to(input)
82
+ input = input.to_sym
83
+ return unless INPUTS.has_key? input
84
+
85
+ do_send(:SOURCE, INPUTS[input].to_s(16), {:name => :inpt_source})
86
+ do_send(:SOURCE, {:name => :inpt_query})
87
+
88
+ logger.debug "-- epson LCD, requested to switch to: #{input}"
89
+
90
+ self[:input] = input # for a responsive UI
91
+ self[:mute] = false
92
+ end
93
+
94
+
95
+
96
+ #
97
+ # Volume commands are sent using the inpt command
98
+ #
99
+ def volume(vol, options = {})
100
100
  vol = vol.to_i
101
101
  vol = 0 if vol < 0
102
102
  vol = 255 if vol > 255
103
103
 
104
104
  do_send(:VOL, vol, options)
105
105
  end
106
-
107
-
108
- #
109
- # Mute Audio and Video
110
- #
111
- def mute
112
- logger.debug "-- epson Proj, requested to mute"
113
- do_send(:MUTE, :ON, {:name => :video_mute}) # Audio + Video
114
- do_send(:MUTE) # request status
115
- end
116
-
117
- def unmute
118
- logger.debug "-- epson Proj, requested to mute"
119
- do_send(:MUTE, :OFF, {:name => :video_mute})
120
- do_send(:MUTE)
121
- end
122
-
123
-
124
- ERRORS = {
125
- 0 => '00: no error'.freeze,
126
- 1 => '01: fan error'.freeze,
127
- 3 => '03: lamp failure at power on'.freeze,
128
- 4 => '04: high internal temperature'.freeze,
129
- 6 => '06: lamp error'.freeze,
130
- 7 => '07: lamp cover door open'.freeze,
131
- 8 => '08: cinema filter error'.freeze,
132
- 9 => '09: capacitor is disconnected'.freeze,
133
- 10 => '0A: auto iris error'.freeze,
134
- 11 => '0B: subsystem error'.freeze,
135
- 12 => '0C: low air flow error'.freeze,
136
- 13 => '0D: air flow sensor error'.freeze,
137
- 14 => '0E: ballast power supply error'.freeze,
138
- 15 => '0F: shutter error'.freeze,
139
- 16 => '10: peltiert cooling error'.freeze,
140
- 17 => '11: pump cooling error'.freeze,
141
- 18 => '12: static iris error'.freeze,
142
- 19 => '13: power supply unit error'.freeze,
143
- 20 => '14: exhaust shutter error'.freeze,
144
- 21 => '15: obstacle detection error'.freeze,
145
- 22 => '16: IF board discernment error'.freeze
146
- }
147
-
148
- #
149
- # epson Response code
150
- #
151
- def received(data, resolve, command) # Data is default received as a string
152
- logger.debug "epson Proj sent: #{data}"
153
-
154
- if data == ':'
155
- return :success
156
- end
157
-
158
- data = data.split(/=|\r:/)
159
- case data[0].to_sym
160
- when :ERR
161
- # Lookup error!
162
- if data[1].nil?
163
- warning = "Epson PJ sent error response"
164
- warning << " for #{command[:data].inspect}" if command
165
- logger.warn warning
166
- return :abort
167
- else
168
- code = data[1].to_i(16)
169
- self[:last_error] = ERRORS[code] || "#{data[1]}: unknown error code #{code}"
170
- logger.warn "Epson PJ error was #{self[:last_error]}"
171
- return :success
172
- end
173
- when :PWR
174
- state = data[1].to_i
175
- self[:power] = state < 3
176
- self[:warming] = state == 2
177
- self[:cooling] = state == 3
178
- if self[:warming] || self[:cooling]
179
- schedule.in('5s') do
180
- power?({:priority => 0})
181
- end
182
- end
183
- if !self[:stable_state] && self[:power_target] == self[:power]
184
- self[:stable_state] = true
185
- self[:mute] = false if !self[:power]
186
- end
187
-
188
- when :MUTE
189
- self[:mute] = data[1] == 'ON'
190
- when :VOL
191
- self[:volume] = data[1].to_i
192
- when :LAMP
193
- self[:lamp] = data[1].to_i
194
- when :SOURCE
195
- self[:source] = INPUTS[data[1].to_i(16)] || :unknown
196
- end
197
-
198
- :success
199
- end
200
-
201
- def inspect_error
202
- do_send(:ERR, priority: 0)
203
- end
204
-
205
-
206
- protected
207
-
208
-
209
- def do_poll(*args)
210
- power?({:priority => 0}) do
211
- if self[:power]
212
- if self[:stable_state] == false && self[:power_target] == Off
213
- power(Off)
214
- else
215
- self[:stable_state] = true
216
- do_send(:SOURCE, {
217
- :name => :inpt_query,
218
- :priority => 0
219
- })
220
- do_send(:MUTE, {
221
- :name => :mute_query,
222
- :priority => 0
223
- })
224
- do_send(:VOL, {
225
- :name => :vol_query,
226
- :priority => 0
227
- })
228
- end
229
- elsif self[:stable_state] == false
230
- if self[:power_target] == On
231
- power(On)
232
- else
233
- self[:stable_state] = true
234
- end
235
- end
236
- end
237
- do_send(:LAMP, {:priority => 0})
238
- end
239
-
240
- def do_send(command, param = nil, options = {})
241
- if param.is_a? Hash
242
- options = param
243
- param = nil
244
- end
245
-
246
- if param.nil?
247
- send("#{command}?\x0D", options)
248
- else
249
- send("#{command} #{param}\x0D", options)
250
- end
251
- end
106
+
107
+
108
+ #
109
+ # Mute Audio and Video
110
+ #
111
+ def mute
112
+ logger.debug "-- epson Proj, requested to mute"
113
+ do_send(:MUTE, :ON, {:name => :video_mute}) # Audio + Video
114
+ do_send(:MUTE) # request status
115
+ end
116
+
117
+ def unmute
118
+ logger.debug "-- epson Proj, requested to mute"
119
+ do_send(:MUTE, :OFF, {:name => :video_mute})
120
+ do_send(:MUTE)
121
+ end
122
+
123
+
124
+ ERRORS = {
125
+ 0 => '00: no error'.freeze,
126
+ 1 => '01: fan error'.freeze,
127
+ 3 => '03: lamp failure at power on'.freeze,
128
+ 4 => '04: high internal temperature'.freeze,
129
+ 6 => '06: lamp error'.freeze,
130
+ 7 => '07: lamp cover door open'.freeze,
131
+ 8 => '08: cinema filter error'.freeze,
132
+ 9 => '09: capacitor is disconnected'.freeze,
133
+ 10 => '0A: auto iris error'.freeze,
134
+ 11 => '0B: subsystem error'.freeze,
135
+ 12 => '0C: low air flow error'.freeze,
136
+ 13 => '0D: air flow sensor error'.freeze,
137
+ 14 => '0E: ballast power supply error'.freeze,
138
+ 15 => '0F: shutter error'.freeze,
139
+ 16 => '10: peltiert cooling error'.freeze,
140
+ 17 => '11: pump cooling error'.freeze,
141
+ 18 => '12: static iris error'.freeze,
142
+ 19 => '13: power supply unit error'.freeze,
143
+ 20 => '14: exhaust shutter error'.freeze,
144
+ 21 => '15: obstacle detection error'.freeze,
145
+ 22 => '16: IF board discernment error'.freeze
146
+ }
147
+
148
+ #
149
+ # epson Response code
150
+ #
151
+ def received(data, resolve, command) # Data is default received as a string
152
+ logger.debug "epson Proj sent: #{data}"
153
+
154
+ if data == ':'
155
+ return :success
156
+ end
157
+
158
+ data = data.split(/=|\r:/)
159
+ case data[0].to_sym
160
+ when :ERR
161
+ # Lookup error!
162
+ if data[1].nil?
163
+ warning = "Epson PJ sent error response"
164
+ warning << " for #{command[:data].inspect}" if command
165
+ logger.warn warning
166
+ return :abort
167
+ else
168
+ code = data[1].to_i(16)
169
+ self[:last_error] = ERRORS[code] || "#{data[1]}: unknown error code #{code}"
170
+ logger.warn "Epson PJ error was #{self[:last_error]}"
171
+ return :success
172
+ end
173
+ when :PWR
174
+ state = data[1].to_i
175
+ self[:power] = state < 3
176
+ self[:warming] = state == 2
177
+ self[:cooling] = state == 3
178
+ if self[:warming] || self[:cooling]
179
+ schedule.in('5s') do
180
+ power?({:priority => 0})
181
+ end
182
+ end
183
+ if !self[:stable_state] && self[:power_target] == self[:power]
184
+ self[:stable_state] = true
185
+ self[:mute] = false if !self[:power]
186
+ end
187
+
188
+ when :MUTE
189
+ self[:mute] = data[1] == 'ON'
190
+ when :VOL
191
+ self[:volume] = data[1].to_i
192
+ when :LAMP
193
+ self[:lamp] = data[1].to_i
194
+ when :SOURCE
195
+ self[:source] = INPUTS[data[1].to_i(16)] || :unknown
196
+ end
197
+
198
+ :success
199
+ end
200
+
201
+ def inspect_error
202
+ do_send(:ERR, priority: 0)
203
+ end
204
+
205
+
206
+ protected
207
+
208
+
209
+ def do_poll(*args)
210
+ power?({:priority => 0}) do
211
+ if self[:power]
212
+ if self[:stable_state] == false && self[:power_target] == Off
213
+ power(Off)
214
+ else
215
+ self[:stable_state] = true
216
+ do_send(:SOURCE, {
217
+ :name => :inpt_query,
218
+ :priority => 0
219
+ })
220
+ do_send(:MUTE, {
221
+ :name => :mute_query,
222
+ :priority => 0
223
+ })
224
+ do_send(:VOL, {
225
+ :name => :vol_query,
226
+ :priority => 0
227
+ })
228
+ end
229
+ elsif self[:stable_state] == false
230
+ if self[:power_target] == On
231
+ power(On)
232
+ else
233
+ self[:stable_state] = true
234
+ end
235
+ end
236
+ end
237
+ do_send(:LAMP, {:priority => 0})
238
+ end
239
+
240
+ def do_send(command, param = nil, options = {})
241
+ if param.is_a? Hash
242
+ options = param
243
+ param = nil
244
+ end
245
+
246
+ if param.nil?
247
+ send("#{command}?\x0D", options)
248
+ else
249
+ send("#{command} #{param}\x0D", options)
250
+ end
251
+ end
252
252
  end
253
253