Subversion Repositories HomeAutomation

Rev

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

Rev 999 Rev 1346
Line 2... Line 2...
2
function DS18x20(type, name, id)
2
function DS18x20(type, name, id)
3
{
3
{
4
    this.CanService(type, name, id);
4
    this.CanService(type, name, id);
5
   
5
   
6
    this.myLastValue = new Array();
6
    this.myLastValue = new Array();
-
 
7
 
7
}
8
}
8
 
9
 
9
extend(DS18x20, CanService);
10
extend(DS18x20, CanService);
10
 
11
 
11
DS18x20.prototype.myReportInterval = null;
12
DS18x20.prototype.myReportInterval = null;
12
DS18x20.prototype.myLastValue = null;
13
DS18x20.prototype.myLastValue = null;
13
 
14
 
14
DS18x20.prototype.canMessageHandler = function(canMessage)
15
DS18x20.prototype.canMessageHandler = function(canMessage)
15
{
16
{
-
 
17
var self = this;
16
    if (canMessage.getDirectionFlag() == "From_Owner")
18
    if (canMessage.getDirectionFlag() == "From_Owner")
17
    {
19
    {
18
        switch (canMessage.getCommandName())
20
        switch (canMessage.getCommandName())
19
        {
21
        {
20
        case "Temperature_Celsius":
22
        case "Temperature_Celsius":
21
        log(this.myName + ":" + this.myId + "> New value: " + canMessage.getData("Value") + "\n");
23
        //log(this.myName + ":" + this.myId + "> New value: " + canMessage.getData("Value") + "\n");
22
        this.myLastValue[canMessage.getData("SensorId")] = canMessage.getData("Value");
24
        this.myLastValue[canMessage.getData("SensorId")] = canMessage.getData("Value");
23
        this.callEvent("newValue", canMessage.getData("SensorId"));
25
        //this.callEvent("newValue", canMessage.getData("SensorId"));
-
 
26
var dataArray = new Array();
-
 
27
dataArray["service"] = self;
-
 
28
dataArray["sensor"] = canMessage.getData("SensorId");
-
 
29
dataArray["value"] = canMessage.getData("Value");
-
 
30
dataArray["moduleName"] = canMessage.getModuleName();
-
 
31
dataArray["moduleId"] = canMessage.getModuleId();
-
 
32
this.callEvent("newValue", dataArray);
24
        break;
33
        break;
25
       
34
       
26
        case "Sensor_Report_Interval":
35
        case "Sensor_Report_Interval":
27
        log(this.myName + ":" + this.myId + "> New report interval: " + canMessage.getData("Time") + "\n");
36
        log(this.myName + ":" + this.myId + "> New report interval: " + canMessage.getData("Time") + "\n");
28
        this.myReportInterval = canMessage.getData("Time");
37
        this.myReportInterval = canMessage.getData("Time");
Line 38... Line 47...
38
    return this.myLastValue[sensorId];
47
    return this.myLastValue[sensorId];
39
}
48
}
40
 
49
 
41
DS18x20.prototype.setReportInterval = function(time)
50
DS18x20.prototype.setReportInterval = function(time)
42
{
51
{
-
 
52
    log("Setting report int\n");
43
    var canMessage = new CanMessage("sns", "To_Owner", this.myName, this.myId, "Sensor_Report_Interval");
53
    var canMessage = new CanMessage("sns", "To_Owner", this.myName, this.myId, "Sensor_Report_Interval");
44
    canMessage.setData("Time", time);
54
    canMessage.setData("Time", time);
45
    sendMessage(canMessage);
55
    sendMessage(canMessage);
46
}
56
}