Class AbstractLight

  • All Implemented Interfaces:
    java.lang.Comparable<NamedBean>, PropertyChangeProvider, DigitalIO, Light, NamedBean
    Direct Known Subclasses:
    AbstractVariableLight, AcelaLight, CbusLight, DCCppLight, IpocsLight, JMRIClientLight, LnLight, NceLight, OlcbLight, SerialLight, SerialLight, SerialLight, SerialLight, SerialLight, XBeeLight, XNetLight

    public abstract class AbstractLight
    extends AbstractNamedBean
    implements Light
    Abstract class providing partial implementation of the Light interface.

    Light objects require a number of instance variables. Since Light objects are created using the standard JMRI systemName/userName concept, accessor routines are provided for setting and editing these instance variables.

    Each Light may have one or more control mechanisms, of the types defined in the Light interface. A Light may also not have any control mechanisms defined.

    Information for each control mechanism is held in LightControl objects, which also implement the logic for control. A list of LightControls, if any, is kept here, and activation and deactivation of LightControls is through this module.

    Instance variables are divided into system-independent and system dependent categories. System independent instance variables are defined here, and their accessor routines are implemented here.

    This implementation provides a notional implementation of intensity and transitions. The user can set intensity so long as it's at least the max value (default 1.0) or no more than the minimum value (default 0.0). In that case, the setTargetIntensity operations become a setState to ON or OFF. Setting a target intensity between the min and max is an error, because this type of Light does not support a true analog intensity. Transitions never happen, and setting a TransitionTime greater than 0.0 gives an exception.

    Since this form of Light does not do variable intensity nor transitions, it stores both CurrentIntensity and TargetIntensity in a single location, forcing them to be the same

    • Constructor Detail

      • AbstractLight

        public AbstractLight​(java.lang.String systemName,
                             java.lang.String userName)
      • AbstractLight

        public AbstractLight​(java.lang.String systemName)
    • Method Detail

      • getBeanType

        public java.lang.String getBeanType()
        Description copied from interface: NamedBean
        For instances in the code where we are dealing with just a bean and a message needs to be passed to the user or in a log.
        Specified by:
        getBeanType in interface NamedBean
        Returns:
        a string of the bean type, eg Turnout, Sensor etc
      • getEnabled

        public boolean getEnabled()
        Get enabled status.
        Specified by:
        getEnabled in interface Light
        Returns:
        enabled status
      • setEnabled

        public void setEnabled​(boolean v)
        Set enabled status.
        Specified by:
        setEnabled in interface Light
        Parameters:
        v - status to set
      • setState

        public void setState​(int newState)
        Handle a request for a state change. For these lights, ON and OFF just transition immediately between MinIntensity and MaxIntensity. Ignores any outputDelay setting for connection.
        Specified by:
        setState in interface Light
        Specified by:
        setState in interface NamedBean
        Parameters:
        newState - new state
      • notifyTargetIntensityChange

        protected void notifyTargetIntensityChange​(double intensity)
        Change the stored target intensity value and do notification, but don't change anything in the hardware.
        Parameters:
        intensity - intensity value
      • notifyStateChange

        protected void notifyStateChange​(int oldState,
                                         int newState)
        Change the stored state value and do notification, but don't change anything in the hardware.
        Parameters:
        oldState - old value
        newState - new value
      • doNewState

        protected void doNewState​(int oldState,
                                  int newState)
        Implement the specific change of state needed by hardware.
        Parameters:
        oldState - old state
        newState - new state
      • getState

        public int getState()
        Description copied from interface: Light
        Get the current state of the Light's output.
        Specified by:
        getState in interface Light
        Specified by:
        getState in interface NamedBean
        Returns:
        the state
      • addLightControl

        public void addLightControl​(LightControl c)
        Add a LightControl to this Light.

        Duplicates are considered the same, hence not added

        Specified by:
        addLightControl in interface Light
        Parameters:
        c - the light control to add.