Class AbstractSensor

java.lang.Object
jmri.implementation.AbstractNamedBean
jmri.implementation.AbstractSensor
All Implemented Interfaces:
Comparable<NamedBean>, PropertyChangeProvider, DigitalIO, NamedBean, Sensor
Direct Known Subclasses:
AcelaSensor, BiDiBSensor, CbusSensor, Dcc4PcSensor, DCCppSensor, EcosSensor, IpocsSensor, JMRIClientSensor, LnSensor, MarklinSensor, MqttSensor, NceSensor, OlcbSensor, RaspberryPiSensor, RfidSensor, RpsSensor, SerialSensor, SerialSensor, SerialSensor, SerialSensor, SerialSensor, SerialSensor, SRCPSensor, TamsSensor, XBeeSensor, XNetSensor, Z21CanSensor, Z21RMBusSensor

public abstract class AbstractSensor extends AbstractNamedBean implements Sensor
Abstract class providing the basic logic of the Sensor interface.
  • Field Details

  • Constructor Details

  • Method Details

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

      public void setSensorDebounceGoingActiveTimer(long time)
      Set the active debounce delay.
      Specified by:
      setSensorDebounceGoingActiveTimer in interface Sensor
      Parameters:
      time - delay in milliseconds; set to zero to de-activate debounce
    • getSensorDebounceGoingActiveTimer

      Get the active debounce delay.
      Specified by:
      getSensorDebounceGoingActiveTimer in interface Sensor
      Returns:
      delay in milliseconds
    • setSensorDebounceGoingInActiveTimer

      public void setSensorDebounceGoingInActiveTimer(long time)
      Set the inactive debounce delay.
      Specified by:
      setSensorDebounceGoingInActiveTimer in interface Sensor
      Parameters:
      time - delay in milliseconds; set to zero to de-activate debounce
    • getSensorDebounceGoingInActiveTimer

      Get the inactive debounce delay.
      Specified by:
      getSensorDebounceGoingInActiveTimer in interface Sensor
      Returns:
      delay in milliseconds
    • setUseDefaultTimerSettings

      public void setUseDefaultTimerSettings(boolean boo)
      Description copied from interface: Sensor
      Use the timers specified in the SensorManager for the debounce delay.
      Specified by:
      setUseDefaultTimerSettings in interface Sensor
      Parameters:
      boo - true to set to current defaults if not previously true
    • getUseDefaultTimerSettings

      public boolean getUseDefaultTimerSettings()
      Description copied from interface: Sensor
      Does this sensor use the default timers values? (A remarkably unfortunate name given the one above)
      Specified by:
      getUseDefaultTimerSettings in interface Sensor
      Returns:
      true if using default debounce values from the SensorManager
    • 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.
    • describeState

      Description copied from class: AbstractNamedBean
      Provide human-readable, localized version of state value.

      This method is intended for use when presenting to a human operator.

      Specified by:
      describeState in interface NamedBean
      Overrides:
      describeState in class AbstractNamedBean
      Parameters:
      state - the state to describe
      Returns:
      the state in localized form
    • 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 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:
      IllegalArgumentException - when needed
    • 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

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

      Set the pull resistance

      In this default implementation, the input value is ignored.

      Specified by:
      setPullResistance in interface Sensor
      Parameters:
      r - PullResistance value to use.
    • getPullResistance

      Get the pull resistance.
      Specified by:
      getPullResistance in interface Sensor
      Returns:
      the currently set PullResistance value. In this default implementation, PullResistance.PULL_OFF is always returned.
    • dispose

      public void dispose()
      Description copied from class: AbstractNamedBean
      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
      Specified by:
      dispose in interface Sensor
      Overrides:
      dispose in class AbstractNamedBean