Subversion Repositories HomeAutomation

Rev

Rev 1242 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

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