workaround: on non-scart modes, set aspect/policy
[enigma2.git] / lib / python / Plugins / SystemPlugins / Videomode / VideoHardware.py
index 258f78b..c6d6b86 100644 (file)
@@ -9,7 +9,7 @@ from Components.Pixmap import Pixmap
 from Screens.MessageBox import MessageBox
 from Screens.Setup import SetupSummary
 from Components.ConfigList import ConfigListScreen
-from Components.config import getConfigListEntry, config, ConfigNothing, ConfigSelection, ConfigSubDict
+from Components.config import getConfigListEntry, config, ConfigSelection, ConfigSubDict, ConfigYesNo
 
 from Tools.CList import CList
 
@@ -43,27 +43,31 @@ class VideoHardware:
                "1920x1080": { 60: "1920x1080"},
                "1920x1080 multi": { 50: "1920x1080", 60: "1920x1080_50"},
                "1280x1024" : { 60: "1280x1024"},
+               "1366x768" : { 60: "1366x768"},
+               "1366x768 multi" : { 50: "1366x768", 60: "1366x768_50"},
+               "1280x768": { 60: "1280x768"},
                "640x480" : { 60: "640x480"} 
        }
 
        modes["Scart"] = ["PAL", "NTSC", "Multi"]
-       modes["YPrPb"] = ["720p", "1080i"]
+       modes["YPbPr"] = ["720p", "1080i"]
        modes["DVI"] = ["720p", "1080i", "PC"]
 
        def __init__(self):
                self.last_modes_preferred =  [ ]
                self.on_hotplug = CList()
 
-               self.on_hotplug.append(self.createConfig)
-               self.ignore_preferred = False   # "edid override"
-
                self.readAvailableModes()
+
+               self.createConfig()
+#              self.on_hotplug.append(self.createConfig)
+
                self.readPreferredModes()
 
                # until we have the hotplug poll socket
-               self.timer = eTimer()
-               self.timer.timeout.get().append(self.readAvailableModes)
-               self.timer.start(1000)
+#              self.timer = eTimer()
+#              self.timer.timeout.get().append(self.readPreferredModes)
+#              self.timer.start(1000)
 
        def readAvailableModes(self):
                try:
@@ -84,6 +88,7 @@ class VideoHardware:
 
                if self.modes_preferred != self.last_modes_preferred:
                        self.last_modes_preferred = self.modes_preferred
+                       print "hotplug on dvi"
                        self.on_hotplug("DVI") # must be DVI
 
        # check if a high-level mode with a given rate is available.
@@ -91,23 +96,25 @@ class VideoHardware:
                rate = self.rates[mode][rate]
                for mode in rate.values():
                        # DVI modes must be in "modes_preferred"
-                       if port == "DVI":
-                               if mode not in self.modes_preferred and not self.ignore_preferred:
-                                       return False
+#                      if port == "DVI":
+#                              if mode not in self.modes_preferred and not config.av.edid_override.value:
+#                                      print "no, not preferred"
+#                                      return False
                        if mode not in self.modes_available:
                                return False
                return True
 
-       def setMode(self, port, mode, rate):
+       def setMode(self, port, mode, rate, force = None):
+               print "setMode - port:", port, "mode:", mode, "rate:", rate
                # we can ignore "port"
                self.current_mode = mode
                modes = self.rates[mode][rate]
 
                mode_50 = modes.get(50)
                mode_60 = modes.get(60)
-               if mode_50 is None:
+               if mode_50 is None or force == 60:
                        mode_50 = mode_60
-               if mode_60 is None:
+               if mode_60 is None or force == 50: 
                        mode_60 = mode_50
 
                try:
@@ -120,10 +127,27 @@ class VideoHardware:
                        except IOError:
                                print "setting videomode failed."
 
+               try:
+                       open("/etc/videomode", "w").write(mode_50) # use 50Hz mode (if available) for booting
+               except IOError:
+                       print "writing initial videomode to /etc/videomode failed."
+
+               # workaround: this should not be set here.
+               if port != "Scart":
+                       open("/proc/stb/video/aspect", "w").write("any")
+                       open("/proc/stb/video/policy", "w").write("panscan")
+
        def isPortAvailable(self, port):
                # fixme
                return True
 
+       def isPortUsed(self, port):
+               if port == "DVI":
+                       self.readPreferredModes()
+                       return len(self.modes_preferred) != 0
+               else:
+                       return True
+
        def getPortList(self):
                return [port for port in self.modes if self.isPortAvailable(port)]
 
@@ -155,4 +179,21 @@ class VideoHardware:
                        for (mode, rates) in modes:
                                config.av.videorate[mode] = ConfigSelection(choices = rates)
 
-video_hw = VideoHardware()
\ No newline at end of file
+       def setConfiguredMode(self):
+               port = config.av.videoport.value
+               if port not in config.av.videomode:
+                       print "current port not available, not setting videomode"
+                       return
+
+               mode = config.av.videomode[port].value
+
+               if mode not in config.av.videorate:
+                       print "current mode not available, not setting videomode"
+                       return
+
+               rate = config.av.videorate[mode].value
+               self.setMode(port, mode, rate)
+
+config.av.edid_override = ConfigYesNo(default = False)
+video_hw = VideoHardware()
+video_hw.setConfiguredMode()