Class Pr2Throttle

All Implemented Interfaces:
PropertyChangeFirer, PropertyChangeProvider, DccThrottle, Throttle

public class Pr2Throttle extends AbstractThrottle
An implementation of DccThrottle via AbstractThrottle with code specific to a PR2 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 speed value
      Returns:
      speed as float 0->1.0
    • intSpeed

      protected int intSpeed(float fSpeed)
      Get an integer speed for the given raw speed value. This is a convenience method that calls AbstractThrottle.intSpeed(float, int) with a maxStep of 127.

      This implementation does not support 128 speed steps.

      Overrides:
      intSpeed in class AbstractThrottle
      Parameters:
      fSpeed - the speed as a percentage of maximum possible speed; negative values indicate a need for an emergency stop
      Returns:
      an integer in the range 0-127
    • writeData

      public void writeData()
    • sendFunctionGroup1

      protected void sendFunctionGroup1()
      Send the LocoNet message to set the state of locomotive direction and functions F0, F1, F2, F3, F4. Invoked by AbstractThrottle when needed.
      Overrides:
      sendFunctionGroup1 in class AbstractThrottle
    • sendFunctionGroup2

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

      protected void sendFunctionGroup3()
      Send the message to set the state of functions F9, F10, F11, F12.

      This is used in the setFn implementations provided in this class, but a real implementation needs to be provided.

      Overrides:
      sendFunctionGroup3 in class AbstractThrottle
    • setSpeedSetting

      public void setSpeedSetting(float speed)
      Set the speed.

      This intentionally skips the emergency stop value of 1.

      Specified by:
      setSpeedSetting in interface Throttle
      Overrides:
      setSpeedSetting in class AbstractThrottle
      Parameters:
      speed - Number from 0 to 1; less than zero is emergency stop
    • setIsForward

      public void setIsForward(boolean forward)
      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 - true if forward; false otherwise
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getLocoAddress

      Locomotive address. The exact format is defined by the specific implementation, as subclasses of LocoAddress will contain different information.

      This is an unbound property.

      Returns:
      The locomotive address
    • throttleDispose

      public void throttleDispose()
      Dispose when finished with this Throttle. May be used in tests for cleanup. Throttles normally call AbstractThrottle.finishRecord() here.
      Specified by:
      throttleDispose in class AbstractThrottle