e95a5b4620bbdc86418359447a6b8b1a08bb4a96
[enigma2.git] / lib / python / Screens / Satconfig.py
1 from Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.ConfigList import ConfigListScreen
4 from Components.MenuList import MenuList
5 from Components.NimManager import nimmanager
6 from Components.config import getConfigListEntry, config, ConfigNothing
7
8 from time import mktime, localtime
9 from datetime import datetime
10
11 class NimSetup(Screen, ConfigListScreen):
12         def createSimpleSetup(self, list, mode):
13                 if mode == "single":
14                         list.append(getConfigListEntry(_("Satellite"), self.nimConfig.diseqcA))
15                 else:
16                         list.append(getConfigListEntry(_("Port A"), self.nimConfig.diseqcA))
17
18                 if mode in ["toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"]:
19                         list.append(getConfigListEntry(_("Port B"), self.nimConfig.diseqcB))
20                         if mode == "diseqc_a_b_c_d":
21                                 list.append(getConfigListEntry(_("Port C"), self.nimConfig.diseqcC))
22                                 list.append(getConfigListEntry(_("Port D"), self.nimConfig.diseqcD))
23
24         def createPositionerSetup(self, list):
25                 nim = self.nimConfig
26                 list.append(getConfigListEntry(_("Longitude"), nim.longitude))
27                 list.append(getConfigListEntry(" ", nim.longitudeOrientation))
28                 list.append(getConfigListEntry(_("Latitude"), nim.latitude))
29                 list.append(getConfigListEntry(" ", nim.latitudeOrientation))
30
31                 self.advancedPowerMeasurement = getConfigListEntry(_("Use Power Measurement"), nim.powerMeasurement)
32                 list.append(self.advancedPowerMeasurement)
33                 if nim.powerMeasurement.value:
34                         list.append(getConfigListEntry(_("Power threshold in mA"), nim.powerThreshold))
35                         self.turningSpeed = getConfigListEntry(_("Rotor turning speed"), nim.turningSpeed)
36                         list.append(self.turningSpeed)
37                         if nim.turningSpeed.value == "fast epoch":
38                                 self.turnFastEpochBegin = getConfigListEntry(_("Begin time"), nim.fastTurningBegin)
39                                 self.turnFastEpochEnd = getConfigListEntry(_("End time"), nim.fastTurningEnd)
40                                 list.append(self.turnFastEpochBegin)
41                                 list.append(self.turnFastEpochEnd)
42
43         def createSetup(self):
44                 print "Creating setup"
45                 self.list = [ ]
46
47                 self.configMode = None
48                 self.diseqcModeEntry = None
49                 self.advancedSatsEntry = None
50                 self.advancedLnbsEntry = None
51                 self.advancedDiseqcMode = None
52                 self.advancedUsalsEntry = None
53                 self.advancedLof = None
54                 self.advancedPowerMeasurement = None
55                 self.turningSpeed = None
56                 self.turnFastEpochBegin = None
57                 self.turnFastEpochEnd = None
58
59                 self.cableScanType = None
60
61                 if self.nim.isCompatible("DVB-S"):
62                         self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
63                         self.list.append(self.configMode)
64
65                         if self.nimConfig.configMode.value == "simple":                 #simple setup
66                                 self.diseqcModeEntry = getConfigListEntry(_("DiSEqC Mode"), self.nimConfig.diseqcMode)
67                                 self.list.append(self.diseqcModeEntry)
68                                 if self.nimConfig.diseqcMode.value in ["single", "toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"]:
69                                         self.createSimpleSetup(self.list, self.nimConfig.diseqcMode.value)
70                                 if self.nimConfig.diseqcMode.value == "positioner":
71                                         self.createPositionerSetup(self.list)
72                         elif self.nimConfig.configMode.value in ["loopthrough", "satposdepends", "nothing", "equal"]:
73                                 pass
74                         elif self.nimConfig.configMode.value == "advanced": # advanced
75                                 # SATs
76                                 self.advancedSatsEntry = getConfigListEntry(_("Satellite"), self.nimConfig.advanced.sats)
77                                 self.list.append(self.advancedSatsEntry)
78                                 cur_orb_pos = self.nimConfig.advanced.sats.orbital_position
79                                 satlist = self.nimConfig.advanced.sat.keys()
80                                 if cur_orb_pos not in satlist:
81                                         cur_orb_pos = satlist[0]
82                                 currSat = self.nimConfig.advanced.sat[cur_orb_pos]
83                                 self.fillListWithAdvancedSatEntrys(currSat)
84                         self.have_advanced = True
85                 elif self.nim.isCompatible("DVB-C"):
86                         self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
87                         self.list.append(self.configMode)
88                         if self.nimConfig.configMode.value == "enabled":
89                                 self.cableScanType=getConfigListEntry(_("Used service scan type"), self.nimConfig.cable.scan_type)
90                                 self.list.append(self.cableScanType)
91                                 if self.nimConfig.cable.scan_type.value == "provider":
92                                         self.list.append(getConfigListEntry(_("Provider to scan"), self.nimConfig.cable.scan_provider))
93                                 else:
94                                         if self.nimConfig.cable.scan_type.value == "bands":
95                                                 self.list.append(getConfigListEntry(_("Scan band EU VHF I"), self.nimConfig.cable.scan_band_EU_VHF_I))
96                                                 self.list.append(getConfigListEntry(_("Scan band EU MID"), self.nimConfig.cable.scan_band_EU_MID))
97                                                 self.list.append(getConfigListEntry(_("Scan band EU VHF III"), self.nimConfig.cable.scan_band_EU_VHF_III))
98                                                 self.list.append(getConfigListEntry(_("Scan band EU UHF IV"), self.nimConfig.cable.scan_band_EU_UHF_IV))
99                                                 self.list.append(getConfigListEntry(_("Scan band EU UHF V"), self.nimConfig.cable.scan_band_EU_UHF_V))
100                                                 self.list.append(getConfigListEntry(_("Scan band EU SUPER"), self.nimConfig.cable.scan_band_EU_SUPER))
101                                                 self.list.append(getConfigListEntry(_("Scan band EU HYPER"), self.nimConfig.cable.scan_band_EU_HYPER))
102                                                 self.list.append(getConfigListEntry(_("Scan band US LOW"), self.nimConfig.cable.scan_band_US_LOW))
103                                                 self.list.append(getConfigListEntry(_("Scan band US MID"), self.nimConfig.cable.scan_band_US_MID))
104                                                 self.list.append(getConfigListEntry(_("Scan band US HIGH"), self.nimConfig.cable.scan_band_US_HIGH))
105                                                 self.list.append(getConfigListEntry(_("Scan band US SUPER"), self.nimConfig.cable.scan_band_US_SUPER))
106                                                 self.list.append(getConfigListEntry(_("Scan band US HYPER"), self.nimConfig.cable.scan_band_US_HYPER))
107                                         elif self.nimConfig.cable.scan_type.value == "steps":
108                                                 self.list.append(getConfigListEntry(_("Frequency scan step size(khz)"), self.nimConfig.cable.scan_frequency_steps))
109                                         self.list.append(getConfigListEntry(_("Scan QAM16"), self.nimConfig.cable.scan_mod_qam16))
110                                         self.list.append(getConfigListEntry(_("Scan QAM32"), self.nimConfig.cable.scan_mod_qam32))
111                                         self.list.append(getConfigListEntry(_("Scan QAM64"), self.nimConfig.cable.scan_mod_qam64))
112                                         self.list.append(getConfigListEntry(_("Scan QAM128"), self.nimConfig.cable.scan_mod_qam128))
113                                         self.list.append(getConfigListEntry(_("Scan QAM256"), self.nimConfig.cable.scan_mod_qam256))
114                                         self.list.append(getConfigListEntry(_("Scan SR6900"), self.nimConfig.cable.scan_sr_6900))
115                                         self.list.append(getConfigListEntry(_("Scan SR6875"), self.nimConfig.cable.scan_sr_6875))
116                                         self.list.append(getConfigListEntry(_("Scan additional SR"), self.nimConfig.cable.scan_sr_ext1))
117                                         self.list.append(getConfigListEntry(_("Scan additional SR"), self.nimConfig.cable.scan_sr_ext2))
118                         self.have_advanced = False
119                 elif self.nim.isCompatible("DVB-T"):
120                         self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
121                         self.have_advanced = False
122                         if self.nimConfig.configMode.value == "enabled":
123                                 self.list.append(getConfigListEntry(_("Terrestrial provider"), self.nimConfig.terrestrial))
124                                 self.list.append(getConfigListEntry(_("Enable 5V for active antenna"), self.nimConfig.terrestrial_5V))
125                 else:
126                         self.have_advanced = False
127                 self["config"].list = self.list
128                 self["config"].l.setList(self.list)
129
130         def newConfig(self):
131                 checkList = (self.configMode, self.diseqcModeEntry, self.advancedSatsEntry, \
132                         self.advancedLnbsEntry, self.advancedDiseqcMode, self.advancedUsalsEntry, \
133                         self.advancedLof, self.advancedPowerMeasurement, self.turningSpeed, self.cableScanType)
134                 for x in checkList:
135                         if self["config"].getCurrent() == x:
136                                 self.createSetup()
137
138         def run(self):
139                 if self.have_advanced and self.nim.config_mode == "advanced":
140                         self.fillAdvancedList()
141                 for x in self["config"].list:
142                         if x in [self.turnFastEpochBegin, self.turnFastEpochEnd]:
143                                 # workaround for storing only hour*3600+min*60 value in configfile
144                                 # not really needed.. just for cosmetics..
145                                 tm = localtime(x[1].value)
146                                 dt = datetime(1970, 1, 1, tm.tm_hour, tm.tm_min)
147                                 x[1].value = int(mktime(dt.timetuple()))
148                         x[1].save()
149                 nimmanager.sec.update()
150
151         def fillListWithAdvancedSatEntrys(self, Sat):
152                 currLnb = self.nimConfig.advanced.lnb[int(Sat.lnb.value)]
153                 
154                 if isinstance(currLnb, ConfigNothing):
155                         currLnb = None
156
157                 self.list.append(getConfigListEntry(_("Voltage mode"), Sat.voltage))
158                 self.list.append(getConfigListEntry(_("Tone mode"), Sat.tonemode))
159                 if currLnb and currLnb.diseqcMode.value == "1_2":
160                         self.advancedUsalsEntry = getConfigListEntry(_("Use usals for this sat"), Sat.usals)
161                         self.list.append(self.advancedUsalsEntry)
162                         if not Sat.usals.value:
163                                 self.list.append(getConfigListEntry(_("Stored position"), Sat.rotorposition))
164
165                 # LNBs
166                 self.advancedLnbsEntry = getConfigListEntry(_("LNB"), Sat.lnb)
167                 self.list.append(self.advancedLnbsEntry)
168                 if currLnb:
169                         self.advancedDiseqcMode = getConfigListEntry(_("DiSEqC mode"), currLnb.diseqcMode)
170                         self.list.append(self.advancedDiseqcMode)
171                         if currLnb.diseqcMode.value != "none":
172                                 self.list.append(getConfigListEntry(_("Toneburst"), currLnb.toneburst))
173                                 self.list.append(getConfigListEntry(_("Committed DiSEqC command"), currLnb.commitedDiseqcCommand))
174                                 self.list.append(getConfigListEntry(_("Fast DiSEqC"), currLnb.fastDiseqc))
175                                 self.list.append(getConfigListEntry(_("Sequence repeat"), currLnb.sequenceRepeat))
176                                 if currLnb.diseqcMode.value == "1_0":
177                                         self.list.append(getConfigListEntry(_("Command order"), currLnb.commandOrder1_0))
178                                 else:
179                                         self.list.append(getConfigListEntry(_("Command order"), currLnb.commandOrder))
180                                         self.list.append(getConfigListEntry(_("Uncommitted DiSEqC command"), currLnb.uncommittedDiseqcCommand))
181                                         self.list.append(getConfigListEntry(_("DiSEqC repeats"), currLnb.diseqcRepeats))
182                                 if currLnb.diseqcMode.value == "1_2":
183                                         self.list.append(getConfigListEntry(_("Longitude"), currLnb.longitude))
184                                         self.list.append(getConfigListEntry(" ", currLnb.longitudeOrientation))
185                                         self.list.append(getConfigListEntry(_("Latitude"), currLnb.latitude))
186                                         self.list.append(getConfigListEntry(" ", currLnb.latitudeOrientation))
187                                         self.advancedPowerMeasurement = getConfigListEntry(_("Use Power Measurement"), currLnb.powerMeasurement)
188                                         self.list.append(self.advancedPowerMeasurement)
189                                         if currLnb.powerMeasurement.value:
190                                                 self.list.append(getConfigListEntry(_("Power threshold in mA"), currLnb.powerThreshold))
191                                                 self.turningSpeed = getConfigListEntry(_("Rotor turning speed"), currLnb.turningSpeed)
192                                                 self.list.append(self.turningSpeed)
193                                                 if currLnb.turningSpeed.value == "fast epoch":
194                                                         self.turnFastEpochBegin = getConfigListEntry(_("Begin time"), currLnb.fastTurningBegin)
195                                                         self.turnFastEpochEnd = getConfigListEntry(_("End time"), currLnb.fastTurningEnd)
196                                                         self.list.append(self.turnFastEpochBegin)
197                                                         self.list.append(self.turnFastEpochEnd)
198                         self.advancedLof = getConfigListEntry(_("LOF"), currLnb.lof)
199                         self.list.append(self.advancedLof)
200                         if currLnb.lof.value == "user_defined":
201                                 self.list.append(getConfigListEntry(_("LOF/L"), currLnb.lofl))
202                                 self.list.append(getConfigListEntry(_("LOF/H"), currLnb.lofh))
203                                 self.list.append(getConfigListEntry(_("Threshold"), currLnb.threshold))
204 #                       self.list.append(getConfigListEntry(_("12V Output"), currLnb.output_12v))
205                         self.list.append(getConfigListEntry(_("Increased voltage"), currLnb.increased_voltage))
206
207         def fillAdvancedList(self):
208                 self.list = [ ]
209                 self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
210                 self.list.append(self.configMode)
211                 self.advancedSatsEntry = getConfigListEntry(_("Satellite"), self.nimConfig.advanced.sats)
212                 self.list.append(self.advancedSatsEntry)
213                 for x in nimmanager.satList:
214                         Sat = self.nimConfig.advanced.sat[x[0]]
215                         self.fillListWithAdvancedSatEntrys(Sat)
216                 self["config"].list = self.list
217
218         def keySave(self):
219                 self.run()
220                 self.close()
221
222         def __init__(self, session, slotid):
223                 Screen.__init__(self, session)
224                 self.list = [ ]
225
226                 ConfigListScreen.__init__(self, self.list)
227
228                 self["actions"] = ActionMap(["SetupActions"],
229                 {
230                         "ok": self.keySave,
231                         "cancel": self.keyCancel,
232                 }, -2)
233
234                 self.nim = nimmanager.nim_slots[slotid]
235                 self.nimConfig = self.nim.config
236                 self.createSetup()
237
238         def keyLeft(self):
239                 ConfigListScreen.keyLeft(self)
240                 self.newConfig()
241
242         def keyRight(self):
243                 ConfigListScreen.keyRight(self)
244                 self.newConfig()
245
246 class NimSelection(Screen):
247         def __init__(self, session):
248                 Screen.__init__(self, session)
249                 
250                 menu = [ ]
251                 for x in nimmanager.nim_slots:
252                         menu.append((x.friendly_full_description, x))
253
254                 self["nimlist"] = MenuList(menu)
255
256                 self["actions"] = ActionMap(["OkCancelActions"],
257                 {
258                         "ok": self.okbuttonClick ,
259                         "cancel": self.close
260                 }, -2)
261
262         def okbuttonClick(self):
263                 nim = self["nimlist"].getCurrent()
264                 nim = nim and nim[1]
265                 if nim is not None and not nim.empty:
266                         self.session.open(NimSetup, nim.slot)