Implement proper detection of used RCU-Type ("standard" or "advanced")
[enigma2-plugins.git] / webinterface / src / WebComponents / Sources / RemoteControl.py
1 from enigma import eActionMap
2 from Components.Sources.Source import Source
3 from Tools.HardwareInfo import HardwareInfo
4 from Components.config import config
5 class RemoteControl(Source):
6         # Flags
7         FLAG_MAKE = 0
8         FLAG_BREAK = 1
9         FLAG_REPEAT = 2
10         FLAG_LONG = 3
11         FLAG_ASCII = 4
12         
13         #Device Types
14         TYPE_STANDARD = "dreambox remote control (native)"
15         TYPE_ADVANCED = "dreambox advanced remote control (native)"
16         TYPE_KEYBOARD = "dreambox ir keyboard"
17                 
18         def __init__(self, session):
19                 self.cmd = None
20                 self.session = session
21                 Source.__init__(self)
22                 self.res = ( False, "Missing or wrong argument" )
23                 self.eam = eActionMap.getInstance()
24                 
25                 #Advanced remote or standard?
26                 
27                 if config.misc.rcused.value == 0:
28                         self.remotetype = self.TYPE_ADVANCED
29                 else:
30                         self.remotetype = self.TYPE_STANDARD
31                         
32                 print "[RemoteControl.__init__] Configured RCU-Type is '%s'" %(self.remotetype)                                                                         
33
34         def handleCommand(self, cmd):
35                 self.cmd = cmd
36                 self.res = self.sendEvent()
37
38         def sendEvent(self):
39                 if len(self.cmd) == 0 or self.cmd is None:
40                         print "[RemoteControl.sendEvent] cmd is empty or None"
41                         return self.res
42                 
43                 if not "command" in self.cmd:
44                         print "[RemoteControl.sendEvent] Obligatory parameter 'command' is missing!"
45                         return ( False, "Obligatory parameter 'command' is missing!" )
46                 
47                 key = int(self.cmd["command"])                  
48                 
49                 if key <= 0:                    
50                         print "[RemoteControl.sendEvent] command <= 0 (%s)" % key
51                         return ( False, "the command was not > 0" )
52                 
53                 #type can be "long" or "ascii", everything else will result in FLAG_MAKE
54                 type = None 
55                 if "type" in self.cmd:
56                         if self.cmd["type"] != "" and self.cmd["type"] != None:
57                                 type = self.cmd["type"];
58                 
59                 #if type is set, set the flag accordingly
60                 flag = self.FLAG_MAKE
61                 if type != None:
62                         if type == "long":
63                                 #Doesn't work yet (WHY?)
64                                 #TODO Fix long key press
65                                 flag = self.FLAG_LONG           
66                         elif type == "ascii":
67                                 flag = self.FLAG_ASCII
68                 
69                 #If type=="long" we need to press send FLAG_MAKE first 
70                 if(flag == self.FLAG_LONG):                     
71                         self.eam.keyPressed(self.remotetype, key, self.FLAG_MAKE)
72
73                 #press the key with the desired flag
74                 self.eam.keyPressed(self.remotetype, key, flag)
75                 #Release the key                
76                 self.eam.keyPressed(self.remotetype, key, self.FLAG_BREAK)
77                         
78                 print "[RemoteControl.sendEvent] command was was sent (key: %s, flag: %s)" %(key,flag)
79                 return ( True, "RC command '" + str(key) + "' has been issued" ) 
80
81         result = property(lambda self: self.res)