Subversion Repositories HomeAutomation

Rev

Rev 1042 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1042 Rev 1590
Line 1... Line 1...
1
 
1
 
2
function Interval(callback, timeout)
2
function Interval(callback, timeout, single)
3
{
3
{
-
 
4
    if (single == null)
-
 
5
    {
-
 
6
        single = false;
-
 
7
    }
-
 
8
   
4
    this.myCallback = callback;
9
    this.myCallback = callback;
5
    this.myTimeout = timeout;
10
    this.myTimeout = timeout;
-
 
11
    this.mySingle = single;
6
    this.myIsRunning = false;
12
    this.myIsRunning = false;
7
}
13
}
8
 
14
 
9
Interval.myIntervals = new Array();
15
Interval.myIntervals = new Array();
10
Interval.prototype.myIsRunning = null;
16
Interval.prototype.myIsRunning = null;
11
Interval.prototype.myId = null;
17
Interval.prototype.myId = null;
12
Interval.prototype.myTimeout = null;
18
Interval.prototype.myTimeout = null;
-
 
19
Interval.prototype.mySingle = null;
13
Interval.prototype.myCallback = null;
20
Interval.prototype.myCallback = null;
14
 
21
 
15
Interval.triggerIntervalCallback = function(id)
22
Interval.triggerIntervalCallback = function(id)
16
{
23
{
17
    if (Interval.myIntervals[id])
24
    if (Interval.myIntervals[id])
Line 19... Line 26...
19
        //log("Interval:" + id + "> Triggered!\n");
26
        //log("Interval:" + id + "> Triggered!\n");
20
        Interval.myIntervals[id].triggerCallback();
27
        Interval.myIntervals[id].triggerCallback();
21
    }
28
    }
22
    else
29
    else
23
    {
30
    {
24
        log("Interval:" + id + "> Encountered a thread that have no javascript Interval object. This is not supposed to be possible, will try to remove this thread also.\n");
31
        log("Interval:" + id + "> Encountered a thread that have no javascript Interval object. This is not supposed to be possible...\n");
25
       
-
 
26
        if (!stopIntervalThread(id))
-
 
27
        {
-
 
28
            log("Interval:" + id + "> Interval thread seems to have already been stopped.\n");
-
 
29
        }
-
 
30
    }
-
 
31
}
-
 
32
 
-
 
33
Interval.prototype.triggerCallback = function()
-
 
34
{
-
 
35
    this.myCallback();
-
 
36
}
-
 
37
 
-
 
38
Interval.prototype.setTimeout = function(timeout)
-
 
39
{
-
 
40
    if (this.myTimeout != timeout)
-
 
41
    {
-
 
42
        this.myTimeout = timeout;
-
 
43
        setIntervalThreadTimeout(this.myId, timeout);
-
 
44
    }
32
    }
45
}
33
}
46
 
34
 
47
Interval.prototype.reset = function()
35
Interval.prototype.triggerCallback = function()
48
{
36
{
49
    setIntervalThreadTimeout(this.myId, this.myTimeout);
37
    this.myCallback();
50
}
38
}
51
 
39
 
52
Interval.prototype.setCallback = function(callback)
40
Interval.prototype.setCallback = function(callback)
53
{
41
{
54
    this.myCallback = callback;
42
    this.myCallback = callback;
Line 57... Line 45...
57
Interval.prototype.start = function()
45
Interval.prototype.start = function()
58
{
46
{
59
    if (!this.myIsRunning)
47
    if (!this.myIsRunning)
60
    {
48
    {
61
        this.myIsRunning = true;
49
        this.myIsRunning = true;
62
        this.myId = startIntervalThread(this.myTimeout)
50
        this.myId = startIntervalThread(this.myTimeout, this.mySingle)
63
        Interval.myIntervals[this.myId] = this;
51
        Interval.myIntervals[this.myId] = this;
64
    }
52
    }
65
}
53
}
66
 
54
 
67
Interval.prototype.stop = function()
55
Interval.prototype.stop = function()