[dvbci] Change the location to add vtuner pid.
[vuplus_dvbapp] / lib / python / Plugins / SystemPlugins / Ultimo4kMiscControl / plugin.py
1 from Screens.Screen import Screen
2 from Components.ConfigList import ConfigListScreen
3 from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigSelection
4 from Components.ActionMap import ActionMap
5 from Screens.MessageBox import MessageBox
6 from Components.Sources.StaticText import StaticText
7 from Plugins.Plugin import PluginDescriptor
8 from Tools.Directories import fileExists
9
10 config.plugins.ultimo4kMiscControl = ConfigSubsection()
11 config.plugins.ultimo4kMiscControl.forceLnbPower = ConfigSelection(default = "off", choices = [ ("on", _("Yes")), ("off", _("No"))] )
12 config.plugins.ultimo4kMiscControl.forceToneBurst = ConfigSelection(default = "disable", choices = [ ("enable", _("Yes")), ("disable", _("No"))] )
13 config.plugins.ultimo4kMiscControl.dvbCiDelay = ConfigSelection(default = "256", choices = [ ("16", _("16")), ("32", _("32")), ("64", _("64")), ("128", _("128")), ("256", _("256"))] )
14
15 PROC_FORCE_LNBPOWER = "/proc/stb/frontend/fbc/force_lnbon"
16 PROC_FORCE_TONEBURST = "/proc/stb/frontend/fbc/force_toneburst"
17 PROC_DVB_CI_DELAY = "/proc/stb/tsmux/rmx_delay"
18
19 def setProcValueOnOff(value, procPath):
20         try:
21                 print "[ultimo4kMiscControl] set %s : %s" % (procPath, value)
22                 fd = open(procPath,'w')
23                 fd.write(value)
24                 fd.close()
25                 return 0
26         except Exception, e:
27                 print "[ultimo4kMiscControl] proc write Error", e
28                 return -1
29
30
31 from enigma import eTimer
32 class checkDriverSupport:
33         def __init__(self):
34                 self.onLayoutFinish.append(self.procCheck)
35                 self.dispErrorTimer = eTimer()
36                 self.dispErrorTimer.callback.append(self.dispErrorMsg)
37
38         def procCheck(self):
39                 if not (fileExists(PROC_FORCE_LNBPOWER) and fileExists(PROC_FORCE_TONEBURST) and fileExists(PROC_DVB_CI_DELAY)):
40                         self.dispErrorTimer.start(0, True)
41
42         def dispErrorMsg(self):
43                 self.session.openWithCallback(self.close ,MessageBox, _("Driver is not supported."), MessageBox.TYPE_ERROR)
44
45 class ultimo4kMiscControl(Screen, ConfigListScreen, checkDriverSupport):
46         skin =  """
47                 <screen position="center,center" size="400,250" title="Ultimo4K Misc. Control" >
48                         <ePixmap pixmap="skin_default/buttons/red.png" position="30,10" size="140,40" alphatest="on" />
49                         <ePixmap pixmap="skin_default/buttons/green.png" position="230,10" size="140,40" alphatest="on" />
50                         <widget source="key_red" render="Label" position="30,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
51                         <widget source="key_green" render="Label" position="230,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
52                         <widget name="config" zPosition="2" position="5,70" size="380,180" scrollbarMode="showOnDemand" transparent="1" />
53                 </screen>
54                 """
55
56         def __init__(self,session):
57                 Screen.__init__(self,session)
58                 self.session = session
59                 self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ],
60                 {
61                         "ok": self.keySave,
62                         "cancel": self.keyCancel,
63                         "red": self.keyCancel,
64                         "green": self.keySave,
65                 }, -2)
66                 self.list = []
67                 ConfigListScreen.__init__(self, self.list,session = self.session)
68                 self["key_red"] = StaticText(_("Cancel"))
69                 self["key_green"] = StaticText(_("Ok"))
70                 self.createSetup()
71
72                 checkDriverSupport.__init__(self)
73
74         def createSetup(self):
75                 self.list = []
76                 self.lnbPowerEntry = getConfigListEntry(_("Force LNB Power"), config.plugins.ultimo4kMiscControl.forceLnbPower)
77                 self.toneBurstEntry = getConfigListEntry(_("Force ToneBurst"), config.plugins.ultimo4kMiscControl.forceToneBurst)
78                 self.ciDelayEntry = getConfigListEntry(_("DVB CI Delay"), config.plugins.ultimo4kMiscControl.dvbCiDelay)
79                 self.list.append( self.lnbPowerEntry )
80                 self.list.append( self.toneBurstEntry )
81                 self.list.append( self.ciDelayEntry )
82                 self["config"].list = self.list
83                 self["config"].l.setList(self.list)
84
85         def keySave(self):
86                 res = setProcValueOnOff(config.plugins.ultimo4kMiscControl.forceLnbPower.value, PROC_FORCE_LNBPOWER)
87                 if res == 0:
88                         res = setProcValueOnOff(config.plugins.ultimo4kMiscControl.forceToneBurst.value, PROC_FORCE_TONEBURST)
89                 if res == 0:
90                         res = setProcValueOnOff(config.plugins.ultimo4kMiscControl.dvbCiDelay.value, PROC_DVB_CI_DELAY)
91
92                 if res == -1:
93                         self.resetConfig()
94                         self.session.openWithCallback(self.close, MessageBox, _("SET FAILED!\n"), MessageBox.TYPE_ERROR)
95                 else:
96                         self.saveAll()
97                         self.close()
98
99         def resetConfig(self):
100                 for x in self["config"].list:
101                         x[1].cancel()
102
103 def main(session, **kwargs):
104         session.open(ultimo4kMiscControl)
105
106 def OnSessionStart(session, **kwargs):
107         setProcValueOnOff(config.plugins.ultimo4kMiscControl.forceLnbPower.value, PROC_FORCE_LNBPOWER)
108         setProcValueOnOff(config.plugins.ultimo4kMiscControl.forceToneBurst.value, PROC_FORCE_TONEBURST)
109         setProcValueOnOff(config.plugins.ultimo4kMiscControl.dvbCiDelay.value, PROC_DVB_CI_DELAY)
110
111 def Plugins(**kwargs):
112         pList = []
113         pList.append( PluginDescriptor(where=PluginDescriptor.WHERE_SESSIONSTART, fnc=OnSessionStart) )
114         pList.append( PluginDescriptor(name=_("Ultimo4K Misc. Control"), description="set Ultimo4K LNB Power and etc..", where = PluginDescriptor.WHERE_PLUGINMENU, needsRestart = False, fnc=main) )
115         return pList
116