for motor 200ms to powerup before send diseqc command should be enough to
[enigma2.git] / lib / python / Components / AVSwitch.py
1 from config import config, ConfigSelection, ConfigYesNo, ConfigEnableDisable, ConfigSubsection, ConfigBoolean
2 import os
3 from enigma import eAVSwitch
4
5 class AVSwitch:
6         INPUT = { "ENCODER": (0, 4), "SCART": (1, 3), "AUX": (2, 4) }
7
8         def setInput(self, input):
9                 eAVSwitch.getInstance().setInput(self.INPUT[input][0])
10                 if self.INPUT[input][1] == 4:
11                         aspect = self.getAspectRatioSetting()
12                         self.setAspectWSS(aspect)
13                         self.setAspectSlowBlank(aspect)
14                 else:
15                         eAVSwitch.getInstance().setSlowblank(self.INPUT[input][1])
16                 # FIXME why do we have to reset the colorformat? bug in avs-driver?
17                 map = {"cvbs": 0, "rgb": 1, "svideo": 2, "yuv": 3}
18                 eAVSwitch.getInstance().setColorFormat(map[config.av.colorformat.value])
19
20         def setColorFormat(self, value):
21                 eAVSwitch.getInstance().setColorFormat(value)
22
23         def setAspectRatio(self, value):
24                 eAVSwitch.getInstance().setAspectRatio(value)
25                 self.setAspectWSS(value)
26                 self.setAspectSlowBlank(value)
27
28         def setSystem(self, value):
29                 eAVSwitch.getInstance().setVideomode(value)
30
31         def getAspectRatioSetting(self):
32                 valstr = config.av.aspectratio.value
33                 if valstr == "4_3_letterbox":
34                         val = 0
35                 elif valstr == "4_3_panscan":
36                         val = 1
37                 elif valstr == "16_9":
38                         val = 2
39                 elif valstr == "16_9_always":
40                         val = 3
41                 elif valstr == "16_10_letterbox":
42                         val = 4
43                 elif valstr == "16_10_panscan":
44                         val = 5
45                 elif valstr == "16_9_letterbox":
46                         val = 6
47                 return val
48
49         def setAspectWSS(self, aspect=None):
50                 if aspect is None:
51                         aspect = self.getAspectRatioSetting()
52                 if aspect == 0 or aspect == 1: # letterbox or panscan
53                         value = 3 # 4:3_full_format
54                 elif aspect == 2: # 16:9
55                         if not config.av.wss.value:
56                                 value = 2 # auto(4:3_off)
57                         else:
58                                 value = 1 # auto
59                 elif aspect == 3 or aspect == 6: # always 16:9
60                         value = 4 # 16:9_full_format
61                 elif aspect == 4 or aspect == 5: # 16:10
62                         value = 10 # 14:9_full_format
63                 eAVSwitch.getInstance().setWSS(value)
64
65         def setAspectSlowBlank(self, aspect=None):
66                 if aspect is None:
67                         aspect = self.getAspectRatioSetting()
68                 if aspect == 0 or aspect == 1: # letterbox or panscan
69                         value = 2 # 12 V
70                 elif aspect == 2: # 16:9
71                         value = 4 # auto
72                 elif aspect == 3 or aspect == 4 or aspect == 5 or aspect == 6: # always 16:9
73                         value = 1 # 6V
74                 eAVSwitch.getInstance().setSlowblank(value)
75
76 def InitAVSwitch():
77         config.av = ConfigSubsection()
78         config.av.yuvenabled = ConfigBoolean(default=False)
79         colorformat_choices = {"cvbs": _("CVBS"), "rgb": _("RGB"), "svideo": _("S-Video")}
80         
81         # when YUV is not enabled, don't let the user select it
82         if config.av.yuvenabled.value:
83                 colorformat_choices["yuv"] = _("YPbPr")
84
85         config.av.colorformat = ConfigSelection(choices=colorformat_choices, default="rgb")
86         config.av.aspectratio = ConfigSelection(choices={
87                         "4_3_letterbox": _("4:3 Letterbox"),
88                         "4_3_panscan": _("4:3 PanScan"), 
89                         "16_9": _("16:9"), 
90                         "16_9_always": _("16:9 always"),
91                         "16_10_letterbox": _("16:10 Letterbox"),
92                         "16_10_panscan": _("16:10 PanScan"), 
93                         "16_9_letterbox": _("16:9 Letterbox")}, 
94                         default = "4_3_letterbox")
95         config.av.tvsystem = ConfigSelection(choices = {"pal": _("PAL"), "ntsc": _("NTSC"), "multinorm": _("multinorm")}, default="pal")
96         config.av.wss = ConfigEnableDisable(default = True)
97         config.av.defaultac3 = ConfigYesNo(default = False)
98         config.av.vcrswitch = ConfigEnableDisable(default = False)
99
100         iAVSwitch = AVSwitch()
101
102         def setColorFormat(configElement):
103                 map = {"cvbs": 0, "rgb": 1, "svideo": 2, "yuv": 3}
104                 iAVSwitch.setColorFormat(map[configElement.value])
105
106         def setAspectRatio(configElement):
107                 map = {"4_3_letterbox": 0, "4_3_panscan": 1, "16_9": 2, "16_9_always": 3, "16_10_letterbox": 4, "16_10_panscan": 5, "16_9_letterbox" : 6}
108                 iAVSwitch.setAspectRatio(map[configElement.value])
109
110         def setSystem(configElement):
111                 map = {"pal": 0, "ntsc": 1, "multinorm" : 2}
112                 iAVSwitch.setSystem(map[configElement.value])
113
114         def setWSS(configElement):
115                 iAVSwitch.setAspectWSS()
116
117         # this will call the "setup-val" initial
118         config.av.colorformat.addNotifier(setColorFormat)
119         config.av.aspectratio.addNotifier(setAspectRatio)
120         config.av.tvsystem.addNotifier(setSystem)
121         config.av.wss.addNotifier(setWSS)
122
123         iAVSwitch.setInput("ENCODER") # init on startup