Changeset 148:453ebaea9090


Ignore:
Timestamp:
05/03/12 18:27:13 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
hg-Phase:
(<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
Message:

Implemented FS time synchronization

Location:
src/mlx
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/config.py

    r147 r148  
    4141        self._onlineACARS = True
    4242        self._flareTimeFromFS = False
     43        self._syncFSTime = False
    4344       
    4445        self._autoUpdate = True       
     
    145146        if flareTimeFromFS!=self._flareTimeFromFS:
    146147            self._flareTimeFromFS = flareTimeFromFS
     148            self._modified = True
     149
     150    @property
     151    def syncFSTime(self):
     152        """Get whether the simulator's time should be synchronized with the
     153        machine's clock."""
     154        return self._syncFSTime
     155
     156    @syncFSTime.setter
     157    def syncFSTime(self, syncFSTime):
     158        """Set whether the simulator's time should be synchronized with the
     159        machine's clock."""
     160        if syncFSTime!=self._syncFSTime:
     161            self._syncFSTime = syncFSTime
    147162            self._modified = True
    148163
     
    213228                                                 "flareTimeFromFS",
    214229                                                 False)
     230        self._syncFSTime = self._getBoolean(config, "general",
     231                                            "syncFSTime",
     232                                            False)
    215233
    216234        self._messageTypeLevels = {}
     
    249267        config.set("general", "flareTimeFromFS",
    250268                   "yes" if self._flareTimeFromFS else "no")
     269        config.set("general", "syncFSTime",
     270                   "yes" if self._syncFSTime else "no")
    251271
    252272        config.add_section(Config._messageTypesSection)
  • src/mlx/fsuipc.py

    r141 r148  
    471471                   (0x0580, "d") ]           # Heading
    472472
     473    TIME_SYNC_INTERVAL = 3.0
     474
    473475    @staticmethod
    474476    def _getTimestamp(data):
     
    514516        self._scroll = False
    515517
     518        self._syncTime = False
     519        self._nextSyncTime = -1
     520       
    516521        self._normalRequestID = None
    517522
     
    536541        self._handler.connect()
    537542        if self._normalRequestID is None:
     543            self._nextSyncTime = -1
    538544            self._startDefaultNormal()
    539545
     
    638644            data.append( (offset, "u", long(level * 128.8 * 65536.0)) )
    639645        self._handler.requestWrite(data, self._handleFuelWritten)
     646
     647    def enableTimeSync(self):
     648        """Enable the time synchronization."""
     649        self._nextSyncTime = -1
     650        self._syncTime = True
     651           
     652    def disableTimeSync(self):
     653        """Enable the time synchronization."""
     654        self._syncTime = False
     655        self._nextSyncTime = -1
    640656           
    641657    def disconnect(self):
     
    678694
    679695        self._scroll = data[7]!=0
     696
     697        self._checkTimeSync()
    680698       
    681699        if self._monitoringRequested and not self._monitoring:
     
    691709            self._aircraft.handleState(aircraftState)
    692710
     711    def _checkTimeSync(self):
     712        """Check if we need to synchronize the FS time."""
     713        if not self._syncTime: return
     714
     715        now = time.time()
     716        seconds = time.gmtime(now).tm_sec
     717
     718        if seconds>30 and seconds<59:
     719            if self._nextSyncTime > (now - 0.49):
     720                return
     721           
     722            self._handler.requestWrite([(0x023a, "b", int(seconds))],
     723                                       self._handleTimeSynced)
     724           
     725            #print "Set the seconds to ", seconds
     726
     727            if self._nextSyncTime<0:
     728                self._nextSyncTime = now
     729               
     730            self._nextSyncTime += Simulator.TIME_SYNC_INTERVAL
     731        else:
     732            self._nextSyncTime = -1
     733
     734    def _handleTimeSynced(self, success, extra):
     735        """Callback for the time sync result."""
     736        pass
     737       
    693738    def _setAircraftName(self, timestamp, name, airPath):
    694739        """Set the name of the aicraft and if it is different from the
  • src/mlx/gui/gui.py

    r147 r148  
    699699            self._simulator = fs.createSimulator(const.SIM_MSFS9, self)
    700700            fs.setupMessageSending(self.config, self._simulator)
    701 
     701            self._setupTimeSync()
     702       
    702703        self._flight.simulator = self._simulator
    703704
     
    853854        """Callback for editing the preferences."""
    854855        self._preferences.run(self.config)
     856        self._setupTimeSync()
     857
     858    def _setupTimeSync(self):
     859        """Enable or disable the simulator time synchronization based on the
     860        configuration."""
     861        simulator = self._simulator
     862        if simulator is not None:
     863            if self.config.syncFSTime:
     864                simulator.enableTimeSync()
     865            else:
     866                simulator.disableTimeSync()
  • src/mlx/gui/prefs.py

    r147 r148  
    7171        self._onlineACARS.set_active(config.onlineACARS)
    7272        self._flareTimeFromFS.set_active(config.flareTimeFromFS)
     73        self._syncFSTime.set_active(config.syncFSTime)
    7374
    7475        for messageType in const.messageTypes:
     
    9697        config.onlineACARS = self._onlineACARS.get_active()
    9798        config.flareTimeFromFS = self._flareTimeFromFS.get_active()
     99        config.syncFSTime = self._syncFSTime.get_active()
    98100
    99101        for messageType in const.messageTypes:
     
    167169        self._flareTimeFromFS.set_tooltip_text(xstr("prefs_flaretimeFromFS_tooltip"))
    168170        mainBox.pack_start(self._flareTimeFromFS, False, False, 4)
     171                                       
     172        self._syncFSTime = gtk.CheckButton(xstr("prefs_syncFSTime"))
     173        self._syncFSTime.set_use_underline(True)
     174        self._syncFSTime.set_tooltip_text(xstr("prefs_syncFSTime_tooltip"))
     175        mainBox.pack_start(self._syncFSTime, False, False, 4)
    169176                                       
    170177        return mainAlignment
  • src/mlx/i18n.py

    r147 r148  
    616616                 "If this is checked, the time of the flare will be calculated "
    617617                 "from timestamps returned by the simulator.")
     618        self.add("prefs_syncFSTime",
     619                 "_Synchronize the time in FS with the computer's clock")
     620        self.add("prefs_syncFSTime_tooltip",
     621                 "If this is checked the flight simulator's internal clock "
     622                 "will always be synchronized to the computer's clock.")
    618623        self.add("prefs_update_auto", "Update the program auto_matically")
    619624        self.add("prefs_update_auto_tooltip",
     
    11641169                 "Ha ezt bejelölöd, a kilebegtetés idejét a szimulátor "
    11651170                 "által visszaadott időbélyegek alapján számolja a program.")
     1171        self.add("prefs_syncFSTime",
     1172                 "_Szinkronizáld a szimulátor idéjét a számítógépével")
     1173        self.add("prefs_syncFSTime_tooltip",
     1174                 "Ha ez bejelölöd, a szimulátor belső óráját a program "
     1175                 "szinkronban tartja a számítógép órájával.")
    11661176        self.add("prefs_update_auto",
    11671177                 "Frissítsd a programot _automatikusan")
Note: See TracChangeset for help on using the changeset viewer.