Ignore:
Location:
src/mlx
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/checks.py

    r477 r478  
    957957        """Check if the fault condition holds."""
    958958        if flight.stage==const.STAGE_CRUISE:
    959             bankLimit = 30
     959            isDH8DXplane = flight.aircraftType==const.AIRCRAFT_DH8D and \
     960                           (flight.fsType==const.SIM_XPLANE10 or
     961                            flight.fsType==const.SIM_XPLANE9)
     962            bankLimit = 35 if isDH8DXplane else 30
    960963        elif flight.stage in [const.STAGE_TAKEOFF, const.STAGE_CLIMB,
    961964                              const.STAGE_DESCENT, const.STAGE_LANDING]:
     
    968971    def logFault(self, flight, aircraft, logger, oldState, state):
    969972        """Log the fault."""
     973        message = "Bank too steep (%.1f)" % (state.bank,)
    970974        flight.handleFault(BankChecker, state.timestamp,
    971                            FaultChecker._appendDuring(flight, "Bank too steep"),
     975                           FaultChecker._appendDuring(flight, message),
    972976                           2)
    973977
  • src/mlx/flight.py

    r391 r430  
    8686        """Get the flight stage."""
    8787        return self._stage
     88
     89    @property
     90    def fsType(self):
     91        """Get the flight simulator type."""
     92        return self._gui.fsType
    8893
    8994    @property
  • src/mlx/fs.py

    r408 r420  
    33from sound import startSound
    44
    5 import fsuipc
     5import os
     6
     7if os.name=="nt" or "FORCE_PYUIPC_SIM" in os.environ:
     8    import fsuipc as sim
     9else:
     10    import xplane as sim
     11
    612import threading
    713import time
     
    5864    assert type in [const.SIM_MSFS9, const.SIM_MSFSX], \
    5965           "Only MS Flight Simulator 2004 and X are supported"
    60     return fsuipc.Simulator(connectionListener, connectAttempts = 3)
     66    return sim.Simulator(connectionListener, connectAttempts = 3)
    6167
    6268#-------------------------------------------------------------------------------
  • src/mlx/gui/gui.py

    r436 r450  
    6868        self._flight = None
    6969        self._simulator = None
     70        self._fsType = None
    7071        self._monitoring = False
    7172
     
    205206
    206207    @property
     208    def fsType(self):
     209        """Get the flight simulator type."""
     210        return self._fsType
     211
     212    @property
    207213    def entranceExam(self):
    208214        """Get whether an entrance exam is about to be taken."""
     
    425431            self._wizard.connected(fsType, descriptor)
    426432        self._reconnecting = False
     433        self._fsType = fsType
    427434        self._listenHotkeys()
    428435
  • src/mlx/gui/monitor.py

    r408 r431  
    226226        table.attach(label, 0, 1, 8, 9)
    227227        table.attach(self._qnh, 1, 2, 8, 9)
     228
     229        (label, self._cog) = self._createLabeledEntry("CoG:", 7)
     230        table.attach(label, 2, 3, 8, 9)
     231        table.attach(self._cog, 3, 4, 8, 9)
    228232
    229233        alignment.add(table)
     
    312316            self._adf2.set_text("-")
    313317            self._qnh.set_text("-")
     318            self._cog.set_text("-")
    314319        else:
    315320            self._timestamp.set_text(time.strftime("%H:%M:%S",
     
    386391            self._gearControlDown.set_sensitive(aircraftState.gearControlDown)
    387392            self._gearsDown.set_sensitive(aircraftState.gearsDown)
    388             self._spoilersArmed.set_sensitive(aircraftState.spoilersArmed)
     393            self._spoilersArmed.set_sensitive(aircraftState.spoilersArmed is True)
    389394            self._spoilersExtension.set_text("%.0f" % (aircraftState.spoilersExtension,))
    390395            self._windSpeed.set_text("%.0f" % (aircraftState.windSpeed,))
     
    404409            self._adf1.set_text("-" if aircraftState.adf1 is None else aircraftState.adf1)
    405410            self._adf2.set_text("-" if aircraftState.adf2 is None else aircraftState.adf2)
     411            self._cog.set_text("%.2f%%" % (aircraftState.cog*100.0,))
    406412
    407413#------------------------------------------------------------------------------
  • src/mlx/sound.py

    r401 r422  
    166166    def startSound(name, finishCallback = None, extra = None):
    167167        """Start playing back the given sound.
    168        
     168
    169169        name should be the name of a sound file relative to the sound directory
    170170        given in initializeSound."""
    171171        _thread.requestSound(name, finishCallback = finishCallback,
    172172                             extra = extra)
    173        
     173
    174174#------------------------------------------------------------------------------
    175175
    176176else: # os.name!="nt"
    177     def initializeSound(soundsDirectory):
    178         """Initialize the sound handling with the given directory containing
    179         the sound files."""
    180         pass
    181 
    182     def startSound(name, finishCallback = None, extra = None):
    183         """Start playing back the given sound.
    184 
    185         FIXME: it does not do anything currently, but it should."""
    186         print "sound.startSound:", name
     177    import threading
     178    try:
     179        import pyglet
     180
     181        class SoundThread(threading.Thread):
     182            """A thread executing the pyglet event loop that directs the
     183            playback of the sound files."""
     184            class Player(pyglet.media.ManagedSoundPlayer):
     185                """Player which handles the end-of-stream condition
     186                properly."""
     187
     188                def __init__(self, finishCallback, extra):
     189                    """Construct the player with the given data."""
     190                    super(SoundThread.Player, self).__init__()
     191
     192                    self._finishCallback = finishCallback
     193                    self._extra = extra
     194
     195                def _on_eos(self):
     196                    if self._finishCallback is not None:
     197                        self._finishCallback(True, self._extra)
     198                    return super(SoundThread.Player, self)._on_eos()
     199
     200            class EventLoop(pyglet.app.EventLoop):
     201                """Own implementation of the event loop that collects the
     202                requested sound files and plays them."""
     203
     204                def __init__(self, soundsDirectory):
     205                    """Construct the event loop."""
     206                    super(SoundThread.EventLoop, self).__init__()
     207
     208                    self._soundsDirectory = soundsDirectory
     209
     210                    self._lock = threading.Lock()
     211                    self._requestedSounds = []
     212
     213                def startSound(self, name, finishCallback, extra):
     214                    """Add the sound with the given name"""
     215                    with self._lock:
     216                        path = os.path.join(self._soundsDirectory, name)
     217                        self._requestedSounds.append( (path,
     218                                                       finishCallback, extra) )
     219
     220                def idle(self):
     221                    """The idle callback."""
     222                    with self._lock:
     223                        requestedSounds = self._requestedSounds
     224                        self._requestedSounds = []
     225
     226                    for (path, finishCallback, extra) in requestedSounds:
     227                        try:
     228                            media = pyglet.media.load(path)
     229                            player = SoundThread.Player(finishCallback, extra)
     230                            player.queue(media)
     231                            player.play()
     232                        except Exception, e:
     233                            print "mlx.SoundThread.EventLoop.idle: " + str(e)
     234                            if finishCallback is not None:
     235                                finishCallback(False, extra)
     236
     237                    timeout = super(SoundThread.EventLoop, self).idle()
     238                    return 0.1 if timeout is None else min(timeout, 0.1)
     239
     240            def __init__(self, soundsDirectory):
     241                """Construct the sound playing thread with the given
     242                directory."""
     243                super(SoundThread, self).__init__()
     244
     245                self.daemon = True
     246                self.eventLoop = SoundThread.EventLoop(soundsDirectory)
     247
     248            def run(self):
     249                """Run the event loop."""
     250                self.eventLoop.run()
     251
     252            def startSound(self, name, finishCallback = None, extra = None):
     253                """Start the playback of the given sound."""
     254                self.eventLoop.startSound(name, finishCallback, extra)
     255
     256        _thread = None
     257
     258        def initializeSound(soundsDirectory):
     259            """Initialize the sound handling with the given directory containing
     260            the sound files."""
     261            global _thread
     262            _thread = SoundThread(soundsDirectory)
     263            _thread.start()
     264
     265
     266        def startSound(name, finishCallback = None, extra = None):
     267            """Start playing back the given sound."""
     268            _thread.startSound(name, finishCallback = finishCallback,
     269                               extra = extra)
     270
     271    except:
     272        print "The pyglet library is missing from your system. It is needed for sound playback on Linux"
     273        def initializeSound(soundsDirectory):
     274            """Initialize the sound handling with the given directory containing
     275            the sound files."""
     276            pass
     277
     278        def startSound(name, finishCallback = None, extra = None):
     279            """Start playing back the given sound.
     280
     281            FIXME: it does not do anything currently, but it should."""
     282            print "sound.startSound:", name
    187283
    188284#------------------------------------------------------------------------------
     
    192288    def callback(result, extra):
    193289        print "callback", result, extra
    194    
     290
    195291    initializeSound("e:\\home\\vi\\tmp")
    196292    startSound("malev.mp3", finishCallback = callback, extra="malev.mp3")
Note: See TracChangeset for help on using the changeset viewer.