Class SpeedMatcher

    • Constructor Detail

      • SpeedMatcher

        public SpeedMatcher​(SpeedMatcherConfig config)
        Constructor for the abstract SpeedMatcher at the core of any Speed Matcher
        Parameters:
        config - SpeedMatcherConfig for initializing the SpeedMatcher
    • Method Detail

      • startSpeedMatcher

        public abstract boolean startSpeedMatcher()
        Starts the speed matching process
        Returns:
        true if speed matching started successfully, false otherwise
      • stopSpeedMatcher

        public abstract void stopSpeedMatcher()
        Stops the speed matching process
      • isSpeedMatcherIdle

        public abstract boolean isSpeedMatcherIdle()
        Indicates if the speed matcher is idle (not currently speed matching)
        Returns:
        true if idle, false otherwise
      • updateCurrentSpeed

        public void updateCurrentSpeed​(float currentSpeedKPH)
        Updates the locomotive's current speed in the speed matcher
        Parameters:
        currentSpeedKPH - the locomotive's current speed in KPH
      • validate

        protected abstract boolean validate()
        Validates the speed matcher's configuration
        Returns:
        true if the configuration is valid, false otherwise
      • cleanUpSpeedMatcher

        protected void cleanUpSpeedMatcher()
        Cleans up the speed matcher when speed matching is stopped or is finished
      • initializeAndStartSpeedMatcher

        protected boolean initializeAndStartSpeedMatcher​(java.awt.event.ActionListener timerActionListener)
        Shared code to initialize the speed matcher's programmer and throttle and start the speed matching timer. Expected to be called in an implementing speed matcher's Start function.
        Parameters:
        timerActionListener - callback to fire when the timer times out
        Returns:
        true if initialization and start is successful, false otherwise
      • setSpeedMatchStateTimerDuration

        protected void setSpeedMatchStateTimerDuration​(int timerDuration)
        Sets the duration for the speed match timer
        Parameters:
        timerDuration - timer duration in milliseconds
      • setThrottle

        protected void setThrottle​(boolean isForward,
                                   int speedStep)
        Sets the speed matcher's throttle direction and speed safely within timers to protect against executing a throttle change to close to setting a CV
        Parameters:
        isForward - true for forward, false for revers
        speedStep - 0-28 or 0-128 depending on mode
      • setSpeedMatchError

        protected void setSpeedMatchError​(float speedTarget)
        Sets the current speed match error
        Parameters:
        speedTarget - - target speed in KPH
      • getNextSpeedMatchValue

        protected int getNextSpeedMatchValue​(int lastValue,
                                             int max,
                                             int min)
        Gets the next value to try for speed matching
        Parameters:
        lastValue - the last speed match CV value tried
        max - the maximum value
        min - the minimum value
        Returns:
        the next value to try for speed matching [min:max]
      • resetSpeedMatcher

        protected void resetSpeedMatcher​(int initialValueDelta)
        Resets the speed matcher with the given value delta
        Parameters:
        initialValueDelta - the value delta to use for the next use of the speed matcher
      • writeVStart

        protected void writeVStart​(int value)
        Starts writing vStart (CV 2) using the ops mode programmer
        Parameters:
        value - vStart value (0-255 inclusive)
      • writeVMid

        protected void writeVMid​(int value)
        Starts writing vMid (CV 6) using the ops mode programmer
        Parameters:
        value - vMid value (0-255 inclusive)
      • writeVHigh

        protected void writeVHigh​(int value)
        Starts writing vHigh (CV 5) using the ops mode programmer
        Parameters:
        value - vHigh value (0-255 inclusive)
      • writeMomentumAccel

        protected void writeMomentumAccel​(int value)
        Starts writing acceleration momentum (CV 3) using the ops mode programmer
        Parameters:
        value - acceleration value (0-255 inclusive)
      • writeMomentumDecel

        protected void writeMomentumDecel​(int value)
        Starts writing deceleration momentum (CV 4) using the ops mode programmer
        Parameters:
        value - deceleration value (0-255 inclusive)
      • writeForwardTrim

        protected void writeForwardTrim​(int value)
        Starts writing forward trim (CV 66) using the ops mode programmer
        Parameters:
        value - forward trim value (0-255 inclusive)
      • writeReverseTrim

        protected void writeReverseTrim​(int value)
        Starts writing reverse trim (CV 95) using the ops mode programmer
        Parameters:
        value - reverse trim value (0-255 inclusive)
      • writeSpeedTableStep

        protected void writeSpeedTableStep​(SpeedMatcher.SpeedTableStep step,
                                           int value)
        Starts writing a Speed Table Step CV (CV 67-94) using the ops mode programmer
        Parameters:
        step - the SpeedTableStep to set
        value - speed table step value (0-255 inclusive)
      • programmingOpReply

        public void programmingOpReply​(int value,
                                       int status)
        Called when the programmer has completed its operation
        Specified by:
        programmingOpReply in interface ProgListener
        Parameters:
        value - value from a read operation, or value written on a write
        status - denotes the completion code. Note that this is a bitwise combination of the various states codes defined in this interface. (see ProgListener.java for possible values)
      • notifyDecisionRequired

        public void notifyDecisionRequired​(LocoAddress address,
                                           ThrottleListener.DecisionType question)
        Called when we must decide whether to steal the throttle for the requested address. This is an automatically stealing implementation, so the throttle will be automatically stolen
        Specified by:
        notifyDecisionRequired in interface ThrottleListener
        Parameters:
        address - the requested address
        question - the question being asked, steal / cancel, share / cancel, steal / share / cancel