public class Timer
extends java.lang.Object
implements java.lang.Runnable
start()
function to run this class in a seperate
thread.Modifier and Type | Field and Description |
---|---|
static int |
SLEEP_PER_CYCLE_DEFAULT
The default amount of time to sleep between two adjustments in
milliseconds.
|
Constructor and Description |
---|
Timer(Lights lights,
long time)
This constructor creates a new timer that dims a group of lights from
full brightness until switched off in the end.
|
Timer(Lights lights,
long time,
int brightnessLevelStart,
int brightnessLevelGoal)
This constructor creates a new timer that dims a group of lights during a
longer time and switches the group of lights off in the end.
|
Timer(Lights lights,
long time,
int brightnessLevelStart,
int brightnessLevelGoal,
boolean switchOff)
This constructor creates a new timer that dims a group of lights during a
longer time.
|
Timer(Lights lights,
long time,
MilightColor colorStart,
MilightColor colorGoal,
boolean switchOff)
This constructor creates a new timer that changes the color and
brightness of a group of lights during a longer time.
|
Modifier and Type | Method and Description |
---|---|
void |
addTimerListener(TimerListener listener)
Use this function to add a new listener to the timer.
|
void |
removeTimerListener(TimerListener listener)
This function removes a listener from this timer which was added before
by
addTimerListener(TimerListener) . |
void |
run()
This function runs the timer with the settings given in the constructor
resp.
|
void |
setSleepPerCycle(int sleepPerCycle)
Set the amount of time to sleep between two cycles.
|
void |
start()
This function starts the timer in a new thread.
|
void |
stop()
This function stops the thread running the timer.
|
java.lang.String |
toString()
This function describes the objet as a string.
|
public static final int SLEEP_PER_CYCLE_DEFAULT
public Timer(Lights lights, long time, MilightColor colorStart, MilightColor colorGoal, boolean switchOff) throws java.io.IOException
start()
to run the timer. The amount of time to sleep
between two adjustments is set to SLEEP_PER_CYCLE_DEFAULT
.
You can change it with setSleepPerCycle(int)
.lights
- is the group of lights to dimtime
- is the overall time until the timer should finish in
millisecondscolorStart
- is color to start withcolorGoal
- is color the group of lights should have in the endswitchOff
- is true if the lights should be switched off after the
animation endsjava.io.IOException
- if the message to the WiFi box could not be sentpublic Timer(Lights lights, long time, int brightnessLevelStart, int brightnessLevelGoal, boolean switchOff) throws java.io.IOException, java.lang.IllegalArgumentException
start()
to run the timer. The amount of time
to sleep between two adjustments is set to
SLEEP_PER_CYCLE_DEFAULT
. You can change it with
setSleepPerCycle(int)
.lights
- is the group of lights to dimtime
- is the overall time until the timer should finish in
millisecondsbrightnessLevelStart
- is the brightness level to start with (between
MilightColor.MIN_BRIGHTNESS and MilightColor.MAX_BRIGHTNESS)brightnessLevelGoal
- is the brightness level the group of lights should have in the
end (between MilightColor.MIN_BRIGHTNESS and
MilightColor.MAX_BRIGHTNESS)switchOff
- is true if the lights should be switched off after the
animation endsjava.io.IOException
- if the message to the WiFi box could not be sentjava.lang.IllegalArgumentException
- if the brightness levels to start with or reach in the end
are not between MilightColor.MIN_BRIGHTNESS and
MilightColor.MAX_BRIGHTNESSpublic Timer(Lights lights, long time, int brightnessLevelStart, int brightnessLevelGoal) throws java.io.IOException, java.lang.IllegalArgumentException
start()
to run the timer. The amount of time to sleep
between two adjustments is set to SLEEP_PER_CYCLE_DEFAULT
.
You can change it with setSleepPerCycle(int)
.lights
- is the group of lights to dimtime
- is the overall time until the timer should finish in
millisecondsbrightnessLevelStart
- is the brightness level to start with (between
MilightColor.MIN_BRIGHTNESS and MilightColor.MAX_BRIGHTNESS)brightnessLevelGoal
- is the brightness level the group of lights should have in the
end (between MilightColor.MIN_BRIGHTNESS and
MilightColor.MAX_BRIGHTNESS)java.io.IOException
- if the message to the WiFi box could not be sentjava.lang.IllegalArgumentException
- if the brightness levels to start with or reach in the end
are not between MilightColor.MIN_BRIGHTNESS and
MilightColor.MAX_BRIGHTNESSpublic Timer(Lights lights, long time) throws java.io.IOException, java.lang.IllegalArgumentException
start()
to run the timer. The amount of time to sleep between two adjustments is
set to SLEEP_PER_CYCLE_DEFAULT
. You can change it with
setSleepPerCycle(int)
.lights
- is the group of lights to dimtime
- is the overall time until the timer should finish in
millisecondsjava.io.IOException
- if the message to the WiFi box could not be sentjava.lang.IllegalArgumentException
public void run()
run
in interface java.lang.Runnable
start()
public void stop()
start()
public void start()
public void setSleepPerCycle(int sleepPerCycle)
sleepPerCycle
- is the amount of time to sleep between two cycles in
milliseconds.public void addTimerListener(TimerListener listener)
listener
- is the listener to addpublic void removeTimerListener(TimerListener listener)
addTimerListener(TimerListener)
.listener
- is the listener to removepublic java.lang.String toString()
toString
in class java.lang.Object