Class LocoNetThrottle

    • Method Detail

      • floatSpeed

        protected float floatSpeed​(int lSpeed)
        Convert a LocoNet speed integer to a float speed value
        Parameters:
        lSpeed - LocoNet style speed value
        Returns:
        speed as float 0->1.0, or -1.0 to indicate E-Stop
      • intSpeed

        protected int intSpeed​(float fSpeed)
        Computes the integer speed value from a float.

        Values of less than 0 indicate Emergency Stop.

        Value of 0.0 indicates stop.

        Values between 0.0+ and 1.0 imply speed step values between 2 and the maximum value allowed for the loco's speed step mode.

        Overrides:
        intSpeed in class AbstractThrottle
        Parameters:
        fSpeed - is the floating-point speed value to be converted
        Returns:
        an integer which represents the speed step value
      • sendFunctionGroup

        protected void sendFunctionGroup​(int functionNum,
                                         boolean momentary)
        Send whole (DCC) Function Group for a particular function number.
        Overrides:
        sendFunctionGroup in class AbstractThrottle
        Parameters:
        functionNum - Function Number
        momentary - False to send normal function status, true to send momentary.
      • sendFunctionGroup1

        protected void sendFunctionGroup1()
        Send the LocoNet message to set the state of locomotive direction and functions F0, F1, F2, F3, F4 Unfortunately this is used by all throttles to send direction changes, but the expanded slots dont use this for direction changes, they use speed... And we don't know if the caller wants to send functions or direction.
        Overrides:
        sendFunctionGroup1 in class AbstractThrottle
      • sendExpFunctionGroup1

        protected void sendExpFunctionGroup1()
        Send the Expanded LocoNet message to set the state of locomotive direction and functions F0, F1, F2, F3, F4, F5, F6
      • sendExpFunctionGroup2

        protected void sendExpFunctionGroup2()
        Send the Expanded LocoNet message to set the state of functions F7, F8, F8, F9, F10, F11, F12, F13
      • sendExpFunctionGroup3

        protected void sendExpFunctionGroup3()
        Sends expanded loconet message F14 thru F20 Message.
      • sendExpFunctionGroup4

        protected void sendExpFunctionGroup4()
        Sends Expanded loconet message F21 thru F28 Message.
      • sendExpSpeedAndDirection

        protected void sendExpSpeedAndDirection​(int speed)
        Send the expanded slot command for speed and direction on change of speed Note we send our stored values as slot is updated via an echo and may not have been updated yet when sending rapid commands
        Parameters:
        speed - the speed to set
      • sendExpSpeedAndDirection

        protected void sendExpSpeedAndDirection​(boolean isFwd)
        Send the expanded slot command for speed and direction on change of direction Note we send our stored speed if slot has not yet been updated by the echo
        Parameters:
        isFwd - new direction
      • setSpeedSettingAgain

        public void setSpeedSettingAgain​(float speed)
        Set the Speed, ensuring that a LocoNet message is sent to update the slot even if the new speed is effectively the same as the current speed. Note: this can cause an increase in LocoNet traffic.
        Specified by:
        setSpeedSettingAgain in interface Throttle
        Overrides:
        setSpeedSettingAgain in class AbstractThrottle
        Parameters:
        speed - Number from 0 to 1; less than zero is emergency stop
      • setSpeedSetting

        public void setSpeedSetting​(float speed,
                                    boolean allowDuplicates,
                                    boolean allowDuplicatesOnStop)
        Set the speed. No LocoNet message is sent if the new speed would result in a 'duplicate' - ie. a speed setting no different to the one the slot currently has - unless the boolean paramters indicate it should be.
        Specified by:
        setSpeedSetting in interface Throttle
        Overrides:
        setSpeedSetting in class AbstractThrottle
        Parameters:
        speed - Number from 0 to 1; less than zero is emergency stop
        allowDuplicates - boolean - if true, send a LocoNet message no matter what
        allowDuplicatesOnStop - boolean - if true, send a LocoNet message if the new speed is 'idle' or 'emergency stop', even if that matches the existing speed.
      • setIsForward

        public void setIsForward​(boolean forward)
        Send a LocoNet message containing the specified direction of travel. LocoNet actually puts forward and backward in the same message as the first function group.
        Specified by:
        setIsForward in interface Throttle
        Overrides:
        setIsForward in class AbstractThrottle
        Parameters:
        forward - is true for forward movement, else false
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • throttleDispose

        public void throttleDispose()
        Dispose the LocoNetThrottle when finished with this object. After this is executed, further use of this Throttle object will result in a JmriException.
        Specified by:
        throttleDispose in class AbstractThrottle
      • startRefresh

        protected void startRefresh()
        Start the "refresh" timer. The "refresh" timer determines when to send a new LocoNet message to "refresh" the slot's speed setting, so that the slot does not get "purged".
      • timeout

        protected void timeout()
        Internal routine to resend the speed on a timeout
      • notifyRefused

        public void notifyRefused​(int addr,
                                  java.lang.String s)
        Get notified when underlying slot acquisition process fails. Slot acquisition failure is handled by @link LnThrottleManager, so no code is required here.
        Parameters:
        addr - Locomotive address
        s - reason the acquisition failed
      • updateFunctions

        protected void updateFunctions()
        update the F0-F29 functions. Invoked by notifyChangedSlot(), this nominally updates from the slot.
      • getLocoAddress

        public LocoAddress getLocoAddress()
        Get the address controlled by this throttle. If the throttle is controlling.
        Specified by:
        getLocoAddress in interface Throttle
        Returns:
        a LocoAddress for the address controlled by this throttle
      • dispatchThrottle

        public void dispatchThrottle​(DccThrottle t,
                                     ThrottleListener l)
        "Dispatch" a LocoNet throttle by setting the slot as "common" then performing a slot move to slot 0.

        The throttle being dispatched no longer has control of the loco, but other throttles may continue to control the loco.

        Parameters:
        t - throttle being dispatched
        l - throttle listener to remove