-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBenQSP890Projector.rb
90 lines (80 loc) · 2.53 KB
/
BenQSP890Projector.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Copyright (C) 2014 Wesleyan University
#
# This file is part of cmdr-devices.
#
# cmdr-devices is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cmdr-devices is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cmdr-devices. If not, see <http://www.gnu.org/licenses/>.
#---
#{
# "name": "BenQSP890Projector",
# "depends_on": "Projector",
# "description": "Controls BenQ SP890 projector. Should also work with MP722, Mp723, MP771 and SP870",
# "author": "Micah Wylde",
# "email": "mwylde@wesleyan.edu"
#}
#---
class BenQSP890Projector < Projector
configure do
message_end(/\n\r|\r\n/)
message_delay 0.2
end
def read data
EM.cancel_timer @_cooling_timer if @_cooling_timer
@_cooling_timer = nil
super data
end
managed_state_var :power,
:type => :boolean,
:display_order => 1,
:action => proc{|on|
# The BenQs don't tell us when they're cooling, so we have to cheat
if !@_cooling_timer && !on
@_cooling_timer = EM.add_timer(5) { puts "Cooling..."; self.cooling = true }
end
"*pow=#{on ? "on" : "off"}#"
}
managed_state_var :input,
:type => :option,
:options => ['HDMI', 'YPBR', 'RGB', 'RGB2', 'VID', 'SVID'],
:display_order => 2,
:action => proc{|source|
"*sour=#{source.downcase}#"
}
managed_state_var :mute,
:type => :boolean,
:action => proc{|on|
"*mute=#{on ? "on" : "off"}#"
}
managed_state_var :video_mute,
:type => :boolean,
:display_order => 4,
:action => proc{|on|
"*blank=#{on ? "on" : "off"}#"
}
responses do
ack /\*[a-z]+?=.+#/
match :power, /\*POW=(.+)#/, proc{|m|
self.power = !(m[1].upcase == "OFF")
self.cooling = (m[1].upcase == "COOL DOWN")
}
match :mute, /\*MUTE=(.+)#/, proc{|m| self.mute = (m[1] == "ON")}
match :video_mute, /\*BLANK=(.+)#/, proc{|m| self.video_mute = (m[1] == "ON")}
match :input, /\*SOUR=(.+)#/, proc{|m| self.input = m[1]}
end
requests do
send :power, "*pow=?#", 1
send :source, "*sour=?#", 1
send :mute, "*blank=?#", 1
# send :lamp_usage, "*ltim=?#", 0.1
end
end