jmri
Class AbstractVariableLight

java.lang.Object
  extended by jmri.AbstractNamedBean
      extended by jmri.AbstractLight
          extended by jmri.AbstractVariableLight
All Implemented Interfaces:
Serializable, Light, NamedBean
Direct Known Subclasses:
SerialLight

public abstract class AbstractVariableLight
extends AbstractLight
implements Serializable

Abstract class providing partial implementation of the logic of the Light interface when the Intensity is variable.

Eventually, this class will include transition code, but it isn't here yet, so the default setTransitionRate() implementation is inherited from AbstractLight

The structure is in part dictated by the limitations of the X10 protocol and implementations. 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:

  1. 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.

    Author:
    Dave Duchamp Copyright (C) 2004, Ken Cameron Copyright (C) 2008, Bob Jacobsen Copyright (C) 2008
    See Also:
    Serialized Form

    Field Summary
    protected  Timer alarmSyncUpdate
               
    protected  Timebase internalClock
               
    protected  PropertyChangeListener minuteChangeListener
               
    protected  Date mLastTransitionDate
               
    protected  long mNextTransitionTs
               
    protected  double mTransitionDuration
              Variables needed for saved values
    protected  double mTransitionTargetIntensity
              Variables needed but not saved to files/panels
     
    Fields inherited from class jmri.AbstractLight
    mActive, mClock, mControlSensor, mControlSensorName, mControlSensorSense, mControlTurnout, mControlTurnoutName, mControlType, mCurrentIntensity, mEnabled, mFastClockOffHour, mFastClockOffMin, mFastClockOnHour, mFastClockOnMin, mLightOnTimerActive, mMaxIntensity, mMinIntensity, mSensorListener, mState, mTimebaseListener, mTimedActive, mTimedControlListener, mTimedControlSensor, mTimedControlTimer, mTimedSensorListener, mTimedSensorName, mTimeOff, mTimeOn, mTimeOnDuration, mTurnoutListener, mTurnoutState
     
    Fields inherited from interface jmri.Light
    FAST_CLOCK_CONTROL, INTERMEDIATE, NO_CONTROL, OFF, ON, SENSOR_CONTROL, TIMED_ON_CONTROL, TRANSITIONING, TRANSITIONINGHIGHER, TRANSITIONINGLOWER, TRANSITIONINGTOFULLOFF, TRANSITIONINGTOFULLON, TURNOUT_STATUS_CONTROL
     
    Fields inherited from interface jmri.NamedBean
    INCONSISTENT, UNKNOWN
     
    Constructor Summary
    AbstractVariableLight(String systemName)
               
    AbstractVariableLight(String systemName, String userName)
               
     
    Method Summary
     double getTransitionTime()
              Get the number of fastclock minutes taken by a transition from full ON to full OFF or vice versa.
     boolean isIntensityVariable()
              Check if this object can handle variable intensity.
     boolean isTransitionAvailable()
              Can the Light change it's intensity setting slowly?
     boolean isTransitioning()
              Convenience method for checking if the intensity of the light is currently changing due to a transition.
    protected  void notifyTargetIntensityChange(double intensity)
              Change the stored target intensity value and do notification, but don't change anything in the hardware
    protected abstract  void sendIntensity(double intensity)
              Send a Dim/Bright commands to the hardware to reach a specific intensity.
    protected abstract  void sendOnOffCommand(int newState)
              Send a On/Off Command to the hardware
     void setState(int newState)
              Handle a request for a state change.
     void setTargetIntensity(double intensity)
              Set the intended new intensity value for the Light.
     void setTransitionTime(double minutes)
              Set the fast-clock duration for a transition from full ON to full OFF or vice-versa.
    protected  void startTransition(double intensity)
              Set up to start a transition
     
    Methods inherited from class jmri.AbstractLight
    activateLight, deactivateLight, doNewState, getControlSensorName, getControlSensorSense, getControlTimedOnSensorName, getControlTurnoutName, getControlTurnoutState, getControlType, getCurrentIntensity, getEnabled, getFastClockOffHour, getFastClockOffMin, getFastClockOnHour, getFastClockOnMin, getMaxIntensity, getMinIntensity, getState, getTargetIntensity, getTimedOnDuration, notifyStateChange, setControlSensor, setControlSensorSense, setControlTimedOnSensor, setControlTurnout, setControlTurnoutState, setControlType, setEnabled, setFastClockControlSchedule, setMaxIntensity, setMinIntensity, setTimedOnDuration, updateClockControlLight, updateIntensityHigh, updateIntensityIntermediate, updateIntensityLow
     
    Methods inherited from class jmri.AbstractNamedBean
    addPropertyChangeListener, dispose, firePropertyChange, getComment, getNumPropertyChangeListeners, getSystemName, getUserName, removePropertyChangeListener, setComment, setUserName
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     
    Methods inherited from interface jmri.NamedBean
    addPropertyChangeListener, dispose, getComment, getNumPropertyChangeListeners, getSystemName, getUserName, removePropertyChangeListener, setComment, setUserName
     

    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 Date mLastTransitionDate

    mNextTransitionTs

    protected long mNextTransitionTs

    internalClock

    protected Timebase internalClock

    alarmSyncUpdate

    protected Timer alarmSyncUpdate

    minuteChangeListener

    protected PropertyChangeListener minuteChangeListener
    Constructor Detail

    AbstractVariableLight

    public AbstractVariableLight(String systemName,
                                 String userName)

    AbstractVariableLight

    public AbstractVariableLight(String systemName)
    Method Detail

    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 permitted

    ON and OFF avoid use of variable intensity if MaxIntensity = 1.0 or MinIntensity = 0.0, and no transition is being used.

    Specified by:
    setState in interface Light
    Specified by:
    setState in interface NamedBean
    Overrides:
    setState in class AbstractLight

    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:
    setTargetIntensity in interface Light
    Overrides:
    setTargetIntensity in class AbstractLight
    Throws:
    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


    sendIntensity

    protected abstract void sendIntensity(double intensity)
    Send a Dim/Bright commands to the hardware to reach a specific intensity.


    sendOnOffCommand

    protected abstract void sendOnOffCommand(int newState)
    Send a On/Off Command to the hardware


    notifyTargetIntensityChange

    protected void notifyTargetIntensityChange(double intensity)
    Change the stored target intensity value and do notification, but don't change anything in the hardware

    Overrides:
    notifyTargetIntensityChange in class AbstractLight

    isIntensityVariable

    public boolean isIntensityVariable()
    Check if this object can handle variable intensity.

    Specified by:
    isIntensityVariable in interface Light
    Overrides:
    isIntensityVariable in class AbstractLight
    Returns:
    true, as this abstract class implements variable intensity.

    isTransitionAvailable

    public boolean isTransitionAvailable()
    Can the Light change it's 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:
    isTransitionAvailable in interface Light
    Overrides:
    isTransitionAvailable in class AbstractLight

    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:
    setTransitionTime in interface Light
    Overrides:
    setTransitionTime in class AbstractLight
    Throws:
    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:
    getTransitionTime in interface Light
    Overrides:
    getTransitionTime in class AbstractLight
    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:
    isTransitioning in interface Light
    Overrides:
    isTransitioning in class AbstractLight


    Copyright © 1997 - 2008 JMRI Community.
    JMRI, DecoderPro, PanelPro, SoundPro, DispatcherPro and associated logos are our trademarks.

    Additional information on copyright, trademarks and licenses is linked here.
    Site hosted by: SourceForge_Logo