Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1713 | arune | 1 | |
| 2 | function PCAPWM(type, name, id) |
||
| 3 | { |
||
| 4 | this.CanService(type, name, id); |
||
| 5 | this.myLastValue = new Array(); |
||
| 6 | } |
||
| 7 | |||
| 8 | extend(PCAPWM, CanService); |
||
| 9 | |||
| 10 | PCAPWM.prototype.currentValue = 0; |
||
| 11 | PCAPWM.prototype.myReportInterval = null; |
||
| 12 | PCAPWM.prototype.myLastValue = null; |
||
| 13 | |||
| 14 | PCAPWM.prototype.canMessageHandler = function(canMessage) |
||
| 15 | { |
||
| 16 | var self = this; |
||
| 17 | if (canMessage.getDirectionFlag() == "From_Owner") |
||
| 18 | { |
||
| 19 | switch (canMessage.getCommandName()) |
||
| 20 | { |
||
| 21 | |||
| 22 | case "Pwm": |
||
| 23 | this.currentValue = canMessage.getData("Value")/39; |
||
| 24 | var dataArray = new Array(); |
||
| 25 | dataArray["service"] = self; |
||
| 26 | dataArray["channel"] = canMessage.getData("Id"); |
||
| 27 | dataArray["currentValue"] = (canMessage.getData("Value")/39); |
||
| 28 | dataArray["moduleName"] = canMessage.getModuleName(); |
||
| 29 | dataArray["moduleId"] = canMessage.getModuleId(); |
||
| 30 | this.callEvent("newValue", dataArray); |
||
| 31 | //log(this.myName + ":" + this.myId + "> Netstatus, " + connectString + frequencyString + "\n"); |
||
| 32 | break; |
||
| 33 | |||
| 34 | /*case "PCAPWM": |
||
| 35 | log(this.myName + ":" + this.myId + "> New value: " + canMessage.getData("Value") + "\n"); |
||
| 36 | this.myLastValue[canMessage.getData("Id")] = canMessage.getData("Value"); |
||
| 37 | this.callEvent("newValue", canMessage.getData("Id")); |
||
| 38 | break; |
||
| 39 | |||
| 40 | case "Report_Interval": |
||
| 41 | log(this.myName + ":" + this.myId + "> New report interval: " + canMessage.getData("Time") + "\n"); |
||
| 42 | this.myReportInterval = canMessage.getData("Time"); |
||
| 43 | break;*/ |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | this.CanService.prototype.canMessageHandler.call(this, canMessage); |
||
| 48 | } |
||
| 49 | |||
| 50 | PCAPWM.prototype.getValue = function(sensorId) |
||
| 51 | { |
||
| 52 | return this.myLastValue[sensorId]; |
||
| 53 | } |
||
| 54 | |||
| 55 | |||
| 56 | /*hwPWM.prototype.setReportInterval = function(time) |
||
| 57 | { |
||
| 58 | var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "Report_Interval"); |
||
| 59 | canMessage.setData("Time", time); |
||
| 60 | sendMessage(canMessage); |
||
| 61 | }*/ |
||
| 62 | |||
| 63 | /** |
||
| 64 | pwmValue in % with 0.01 resolution (Example: 55.25%) |
||
| 65 | */ |
||
| 66 | PCAPWM.prototype.setPWMValue = function(pwmvalue, sensorId) |
||
| 67 | { |
||
| 68 | var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "Pwm"); |
||
| 69 | canMessage.setData("Id", sensorId); |
||
| 70 | canMessage.setData("Value", pwmvalue*100); |
||
| 71 | sendMessage(canMessage); |
||
| 72 | |||
| 73 | this.myLastValue[sensorId] = pwmvalue; |
||
| 74 | } |
||
| 75 | /*hwPWM.prototype.configure = function(pwmPeriod, pwmDefaultValue, DefaultState, StartUpState) |
||
| 76 | { |
||
| 77 | var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "CONFIG"); |
||
| 78 | canMessage.setData("pwmPeriod", pwmPeriod); |
||
| 79 | canMessage.setData("pwmDefaultValue", pwmDefaultValue); |
||
| 80 | canMessage.setData("DefaultState", DefaultState); |
||
| 81 | canMessage.setData("StartUpState", StartUpState); |
||
| 82 | sendMessage(canMessage); |
||
| 83 | }*/ |
||
| 84 | |||
| 85 | PCAPWM.prototype.startFade = function(channel, speed, direction) |
||
| 86 | { |
||
| 87 | var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "Start_Fade"); |
||
| 88 | canMessage.setData("Channel", channel); |
||
| 89 | canMessage.setData("Speed", speed); |
||
| 90 | canMessage.setData("Direction", direction); |
||
| 91 | sendMessage(canMessage); |
||
| 92 | } |
||
| 93 | |||
| 94 | PCAPWM.prototype.stopFade = function(channel) |
||
| 95 | { |
||
| 96 | var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "Stop_Fade"); |
||
| 97 | canMessage.setData("Channel", channel); |
||
| 98 | sendMessage(canMessage); |
||
| 99 | } |
||
| 100 | |||
| 101 | PCAPWM.prototype.absFade = function(channel, speed, endValue) |
||
| 102 | { |
||
| 103 | log("sending: "+channel+" "+speed+" "+endValue*39+"\n"); |
||
| 104 | var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "Abs_Fade"); |
||
| 105 | canMessage.setData("Channel", channel); |
||
| 106 | canMessage.setData("Speed", speed); |
||
| 107 | canMessage.setData("EndValue", endValue*39); |
||
| 108 | sendMessage(canMessage); |
||
| 109 | } |
||
| 110 | |||
| 111 | PCAPWM.prototype.relFade = function(channel, speed, direction, steps) |
||
| 112 | { |
||
| 113 | var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "Rel_Fade"); |
||
| 114 | canMessage.setData("Channel", channel); |
||
| 115 | canMessage.setData("Speed", speed); |
||
| 116 | canMessage.setData("Direction", direction); |
||
| 117 | canMessage.setData("Steps", steps*39); |
||
| 118 | sendMessage(canMessage); |
||
| 119 | } |
||
| 120 | |||
| 121 | PCAPWM.prototype.demo = function(channel, speed, steps) |
||
| 122 | { |
||
| 123 | var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "Demo"); |
||
| 124 | canMessage.setData("Channel", channel); |
||
| 125 | canMessage.setData("Speed", speed); |
||
| 126 | canMessage.setData("Steps", steps*39); |
||
| 127 | sendMessage(canMessage); |
||
| 128 | } |
||
| 129 |