handle 'equal' option in tuner config correctly for -s2 tuners
[enigma2.git] / lib / python / Screens / Satconfig.py
1 from enigma import eDVBDB
2 from Screen import Screen
3 from Components.SystemInfo import SystemInfo
4 from Components.ActionMap import ActionMap
5 from Components.ConfigList import ConfigListScreen
6 from Components.MenuList import MenuList
7 from Components.NimManager import nimmanager
8 from Components.config import getConfigListEntry, config, ConfigNothing, ConfigSelection
9 from Screens.MessageBox import MessageBox
10
11 from time import mktime, localtime
12 from datetime import datetime
13
14 class NimSetup(Screen, ConfigListScreen):
15         def createSimpleSetup(self, list, mode):
16                 if mode == "single":
17                         list.append(getConfigListEntry(_("Satellite"), self.nimConfig.diseqcA))
18                 else:
19                         list.append(getConfigListEntry(_("Port A"), self.nimConfig.diseqcA))
20
21                 if mode in ["toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"]:
22                         list.append(getConfigListEntry(_("Port B"), self.nimConfig.diseqcB))
23                         if mode == "diseqc_a_b_c_d":
24                                 list.append(getConfigListEntry(_("Port C"), self.nimConfig.diseqcC))
25                                 list.append(getConfigListEntry(_("Port D"), self.nimConfig.diseqcD))
26
27         def createPositionerSetup(self, list):
28                 nim = self.nimConfig
29                 list.append(getConfigListEntry(_("Longitude"), nim.longitude))
30                 list.append(getConfigListEntry(" ", nim.longitudeOrientation))
31                 list.append(getConfigListEntry(_("Latitude"), nim.latitude))
32                 list.append(getConfigListEntry(" ", nim.latitudeOrientation))
33                 if SystemInfo["CanMeasureFrontendInputPower"]:
34                         self.advancedPowerMeasurement = getConfigListEntry(_("Use Power Measurement"), nim.powerMeasurement)
35                         list.append(self.advancedPowerMeasurement)
36                         if nim.powerMeasurement.value:
37                                 list.append(getConfigListEntry(_("Power threshold in mA"), nim.powerThreshold))
38                                 self.turningSpeed = getConfigListEntry(_("Rotor turning speed"), nim.turningSpeed)
39                                 list.append(self.turningSpeed)
40                                 if nim.turningSpeed.value == "fast epoch":
41                                         self.turnFastEpochBegin = getConfigListEntry(_("Begin time"), nim.fastTurningBegin)
42                                         self.turnFastEpochEnd = getConfigListEntry(_("End time"), nim.fastTurningEnd)
43                                         list.append(self.turnFastEpochBegin)
44                                         list.append(self.turnFastEpochEnd)
45                 else:
46                         if nim.powerMeasurement.value:
47                                 nim.powerMeasurement.value = False
48                                 nim.powerMeasurement.save()
49                                 
50         def createSetup(self):
51                 print "Creating setup"
52                 self.list = [ ]
53
54                 self.configMode = None
55                 self.diseqcModeEntry = None
56                 self.advancedSatsEntry = None
57                 self.advancedLnbsEntry = None
58                 self.advancedDiseqcMode = None
59                 self.advancedUsalsEntry = None
60                 self.advancedLof = None
61                 self.advancedPowerMeasurement = None
62                 self.turningSpeed = None
63                 self.turnFastEpochBegin = None
64                 self.turnFastEpochEnd = None
65                 self.uncommittedDiseqcCommand = None
66                 self.cableScanType = None
67                 self.have_advanced = False
68
69                 if self.nim.isCompatible("DVB-S"):
70                         self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
71                         self.list.append(self.configMode)
72
73                         if self.nimConfig.configMode.value == "simple":                 #simple setup
74                                 self.diseqcModeEntry = getConfigListEntry(_("DiSEqC Mode"), self.nimConfig.diseqcMode)
75                                 self.list.append(self.diseqcModeEntry)
76                                 if self.nimConfig.diseqcMode.value in ["single", "toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"]:
77                                         self.createSimpleSetup(self.list, self.nimConfig.diseqcMode.value)
78                                 if self.nimConfig.diseqcMode.value == "positioner":
79                                         self.createPositionerSetup(self.list)
80                         elif self.nimConfig.configMode.value in ["satposdepends", "equal"]:
81                                 choices = []
82                                 if self.nim.type == "DVB-S2":
83                                         nimlist = nimmanager.getNimListOfType("DVB-S", exception = self.nim.slot)
84                                 else:
85                                         nimlist = nimmanager.getNimListOfType(self.nim.type, exception = self.nim.slot)
86                                 for id in nimlist:
87                                         #choices.append((str(id), str(chr(65 + id))))
88                                         choices.append((str(id), nimmanager.getNimDescription(id)))
89                                 self.nimConfig.connectedTo = ConfigSelection(choices = choices)
90                                 self.list.append(getConfigListEntry(_("Tuner"), self.nimConfig.connectedTo))
91                         elif self.nimConfig.configMode.value == "loopthrough":
92                                 choices = []
93                                 print "connectable to:", nimmanager.connectableTo(self.slotid)
94                                 connectable = nimmanager.connectableTo(self.slotid) 
95                                 for id in connectable:
96                                         choices.append((str(id), nimmanager.getNimDescription(id)))
97                                 self.nimConfig.connectedTo = ConfigSelection(choices = choices)
98                                 self.list.append(getConfigListEntry(_("Connected to"), self.nimConfig.connectedTo))
99                         elif self.nimConfig.configMode.value == "nothing":
100                                 pass
101                         elif self.nimConfig.configMode.value == "advanced": # advanced
102                                 # SATs
103                                 self.advancedSatsEntry = getConfigListEntry(_("Satellite"), self.nimConfig.advanced.sats)
104                                 self.list.append(self.advancedSatsEntry)
105                                 cur_orb_pos = self.nimConfig.advanced.sats.orbital_position
106                                 satlist = self.nimConfig.advanced.sat.keys()
107                                 if cur_orb_pos is not None:
108                                         if cur_orb_pos not in satlist:
109                                                 cur_orb_pos = satlist[0]
110                                         currSat = self.nimConfig.advanced.sat[cur_orb_pos]
111                                         self.fillListWithAdvancedSatEntrys(currSat)
112                                 self.have_advanced = True
113                 elif self.nim.isCompatible("DVB-C"):
114                         self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
115                         self.list.append(self.configMode)
116                         if self.nimConfig.configMode.value == "enabled":
117                                 self.cableScanType=getConfigListEntry(_("Used service scan type"), self.nimConfig.cable.scan_type)
118                                 self.list.append(self.cableScanType)
119                                 if self.nimConfig.cable.scan_type.value == "provider":
120                                         self.list.append(getConfigListEntry(_("Provider to scan"), self.nimConfig.cable.scan_provider))
121                                 else:
122                                         if self.nimConfig.cable.scan_type.value == "bands":
123                                                 self.list.append(getConfigListEntry(_("Scan band EU VHF I"), self.nimConfig.cable.scan_band_EU_VHF_I))
124                                                 self.list.append(getConfigListEntry(_("Scan band EU MID"), self.nimConfig.cable.scan_band_EU_MID))
125                                                 self.list.append(getConfigListEntry(_("Scan band EU VHF III"), self.nimConfig.cable.scan_band_EU_VHF_III))
126                                                 self.list.append(getConfigListEntry(_("Scan band EU UHF IV"), self.nimConfig.cable.scan_band_EU_UHF_IV))
127                                                 self.list.append(getConfigListEntry(_("Scan band EU UHF V"), self.nimConfig.cable.scan_band_EU_UHF_V))
128                                                 self.list.append(getConfigListEntry(_("Scan band EU SUPER"), self.nimConfig.cable.scan_band_EU_SUPER))
129                                                 self.list.append(getConfigListEntry(_("Scan band EU HYPER"), self.nimConfig.cable.scan_band_EU_HYPER))
130                                                 self.list.append(getConfigListEntry(_("Scan band US LOW"), self.nimConfig.cable.scan_band_US_LOW))
131                                                 self.list.append(getConfigListEntry(_("Scan band US MID"), self.nimConfig.cable.scan_band_US_MID))
132                                                 self.list.append(getConfigListEntry(_("Scan band US HIGH"), self.nimConfig.cable.scan_band_US_HIGH))
133                                                 self.list.append(getConfigListEntry(_("Scan band US SUPER"), self.nimConfig.cable.scan_band_US_SUPER))
134                                                 self.list.append(getConfigListEntry(_("Scan band US HYPER"), self.nimConfig.cable.scan_band_US_HYPER))
135                                         elif self.nimConfig.cable.scan_type.value == "steps":
136                                                 self.list.append(getConfigListEntry(_("Frequency scan step size(khz)"), self.nimConfig.cable.scan_frequency_steps))
137                                         self.list.append(getConfigListEntry(_("Scan QAM16"), self.nimConfig.cable.scan_mod_qam16))
138                                         self.list.append(getConfigListEntry(_("Scan QAM32"), self.nimConfig.cable.scan_mod_qam32))
139                                         self.list.append(getConfigListEntry(_("Scan QAM64"), self.nimConfig.cable.scan_mod_qam64))
140                                         self.list.append(getConfigListEntry(_("Scan QAM128"), self.nimConfig.cable.scan_mod_qam128))
141                                         self.list.append(getConfigListEntry(_("Scan QAM256"), self.nimConfig.cable.scan_mod_qam256))
142                                         self.list.append(getConfigListEntry(_("Scan SR6900"), self.nimConfig.cable.scan_sr_6900))
143                                         self.list.append(getConfigListEntry(_("Scan SR6875"), self.nimConfig.cable.scan_sr_6875))
144                                         self.list.append(getConfigListEntry(_("Scan additional SR"), self.nimConfig.cable.scan_sr_ext1))
145                                         self.list.append(getConfigListEntry(_("Scan additional SR"), self.nimConfig.cable.scan_sr_ext2))
146                         self.have_advanced = False
147                 elif self.nim.isCompatible("DVB-T"):
148                         self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
149                         self.list.append(self.configMode)
150                         self.have_advanced = False
151                         if self.nimConfig.configMode.value == "enabled":
152                                 self.list.append(getConfigListEntry(_("Terrestrial provider"), self.nimConfig.terrestrial))
153                                 self.list.append(getConfigListEntry(_("Enable 5V for active antenna"), self.nimConfig.terrestrial_5V))
154                 else:
155                         self.have_advanced = False
156                 self["config"].list = self.list
157                 self["config"].l.setList(self.list)
158
159         def newConfig(self):
160                 checkList = (self.configMode, self.diseqcModeEntry, self.advancedSatsEntry, \
161                         self.advancedLnbsEntry, self.advancedDiseqcMode, self.advancedUsalsEntry, \
162                         self.advancedLof, self.advancedPowerMeasurement, self.turningSpeed, \
163                         self.uncommittedDiseqcCommand, self.cableScanType)
164                 for x in checkList:
165                         if self["config"].getCurrent() == x:
166                                 self.createSetup()
167
168         def run(self):
169                 if self.have_advanced and self.nim.config_mode == "advanced":
170                         self.fillAdvancedList()
171                 for x in self.list:
172                         if x in [self.turnFastEpochBegin, self.turnFastEpochEnd]:
173                                 # workaround for storing only hour*3600+min*60 value in configfile
174                                 # not really needed.. just for cosmetics..
175                                 tm = localtime(x[1].value)
176                                 dt = datetime(1970, 1, 1, tm.tm_hour, tm.tm_min)
177                                 x[1].value = int(mktime(dt.timetuple()))
178                         x[1].save()
179                 nimmanager.sec.update()
180
181         def fillListWithAdvancedSatEntrys(self, Sat):
182                 currLnb = self.nimConfig.advanced.lnb[int(Sat.lnb.value)]
183                 
184                 if isinstance(currLnb, ConfigNothing):
185                         currLnb = None
186
187                 self.list.append(getConfigListEntry(_("Voltage mode"), Sat.voltage))
188                 self.list.append(getConfigListEntry(_("Tone mode"), Sat.tonemode))
189                 if currLnb and currLnb.diseqcMode.value == "1_2":
190                         self.advancedUsalsEntry = getConfigListEntry(_("Use usals for this sat"), Sat.usals)
191                         self.list.append(self.advancedUsalsEntry)
192                         if not Sat.usals.value:
193                                 self.list.append(getConfigListEntry(_("Stored position"), Sat.rotorposition))
194
195                 # LNBs
196                 self.advancedLnbsEntry = getConfigListEntry(_("LNB"), Sat.lnb)
197                 self.list.append(self.advancedLnbsEntry)
198                 if currLnb:
199                         self.advancedDiseqcMode = getConfigListEntry(_("DiSEqC mode"), currLnb.diseqcMode)
200                         self.list.append(self.advancedDiseqcMode)
201                         if currLnb.diseqcMode.value != "none":
202                                 self.list.append(getConfigListEntry(_("Toneburst"), currLnb.toneburst))
203                                 self.list.append(getConfigListEntry(_("Committed DiSEqC command"), currLnb.commitedDiseqcCommand))
204                                 self.list.append(getConfigListEntry(_("Fast DiSEqC"), currLnb.fastDiseqc))
205                                 self.list.append(getConfigListEntry(_("Sequence repeat"), currLnb.sequenceRepeat))
206                                 if currLnb.diseqcMode.value == "1_0":
207                                         self.list.append(getConfigListEntry(_("Command order"), currLnb.commandOrder1_0))
208                                 else:
209                                         if currLnb.uncommittedDiseqcCommand.index:
210                                                 if currLnb.commandOrder.value == "ct":
211                                                         currLnb.commandOrder.value = "cut"
212                                                 elif currLnb.commandOrder.value == "tc":
213                                                         currLnb.commandOrder.value = "tcu"
214                                         else:
215                                                 if currLnb.commandOrder.index & 1:
216                                                         currLnb.commandOrder.value = "tc"
217                                                 else:
218                                                         currLnb.commandOrder.value = "ct"
219                                         self.list.append(getConfigListEntry(_("Command order"), currLnb.commandOrder))
220                                         self.uncommittedDiseqcCommand = getConfigListEntry(_("Uncommitted DiSEqC command"), currLnb.uncommittedDiseqcCommand)
221                                         self.list.append(self.uncommittedDiseqcCommand)
222                                         self.list.append(getConfigListEntry(_("DiSEqC repeats"), currLnb.diseqcRepeats))
223                                 if currLnb.diseqcMode.value == "1_2":
224                                         self.list.append(getConfigListEntry(_("Longitude"), currLnb.longitude))
225                                         self.list.append(getConfigListEntry(" ", currLnb.longitudeOrientation))
226                                         self.list.append(getConfigListEntry(_("Latitude"), currLnb.latitude))
227                                         self.list.append(getConfigListEntry(" ", currLnb.latitudeOrientation))
228                                         if SystemInfo["CanMeasureFrontendInputPower"]:
229                                                 self.advancedPowerMeasurement = getConfigListEntry(_("Use Power Measurement"), currLnb.powerMeasurement)
230                                                 self.list.append(self.advancedPowerMeasurement)
231                                                 if currLnb.powerMeasurement.value:
232                                                         self.list.append(getConfigListEntry(_("Power threshold in mA"), currLnb.powerThreshold))
233                                                         self.turningSpeed = getConfigListEntry(_("Rotor turning speed"), currLnb.turningSpeed)
234                                                         self.list.append(self.turningSpeed)
235                                                         if currLnb.turningSpeed.value == "fast epoch":
236                                                                 self.turnFastEpochBegin = getConfigListEntry(_("Begin time"), currLnb.fastTurningBegin)
237                                                                 self.turnFastEpochEnd = getConfigListEntry(_("End time"), currLnb.fastTurningEnd)
238                                                                 self.list.append(self.turnFastEpochBegin)
239                                                                 self.list.append(self.turnFastEpochEnd)
240                                         else:
241                                                 if currLnb.powerMeasurement.value:
242                                                         currLnb.powerMeasurement.value = False
243                                                         currLnb.powerMeasurement.save()
244                         self.advancedLof = getConfigListEntry(_("LOF"), currLnb.lof)
245                         self.list.append(self.advancedLof)
246                         if currLnb.lof.value == "user_defined":
247                                 self.list.append(getConfigListEntry(_("LOF/L"), currLnb.lofl))
248                                 self.list.append(getConfigListEntry(_("LOF/H"), currLnb.lofh))
249                                 self.list.append(getConfigListEntry(_("Threshold"), currLnb.threshold))
250 #                       self.list.append(getConfigListEntry(_("12V Output"), currLnb.output_12v))
251                         self.list.append(getConfigListEntry(_("Increased voltage"), currLnb.increased_voltage))
252
253         def fillAdvancedList(self):
254                 self.list = [ ]
255                 self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
256                 self.list.append(self.configMode)
257                 self.advancedSatsEntry = getConfigListEntry(_("Satellite"), self.nimConfig.advanced.sats)
258                 self.list.append(self.advancedSatsEntry)
259                 for x in nimmanager.satList:
260                         Sat = self.nimConfig.advanced.sat[x[0]]
261                         self.fillListWithAdvancedSatEntrys(Sat)
262                 self["config"].list = self.list
263
264         def keySave(self):
265                 old_configured_sats = nimmanager.getConfiguredSats()
266                 self.run()
267                 new_configured_sats = nimmanager.getConfiguredSats()
268                 self.unconfed_sats = old_configured_sats - new_configured_sats
269                 self.satpos_to_remove = None
270                 self.deleteConfirmed(False)
271
272         def deleteConfirmed(self, confirmed):
273                 if confirmed:
274                         eDVBDB.getInstance().removeServices(-1, -1, -1, self.satpos_to_remove)
275
276                 if self.satpos_to_remove is not None:
277                         self.unconfed_sats.remove(self.satpos_to_remove)
278
279                 self.satpos_to_remove = None
280                 for orbpos in self.unconfed_sats:
281                         self.satpos_to_remove = orbpos
282                         orbpos = self.satpos_to_remove
283                         try:
284                                 # why we need this cast?
285                                 sat_name = str(nimmanager.getSatDescription(orbpos))
286                         except:
287                                 if orbpos > 1800: # west
288                                         orbpos = 3600 - orbpos
289                                         h = _("W")
290                                 else:
291                                         h = _("E")
292                                 sat_name = ("%d.%d" + h) % (orbpos / 10, orbpos % 10)
293                         self.session.openWithCallback(self.deleteConfirmed, MessageBox, _("Delete no more configured satellite\n%s?") %(sat_name))
294                         break
295                 if not self.satpos_to_remove:
296                         self.close()
297
298         def __init__(self, session, slotid):
299                 Screen.__init__(self, session)
300                 self.list = [ ]
301
302                 ConfigListScreen.__init__(self, self.list)
303
304                 self["actions"] = ActionMap(["SetupActions"],
305                 {
306                         "ok": self.keySave,
307                         "cancel": self.keyCancel,
308                 }, -2)
309
310                 self.slotid = slotid
311                 self.nim = nimmanager.nim_slots[slotid]
312                 self.nimConfig = self.nim.config
313                 self.createSetup()
314
315         def keyLeft(self):
316                 ConfigListScreen.keyLeft(self)
317                 self.newConfig()
318
319         def keyRight(self):
320                 ConfigListScreen.keyRight(self)
321                 self.newConfig()
322
323 class NimSelection(Screen):
324         def __init__(self, session):
325                 Screen.__init__(self, session)
326                 
327                 menu = [ ]
328                 for x in nimmanager.nim_slots:
329                         menu.append((x.friendly_full_description, x))
330
331                 self["nimlist"] = MenuList(menu)
332
333                 self["actions"] = ActionMap(["OkCancelActions"],
334                 {
335                         "ok": self.okbuttonClick ,
336                         "cancel": self.close
337                 }, -2)
338
339         def okbuttonClick(self):
340                 nim = self["nimlist"].getCurrent()
341                 nim = nim and nim[1]
342                 if nim is not None and not nim.empty:
343                         self.session.open(NimSetup, nim.slot)