Index: src/checks.py
===================================================================
--- src/checks.py	(revision 21)
+++ src/checks.py	(revision 22)
@@ -153,4 +153,8 @@
         self._logInitial = logInitial    
 
+    def _getLogTimestamp(self, state):
+        """Get the log timestamp."""
+        return state.timestamp
+
     def check(self, flight, aircraft, logger, oldState, state):
         """Check if the state has changed, and if so, log the new state."""
@@ -162,5 +166,5 @@
         
         if shouldLog:
-            logger.message(state.timestamp, self._getMessage(state))
+            logger.message(self._getLogTimestamp(state), self._getMessage(state))
         
 #---------------------------------------------------------------------------------------
@@ -197,10 +201,12 @@
     Child classes should define the following function:
     - _getValue(state): get the value we are interested in."""
-    def __init__(self, delay = 10.0):
+    def __init__(self, minDelay = 3.0, maxDelay = 10.0):
         """Construct the mixin with the given delay in seconds."""
-        self._delay = delay
+        self._minDelay = minDelay
+        self._maxDelay = maxDelay
         self._oldValue = None
         self._firstChange = None
-
+        self._lastChangeState = None
+        
     def _changed(self, oldState, state):
         """Determine if the value has changed."""
@@ -209,15 +215,22 @@
             
         newValue = self._getValue(state)
-        if newValue!=self._oldValue:
+        if self._oldValue!=newValue:
             if self._firstChange is None:
                 self._firstChange = state.timestamp
-            if state.timestamp >= (self._firstChange + self._delay):
-                self._oldValue = newValue
+            self._lastChangeState = state
+            self._oldValue = newValue
+
+        if self._firstChange is not None:
+            if state.timestamp >= min(self._lastChangeState.timestamp + self._minDelay,
+                                      self._firstChange + self._maxDelay):
                 self._firstChange = None
                 return True
-        else:
-            self._firstChange = None
-
+            
         return False
+
+    def _getLogTimestamp(self, state):
+        """Get the log timestamp."""
+        return self._lastChangeState.timestamp if \
+               self._lastChangeState is not None else state.timestamp
 
 #---------------------------------------------------------------------------------------
@@ -242,10 +255,13 @@
     """Base for generic state change loggers that monitor a single value in the
     state possibly with a delay and the logged message comes from a template"""
-    def __init__(self, attrName, template, logInitial = True, delay = 0.0):
+    def __init__(self, attrName, template, logInitial = True,
+                 minDelay = 0.0, maxDelay = 0.0):
         """Construct the object."""
         StateChangeLogger.__init__(self, logInitial = logInitial)
         SingleValueMixin.__init__(self, attrName)
-        DelayedChangeMixin.__init__(self, delay = delay)
+        DelayedChangeMixin.__init__(self, minDelay = minDelay, maxDelay = maxDelay)
         TemplateMessageMixin.__init__(self, template)
+        self._getLogTimestamp = lambda state: \
+                                DelayedChangeMixin._getLogTimestamp(self, state)
 
 #---------------------------------------------------------------------------------------
@@ -259,8 +275,13 @@
         SingleValueMixin.__init__(self, "altimeter")
         DelayedChangeMixin.__init__(self)
+        self._getLogTimestamp = lambda state: \
+                                DelayedChangeMixin._getLogTimestamp(self, state)
 
     def _getMessage(self, state):
         """Get the message to log on a change."""
-        return "Altimeter: %.0f hPa at %.0f feet" % (state.altimeter, state.altitude)
+        logState = self._lastChangeState if \
+                   self._lastChangeState is not None else state
+        return "Altimeter: %.0f hPa at %.0f feet" % \
+               (logState.altimeter, logState.altitude)
 
 #---------------------------------------------------------------------------------------
@@ -287,5 +308,5 @@
         """Construct the logger."""
         super(SquawkLogger, self).__init__("squawk", "Squawk code: %s",
-                                           delay = 10.0)
+                                           minDelay = 3.0, maxDelay = 10.0)
 
 #---------------------------------------------------------------------------------------
