Class AbstractSensor

    • Constructor Detail

      • AbstractSensor

        public AbstractSensor​(java.lang.String systemName)
      • AbstractSensor

        public AbstractSensor​(java.lang.String systemName,
                              java.lang.String userName)
    • Method Detail

      • getBeanType

        @Nonnull
        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
      • getKnownState

        public int getKnownState()
        Description copied from interface: DigitalIO
        Query the known state. This is a bound parameter, so you can also register a listener to be informed of changes. A result is always returned; if no other feedback method is available, the commanded state will be used.
        Specified by:
        getKnownState in interface DigitalIO
        Returns:
        the known state
      • sensorDebounce

        protected void sensorDebounce()
        Before going active or inactive or checking that we can go active, we will wait for sensorDebounceGoing(In)Active for things to settle down to help prevent a race condition.
      • setKnownState

        public void setKnownState​(int newState)
                           throws JmriException
        Perform setKnownState(int) for implementations that can't actually do it on the layout. Not intended for use by implementations that can.
        Specified by:
        setKnownState in interface Sensor
        Parameters:
        newState - the state to set
        Throws:
        JmriException - if unable to set the state
      • stateChangeCheck

        protected boolean stateChangeCheck​(int newState)
                                    throws java.lang.IllegalArgumentException
        Preprocess a Sensor state change request for specific implementations of setKnownState(int)
        Parameters:
        newState - the Sensor state command value passed
        Returns:
        true if a Sensor.ACTIVE was requested and Sensor is not set to _inverted
        Throws:
        java.lang.IllegalArgumentException
      • setOwnState

        public void setOwnState​(int s)
        Set our internal state information, and notify bean listeners.
        Parameters:
        s - the new state
      • getRawState

        public int getRawState()
        Description copied from interface: Sensor
        Used to return the Raw state of a sensor prior to the known state of a sensor being set. The raw state value can be different from the known state when the sensor debounce option is used.
        Specified by:
        getRawState in interface Sensor
        Returns:
        raw state value
      • setState

        public void setState​(int s)
                      throws JmriException
        Implement a shorter name for setKnownState.

        This generally shouldn't be used by Java code; use setKnownState instead. The is provided to make Jython script access easier to read.

        Specified by:
        setState in interface NamedBean
        Parameters:
        s - the state
        Throws:
        JmriException - general error when setting the state fails
      • getState

        public int getState()
        Implement a shorter name for getKnownState.

        This generally shouldn't be used by Java code; use getKnownState instead. The is provided to make Jython script access easier to read.

        Specified by:
        getState in interface NamedBean
        Returns:
        the state
      • setInverted

        public void setInverted​(boolean inverted)
        Control whether the actual sensor input is considered to be inverted, e.g. the normal electrical signal that results in an ACTIVE state now results in an INACTIVE state.
        Specified by:
        setInverted in interface Sensor
        Parameters:
        inverted - true if the sensor should be inverted; false otherwise
      • getInverted

        public final boolean getInverted()
        Get the inverted state. If true, the electrical signal that results in an ACTIVE state now results in an INACTIVE state.

        Used in polling loops in system-specific code, so made final to allow optimization.

        Specified by:
        getInverted in interface Sensor
        Returns:
        true if the electrical signal that normally results in an ACTIVE state now results in an INACTIVE state; false otherwise
      • canInvert

        public boolean canInvert()
        By default, all implementations based on this can invert
        Specified by:
        canInvert in interface Sensor
        Returns:
        true if can be inverted; false otherwise
      • setReporter

        public void setReporter​(Reporter er)
        Some sensor boards also serve the function of being able to report back train identities via such methods as RailCom. The setting and creation of the reporter against the sensor should be done when the sensor is created. This information is not saved.
        Specified by:
        setReporter in interface Sensor
        Parameters:
        er - the reporter to set
      • getReporter

        public Reporter getReporter()
        Description copied from interface: Sensor
        Retrieve the reporter associated with this sensor if there is one.
        Specified by:
        getReporter in interface Sensor
        Returns:
        the reporter or null if there is no associated reporter