2 from config import config, ConfigSelection, ConfigYesNo, ConfigSubsection, ConfigText
3 from enigma import eHdmiCEC, eTimer
4 from Screens.Standby import inStandby
6 from Tools import Notifications
9 from Tools.Directories import fileExists
14 config.hdmicec = ConfigSubsection()
15 config.hdmicec.enabled = ConfigYesNo(default = False)
16 config.hdmicec.logenabledserial = ConfigYesNo(default = False)
17 config.hdmicec.logenabledfile = ConfigYesNo(default = False)
18 config.hdmicec.tvstandby = ConfigYesNo(default = False)
19 config.hdmicec.tvwakeup = ConfigYesNo(default = False)
20 config.hdmicec.boxstandby = ConfigYesNo(default = False)
21 config.hdmicec.enabletvrc = ConfigYesNo(default = True)
22 config.hdmicec.active_source_reply = ConfigYesNo(default = True)
23 config.hdmicec.standby_message = ConfigSelection(
25 "standby,inactive": _("TV standby"),
26 "standby,avpwroff,inactive,": _("TV + A/V standby"),
27 "inactive": _("Source inactive"),
28 "nothing": _("Nothing"),
30 default = "standby,inactive")
31 config.hdmicec.deepstandby_message = ConfigSelection(
33 "standby,inactive": _("TV standby"),
34 "standby,avdeeppwroff,inactive": _("TV + A/V standby"),
35 "inactive": _("Source inactive"),
36 "nothing": _("Nothing"),
38 default = "standby,inactive")
39 config.hdmicec.wakeup_message = ConfigSelection(
41 "wakeup,active,activevu": _("TV wakeup"),
42 "wakeup,avpwron,active,activevu": _("TV + A/V wakeup"),
43 "active": _("Source active"),
44 "nothing": _("Nothing"),
46 default = "wakeup,active,activevu")
47 config.hdmicec.vustandby_message = ConfigSelection(
49 "vustandby": _("VU standby"),
50 "vudeepstandby": _("VU DeepStandby"),
51 "vunothing": _("Nothing"),
53 default = "vustandby")
54 config.hdmicec.vuwakeup_message = ConfigSelection(
56 "vuwakeup": _("VU wakeup"),
57 "vunothing": _("Nothing"),
60 config.hdmicec.tvinput = ConfigSelection(default = "1",
67 config.hdmicec.avinput = ConfigSelection(default ="0",
69 ("0", _("no A/V Receiver")),
75 config.hdmicec.devicename = ConfigText(default = self.getDeviceName(), visible_width = 50, fixed_size = False)
76 config.misc.standbyCounter.addNotifier(self.enterStandby, initial_call = False)
77 config.misc.DeepStandbyOn.addNotifier(self.enterDeepStandby, initial_call = False)
78 self.leaveDeepStandby()
80 def getDeviceName(self):
85 "ultimo": "VU+ Ultimo",
88 "solose": "VU+ SoloSE",
90 if fileExists("/proc/stb/info/vumodel"):
91 vumodel = open("/proc/stb/info/vumodel")
92 info=vumodel.read().strip()
94 return deviceList.setdefault(info, "VU+")
98 def sendMessages(self, messages):
99 for message in messages.split(','):
102 addressvaluebroadcast = int("0F",16)
103 addressvalue = int("0",16)
104 addressvalueav = int("5",16)
105 wakeupmessage = int("04",16)
106 standbymessage=int("36",16)
107 activesourcemessage=int("82",16)
108 inactivesourcemessage=int("9D",16)
109 sendkeymessage = int("44",16)
110 sendkeypwronmessage = int("6D",16)
111 sendkeypwroffmessage = int("6C",16)
112 activevumessage=int("85",16)
113 physaddress1 = int("0x" + str(config.hdmicec.tvinput.value) + str(config.hdmicec.avinput.value),16)
114 physaddress2 = int("0x00",16)
116 if message == "wakeup":
117 cmd = struct.pack('B', wakeupmessage)
118 logcmd = "[HDMI-CEC] ** WakeUpMessage ** send message: %x to address %x" % (wakeupmessage, addressvalue)
119 elif message == "active":
120 addressvalue = addressvaluebroadcast
121 cmd = struct.pack('BBB', activesourcemessage,physaddress1,physaddress2)
122 logcmd = "[HDMI-CEC] ** ActiveSourceMessage ** send message: %x:%x:%x to address %x" % (activesourcemessage,physaddress1,physaddress2,addressvalue)
123 elif message == "standby":
124 cmd = struct.pack('B', standbymessage)
125 logcmd = "[HDMI-CEC] ** StandByMessage ** send message: %x to address %x" % (standbymessage, addressvalue)
126 elif message == "inactive":
127 addressvalue = addressvaluebroadcast
128 cmd = struct.pack('BBB', inactivesourcemessage,physaddress1,physaddress2)
129 logcmd = "[HDMI-CEC] ** InActiveSourceMessage ** send message: %x:%x:%x to address %x" % (inactivesourcemessage,physaddress1,physaddress2,addressvalue)
130 elif message == "avpwron":
131 cmd = struct.pack('BB', sendkeymessage,sendkeypwronmessage)
132 addressvalue = addressvalueav
133 logcmd = "[HDMI-CEC] ** Power on A/V ** send message: %x:%x to address %x" % (sendkeymessage, sendkeypwronmessage, addressvalue)
134 elif message == "avdeeppwroff":
135 cmd = struct.pack('BB',sendkeymessage,sendkeypwroffmessage)
136 addressvalue = addressvalueav
137 logcmd = "[HDMI-CEC] ** Standby A/V (Deepstandby)** send message: %x:%x to address %x" % (sendkeymessage,sendkeypwroffmessage, addressvalue)
138 elif message == "avpwroff":
139 addressvalue = addressvalueav
140 cmd = struct.pack('BB',sendkeymessage,sendkeypwroffmessage)
141 logcmd = "[HDMI-CEC] ** Standby A/V ** send message: %x:%x to address %x" % (sendkeymessage,sendkeypwroffmessage, addressvalue)
142 elif message == "activevu":
143 addressvalue = addressvaluebroadcast
144 cmd = struct.pack('B', activevumessage)
145 logcmd = "[HDMI-CEC] ** Active VU Message ** send message: %x to address %x" % (activevumessage,addressvalue)
147 eHdmiCEC.getInstance().sendMessage(addressvalue, len(cmd), str(cmd))
150 if config.hdmicec.logenabledserial.value:
152 if config.hdmicec.logenabledfile.value:
153 filelog = "echo %s >> /tmp/hdmicec.log" % (logcmd)
157 def leaveStandby(self):
158 if config.hdmicec.enabled.value is True:
159 self.sendMessages(config.hdmicec.wakeup_message.value)
161 def enterStandby(self, configElement):
162 from Screens.Standby import inStandby
163 inStandby.onClose.append(self.leaveStandby)
164 if config.hdmicec.enabled.value is True:
165 self.sendMessages(config.hdmicec.standby_message.value)
167 def enterDeepStandby(self,configElement):
168 if config.hdmicec.enabled.value is True:
169 self.sendMessages(config.hdmicec.deepstandby_message.value)
171 def leaveDeepStandby(self):
172 if config.hdmicec.enabled.value is True:
173 self.sendMessages(config.hdmicec.wakeup_message.value)
176 def activeSource(self):
177 if config.hdmicec.enabled.value is True:
178 physadress1 = "0x" + str(config.hdmicec.tvinput.value) + str(config.hdmicec.avinput.value)
180 cecmessage = int('0x82',16)
181 address = int('0x0F',16)
182 valuethree = int(physadress1,16)
183 valuefour = int(physadress2,16)
184 cmd = struct.pack('BBB',cecmessage,valuethree,valuefour)
185 eHdmiCEC.getInstance().sendMessage(address, len(cmd), str(cmd))
186 if config.hdmicec.enabletvrc.value:
187 cecmessage = int('0x8E',16)
188 address = int('0',16)
189 valuethree = int('0',16)
190 cmd = struct.pack('BB',cecmessage,valuethree)
191 eHdmiCEC.getInstance().sendMessage(address, len(cmd), str(cmd))