Package jmri
Interface Sensor
-
- All Superinterfaces:
java.lang.Comparable<NamedBean>,DigitalIO,NamedBean,PropertyChangeProvider
- All Known Implementing Classes:
AbstractSensor,AcelaSensor,BiDiBSensor,CbusSensor,Dcc4PcSensor,DCCppSensor,EcosSensor,IpocsSensor,JMRIClientSensor,LnSensor,MarklinSensor,MqttSensor,NceSensor,OlcbSensor,RaspberryPiSensor,RfidSensor,RpsSensor,SerialSensor,SerialSensor,SerialSensor,SerialSensor,SerialSensor,SerialSensor,SRCPSensor,TamsSensor,TimeoutRfidSensor,XBeeSensor,XNetSensor,Z21CanSensor,Z21RMBusSensor
public interface Sensor extends DigitalIO
General input device representation. Often subclassed for specific types of sensors.
This file is part of JMRI.JMRI is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. See the "COPYING" file for a copy of this license.
JMRI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classSensor.PullResistance-
Nested classes/interfaces inherited from interface jmri.NamedBean
NamedBean.BadNameException, NamedBean.BadSystemNameException, NamedBean.BadUserNameException, NamedBean.DisplayOptions, NamedBean.DuplicateSystemNameException
-
-
Field Summary
Fields Modifier and Type Field Description static intACTIVEstatic intINACTIVEstatic org.slf4j.Loggerlogstatic java.lang.LongMAX_DEBOUNCEstatic java.lang.StringPROPERTY_ACTIVE_TIMERString constant for the Active Timer property.static java.lang.StringPROPERTY_GLOBAL_TIMERString constant for the Global Timer property.static java.lang.StringPROPERTY_INACTIVE_TIMERString constant for the InActive Timer property.static java.lang.StringPROPERTY_SENSOR_INVERTEDString constant for the inverted property.-
Fields inherited from interface jmri.NamedBean
DISPLAY_NAME_FORMAT, INCONSISTENT, PROPERTY_COMMENT, PROPERTY_ENABLED, PROPERTY_KNOWN_STATE, PROPERTY_STATE, PROPERTY_USERNAME, QUOTED_NAME_FORMAT, UNKNOWN
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description booleancanInvert()Determine if sensor can be inverted.voiddispose()Remove references to and from this object, so that it can eventually be garbage-collected.default intgetCommandedState()Query the commanded state.booleangetInverted()Get the inverted state.Sensor.PullResistancegetPullResistance()Get the pull resistanceintgetRawState()Used to return the Raw state of a sensor prior to the known state of a sensor being set.ReportergetReporter()Retrieve the reporter associated with this sensor if there is one.longgetSensorDebounceGoingActiveTimer()Get the active debounce delay.longgetSensorDebounceGoingInActiveTimer()Get the inactive debounce delay.booleangetUseDefaultTimerSettings()Does this sensor use the default timers values?default booleanisConsistentState()Show whether state is stable.default voidsetCommandedState(int s)Change the commanded state, which results in the relevant command(s) being sent to the hardware.voidsetInverted(boolean inverted)Control whether the actual sensor input is considered to be inverted, such that the normal electrical signal that normally results in an ACTIVE state now results in an INACTIVE state.voidsetKnownState(int newState)Set the known state on the layout.voidsetPullResistance(Sensor.PullResistance r)Set the pull resistancevoidsetReporter(Reporter re)Some sensor boards also serve the function of being able to report back train identities via such methods as RailCom.voidsetSensorDebounceGoingActiveTimer(long timer)Set the active debounce delay.voidsetSensorDebounceGoingInActiveTimer(long timer)Set the inactive debounce delay.voidsetUseDefaultTimerSettings(boolean flag)Use the timers specified in theSensorManagerfor the debounce delay.-
Methods inherited from interface jmri.DigitalIO
getKnownState, requestUpdateFromLayout
-
Methods inherited from interface jmri.NamedBean
addPropertyChangeListener, addPropertyChangeListener, compareSystemNameSuffix, compareTo, describeState, getBeanType, getComment, getDisplayName, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListenersByReference, getPropertyKeys, getRecommendedToolTip, getState, getSystemName, getUsageReport, getUserName, removeProperty, setComment, setProperty, setState, setUserName, toString, updateListenerRef, vetoableChange
-
Methods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
-
-
-
Field Detail
-
ACTIVE
static final int ACTIVE
- See Also:
- Constant Field Values
-
INACTIVE
static final int INACTIVE
- See Also:
- Constant Field Values
-
MAX_DEBOUNCE
static final java.lang.Long MAX_DEBOUNCE
-
PROPERTY_ACTIVE_TIMER
static final java.lang.String PROPERTY_ACTIVE_TIMER
String constant for the Active Timer property.- See Also:
- Constant Field Values
-
PROPERTY_INACTIVE_TIMER
static final java.lang.String PROPERTY_INACTIVE_TIMER
String constant for the InActive Timer property.- See Also:
- Constant Field Values
-
PROPERTY_GLOBAL_TIMER
static final java.lang.String PROPERTY_GLOBAL_TIMER
String constant for the Global Timer property.- See Also:
- Constant Field Values
-
PROPERTY_SENSOR_INVERTED
static final java.lang.String PROPERTY_SENSOR_INVERTED
String constant for the inverted property.- See Also:
- Constant Field Values
-
log
static final org.slf4j.Logger log
-
-
Method Detail
-
isConsistentState
default boolean isConsistentState()
Show whether state is stable. For turnouts, a consistent state is one you can safely run trains over. For lights, it's a state which is either on or off, not in between.- Specified by:
isConsistentStatein interfaceDigitalIO- Returns:
- true if state is valid and the known state is the same as commanded
-
setCommandedState
@InvokeOnLayoutThread default void setCommandedState(int s)
Change the commanded state, which results in the relevant command(s) being sent to the hardware. The exception is thrown if there are problems communicating with the layout hardware.- Specified by:
setCommandedStatein interfaceDigitalIO- Parameters:
s- the desired state
-
getCommandedState
default int getCommandedState()
Query the commanded state. This is a bound parameter, so you can also register a listener to be informed of changes.- Specified by:
getCommandedStatein interfaceDigitalIO- Returns:
- the commanded state
-
setKnownState
@InvokeOnLayoutThread void setKnownState(int newState) throws JmriException
Set the known state on the layout. This might not always be available, or effective, depending on the limits of the underlying system and implementation.- Parameters:
newState- the state to set- Throws:
JmriException- if unable to set the state
-
setInverted
@InvokeOnLayoutThread void setInverted(boolean inverted)
Control whether the actual sensor input is considered to be inverted, such that the normal electrical signal that normally results in an ACTIVE state now results in an INACTIVE state.Changing this changes the state from ACTIVE to INACTIVE and vice-versa, with notifications; UNKNOWN and INCONSISTENT are left unchanged.
- Parameters:
inverted- true if the sensor should be inverted; false otherwise
-
getInverted
boolean getInverted()
Get the inverted state.- Returns:
- true if the electrical signal that normally results in an ACTIVE state now results in an INACTIVE state; false otherwise
-
canInvert
boolean canInvert()
Determine if sensor can be inverted. When a turnout is inverted theACTIVEandINACTIVEstates are inverted on the layout.- Returns:
- true if can be inverted; false otherwise
-
dispose
void dispose()
Remove references to and from this object, so that it can eventually be garbage-collected.
-
getRawState
int getRawState()
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.- Returns:
- raw state value
-
setSensorDebounceGoingActiveTimer
void setSensorDebounceGoingActiveTimer(long timer)
Set the active debounce delay.- Parameters:
timer- delay in milliseconds; set to zero to de-activate debounce
-
getSensorDebounceGoingActiveTimer
long getSensorDebounceGoingActiveTimer()
Get the active debounce delay.- Returns:
- delay in milliseconds
-
setSensorDebounceGoingInActiveTimer
void setSensorDebounceGoingInActiveTimer(long timer)
Set the inactive debounce delay.- Parameters:
timer- delay in milliseconds; set to zero to de-activate debounce
-
getSensorDebounceGoingInActiveTimer
long getSensorDebounceGoingInActiveTimer()
Get the inactive debounce delay.- Returns:
- delay in milliseconds
-
setUseDefaultTimerSettings
void setUseDefaultTimerSettings(boolean flag)
Use the timers specified in theSensorManagerfor the debounce delay.- Parameters:
flag- true to set to current defaults if not previously true- Since:
- 4.9.2
-
getUseDefaultTimerSettings
boolean getUseDefaultTimerSettings()
Does this sensor use the default timers values? (A remarkably unfortunate name given the one above)- Returns:
- true if using default debounce values from the
SensorManager - Since:
- 4.9.2
-
setReporter
void setReporter(@CheckForNull Reporter re)
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.- Parameters:
re- the reporter to associate with the sensor
-
getReporter
@CheckForNull Reporter getReporter()
Retrieve the reporter associated with this sensor if there is one.- Returns:
- the reporter or null if there is no associated reporter
-
setPullResistance
@InvokeOnLayoutThread void setPullResistance(Sensor.PullResistance r)
Set the pull resistance- Parameters:
r- PullResistance value to use.
-
getPullResistance
Sensor.PullResistance getPullResistance()
Get the pull resistance- Returns:
- the currently set PullResistance value.
-
-