Merge branch 'vuplus_experimental_HdmiCec' into vuplus_experimental
[vuplus_dvbapp] / lib / python / Plugins / SystemPlugins / HDMICEC / plugin.py
1 # -*- coding: utf-8 -*-
2
3 # maintainer: <plnick@vuplus-support.org>
4
5 #This plugin is free software, you are allowed to
6 #modify it (if you keep the license),
7 #but you are not allowed to distribute/publish
8 #it without source code (this version and your modifications).
9 #This means you also have to distribute
10 #source code of your modifications.
11
12
13
14 from Screens.Screen import Screen
15 from Screens.MessageBox import MessageBox
16 from Plugins.Plugin import PluginDescriptor
17 from Components.ActionMap import ActionMap,NumberActionMap
18 from enigma import eActionMap
19 from Components.config import config, getConfigListEntry, ConfigInteger, ConfigSubsection, ConfigSelection, ConfigText, ConfigYesNo, NoSave, ConfigNothing
20 from Components.ConfigList import ConfigListScreen
21 from Components.HdmiCec import HdmiCec
22 from Components.Sources.StaticText import StaticText
23 from Tools import Notifications
24 import struct
25 from enigma import eHdmiCEC
26 from os import system
27 from Components.InputDevice import iInputDevices
28
29 class HdmiCecPlugin(Screen,ConfigListScreen):
30         skin = """
31                 <screen name="HDMICEC" position="center,center" size="700,400" title="HDMI-CEC Plugin" >
32                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
33                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
34                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
35                         <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
36                         <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" foregroundColor="#ececec" backgroundColor="#9f1313" transparent="1" />
37                         <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" foregroundColor="#ececec" backgroundColor="#1f771f" transparent="1" />
38                         <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" foregroundColor="#ececec" backgroundColor="#1f771f" transparent="1" />
39                         <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" foregroundColor="#ececec" backgroundColor="#1f771f" transparent="1" />
40                         <widget name="config" zPosition="2" position="5,50" size="650,300" scrollbarMode="showOnDemand" transparent="1" />
41                 </screen>"""
42         def __init__(self, session):
43                 Screen.__init__(self, session)
44                 
45                 
46                 config.hdmicec.input_address = ConfigText(default = "0", visible_width = 50, fixed_size = False)
47                 config.hdmicec.input_value1 = ConfigText(default = "0", visible_width = 50, fixed_size = False)
48                 config.hdmicec.input_value2 = ConfigText(default = "", visible_width = 50, fixed_size = False)
49                 config.hdmicec.input_value3 = ConfigText(default = "", visible_width = 50, fixed_size = False)
50                 config.hdmicec.input_value4 = ConfigText(default = "", visible_width = 50, fixed_size = False)
51                 config.hdmicec.avvolup = NoSave(ConfigNothing())
52                 config.hdmicec.avvoldown = NoSave(ConfigNothing())
53                 config.hdmicec.avvolmute = NoSave(ConfigNothing())
54                 config.hdmicec.avpwroff = NoSave(ConfigNothing())
55                 config.hdmicec.avpwron = NoSave(ConfigNothing())
56                 config.hdmicec.tvpwroff = NoSave(ConfigNothing())
57                 config.hdmicec.tvpwron = NoSave(ConfigNothing())
58                 self["key_red"] = StaticText(_("Close"))
59                 self["key_green"] = StaticText(_("Save"))
60                 self["key_yellow"] = StaticText(_("Connect"))
61                 self["key_blue"] = StaticText(_("Disconnect"))
62                 self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions", "NumberActions" ],
63                 {
64                         "ok": self.keyOk,
65                         "cancel": self.keyCancel,
66                         "red": self.keyCancel,
67                         "green": self.keySave,
68                         "yellow": self.keyConnect,
69                         "blue": self.keyDisconnect,
70                 }, -2)
71                 self.list = []
72                 ConfigListScreen.__init__(self, self.list,session = session)
73                 self.createSetup()
74
75         def createSetup(self):
76                 self.list = []
77                 self.hdmienabled = getConfigListEntry(_(_("HDMI CEC enabled:")), config.hdmicec.enabled)
78                 self.hdmiactivesourcereply = getConfigListEntry(_(_("Active Source Reply On:")), config.hdmicec.active_source_reply)
79                 self.hdmitvstandby = getConfigListEntry(_("VU standby => TV activity:"), config.hdmicec.standby_message)
80                 self.hdmitvdeepstandby = getConfigListEntry(_("VU deepstandby => TV activity:"), config.hdmicec.deepstandby_message)
81                 self.hdmitvwakeup = getConfigListEntry(_("VU on => TV activity:"), config.hdmicec.wakeup_message)
82                 self.hdmivustandby = getConfigListEntry(_("TV standby => VU+ activity:"), config.hdmicec.vustandby_message)
83                 self.hdmivuwakeup = getConfigListEntry(_("TV on => VU+ activity:"), config.hdmicec.vuwakeup_message)
84                 self.hdmitvinput = getConfigListEntry(_("Choose TV HDMI input:"), config.hdmicec.tvinput)
85                 self.hdmiavinput = getConfigListEntry(_("Choose A/V-Receiver HDMI input:"), config.hdmicec.avinput)
86                 self.hdmiavvolup = getConfigListEntry(_("A/V-Receiver volume up:"), config.hdmicec.avvolup)
87                 self.hdmiavvoldown = getConfigListEntry(_("A/V-Receiver volume down:"), config.hdmicec.avvoldown)
88                 self.hdmiavvolmute = getConfigListEntry(_("A/V-Receiver toggle mute:"), config.hdmicec.avvolmute)
89                 self.hdmiavpwron = getConfigListEntry(_("A/V-Receiver power on:"), config.hdmicec.avpwron)
90                 self.hdmiavpwroff = getConfigListEntry(_("A/V-Receiver power off:"), config.hdmicec.avpwroff)
91                 self.hdmitvpwron = getConfigListEntry(_("TV power on:"), config.hdmicec.tvpwron)
92                 self.hdmitvpwroff = getConfigListEntry(_("TV power off:"), config.hdmicec.tvpwroff)
93                 self.hdmienabletvrc = getConfigListEntry(_("Use TV remotecontrol:"), config.hdmicec.enabletvrc)
94                 self.hdmidevicename = getConfigListEntry(_("Set VU device name:"), config.hdmicec.devicename)
95                 self.hdmiinputaddress = getConfigListEntry(_("Address (0~FF):"), config.hdmicec.input_address)
96                 self.hdmiinputvalue1 = getConfigListEntry("Value 1 (message):", config.hdmicec.input_value1)
97                 self.hdmiinputvalue2 = getConfigListEntry("Value 2 (optional):", config.hdmicec.input_value2)
98                 self.hdmiinputvalue3 = getConfigListEntry("Value 3 (optional):", config.hdmicec.input_value3)
99                 self.hdmiinputvalue4 = getConfigListEntry("Value 4 (optional):", config.hdmicec.input_value4)
100                 self.hdmilogenabledfile = getConfigListEntry("Log to file enabled :", config.hdmicec.logenabledfile)
101                 self.hdmilogenabledserial = getConfigListEntry("Serial log enabled :", config.hdmicec.logenabledserial)
102 #               self.list.append( self.hdmiinputaddress )
103 #               self.list.append( self.hdmiinputvalue1 )
104 #               self.list.append( self.hdmiinputvalue2 )
105 #               self.list.append( self.hdmiinputvalue3 )
106 #               self.list.append( self.hdmiinputvalue4 )
107 #               self.list.append( self.hdmilogenabledfile )
108                 self.list.append( self.hdmienabled )
109                 if config.hdmicec.enabled.value is True:
110                         self.list.append( self.hdmidevicename )
111                         self.list.append( self.hdmitvinput )
112                         self.list.append( self.hdmiavinput )
113                         self.list.append( self.hdmivuwakeup )
114                         self.list.append( self.hdmivustandby )
115                         self.list.append( self.hdmitvwakeup )
116                         self.list.append( self.hdmitvstandby )
117                         self.list.append( self.hdmitvdeepstandby )
118                         if config.hdmicec.avinput.value is not "0":
119                                 self.list.append( self.hdmiavvolup )
120                                 self.list.append( self.hdmiavvoldown )
121                                 self.list.append( self.hdmiavvolmute )
122                                 self.list.append( self.hdmiavpwron )
123                                 self.list.append( self.hdmiavpwroff )
124                         self.list.append( self.hdmitvpwron )
125                         self.list.append( self.hdmitvpwroff )
126                         self.list.append( self.hdmienabletvrc )
127                         self.list.append( self.hdmiactivesourcereply )
128                         self.list.append( self.hdmilogenabledserial )
129                 self["config"].list = self.list
130                 self["config"].l.setList(self.list)
131                 
132         def keyDisconnect(self):
133                 cmd = None
134                 logcmd = None
135                 physaddress1 = int("0x" + str(config.hdmicec.tvinput.value) + str(config.hdmicec.avinput.value),16)
136                 physaddress2 = int("0x00",16)
137                 address = int('0',16)
138                 cecmessage = int('0x9D',16)
139                 cecmessagetwo = physaddress1
140                 cecmessagethree = physaddress2
141                 cmd = struct.pack('BBB',cecmessage,cecmessagetwo,cecmessagethree)
142                 logcmd = "[HDMI-CEC] send cec message %x:%x:%x to %x" % (cecmessage,cecmessagetwo,cecmessagethree,address)
143
144                 if cmd:
145                         eHdmiCEC.getInstance().sendMessage(address, len(cmd), str(cmd))
146                         
147                 if logcmd:
148                         if config.hdmicec.logenabledserial.value:
149                                 print logcmd
150                                 if config.hdmicec.logenabledfile.value:
151                                         filelog = "echo %s >> /tmp/hdmicec.log" % (logcmd)
152                                         system(filelog)
153
154         def keySend(self):
155                 cmd = None
156                 logcmd = None
157                 addresstmp=config.hdmicec.input_address.value
158                 tmp1=config.hdmicec.input_value1.value
159                 tmp2=config.hdmicec.input_value2.value
160                 tmp3=config.hdmicec.input_value3.value
161                 tmp4=config.hdmicec.input_value4.value
162                 address=int(addresstmp,16)
163                 if address not in range(0,256):
164                                 address = 255
165                 if tmp4:
166                         val1=int(tmp1,16)
167                         val2=int(tmp2,16)
168                         val3=int(tmp3,16)
169                         val4=int(tmp4,16)
170                         if val1 not in range(0,256):
171                                 val1 = 00
172                         if val2 not in range(0,256):
173                                 val2 = 00
174                         if val3 not in range(0,256):
175                                 val3 = 00
176                         if val4 not in range(0,256):
177                                 val4 = 00
178                         cmd = struct.pack('BBBB',val1,val2,val3,val4)
179                         logcmd = "[HDMI-CEC] ** Test Message ** Send message value: %x:%x:%x:%x to address %x" % (val1,val2,val3,val4,address)
180                 else:
181
182                         if tmp3:
183                                 val1=int(tmp1,16)
184                                 val2=int(tmp2,16)
185                                 val3=int(tmp3,16)
186                                 if val1 not in range(0,256):
187                                         val1 = 00
188                                 if val2 not in range(0,256):
189                                         val2 = 00
190                                 if val3 not in range(0,256):
191                                         val3 = 00
192                                 cmd = struct.pack('BBB',val1,val2,val3)
193                                 logcmd = "[HDMI-CEC] ** Test Message ** Send message value: %x:%x:%x to address %x" % (val1,val2,val3,address)
194                         else:
195                           
196                                 if tmp2:
197                                         val1=int(tmp1,16)
198                                         val2=int(tmp2,16)
199                                         if val1 not in range(0,256):
200                                                 val1 = 00
201                                         if val2 not in range(0,256):
202                                                 val2 = 00
203                                         cmd = struct.pack('BB',val1,val2)
204                                         logcmd = "[HDMI-CEC] ** Test Message ** Send message value: %x:%x to address %x" % (val1,val2,address)
205                                 else:
206                                         val1=int(tmp1,16)
207                                         if val1 not in range(0,256):
208                                                 val1 = 00
209                                         cmd = struct.pack('B',val1)
210                                         logcmd = "[HDMI-CEC] ** Test Message ** Send message value: %x to address %x" % (val1, address)
211
212                 if cmd:
213                         eHdmiCEC.getInstance().sendMessage(address, len(cmd), str(cmd))
214                         
215                 if logcmd:
216                         if config.hdmicec.logenabledserial.value:
217                                 print logcmd
218                                 if config.hdmicec.logenabledfile.value:
219                                         filelog = "echo %s >> /tmp/hdmicec.log" % (logcmd)
220                                         system(filelog)
221                 
222         def keyOk(self):
223                 cmd = None
224                 logcmd = None
225                 if self["config"].getCurrent() == self.hdmiavvolup:
226                         address = int("5",16)
227                         cecmessage = int("44",16)
228                         cecmessagetwo = int("41",16)
229                         cmd = struct.pack('BB',cecmessage,cecmessagetwo)
230                         logcmd = "[HDMI-CEC] send cec message %x:%x to %x" % (cecmessage,cecmessagetwo,address)
231                 elif self["config"].getCurrent() == self.hdmiavvoldown:
232                         address = int("5",16)
233                         cecmessage = int("44",16)
234                         cecmessagetwo = int("42",16)
235                         cmd = struct.pack('BB',cecmessage,cecmessagetwo)
236                         logcmd = "[HDMI-CEC] send cec message %x:%x to %x" % (cecmessage,cecmessagetwo,address)
237                 elif self["config"].getCurrent() == self.hdmiavvolmute:
238                         address = int("5",16)
239                         cecmessage = int("44",16)
240                         cecmessagetwo = int("43",16)
241                         cmd = struct.pack('BB',cecmessage,cecmessagetwo)
242                         logcmd = "[HDMI-CEC] send cec message %x:%x to %x" % (cecmessage,cecmessagetwo,address)
243                 elif self["config"].getCurrent() == self.hdmiavpwron:
244                         address = int("5",16)
245                         cecmessage = int("44",16)
246                         cecmessagetwo = int("6D",16)
247                         cmd = struct.pack('BB',cecmessage,cecmessagetwo)
248                         logcmd = "[HDMI-CEC] send cec message %x:%x to %x" % (cecmessage,cecmessagetwo,address)
249                 elif self["config"].getCurrent() == self.hdmiavpwroff:
250                         address = int("5",16)
251                         cecmessage = int("44",16)
252                         cecmessagetwo = int("6C",16)
253                         cmd = struct.pack('BB',cecmessage,cecmessagetwo)
254                         logcmd = "[HDMI-CEC] send cec message %x:%x to %x" % (cecmessage,cecmessagetwo,address)
255                 elif self["config"].getCurrent() == self.hdmitvpwroff:
256                         address = int("0",16)
257                         cecmessage = int("36",16)
258                         cmd = struct.pack('B',cecmessage)
259                         logcmd = "[HDMI-CEC] send cec message %x to %x" % (cecmessage,address)
260                 elif self["config"].getCurrent() == self.hdmitvpwron:
261                         address = int("0",16)
262                         cecmessage = int("04",16)
263                         cmd = struct.pack('B',cecmessage)
264                         logcmd = "[HDMI-CEC] send cec message %x to %x" % (cecmessage,address)
265                 else:
266                         ConfigListScreen.keySave(self)
267                 if cmd:
268                         eHdmiCEC.getInstance().sendMessage(address, len(cmd), str(cmd))
269                         messagecmd = int("45",16)
270
271                 if logcmd:
272                         if config.hdmicec.logenabledserial.value:
273                                 print logcmd
274                                 if config.hdmicec.logenabledfile.value:
275                                         filelog = "echo %s >> /tmp/hdmicec.log" % (logcmd)
276                                         system(filelog)
277
278         def keyConnect(self):
279                         address = 0
280                         message = 0x85
281                         messageReceived(address, message)
282         
283         def keyLeft(self):
284                 ConfigListScreen.keyLeft(self)
285                 if self["config"].getCurrent() == self.hdmienabled:
286                         self.createSetup()
287                 if self["config"].getCurrent() == self.hdmiavinput:
288                         self.createSetup()
289
290         def keyRight(self):
291                 ConfigListScreen.keyRight(self)
292                 if self["config"].getCurrent() == self.hdmienabled:
293                         self.createSetup()
294                 if self["config"].getCurrent() == self.hdmiavinput:
295                         self.createSetup()
296
297         def keyCancel(self):
298                 self.close()
299
300         def keySave(self):
301                 ConfigListScreen.keySave(self)
302
303 def openconfig(session, **kwargs):
304         session.open(HdmiCecPlugin)
305         
306 def autostart(reason, **kwargs):
307         global session
308         if kwargs.has_key("session") and reason == 0:
309                 session = kwargs["session"]
310                 eHdmiCEC.getInstance().messageReceived.get().append(messageReceived)
311                 eHdmiCEC.getInstance().messageReceivedKey.get().append(messageReceivedKey)
312
313 def Plugins(**kwargs):
314         return [PluginDescriptor(name=_("HDMI-CEC"), description="HDMI-CEC Configuration", where = PluginDescriptor.WHERE_PLUGINMENU, icon="hdmicec.png", needsRestart = True, fnc=openconfig),
315                 PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART, PluginDescriptor.WHERE_AUTOSTART], fnc = autostart)]
316                 
317 def messageReceived(address, message):
318         logcmd = "[HDMI-CEC] received cec message %x from %x" % (message, address)
319         if logcmd:
320                 if config.hdmicec.logenabledserial.value:
321                         print logcmd
322                         if config.hdmicec.logenabledfile.value:
323                                 filelog = "echo %s >> /tmp/hdmicec.log" % (logcmd)
324                                 system(filelog)
325
326         if config.hdmicec.enabled.value is True:
327                 from Screens.Standby import inStandby
328                 from Screens.Standby import Standby
329
330                 cmd = None
331                 cmdtwo = None
332                 addresstwo = None
333                 logcmd = None
334                 logcmdtwo = None
335
336                 physaddress1 = int("0x" + str(config.hdmicec.tvinput.value) + str(config.hdmicec.avinput.value),16)
337                 physaddress2 = int("0x00",16)
338
339                 addresstv = int("0x00",16)
340                 addressav = int("0x05",16)
341                 addressglobal = int("0x0F",16)
342
343                 powerstatereportmessage = int("0x90",16)
344                 powerstate = int("0x00",16)
345
346                 physaddressmessage = int('0x84',16)
347                 devicetypmessage = int('0x03',16)
348
349                 activesourcemessage = int('0x82',16)
350
351                 menuonmessage = int('0x8E',16)
352                 menustatemessage = int('0x00',16)
353
354                 setnamemessage = int('0x47',16)
355
356                 sendkeymessage = int("44",16)
357                 sendkeypwronmessage = int("6D",16)
358                 sendkeypwroffmessage = int("6C",16)
359
360                 if message == 0x8f: # request power state
361                         address = addresstv
362                         cecmessage = powerstatereportmessage
363                         cecmessagetwo = powerstate
364                         cmd = struct.pack('BB',cecmessage,cecmessagetwo)
365                         logcmd = "[HDMI-CEC] send cec message %x:%x to %x" % (cecmessage,cecmessagetwo,address)
366
367                 elif message == 0x83: # request physical address
368                         address = addressglobal
369                         cecmessage = physaddressmessage
370                         cecmessagetwo = physaddress1
371                         cecmessagethree = physaddress2
372                         cecmessagefour = devicetypmessage
373                         cmd = struct.pack('BBBB',cecmessage,cecmessagetwo,cecmessagethree,cecmessagefour)
374                         logcmd = "[HDMI-CEC] send cec message %x:%x:%x:%x to %x" % (cecmessage,cecmessagetwo,cecmessagethree,cecmessagefour,address)
375
376                 elif message == 0x86: # request streampath
377                         address = addressglobal
378                         cecmessage = activesourcemessage
379                         cecmessagetwo = physaddress1
380                         cecmessagethree = physaddress2
381                         cmd = struct.pack('BBB',cecmessage,cecmessagetwo,cecmessagethree)
382                         logcmd = "[HDMI-CEC] send cec message %x:%x:%x to %x" % (cecmessage,cecmessagetwo,cecmessagethree,address)
383
384                         if config.hdmicec.enabletvrc.value:
385                                         addresstwo = addresstv
386                                         cecmessage = menuonmessage
387                                         cecmessagetwo = menustatemessage
388                                         cmdtwo = struct.pack('BB',cecmessage,cecmessagetwo)
389                                         logcmdtwo = "[HDMI-CEC] send cec message %x:%x to %x" % (cecmessage,cecmessagetwo,address)
390
391                 elif message == 0x8d: # request menu state
392                         if config.hdmicec.enabletvrc.value:
393                                 address = addresstv
394                                 cecmessage = menuonmessage
395                                 cecmessagetwo = menustatemessage
396                                 cmd = struct.pack('BB',cecmessage,cecmessagetwo)
397                                 logcmd = "[HDMI-CEC] send cec message %x:%x to %x" % (cecmessage,cecmessagetwo,address)
398
399                 elif message == 0x46: # request device name
400                         address = addresstv
401                         cecmessage = setnamemessage
402                         if config.hdmicec.devicename.value == "vuduo":
403                                 cecmessagetwo ="VU+ Duo"
404                                 cmd = struct.pack('B8s',cecmessage,cecmessagetwo)
405                         elif config.hdmicec.devicename.value == "vusolo":
406                                 cecmessagetwo ="VU+ Solo"
407                                 cmd = struct.pack('B9s',cecmessage,cecmessagetwo)
408                         elif config.hdmicec.devicename.value == "vuuno":
409                                 cecmessagetwo ="VU+ Uno"
410                                 cmd = struct.pack('B8s',cecmessage,cecmessagetwo)
411                         elif config.hdmicec.devicename.value == "vuultimo":
412                                 cecmessagetwo ="VU+ Ultimo"
413                                 cmd = struct.pack('B8s',cecmessage,cecmessagetwo)
414                         else:
415                                 cecmessagetwo ="VU+"
416                                 cmd = struct.pack('B4s',cecmessage,cecmessagetwo)
417                         logcmd = "[HDMI-CEC] send cec message %x:%s to %x" % (cecmessage,cecmessagetwo,address)
418
419                 elif message == 0x85: # request active source
420                         if not inStandby:
421                                 address = addressglobal
422                                 cecmessage = activesourcemessage
423                                 cecmessagetwo = physaddress1
424                                 cecmessagethree = physaddress2
425                                 cmd = struct.pack('BBB',cecmessage,cecmessagetwo,cecmessagethree)
426                                 logcmd = "[HDMI-CEC] send cec message %x:%x:%x to %x" % (cecmessage,cecmessagetwo,cecmessagethree,address)
427
428                                 if config.hdmicec.enabletvrc.value:
429                                         addresstwo = addresstv
430                                         cecmessage = menuonmessage
431                                         cecmessagetwo = menustatemessage
432                                         cmdtwo = struct.pack('BB',cecmessage,cecmessagetwo)
433                                         logcmdtwo = "[HDMI-CEC] send cec message %x:%x to %x" % (cecmessage,cecmessagetwo,address)
434
435                         elif inStandby:
436                                 if config.hdmicec.vuwakeup_message.value == "vuwakeup":
437                                         inStandby.Power()
438                                         address = addressglobal
439                                         cecmessage = activesourcemessage
440                                         cecmessagetwo = physaddress1
441                                         cecmessagethree = physaddress2
442                                         cmd = struct.pack('BBB',cecmessage,cecmessagetwo,cecmessagethree)
443                                         logcmd = "[HDMI-CEC] send cec message %x:%x:%x to %x" % (cecmessage,cecmessagetwo,cecmessagethree,address)
444                                         
445                                         if config.hdmicec.enabletvrc.value:
446                                                 addresstwo = addresstv
447                                                 cecmessage = menuonmessage
448                                                 cecmessagetwo = menustatemessage
449                                                 cmdtwo = struct.pack('BB',cecmessage,cecmessagetwo)
450                                                 logcmdtwo = "[HDMI-CEC] send cec message %x:%x to %x" % (cecmessage,cecmessagetwo,address)
451
452                 elif message == 0x36:
453                         if config.hdmicec.vustandby_message.value == "vustandby":
454                                 if inStandby == None:
455                                         logcmd = "[HDMI-CEC] VU+ STB goto standby"
456                                         session.open(Standby)
457                         elif config.hdmicec.vustandby_message.value == "vudeepstandby":
458                                 import Screens.Standby
459                                 logcmd = "[HDMI-CEC] VU+ STB goto deepstandby"
460                                 session.open(Screens.Standby.TryQuitMainloop,1)
461
462                 if cmd:
463                         eHdmiCEC.getInstance().sendMessage(address, len(cmd), str(cmd))
464                 if cmdtwo:
465                         eHdmiCEC.getInstance().sendMessage(addresstwo, len(cmdtwo), str(cmdtwo))
466
467                 if logcmd:
468                         if config.hdmicec.logenabledserial.value:
469                                 print logcmd
470                                 if config.hdmicec.logenabledfile.value:
471                                         filelog = "echo %s >> /tmp/hdmicec.log" % (logcmd)
472                                         system(filelog)
473                 if logcmdtwo:
474                         if config.hdmicec.logenabledserial.value:
475                                 print logcmdtwo
476                                 if config.hdmicec.logenabledfile.value:
477                                         filelog = "echo %s >> /tmp/hdmicec.log" % (logcmdtwo)
478                                         system(filelog)
479
480 def messageReceivedKey(address, message):
481         logcmd = "[HDMI-CEC] received cec message part two %x from %x" % (message, address)
482         if logcmd:
483                 if config.hdmicec.logenabledserial.value:
484                         print logcmd
485                         if config.hdmicec.logenabledfile.value:
486                                 filelog = "echo %s >> /tmp/hdmicec.log" % (logcmd)
487                                 system(filelog)
488         if config.hdmicec.enabled.value is True:
489                 rcdevicename = iInputDevices.getDeviceName('event0') # hschang : get rc device name, /dev/input/event0
490                 keyaction = eActionMap.getInstance()
491                 key = None
492 #start translate keycodes
493                 if message == 0x32 or message == 0x09: #key menu
494                         key = int(139)
495                 elif message == 0x20: #key 0
496                         key = int(11)
497                 elif message == 0x21: #key 1
498                         key = int(2)
499                 elif message == 0x22: #key 2
500                         key = int(3)
501                 elif message == 0x23: #key 3
502                         key = int(4)
503                 elif message == 0x24: #key 4
504                         key = int(5)
505                 elif message == 0x25: #key 5
506                         key = int(6)
507                 elif message == 0x26: #key 6
508                         key = int(7)
509                 elif message == 0x27: #key 7
510                         key = int(8)
511                 elif message == 0x28: #key 8
512                         key = int(9)
513                 elif message == 0x29: #key 10
514                         key = int(10)
515                 elif message == 0x30: #key bouquet up
516                         key = int(402)
517                 elif message == 0x31: #key bouquet down
518                         key = int(403)
519                 elif message == 0x53: #key info/epg
520                         key = int(358)
521                 elif message == 0x00: #key ok
522                         key = int(352)
523                 elif message == 0x03: #key left
524                         key = int(105)
525                 elif message == 0x04: #key right
526                         key = int(106)
527                 elif message == 0x01: #key up
528                         key = int(103)
529                 elif message == 0x02: #key down
530                         key = int(108)
531                 elif message == 0x0d: #key exit
532                         key = int(174)
533                 elif message == 0x72: #key red
534                         key = int(398)
535                 elif message == 0x71: #key blue
536                         key = int(401)
537                 elif message == 0x73: #key green
538                         key = int(399)
539                 elif message == 0x74: #key yellow
540                         key = int(400)
541                 elif message == 0x44: #key play
542                         if rcdevicename.find("advanced"):
543                                 key = int(164) # KEY_PLAYPAUSE
544                         else:
545                                 key = int(207) # KEY_PLAY
546                 elif message == 0x46: #key pause
547                         if rcdevicename.find("advanced"):
548                                 key = int(164) # KEY_PLAYPAUSE
549                         else:
550                                 key = int(119) # KEY_PAUSE
551                 elif message == 0x45: #key stop
552                         key = int(128)
553                 elif message == 0x47: #key record
554                         key = int(167)
555                 elif message == 0x49: #fast forward
556                         if rcdevicename.find("advanced"):
557                                 key = int(163) # KEY_NEXTSONG
558                         else:
559                                 key = int(208) # KEY_FASTFORWARD
560                 elif message == 0x48: #rewind
561                         if rcdevicename.find("advanced"):
562                                 key = int(165) # KEY_NEXTSONG
563                         else:
564                                 key = int(168) # KEY_FASTFORWARD
565                 elif message == 0x60: #play 2
566                         key = int(207)
567                 elif message == 0x61: #key pause 2
568                         if rcdevicename.find("advanced"):
569                                 key = int(164) # KEY_PLAYPAUSE
570                         else:
571                                 key = int(119) # KEY_PAUSE
572                 elif message == 0x64: #key stop 2
573                         key = int(128)
574                 elif message == 0x62: #key record 2
575                         key = int(167)
576 #end translate keycodes
577                 if key:
578                         keyaction.keyPressed(rcdevicename, key, int(0))
579                         keyaction.keyPressed(rcdevicename, key, int(1))