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