Class AbstractVariableLight
- java.lang.Object
-
- jmri.implementation.AbstractNamedBean
-
- jmri.implementation.AbstractLight
-
- jmri.implementation.AbstractVariableLight
-
- All Implemented Interfaces:
java.lang.Comparable<NamedBean>,AnalogIO,PropertyChangeProvider,DigitalIO,Light,NamedBean,VariableLight
- Direct Known Subclasses:
AnymaDMX_UsbLight,BiDiBLight,MqttLight,SerialLight
public abstract class AbstractVariableLight extends AbstractLight implements VariableLight
Abstract class providing partial implementation of the logic of the Light interface when the Intensity is variable.Now it includes the transition code, but it only does the steps on the fast minute clock. Later it may do its own timing but this was simple to piggy back on the fast minute listener.
The structure is in part dictated by the limitations of the X10 protocol and implementations. However, it is not limited to X10 devices only. Other interfaces that have a way to provide a dimmable light should use it.
X10 has on/off commands, and separate commands for setting a variable intensity via "dim" commands. Some X10 implementations use relative dimming, some use absolute dimming. Some people set the dim level of their Lights and then just use on/off to turn control the lamps; in that case we don't want to send dim commands. Further, X10 communications is very slow, and sending a complete set of dim operations can take a long time. So the algorithm is:
- Until the intensity has been explicitly set different from 1.0 or 0.0, no intensity commands are to be sent over the power line.
Unlike the parent class, this stores CurrentIntensity and TargetIntensity in separate variables.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jmri.AnalogIO
AnalogIO.AbsoluteOrRelative
-
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 protected javax.swing.TimeralarmSyncUpdateprotected TimebaseinternalClockprotected java.beans.PropertyChangeListenerminuteChangeListenerprotected java.util.DatemLastTransitionDateprotected longmNextTransitionTsprotected doublemTransitionDurationVariables needed for saved valuesprotected doublemTransitionTargetIntensityVariables needed but not saved to files/panels-
Fields inherited from class jmri.implementation.AbstractLight
lightControlList, mActive, mCurrentIntensity, mEnabled, mMaxIntensity, mMinIntensity, mState
-
Fields inherited from class jmri.implementation.AbstractNamedBean
listenerRefs, mSystemName, register
-
Fields inherited from interface jmri.Light
FAST_CLOCK_CONTROL, INTERMEDIATE, NO_CONTROL, PROPERTY_TARGET_INTENSITY, SENSOR_CONTROL, TIMED_ON_CONTROL, TRANSITIONING, TRANSITIONINGHIGHER, TRANSITIONINGLOWER, TRANSITIONINGTOFULLOFF, TRANSITIONINGTOFULLON, TURNOUT_STATUS_CONTROL, TWO_SENSOR_CONTROL
-
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
-
Fields inherited from interface jmri.VariableLight
PROPERTY_CURRENT_INTENSITY, PROPERTY_MAX_INTENSITY, PROPERTY_MIN_INTENSITY
-
-
Constructor Summary
Constructors Constructor Description AbstractVariableLight(java.lang.String systemName)AbstractVariableLight(java.lang.String systemName, java.lang.String userName)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.StringdescribeState(int state)System independent operational instance variables (not saved between runs).AnalogIO.AbsoluteOrRelativegetAbsoluteOrRelative()Is this AnalogIO absolute or relative?doublegetCommandedAnalogValue()Query the commanded value.doublegetCurrentIntensity()Get the current intensity value.doublegetMax()Get the maximum value of this AnalogIO.doublegetMaxIntensity()Get the current value of the maxIntensity property.doublegetMin()Get the minimum value of this AnalogIO.doublegetMinIntensity()Get the current value of the minIntensity property.protected abstract intgetNumberOfSteps()Provide the number of steps available between min and max intensitydoublegetResolution()Get the resolution of this AnalogIO.doublegetState(double v)Provide generic access to internal state.doublegetTargetIntensity()Get the target intensity value for the current transition, if any.doublegetTransitionTime()Get the number of fastclock minutes taken by a transition from full ON to full OFF or vice versa.booleanisTransitionAvailable()Can the Light change its intensity setting slowly?booleanisTransitioning()Convenience method for checking if the intensity of the light is currently changing due to a transition.protected voidnewInternalMinute()Layout time has changed to a new minute.protected voidnotifyTargetIntensityChange(double intensity)Change the stored target intensity value and do notification, but don't change anything in the hardwareprotected abstract voidsendIntensity(double intensity)Send a Dim/Bright commands to the hardware to reach a specific intensity.protected abstract voidsendOnOffCommand(int newState)Send a On/Off Command to the hardwarevoidsetCommandedAnalogValue(double value)Change the commanded value, which results in the relevant command(s) being sent to the hardware.voidsetMaxIntensity(double intensity)Set the value of the maxIntensity property.voidsetMinIntensity(double intensity)Set the value of the minIntensity property.protected voidsetObservedAnalogValue(double value)Used when current state comes from layoutvoidsetState(double newState)Provide generic access to internal state.voidsetState(int newState)Handle a request for a state change.voidsetTargetIntensity(double intensity)Set the intended new intensity value for the Light.voidsetTransitionTime(double minutes)Set the fast-clock duration for a transition from full ON to full OFF or vice-versa.protected voidstartTransition(double intensity)Set up to start a transition-
Methods inherited from class jmri.implementation.AbstractLight
activateLight, addLightControl, clearLightControls, deactivateLight, doNewState, getBeanType, getEnabled, getLightControlList, getState, getUsageReport, notifyStateChange, setEnabled
-
Methods inherited from class jmri.implementation.AbstractNamedBean
addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListener, compareSystemNameSuffix, dispose, 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, vetoableChange
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jmri.AnalogIO
getKnownAnalogValue
-
Methods inherited from interface jmri.Light
activateLight, addLightControl, clearLightControls, deactivateLight, getCommandedState, getEnabled, getKnownState, getLightControlList, getState, setCommandedState, setEnabled
-
Methods inherited from interface jmri.NamedBean
addPropertyChangeListener, addPropertyChangeListener, compareSystemNameSuffix, compareTo, dispose, getBeanType, getComment, getDisplayName, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListenersByReference, getPropertyKeys, getRecommendedToolTip, getSystemName, getUsageReport, getUserName, removeProperty, setComment, setProperty, setUserName, toString, updateListenerRef, vetoableChange
-
Methods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
Methods inherited from interface jmri.VariableLight
isConsistentState, isConsistentValue, requestUpdateFromLayout
-
-
-
-
Field Detail
-
mTransitionDuration
protected double mTransitionDuration
Variables needed for saved values
-
mTransitionTargetIntensity
protected double mTransitionTargetIntensity
Variables needed but not saved to files/panels
-
mLastTransitionDate
protected java.util.Date mLastTransitionDate
-
mNextTransitionTs
protected long mNextTransitionTs
-
internalClock
protected Timebase internalClock
-
alarmSyncUpdate
protected javax.swing.Timer alarmSyncUpdate
-
minuteChangeListener
protected java.beans.PropertyChangeListener minuteChangeListener
-
-
Constructor Detail
-
AbstractVariableLight
public AbstractVariableLight(java.lang.String systemName, java.lang.String userName)
-
AbstractVariableLight
public AbstractVariableLight(java.lang.String systemName)
-
-
Method Detail
-
describeState
@Nonnull public java.lang.String describeState(int state)
System independent operational instance variables (not saved between runs).- Specified by:
describeStatein interfaceNamedBean- Overrides:
describeStatein classAbstractLight- Parameters:
state- the state to describe- Returns:
- the state in localized form
-
setState
public void setState(int newState)
Handle a request for a state change. ON and OFF go to the MaxIntensity and MinIntensity, specifically, and all others are not permittedON and OFF avoid use of variable intensity if MaxIntensity = 1.0 or MinIntensity = 0.0, and no transition is being used.
-
setTargetIntensity
public void setTargetIntensity(double intensity)
Set the intended new intensity value for the Light. If transitions are in use, they will be applied.Bound property between 0 and 1.
A value of 0.0 corresponds to full off, and a value of 1.0 corresponds to full on.
Values at or below the minIntensity property will result in the Light going to the OFF state immediately. Values at or above the maxIntensity property will result in the Light going to the ON state immediately.
- Specified by:
setTargetIntensityin interfaceVariableLight- Parameters:
intensity- the desired brightness- Throws:
java.lang.IllegalArgumentException- when intensity is less than 0.0 or more than 1.0
-
startTransition
protected void startTransition(double intensity)
Set up to start a transition- Parameters:
intensity- target intensity
-
sendIntensity
protected abstract void sendIntensity(double intensity)
Send a Dim/Bright commands to the hardware to reach a specific intensity.- Parameters:
intensity- new intensity
-
sendOnOffCommand
protected abstract void sendOnOffCommand(int newState)
Send a On/Off Command to the hardware- Parameters:
newState- new state
-
newInternalMinute
protected void newInternalMinute()
Layout time has changed to a new minute. Process effect that might be having on intensity. Currently, this implementation assumes there's a fixed number of steps between min and max brightness.
-
getNumberOfSteps
protected abstract int getNumberOfSteps()
Provide the number of steps available between min and max intensity- Returns:
- number of steps
-
notifyTargetIntensityChange
protected void notifyTargetIntensityChange(double intensity)
Change the stored target intensity value and do notification, but don't change anything in the hardware- Overrides:
notifyTargetIntensityChangein classAbstractLight- Parameters:
intensity- intensity value
-
isTransitionAvailable
public boolean isTransitionAvailable()
Description copied from interface:VariableLightCan the Light change its intensity setting slowly?If true, this Light supports a non-zero value of the transitionTime property, which controls how long the Light will take to change from one intensity level to another.
Unbound property
- Specified by:
isTransitionAvailablein interfaceVariableLight- Returns:
- true if brightness can fade between two states; false otherwise
-
setTransitionTime
public void setTransitionTime(double minutes)
Set the fast-clock duration for a transition from full ON to full OFF or vice-versa.Bound property
- Specified by:
setTransitionTimein interfaceVariableLight- Parameters:
minutes- time to fade- Throws:
java.lang.IllegalArgumentException- if minutes is not valid
-
getTransitionTime
public double getTransitionTime()
Get the number of fastclock minutes taken by a transition from full ON to full OFF or vice versa.- Specified by:
getTransitionTimein interfaceVariableLight- Returns:
- 0.0 if the output intensity transition is instantaneous
-
isTransitioning
public boolean isTransitioning()
Convenience method for checking if the intensity of the light is currently changing due to a transition.Bound property so that listeners can conveniently learn when the transition is over.
- Specified by:
isTransitioningin interfaceVariableLight- Returns:
- is transitioning
-
getCurrentIntensity
public double getCurrentIntensity()
Get the current intensity value. If the Light is currently transitioning, this may be either an intermediate or final value.A value of 0.0 corresponds to full off, and a value of 1.0 corresponds to full on.
- Specified by:
getCurrentIntensityin interfaceVariableLight- Returns:
- current intensity
-
getTargetIntensity
public double getTargetIntensity()
Get the target intensity value for the current transition, if any. If the Light is not currently transitioning, this is the current intensity value.A value of 0.0 corresponds to full off, and a value of 1.0 corresponds to full on.
Bound property
- Specified by:
getTargetIntensityin interfaceVariableLight- Returns:
- target intensity
-
setObservedAnalogValue
protected void setObservedAnalogValue(double value)
Used when current state comes from layout- Parameters:
value- Observed current state
-
setCommandedAnalogValue
public void setCommandedAnalogValue(double value) throws JmriException
Description copied from interface:AnalogIOChange the commanded value, 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.The value must be a valid number, not a NaN or infinity number.
- Specified by:
setCommandedAnalogValuein interfaceAnalogIO- Parameters:
value- the desired analog value- Throws:
JmriException- general error when setting the value fails
-
getMinIntensity
public double getMinIntensity()
Get the current value of the minIntensity property.A value of 0.0 corresponds to full off, and a value of 1.0 corresponds to full on.
- Specified by:
getMinIntensityin interfaceVariableLight- Returns:
- min intensity value
-
setMinIntensity
public void setMinIntensity(double intensity)
Set the value of the minIntensity property.Bound property between 0 and 1.
A value of 0.0 corresponds to full off, and a value of 1.0 corresponds to full on.
- Specified by:
setMinIntensityin interfaceVariableLight- Parameters:
intensity- intensity value- Throws:
java.lang.IllegalArgumentException- when intensity is less than 0.0 or more than 1.0java.lang.IllegalArgumentException- when intensity is not less than the current value of the maxIntensity property
-
getMaxIntensity
public double getMaxIntensity()
Get the current value of the maxIntensity property.A value of 0.0 corresponds to full off, and a value of 1.0 corresponds to full on.
- Specified by:
getMaxIntensityin interfaceVariableLight- Returns:
- max intensity
-
setMaxIntensity
public void setMaxIntensity(double intensity)
Set the value of the maxIntensity property.Bound property between 0 and 1.
A value of 0.0 corresponds to full off, and a value of 1.0 corresponds to full on.
- Specified by:
setMaxIntensityin interfaceVariableLight- Parameters:
intensity- max intensity- Throws:
java.lang.IllegalArgumentException- when intensity is less than 0.0 or more than 1.0java.lang.IllegalArgumentException- when intensity is not greater than the current value of the minIntensity property
-
getState
public double getState(double v)
Provide generic access to internal state.This generally shouldn't be used by Java code; use the class-specific form instead (getCommandedAnalogValue). This is provided to make scripts easier to read.
-
setState
public void setState(double newState) throws JmriException
Provide generic access to internal state.This generally shouldn't be used by Java code; use the class-specific form instead (setCommandedAnalogValue). This is provided to make scripts access easier to read.
- Specified by:
setStatein interfaceAnalogIO- Parameters:
newState- the analog value- Throws:
JmriException- general error when setting the state fails
-
getResolution
public double getResolution()
Description copied from interface:AnalogIOGet the resolution of this AnalogIO.- Specified by:
getResolutionin interfaceAnalogIO- Returns:
- analog resolution.
-
getCommandedAnalogValue
public double getCommandedAnalogValue()
Description copied from interface:AnalogIOQuery the commanded value. This is a bound parameter, so you can also register a listener to be informed of changes.The result must be a valid number, not a NaN or infinity number.
- Specified by:
getCommandedAnalogValuein interfaceAnalogIO- Returns:
- the analog value
-
getMin
public double getMin()
Description copied from interface:AnalogIOGet the minimum value of this AnalogIO.
-
getMax
public double getMax()
Description copied from interface:AnalogIOGet the maximum value of this AnalogIO.
-
getAbsoluteOrRelative
public AnalogIO.AbsoluteOrRelative getAbsoluteOrRelative()
Description copied from interface:AnalogIOIs this AnalogIO absolute or relative?- Specified by:
getAbsoluteOrRelativein interfaceAnalogIO- Returns:
- if absolute or relative.
-
-