Class LocoNetThrottle

All Implemented Interfaces:
EventListener, PropertyChangeFirer, PropertyChangeProvider, DccThrottle, SlotListener, Throttle
Direct Known Subclasses:
Ib1Throttle, Ib2Throttle

public class LocoNetThrottle extends AbstractThrottle implements SlotListener
An implementation of DccThrottle via AbstractThrottle with code specific to a LocoNet connection.

Speed in the Throttle interfaces and AbstractThrottle is a float, but in LocoNet is an int with values from 0 to 127.

  • Field Details

  • Constructor Details

  • Method Details

    • 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
    • sendFunctionGroup2

      protected void sendFunctionGroup2()
      Send the LocoNet message to set the state of functions F5, F6, F7, F8
      Overrides:
      sendFunctionGroup2 in class AbstractThrottle
    • sendFunctionGroup3

      protected void sendFunctionGroup3()
      Sends Function Group 3 values - F9 thru F12, using an "OPC_IMM_PACKET" LocoNet Message.
      Overrides:
      sendFunctionGroup3 in class AbstractThrottle
    • sendFunctionGroup4

      protected void sendFunctionGroup4()
      Sends Function Group 4 values - F13 thru F20, using an "OPC_IMM_PACKET" LocoNet Message.
      Overrides:
      sendFunctionGroup4 in class AbstractThrottle
    • sendFunctionGroup5

      protected void sendFunctionGroup5()
      Sends Function Group 5 values - F21 thru F28, using an "OPC_IMM_PACKET" LocoNet Message.
      Overrides:
      sendFunctionGroup5 in class AbstractThrottle
    • sendFunctionGroup6

      protected void sendFunctionGroup6()
      Sends Function Group 6 values - F29 thru F36, using an "OPC_IMM_PACKET" LocoNet Message.
      Overrides:
      sendFunctionGroup6 in class AbstractThrottle
    • sendFunctionGroup7

      protected void sendFunctionGroup7()
      Sends Function Group 7 values - F37 thru F44, using an "OPC_IMM_PACKET" LocoNet Message.
      Overrides:
      sendFunctionGroup7 in class AbstractThrottle
    • sendFunctionGroup8

      protected void sendFunctionGroup8()
      Sends Function Group 8 values - F45 thru F52, using an "OPC_IMM_PACKET" LocoNet Message.
      Overrides:
      sendFunctionGroup8 in class AbstractThrottle
    • sendFunctionGroup9

      protected void sendFunctionGroup9()
      Sends Function Group 9 values - F53 thru F60, using an "OPC_IMM_PACKET" LocoNet Message.
      Overrides:
      sendFunctionGroup9 in class AbstractThrottle
    • sendFunctionGroup10

      protected void sendFunctionGroup10()
      Sends Function Group 10 values - F61 thru F68, using an "OPC_IMM_PACKET" LocoNet Message.
      Overrides:
      sendFunctionGroup10 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
    • setSpeedSetting

      public void setSpeedSetting(float speed)
      Send a LocoNet message to set the loco speed speed.
      Specified by:
      setSpeedSetting in interface Throttle
      Overrides:
      setSpeedSetting in class AbstractThrottle
      Parameters:
      speed - Number from 0 to 1; less than zero is "emergency stop"
    • 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
    • getLocoNetSlot

      Get the LocoNetSlot which is used for controlling the loco assoicated with this throttle.
      Returns:
      the LocoNetSlot
    • toString

      public String toString()
      Overrides:
      toString in class 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, 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
    • notifyChangedSlot

      public void notifyChangedSlot(LocoNetSlot pSlot)
      Get notified when underlying slot information changes
      Specified by:
      notifyChangedSlot in interface SlotListener
      Parameters:
      pSlot - the slot which was changed
    • updateFunctions

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

      public void setSpeedStepMode(SpeedStepMode Mode)
      Set the speed step value and the related speedIncrement value.
      Specified by:
      setSpeedStepMode in interface DccThrottle
      Overrides:
      setSpeedStepMode in class AbstractThrottle
      Parameters:
      Mode - the current speed step mode - default should be 128 speed step mode in most cases
    • 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

      "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