Subversion Repositories HomeAutomation

Rev

Rev 1242 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  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"));
  22.         break;
  23.        
  24.         case "Report_Interval":
  25.         this.myReportInterval = canMessage.getData("Time");
  26.         break;
  27.         }
  28.     }
  29.     this.CanService.prototype.canMessageHandler.call(this, canMessage);
  30. }
  31.  
  32. softPWM.prototype.getValue = function(sensorId)
  33. {
  34.     return this.myLastValue[sensorId];
  35. }
  36.  
  37.  
  38. softPWM.prototype.setReportInterval = function(time)
  39. {
  40.     var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "Report_Interval");
  41.     canMessage.setData("Time", time);
  42.     sendMessage(canMessage);
  43. }
  44. softPWM.prototype.setPWMValue = function(pwmvalue, sensorId)
  45. {
  46.     var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "Pwm");
  47.     canMessage.setData("Id", sensorId);
  48.     canMessage.setData("Value", pwmvalue);
  49.     sendMessage(canMessage);
  50. }
  51. softPWM.prototype.configure = function(pwmPeriod, pwmResolution)
  52. {
  53.     var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "CONFIG");
  54.     canMessage.setData("Period", pwmPeriod);
  55.     canMessage.setData("Resolution", pwmResolution);
  56.     sendMessage(canMessage);
  57. }
  58.  
  59.