stella.roof
Class Blinker

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by stella.parameter.AbstractParameter
                  extended by stella.parameter.AbstractTrigger
                      extended by stella.parameter.SimpleTrigger
                          extended by stella.parameter.SimpleEventTrigger
                              extended by stella.roof.Blinker
All Implemented Interfaces:
Cloneable, EventListener, EventTrigger, Parameter, ParameterDepending, Trigger, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, Reloadable, ResourceSupplying

public class Blinker
extends SimpleEventTrigger
implements ParameterDepending

A blinker is used to provide some sort of a warning signal before the STELLA roof starts moving. Currently a solution with flashing light is favoured, but in principle also a sound-signal is possible.
The blinker provides a method for preceeding a roof-close event, blinkClose() and a method for preceeding a roof-open event, blinkOpen(). Both methods may notify a monitor when the blinking phase ended. Two different methods are used to allow different flashing intervals on open and close which may be desired if quick closing of the roof is more important than proper warning. The trigger value is true if the blinker is in its flashing state.

The blinking interval is definable via the KEY_PHASEON and the KEY_PHASEOFF properties. These give the on/off durations in ms. The entire length of the blinking phase is determined via the KEY_BLINKOPEN and KEY_BLINKCLOSE properties, the required blinker paramter is stated in #KEY_LIGHTSWITCH.


Nested Class Summary
private  class Blinker.SwitchTask
          A timer task class that writes a string to the serial line.
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private  TimerTask blink
          The timer task ending the blinking phase.
private static long DEFBLINKCLOSE
          The default duration of the blink phase on close.
private static long DEFBLINKOPEN
          The default duration of the blink phase on open.
static String DEFNAME
          The default name of this trigger.
private static long DEFPHASEOFF
          The default duration of the off-phase.
private static long DEFPHASEON
          The default duration of the on-phase.
static String KEY_BLINKCLOSE
          The key for the duration of the entire blink phase on close, in ms.
static String KEY_BLINKOPEN
          The key for the duration of the entire blink phase on open, in ms.
static String KEY_PHASEOFF
          The key determining the duration of the off-phase, in ms.
static String KEY_PHASEON
          The key determining the duration of the on-phase, in ms.
static String KEY_SIGNALSWITCH
          The name of the light switch trigger.
private  Switch light
          The serial server for switching the light.
private  TimerTask off
          The timer task switching the light off.
private  TimerTask on
          The timer task switching the light on.
private  Timer timer
          The timer task scheduler used for blinking and stopping.
 
Fields inherited from class stella.parameter.SimpleTrigger
KEY_INITBOOLEAN
 
Fields inherited from class stella.parameter.AbstractParameter
KEY_FORMAT, KEY_NAME, KEY_PRESERVE, UNKNOWN
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Constructor Summary
Blinker(Map prop)
          Constructs a new blinker object.
 
Method Summary
 void blinkClose()
          Blinks before closing the roof.
 void blinkOpen()
          Blinks before opening the roof.
private  void doBlink(long onperiod, long offperiod, long duration)
          Performs the blinking, set the trigger to true on start and resets it after the blinking phase.
 long getCloseBlinkPeriod()
          Returns the entire time of the blinking period on close-roof actions.
 long getOpenBlinkPeriod()
          Returns the entire time of the blinking period on open-roof actions.
 void registerParameter(Parameter lux)
          Registers the paramters.
 void stopBlink()
          Quit blinking phase immediately.
 
Methods inherited from class stella.parameter.SimpleEventTrigger
getMonitor, registerMonitor, setTrigger, toggleTrigger
 
Methods inherited from class stella.parameter.SimpleTrigger
getLastToggleTime, getTrigger, init, rescanned
 
Methods inherited from class stella.parameter.AbstractTrigger
get, getElapsedToggleTime, isTrue, set
 
Methods inherited from class stella.parameter.AbstractParameter
createParameter, delivers, exit, getFormatted, getFormatted, getName, getPreserveFile, getString, getString, register, setName, toString
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, keyCreate, keyCreate, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, reload, removeProperty, setObject, setProperties, setProperty, stringProperties
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.Reloadable
reload
 
Methods inherited from interface stella.Parameter
getFormatted, getName, getString
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 

Field Detail

KEY_PHASEON

public static final String KEY_PHASEON
The key determining the duration of the on-phase, in ms.

See Also:
Constant Field Values

KEY_PHASEOFF

public static final String KEY_PHASEOFF
The key determining the duration of the off-phase, in ms.

See Also:
Constant Field Values

KEY_BLINKOPEN

public static final String KEY_BLINKOPEN
The key for the duration of the entire blink phase on open, in ms.

See Also:
Constant Field Values

KEY_BLINKCLOSE

public static final String KEY_BLINKCLOSE
The key for the duration of the entire blink phase on close, in ms.

See Also:
Constant Field Values

KEY_SIGNALSWITCH

public static final String KEY_SIGNALSWITCH
The name of the light switch trigger.

See Also:
Constant Field Values

DEFNAME

public static final String DEFNAME
The default name of this trigger.

See Also:
Constant Field Values

DEFPHASEON

private static final long DEFPHASEON
The default duration of the on-phase.

See Also:
Constant Field Values

DEFPHASEOFF

private static final long DEFPHASEOFF
The default duration of the off-phase.

See Also:
Constant Field Values

DEFBLINKOPEN

private static final long DEFBLINKOPEN
The default duration of the blink phase on open.

See Also:
Constant Field Values

DEFBLINKCLOSE

private static final long DEFBLINKCLOSE
The default duration of the blink phase on close.

See Also:
Constant Field Values

light

private Switch light
The serial server for switching the light.


timer

private Timer timer
The timer task scheduler used for blinking and stopping.


on

private TimerTask on
The timer task switching the light on.


off

private TimerTask off
The timer task switching the light off.


blink

private TimerTask blink
The timer task ending the blinking phase.

Constructor Detail

Blinker

public Blinker(Map prop)
Constructs a new blinker object. After construction, the serial server has to be registered before the blinker is useable. Additionally, the main timer task scheduler is constructed as a demon timer.

Method Detail

registerParameter

public void registerParameter(Parameter lux)
Registers the paramters. Only if a trigger of instance RS485Switch and named after KEY_SIGNALSWITCH is found blinking will occur as planned.

Specified by:
registerParameter in interface ParameterDepending

getOpenBlinkPeriod

public long getOpenBlinkPeriod()
Returns the entire time of the blinking period on open-roof actions. Note that the elapsed time of the blinking phase can be queried with the generic trigger methods SimpleTrigger.getLastToggleTime() and AbstractTrigger.getElapsedToggleTime().

Returns:
The entire duration of the blinking phase in ms.

getCloseBlinkPeriod

public long getCloseBlinkPeriod()
Returns the entire time of the blinking period on close-roof actions. Note that the elapsed time of the blinking phase can be queried with the generic trigger methods SimpleTrigger.getLastToggleTime() and AbstractTrigger.getElapsedToggleTime().

Returns:
The entire duration of the blinking phase in ms.

blinkOpen

public void blinkOpen()
Blinks before opening the roof. The method is non-blocking. When the blinking period is over, a registered monitor is notified. Note that due to timing problems it may happen that a monitor is also notified at the beginning of the blinking phase.


blinkClose

public void blinkClose()
Blinks before closing the roof. The method is non-blocking. When the blinking period is over, a registered monitor is notified. Note that due to timing problems it may happen that a monitor is also notified at the beginning of the blinking phase.


stopBlink

public void stopBlink()
Quit blinking phase immediately. The timer tasks ruling the blinking and the canceling of the blink phase are all canceled premature.


doBlink

private void doBlink(long onperiod,
                     long offperiod,
                     long duration)
Performs the blinking, set the trigger to true on start and resets it after the blinking phase. If a monitor was registered it is probably invoked twice, at the start and at the end of the blinking phase.
The method takes three arguments, the length of the on-state, the length of the off-state and the entire duration of the blinking phase. The entire blinking is solved with three timer tasks, the first switching the light on periodically starts immediately at an on+off period, the second one switching off the light periodically at the same period, but delayed for the on-phase and the third timer task scheduled for a single execution after the entire blinking phase has ended.

Parameters:
onperiod - The duration of the on-phase, in ms.
offperiod - The duration of the off-phase, in ms.
duration - The entire duration of the blinking phase, in ms.