Class AbstractVariableLight
- All Implemented Interfaces:
Comparable<NamedBean>,AnalogIO,PropertyChangeProvider,DigitalIO,Light,NamedBean,VariableLight
- Direct Known Subclasses:
AnymaDMX_UsbLight,BiDiBLight,MqttLight,SerialLight
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.AbsoluteOrRelativeNested classes/interfaces inherited from interface jmri.NamedBean
NamedBean.BadNameException, NamedBean.BadSystemNameException, NamedBean.BadUserNameException, NamedBean.DisplayOptions, NamedBean.DuplicateSystemNameException -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Timerprotected Timebaseprotected PropertyChangeListenerprotected Dateprotected longprotected doubleVariables needed for saved valuesprotected doubleVariables needed but not saved to files/panelsFields inherited from class jmri.implementation.AbstractLight
lightControlList, mActive, mCurrentIntensity, mEnabled, mMaxIntensity, mMinIntensity, mStateFields inherited from class jmri.implementation.AbstractNamedBean
listenerRefs, mSystemName, registerFields 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_CONTROLFields 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.VariableLight
PROPERTY_CURRENT_INTENSITY, PROPERTY_MAX_INTENSITY, PROPERTY_MIN_INTENSITY -
Constructor Summary
ConstructorsConstructorDescriptionAbstractVariableLight(String systemName) AbstractVariableLight(String systemName, String userName) -
Method Summary
Modifier and TypeMethodDescriptiondescribeState(int state) System independent operational instance variables (not saved between runs).Is this AnalogIO absolute or relative?doubleQuery the commanded value.doubleGet the current intensity value.doublegetMax()Get the maximum value of this AnalogIO.doubleGet the current value of the maxIntensity property.doublegetMin()Get the minimum value of this AnalogIO.doubleGet the current value of the minIntensity property.protected abstract intProvide the number of steps available between min and max intensitydoubleGet the resolution of this AnalogIO.doublegetState(double v) Provide generic access to internal state.doubleGet the target intensity value for the current transition, if any.doubleGet the number of fastclock minutes taken by a transition from full ON to full OFF or vice versa.booleanCan the Light change its intensity setting slowly?booleanConvenience method for checking if the intensity of the light is currently changing due to a transition.protected voidLayout 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 transitionMethods inherited from class jmri.implementation.AbstractLight
activateLight, addLightControl, clearLightControls, deactivateLight, doNewState, getBeanType, getEnabled, getLightControlList, getState, getUsageReport, notifyStateChange, setEnabledMethods 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, vetoableChangeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface jmri.AnalogIO
getKnownAnalogValueMethods inherited from interface jmri.Light
activateLight, addLightControl, clearLightControls, deactivateLight, getCommandedState, getEnabled, getKnownState, getLightControlList, getState, setCommandedState, setEnabledMethods 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, vetoableChangeMethods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListenerMethods inherited from interface jmri.VariableLight
isConsistentState, isConsistentValue, requestUpdateFromLayout
-
Field Details
-
mTransitionDuration
Variables needed for saved values -
mTransitionTargetIntensity
Variables needed but not saved to files/panels -
mLastTransitionDate
-
mNextTransitionTs
-
internalClock
-
alarmSyncUpdate
-
minuteChangeListener
-
-
Constructor Details
-
AbstractVariableLight
-
AbstractVariableLight
-
-
Method Details
-
describeState
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
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
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:
IllegalArgumentException- when intensity is less than 0.0 or more than 1.0
-
startTransition
Set up to start a transition- Parameters:
intensity- target intensity
-
sendIntensity
Send a Dim/Bright commands to the hardware to reach a specific intensity.- Parameters:
intensity- new intensity
-
sendOnOffCommand
Send a On/Off Command to the hardware- Parameters:
newState- new state
-
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
Provide the number of steps available between min and max intensity- Returns:
- number of steps
-
notifyTargetIntensityChange
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
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
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:
IllegalArgumentException- if minutes is not valid
-
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
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
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
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
Used when current state comes from layout- Parameters:
value- Observed current state
-
setCommandedAnalogValue
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
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
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:
IllegalArgumentException- when intensity is less than 0.0 or more than 1.0IllegalArgumentException- when intensity is not less than the current value of the maxIntensity property
-
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
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:
IllegalArgumentException- when intensity is less than 0.0 or more than 1.0IllegalArgumentException- when intensity is not greater than the current value of the minIntensity property
-
getState
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
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
Description copied from interface:AnalogIOGet the resolution of this AnalogIO.- Specified by:
getResolutionin interfaceAnalogIO- Returns:
- analog resolution.
-
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
Description copied from interface:AnalogIOGet the minimum value of this AnalogIO. -
getMax
Description copied from interface:AnalogIOGet the maximum value of this AnalogIO. -
getAbsoluteOrRelative
Description copied from interface:AnalogIOIs this AnalogIO absolute or relative?- Specified by:
getAbsoluteOrRelativein interfaceAnalogIO- Returns:
- if absolute or relative.
-