using /dev/input/event2 on dm8000 hardware
[vuplus_dvbapp-plugin] / webinterface / src / WebComponents / Sources / RemoteControl.py
1 from struct import pack
2 from Components.Sources.Source import Source
3 from Tools.HardwareInfo import HardwareInfo
4
5 class RemoteControl(Source):
6     def __init__(self, session):
7         self.cmd = None
8         self.session = session
9         Source.__init__(self)
10         self.res = [ False, "Missing or wrong argument" ]
11
12     def handleCommand(self, cmd):
13         self.cmd = cmd
14         self.res = self.sendEvent()
15
16     def sendEvent(self):
17         if self.cmd == "" or self.cmd is None:
18             print "[RemoteControl.py] cmd is empty or None"
19             return self.res
20
21         type = int(self.cmd)
22         if type <= 0:
23             print "[RemoteControl.py] command <= 0 (%s)" % type
24             return  [ False, "the command was not > 0" ]
25
26         dataon = pack('iiHHi', 0, 0, 1, type, 1)
27         dataoff = pack('iiHHi', 0, 0, 1, type, 0)
28
29         if HardwareInfo.device_name == "dm8000":
30             fp = open("/dev/input/event2", 'wb')
31         else:
32             fp = open("/dev/input/event1", 'wb')
33         fp.write(dataon)
34         fp.write(dataoff)
35         fp.close()
36
37         print "[RemoteControl.py] command was was sent (%s)" % type
38         return [ True, "command was was sent" ]
39
40     def getResult(self):
41         return self.res
42
43
44     result = property(getResult)