Class 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
-
Nested Class Summary
Nested classes/interfaces inherited from interface jmri.NamedBean
NamedBean.BadNameException, NamedBean.BadSystemNameException, NamedBean.BadUserNameException, NamedBean.DisplayOptions, NamedBean.DuplicateSystemNameExceptionNested classes/interfaces inherited from interface jmri.Sensor
Sensor.PullResistance -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected intprotected intprotected Runnable(package private) Reporter(package private) intprotected longprotected longprotected Threadprotected booleanFields inherited from class jmri.implementation.AbstractNamedBean
listenerRefs, mSystemName, registerFields inherited from interface jmri.NamedBean
DISPLAY_NAME_FORMAT, INCONSISTENT, PROPERTY_COMMENT, PROPERTY_ENABLED, PROPERTY_KNOWN_STATE, PROPERTY_STATE, PROPERTY_USERNAME, QUOTED_NAME_FORMAT, UNKNOWNFields inherited from interface jmri.Sensor
ACTIVE, INACTIVE, MAX_DEBOUNCE, PROPERTY_ACTIVE_TIMER, PROPERTY_GLOBAL_TIMER, PROPERTY_INACTIVE_TIMER, PROPERTY_SENSOR_INVERTED -
Constructor Summary
ConstructorsConstructorDescriptionAbstractSensor(String systemName) AbstractSensor(String systemName, String userName) -
Method Summary
Modifier and TypeMethodDescriptionbooleanBy default, all implementations based on this can invertdescribeState(int state) Provide human-readable, localized version of state value.voiddispose()Deactivate this object, so that it releases as many resources as possible and no longer effects others.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.final booleanGet the inverted state.intQuery the known state.Get the pull resistance.intUsed to return the Raw state of a sensor prior to the known state of a sensor being set.Retrieve the reporter associated with this sensor if there is one.longGet the active debounce delay.longGet the inactive debounce delay.intgetState()Implement a shorter name for getKnownState.booleanDoes this sensor use the default timers values?protected voidBefore 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.voidsetInverted(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.voidsetKnownState(int newState) Perform setKnownState(int) for implementations that can't actually do it on the layout.voidsetOwnState(int s) Set our internal state information, and notify bean listeners.voidSet the pull resistancevoidsetReporter(Reporter er) Some sensor boards also serve the function of being able to report back train identities via such methods as RailCom.voidsetSensorDebounceGoingActiveTimer(long time) Set the active debounce delay.voidsetSensorDebounceGoingInActiveTimer(long time) Set the inactive debounce delay.voidsetState(int s) Implement a shorter name for setKnownState.voidsetUseDefaultTimerSettings(boolean boo) Use the timers specified in theSensorManagerfor the debounce delay.protected booleanstateChangeCheck(int newState) Preprocess a Sensor state change request for specific implementations ofsetKnownState(int)Methods inherited from class jmri.implementation.AbstractNamedBean
addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListener, compareSystemNameSuffix, equals, firePropertyChange, getComment, getDisplayName, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeListenersByReference, getPropertyKeys, getSystemName, getUserName, hashCode, removeProperty, removePropertyChangeListener, removePropertyChangeListener, setComment, setProperty, setUserName, toString, toStringSuffix, updateListenerRef, vetoableChangeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface jmri.DigitalIO
requestUpdateFromLayoutMethods inherited from interface jmri.NamedBean
addPropertyChangeListener, addPropertyChangeListener, compareSystemNameSuffix, compareTo, getComment, getDisplayName, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListenersByReference, getPropertyKeys, getRecommendedToolTip, getSystemName, getUsageReport, getUserName, removeProperty, setComment, setProperty, setUserName, toString, updateListenerRef, vetoableChangeMethods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListenerMethods inherited from interface jmri.Sensor
getCommandedState, isConsistentState, setCommandedState
-
Field Details
-
sensorDebounceGoingActive
-
sensorDebounceGoingInActive
-
useDefaultTimerSettings
-
thr
-
r
-
restartcount
int restartcount -
_inverted
-
_knownState
-
_rawState
-
reporter
-
-
Constructor Details
-
AbstractSensor
-
AbstractSensor
-
-
Method Details
-
getBeanType
Description copied from interface:NamedBeanFor 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:
getBeanTypein interfaceNamedBean- Returns:
- a string of the bean type, eg Turnout, Sensor etc
-
getKnownState
Description copied from interface:DigitalIOQuery 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:
getKnownStatein interfaceDigitalIO- Returns:
- the known state
-
setSensorDebounceGoingActiveTimer
Set the active debounce delay.- Specified by:
setSensorDebounceGoingActiveTimerin interfaceSensor- Parameters:
time- delay in milliseconds; set to zero to de-activate debounce
-
getSensorDebounceGoingActiveTimer
Get the active debounce delay.- Specified by:
getSensorDebounceGoingActiveTimerin interfaceSensor- Returns:
- delay in milliseconds
-
setSensorDebounceGoingInActiveTimer
Set the inactive debounce delay.- Specified by:
setSensorDebounceGoingInActiveTimerin interfaceSensor- Parameters:
time- delay in milliseconds; set to zero to de-activate debounce
-
getSensorDebounceGoingInActiveTimer
Get the inactive debounce delay.- Specified by:
getSensorDebounceGoingInActiveTimerin interfaceSensor- Returns:
- delay in milliseconds
-
setUseDefaultTimerSettings
Description copied from interface:SensorUse the timers specified in theSensorManagerfor the debounce delay.- Specified by:
setUseDefaultTimerSettingsin interfaceSensor- Parameters:
boo- true to set to current defaults if not previously true
-
getUseDefaultTimerSettings
Description copied from interface:SensorDoes this sensor use the default timers values? (A remarkably unfortunate name given the one above)- Specified by:
getUseDefaultTimerSettingsin interfaceSensor- Returns:
- true if using default debounce values from the
SensorManager
-
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:AbstractNamedBeanProvide human-readable, localized version of state value.This method is intended for use when presenting to a human operator.
- Specified by:
describeStatein interfaceNamedBean- Overrides:
describeStatein classAbstractNamedBean- Parameters:
state- the state to describe- Returns:
- the state in localized form
-
setKnownState
Perform setKnownState(int) for implementations that can't actually do it on the layout. Not intended for use by implementations that can.- Specified by:
setKnownStatein interfaceSensor- Parameters:
newState- the state to set- Throws:
JmriException- if unable to set the state
-
stateChangeCheck
Preprocess a Sensor state change request for specific implementations ofsetKnownState(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
Set our internal state information, and notify bean listeners.- Parameters:
s- the new state
-
getRawState
Description copied from interface:SensorUsed 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:
getRawStatein interfaceSensor- Returns:
- raw state value
-
setState
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:
setStatein interfaceNamedBean- Parameters:
s- the state- Throws:
JmriException- general error when setting the state fails
-
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.
-
setInverted
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:
setInvertedin interfaceSensor- Parameters:
inverted- true if the sensor should be inverted; false otherwise
-
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:
getInvertedin interfaceSensor- Returns:
- true if the electrical signal that normally results in an ACTIVE state now results in an INACTIVE state; false otherwise
-
canInvert
By default, all implementations based on this can invert -
setReporter
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:
setReporterin interfaceSensor- Parameters:
er- the reporter to set
-
getReporter
Description copied from interface:SensorRetrieve the reporter associated with this sensor if there is one.- Specified by:
getReporterin interfaceSensor- Returns:
- the reporter or null if there is no associated reporter
-
setPullResistance
Set the pull resistanceIn this default implementation, the input value is ignored.
- Specified by:
setPullResistancein interfaceSensor- Parameters:
r- PullResistance value to use.
-
getPullResistance
Get the pull resistance.- Specified by:
getPullResistancein interfaceSensor- Returns:
- the currently set PullResistance value. In this default implementation, PullResistance.PULL_OFF is always returned.
-
dispose
Description copied from class:AbstractNamedBeanDeactivate 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.
-