ef39ec0d994e8549d1de7aeea10e3c6403f83cf3
[enigma2.git] / lib / python / Plugins / SystemPlugins / PositionerSetup / plugin.py
1 from enigma import eTimer, eDVBSatelliteEquipmentControl, eDVBResourceManager, eDVBDiseqcCommand, eDVBResourceManagerPtr, iDVBChannelPtr, iDVBFrontendPtr
2 from Screens.Screen import Screen
3 from Plugins.Plugin import PluginDescriptor
4
5 from Components.Label import Label
6 from Components.ConfigList import ConfigList
7 from Components.TunerInfo import TunerInfo
8 from Components.ActionMap import ActionMap
9 from Components.config import config, ConfigSubsection, configElement_nonSave, configNothing, getConfigListEntry, configSelection
10
11 class PositionerSetup(Screen):
12         skin = """
13                 <screen position="100,100" size="560,400" title="Positioner setup..." >
14                         <widget name="list" position="100,0" size="350,120" />
15
16                         <widget name="red" position="0,120" size="140,80" backgroundColor="red" halign="center" valign="center" font="Regular;21" />
17                         <widget name="green" position="140,120" size="140,80" backgroundColor="green" halign="center" valign="center" font="Regular;21" />
18                         <widget name="yellow" position="280,120" size="140,80" backgroundColor="yellow" halign="center" valign="center" font="Regular;21" />
19                         <widget name="blue" position="420,120" size="140,80" backgroundColor="blue" halign="center" valign="center" font="Regular;21" />
20                         <widget name="status" position="0,320" size="550,40" font="Regular;15" />
21                         
22                         <widget name="snr" text="SNR:" position="0,220" size="60,22" font="Regular;21" />
23                         <widget name="agc" text="AGC:" position="0,245" size="60,22" font="Regular;21" />
24                         <widget name="ber" text="BER:" position="0,270" size="60,22" font="Regular;21" />
25                         <widget name="lock" text="Lock:" position="0,295" size="60,22" font="Regular;21" />
26                         <widget name="snr_percentage" position="220,220" size="60,22" font="Regular;21" />
27                         <widget name="agc_percentage" position="220,245" size="60,22" font="Regular;21" />
28                         <widget name="ber_value" position="220,270" size="60,22" font="Regular;21" />
29                         <widget name="lock_state" position="60,295" size="150,22" font="Regular;21" />
30                         <widget name="snr_bar" position="60,220" size="150,22" />
31                         <widget name="agc_bar" position="60,245" size="150,22" />
32                         <widget name="ber_bar" position="60,270" size="150,22" />
33                 </screen>"""
34         def __init__(self, session):
35                 self.skin = PositionerSetup.skin
36                 Screen.__init__(self, session)
37                 
38                 self.createConfig()
39                 
40                 self.isMoving = False
41                 
42                 self.status = Label("")
43                 self["status"] = self.status
44                 
45                 self.red = Label("")
46                 self["red"] = self.red
47                 self.green = Label("")
48                 self["green"] = self.green
49                 self.yellow = Label("")
50                 self["yellow"] = self.yellow
51                 self.blue = Label("")
52                 self["blue"] = self.blue
53                 
54                 self.feid = 0
55
56                 self.list = []
57                 self["list"] = ConfigList(self.list)
58                 self.createSetup()
59                 
60                 self["snr"] = Label()
61                 self["agc"] = Label()
62                 self["ber"] = Label()
63                 self["lock"] = Label()
64                 self["snr_percentage"] = TunerInfo(TunerInfo.SNR_PERCENTAGE, self.session.nav.getCurrentService)
65                 self["agc_percentage"] = TunerInfo(TunerInfo.AGC_PERCENTAGE, self.session.nav.getCurrentService)
66                 self["ber_value"] = TunerInfo(TunerInfo.BER_VALUE, self.session.nav.getCurrentService)
67                 self["snr_bar"] = TunerInfo(TunerInfo.SNR_BAR, self.session.nav.getCurrentService)
68                 self["agc_bar"] = TunerInfo(TunerInfo.AGC_BAR, self.session.nav.getCurrentService)
69                 self["ber_bar"] = TunerInfo(TunerInfo.BER_BAR, self.session.nav.getCurrentService)
70                 self["lock_state"] = TunerInfo(TunerInfo.LOCK_STATE, self.session.nav.getCurrentService)
71                 
72                 self["actions"] = ActionMap(["DirectionActions", "OkCancelActions", "ColorActions"],
73                 {
74                         "ok": self.go,
75                         "cancel": self.close,
76                         "up": self.up,
77                         "down": self.down,
78                         "left": self.left,
79                         "right": self.right,
80                         "red": self.redKey,
81                         "green": self.greenKey,
82                         "yellow": self.yellowKey,
83                         "blue": self.blueKey,
84                 }, -1)
85                 
86                 self.updateColors("tune")
87                 
88                 self.statusTimer = eTimer()
89                 self.statusTimer.timeout.get().append(self.updateStatus)
90                 self.statusTimer.start(200, False)
91                 
92         def createConfig(self):
93                 config.positioner = ConfigSubsection()
94                 config.positioner.tune = configElement_nonSave("tune", configNothing, 0, None)
95                 config.positioner.move = configElement_nonSave("move", configNothing, 0, None)
96                 config.positioner.limits = configElement_nonSave("limits", configNothing, 0, None)
97                 config.positioner.storage = configElement_nonSave("storage", configSelection, 0, ("1", "2", "3"))
98         
99         def createSetup(self):
100                 self.list.append(getConfigListEntry(_("Tune"), config.positioner.tune))
101                 self.list.append(getConfigListEntry(_("Positioner movement"), config.positioner.move))
102                 self.list.append(getConfigListEntry(_("Set limits"), config.positioner.limits))
103                 self.list.append(getConfigListEntry(_("Positioner storage"), config.positioner.storage))
104                 
105                 self["list"].l.setList(self.list)
106                 
107         def go(self):
108                 pass
109         
110         def getCurrentConfigPath(self):
111                 return self["list"].getCurrent()[1].parent.configPath
112         
113         def up(self):
114                 self["list"].instance.moveSelection(self["list"].instance.moveUp)
115                 self.updateColors(self.getCurrentConfigPath())
116         
117         def down(self):
118                 self["list"].instance.moveSelection(self["list"].instance.moveDown)
119                 self.updateColors(self.getCurrentConfigPath())
120         
121         def left(self):
122                 self["list"].handleKey(config.key["prevElement"])
123         
124         def right(self):
125                 self["list"].handleKey(config.key["nextElement"])
126         
127         def updateColors(self, entry):
128                 if entry == "tune":
129                         self.red.setText("tune manually")
130                         self.green.setText("predefined transponder")
131                         self.yellow.setText("")
132                         self.blue.setText("")
133                 elif entry == "move":
134                         if self.isMoving:
135                                 self.red.setText(_("Stop"))
136                                 self.green.setText(_("Stop"))
137                                 self.yellow.setText(_("Stop"))
138                                 self.blue.setText(_("Stop"))
139                         else:
140                                 self.red.setText(_("Move east"))
141                                 self.green.setText(_("Step east"))
142                                 self.yellow.setText(_("Step west"))
143                                 self.blue.setText(_("Move west"))
144                 elif entry == "limits":
145                         self.red.setText(_("Limits off"))
146                         self.green.setText(_("Limit east"))
147                         self.yellow.setText(_("Limit west"))
148                         self.blue.setText("")
149                 elif entry == "storage":
150                         self.red.setText(_("Apply satellite"))
151                         self.green.setText(_("Store position"))
152                         self.yellow.setText(_("Goto position"))
153                         self.blue.setText("")
154                 else:
155                         self.red.setText("")
156                         self.green.setText("")
157                         self.yellow.setText("")
158                         self.blue.setText("")
159         
160         def redKey(self):
161                 entry = self.getCurrentConfigPath()
162                 if entry == "move":
163                         print "moving east"
164                         self.diseqc()
165         
166         def greenKey(self):
167                 entry = self.getCurrentConfigPath()
168                 if entry == "move":
169                         print "stepping east"
170         
171         def yellowKey(self):
172                 entry = self.getCurrentConfigPath()
173                 if entry == "move":
174                         print "stepping east"
175         
176         def blueKey(self):
177                 entry = self.getCurrentConfigPath()
178                 if entry == "move":
179                         print "moving west"
180                         if self.isMoving:
181                                 self.diseqc("stop")
182                         else:
183                                 self.diseqc("moveWest")
184                         print "stepping west"
185
186         def diseqc(self, what):
187                 res_mgr = eDVBResourceManagerPtr()
188                 if eDVBResourceManager.getInstance(res_mgr) == 0:
189                         raw_channel = iDVBChannelPtr()
190                         if res_mgr.allocateRawChannel(raw_channel, self.feid) == 0:
191                                 frontend = iDVBFrontendPtr()
192                                 if raw_channel.getFrontend(frontend) == 0:
193                                         cmd = eDVBDiseqcCommand()
194                                         if what == "moveWest":
195                                                 cmd.setCommandString('\xe1\x31\x69\x40') 
196                                         elif what == "moveEast":
197                                                 cmd.setCommandString('\xe1\x31\x68\x40') 
198                                         else:
199                                                 cmd.setCommandString('\xe0\x31\x60') #positioner stop
200                                         frontend.sendDiseqc(cmd)
201                                 else:
202                                         print "getFrontend failed"
203                         else:
204                                 print "getRawChannel failed"
205                 else:
206                                 print "getResourceManager instance failed"
207
208         def updateStatus(self):
209                 if eDVBSatelliteEquipmentControl.getInstance().isRotorMoving():
210                         if not self.isMoving:
211                                 self.isMoving = True
212                                 self.updateColors(self.getCurrentConfigPath())
213                         self.status.setText("moving...")
214                 else:
215                         if self.isMoving:
216                                 self.isMoving = False
217                                 self.updateColors(self.getCurrentConfigPath())
218                         self.status.setText("not moving")
219                         
220                 self["snr_percentage"].update()
221                 self["agc_percentage"].update()
222                 self["ber_value"].update()
223                 self["snr_bar"].update()
224                 self["agc_bar"].update()
225                 self["ber_bar"].update()
226                 
227 def PositionerMain(session, **kwargs):
228         session.open(PositionerSetup)
229
230 def Plugins(**kwargs):
231         return PluginDescriptor(name="Positioner setup", description="Setup your positioner", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=PositionerMain)