Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
1118 linlun 1
 
2
function SlowPWM(type, name, id)
3
{
4
    this.CanService(type, name, id);
5
    this.myLastValue = new Array();
6
}
7
 
8
extend(SlowPWM, CanService);
9
 
10
SlowPWM.prototype.myReportInterval = null;
11
SlowPWM.prototype.myLastValue = null;
12
 
13
SlowPWM.prototype.canMessageHandler = function(canMessage)
14
{
15
    if (canMessage.getDirectionFlag() == "From_Owner")
16
    {
17
        switch (canMessage.getCommandName())
18
        {
19
        case "SlowPWM":
20
        log(this.myName + ":" + this.myId + "> New value: " + canMessage.getData("Value") + "\n");
21
        this.myLastValue[canMessage.getData("Id")] = canMessage.getData("Value");
22
        this.callEvent("newValue", canMessage.getData("Id"));
23
        break;
24
 
25
        case "Report_Interval":
26
        log(this.myName + ":" + this.myId + "> New report interval: " + canMessage.getData("Time") + "\n");
27
        this.myReportInterval = canMessage.getData("Time");
28
        break;
29
        }
30
    }
31
 
32
    this.CanService.prototype.canMessageHandler.call(this, canMessage);
33
}
34
 
35
SlowPWM.prototype.getValue = function(sensorId)
36
{
37
    return this.myLastValue[sensorId];
38
}
39
 
40
 
41
SlowPWM.prototype.setReportInterval = function(time)
42
{
43
    var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "Report_Interval");
44
    canMessage.setData("Time", time);
45
    sendMessage(canMessage);
46
}
47
SlowPWM.prototype.setPWMValue = function(pwmvalue, sensorId)
48
{
49
    var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "SlowPWM");
50
    canMessage.setData("ChannelId", sensorId);
51
    canMessage.setData("Value", pwmvalue);
52
    sendMessage(canMessage);
53
}
54
SlowPWM.prototype.configure = function(pwmPeriod, pwmDefaultValue, DefaultState, StartUpState)
55
{
56
    var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "CONFIG");
57
    canMessage.setData("pwmPeriod", pwmPeriod);
58
    canMessage.setData("pwmDefaultValue", pwmDefaultValue);
59
    canMessage.setData("DefaultState", DefaultState);
60
    canMessage.setData("StartUpState", StartUpState);
61
    sendMessage(canMessage);
62
}
63