Class LnTurnout

  • All Implemented Interfaces:
    java.beans.PropertyChangeListener, java.lang.Comparable<NamedBean>, java.util.EventListener, PropertyChangeProvider, DigitalIO, NamedBean, Turnout, VariableControlSpanBean

    public class LnTurnout
    extends AbstractTurnout
    Extend jmri.AbstractTurnout for LocoNet layouts

    This implementation implements the "SENT" feedback, where LocoNet messages originating on the layout can change both KnownState and CommandedState. We change both because we consider a LocoNet message to reflect how the turnout should be, even if it's a readback status message. E.g. if you use a DS54 local input to change the state, resulting in a status message, we still consider that to be a commanded state change.

    Adds several additional feedback modes:

    • MONITORING - listen to the LocoNet, so that commands from other LocoNet sources (e.g. throttles) are properly reflected in the turnout state. This is the default for LnTurnout objects as created.
    • INDIRECT - listen to the LocoNet for messages back from a DS54 that has a microswitch attached to its Switch input.
    • EXACT - listen to the LocoNet for messages back from a DS54 that has two microswitches, one connected to the Switch input and one to the Aux input.
    • ALTERNATE - listen to the LocoNet for messages back from a MGP decoders that has reports servo moving.
    Some of the message formats used in this class are Copyright Digitrax, Inc. and used with permission as part of the JMRI project. That permission does not extend to uses in other software products. If you wish to use this code, algorithm or these message formats outside of JMRI, please contact Digitrax Inc for separate permission.
    • Constructor Detail

      • LnTurnout

        public LnTurnout​(java.lang.String prefix,
                         int number,
                         LocoNetInterface controller)
                  throws java.lang.IllegalArgumentException
        Throws:
        java.lang.IllegalArgumentException
    • Method Detail

      • setFeedbackMode

        public void setFeedbackMode​(int mode)
                             throws java.lang.IllegalArgumentException
        Description copied from class: AbstractTurnout
        On change, fires Property Change "feedbackchange". Set the feedback mode from a integer. This must be one of the bit values defined in a previous Turnout.getValidFeedbackTypes() call. Having more than one bit set is an error.
        Specified by:
        setFeedbackMode in interface Turnout
        Overrides:
        setFeedbackMode in class AbstractTurnout
        Parameters:
        mode - the feedback type to set
        Throws:
        java.lang.IllegalArgumentException - if mode is not valid
      • forwardCommandChangeToLayout

        protected void forwardCommandChangeToLayout​(int newstate)
        Handle a request to change state, typically by sending a message to the layout in some child class. Public version (used by TurnoutOperator) sends the current commanded state without changing it. Implementing classes will typically check the value of s and send a system specific sendMessage command.
        Specified by:
        forwardCommandChangeToLayout in class AbstractTurnout
        Parameters:
        newstate - new state value
      • sendOpcSwReqMessage

        void sendOpcSwReqMessage​(int state,
                                 boolean on)
        Send a single OPC_SW_REQ message for this turnout, with the CLOSED/THROWN ON/OFF state.

        Inversion is to already have been handled.

        Parameters:
        state - the state to set
        on - if true the C bit of the NMRA DCC packet is 1; if false the C bit is 0
      • sendSetOffMessage

        void sendSetOffMessage​(int state)
        Set the turnout DCC C bit to OFF. This is typically used to set a C bit that was set ON to OFF after a timeout.
        Parameters:
        state - the turnout state
      • dispose

        public void dispose()
        Description copied from class: AbstractTurnout
        Deactivate this object, so that it releases as many resources as possible and no longer effects others.

        For example, if this object has listeners, after a call to this method it should no longer notify those listeners. Any native or system-wide resources it maintains should be released, including threads, files, etc.

        It is an error to invoke any other methods on this object once dispose() has been called. Note, however, that there is no guarantee about behavior in that case.

        Afterwards, references to this object may still exist elsewhere, preventing its garbage collection. But it's formally dead, and shouldn't be keeping any other objects alive. Therefore, this method should null out any references to other objects that this NamedBean contained.

        Specified by:
        dispose in interface NamedBean
        Overrides:
        dispose in class AbstractTurnout