Subversion Repositories HomeAutomation

Rev

Rev 1830 | Rev 1844 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2.  
  3. function irTransceive(type, name, id)
  4. {
  5.     this.CanService(type, name, id);
  6. }
  7.  
  8. extend(irTransceive, CanService);
  9.  
  10. irTransceive.prototype.canMessageHandler = function(canMessage)
  11. {
  12.     /*if (canMessage.getDirectionFlag() == "From_Owner")
  13.     {
  14.         switch (canMessage.getCommandName())
  15.         {
  16.         case "IR":
  17.         break;
  18.         }
  19.     }*/
  20.    
  21.     this.CanService.prototype.canMessageHandler.call(this, canMessage);
  22. }
  23.  
  24. irTransceive.prototype.sendClick = function(channel, remoteName, buttonName, time)
  25. {
  26.     this.sendButton(channel, remoteName, buttonName, true);
  27.    
  28.     if (time)
  29.     {
  30.         sleep(time);
  31.     }
  32.     else
  33.     {
  34.         sleep(50000);
  35.     }
  36.    
  37.     this.sendButton(channel, remoteName, buttonName, false);
  38. }
  39.  
  40. irTransceive.prototype.sendButton = function(channel, remoteName, buttonName, down)
  41. {
  42.     var remotesStore = DataStore.getStore("IRRemotes");
  43.    
  44.     if (remotesStore)
  45.     {
  46.         for (var n = 0; n < remotesStore['remotes'].length; n++)
  47.         {
  48.             if (remotesStore['remotes'][n]['name'] == remoteName)
  49.             {
  50.                 for (var code in remotesStore['remotes'][n]['codes'])
  51.                 {
  52.                     if (remotesStore['remotes'][n]['codes'][code] == buttonName)
  53.                     {
  54.                         this.sendData(channel, remotesStore['remotes'][n]['protocol'], code, down ? "Pressed" : "Released");
  55.                         return;
  56.                     }
  57.                 }
  58.             }
  59.         }
  60.     }
  61. }
  62.  
  63. irTransceive.prototype.sendData = function(channel, protocol, data, status)
  64. {
  65.     var canMessage = new CanMessage("sns", "To_Owner", this.myName, this.myId, "IR");
  66.     canMessage.setData("Channel", channel);
  67.     canMessage.setData("Status", status);
  68.     canMessage.setData("Protocol", protocol);
  69.     canMessage.setData("IRdata", data);
  70.     sendMessage(canMessage);
  71. }
  72.  
  73. irTransceive.prototype.sendConfig = function(channel, direction, power, modfreq)
  74. {
  75.     var canMessage2 = new CanMessage("sns", "To_Owner", this.myName, this.myId, "IrConfig");
  76.     canMessage2.setData("Channel", channel);
  77.     canMessage2.setData("Direction", direction);
  78.     canMessage2.setData("Transmit power", power);
  79.     canMessage2.setData("Modulation frequency", modfreq);
  80.     sendMessage(canMessage2);
  81. }
  82.  
  83. irTransceive.prototype.sendProntoTest = function(channel)
  84. {
  85.     // pronto start
  86.     var msg = new CanMessage("sns", "To_Owner", this.myName, this.myId, "IrProntoStart");
  87.     msg.setData("Channel", channel);
  88.     msg.setData("Format", 0);
  89.     msg.setData("wFrqDiv", 109); // 4.145146MHz / 38kHz
  90.     msg.setData("OnceSeqLen", 8);
  91.     msg.setData("RepSeqLen", 0);
  92.     sendMessage(msg);
  93.     sleep(1);
  94.    
  95.     // pronto data
  96.     msg = new CanMessage("sns", "To_Owner", this.myName, this.myId, "IrProntoData1");
  97.     msg.setData("Act1", 80);
  98.     msg.setData("Pas1", 40);
  99.     msg.setData("Act2", 40);
  100.     msg.setData("Pas2", 80);
  101.     msg.setData("Act3", 80);
  102.     msg.setData("Pas3", 40);
  103.     msg.setData("Act4", 40);
  104.     msg.setData("Pas4", 80);
  105.     sendMessage(msg);
  106.     sleep(1);
  107.    
  108.     // pronto data/end
  109.     msg = new CanMessage("sns", "To_Owner", this.myName, this.myId, "IrProntoEnd2");
  110.     msg.setData("Act1", 80);
  111.     msg.setData("Pas1", 40);
  112.     msg.setData("Act2", 40);
  113.     msg.setData("Pas2", 80);
  114.     msg.setData("Act3", 80);
  115.     msg.setData("Pas3", 40);
  116.     msg.setData("Act4", 40);
  117.     msg.setData("Pas4", 37);
  118.     sendMessage(msg);
  119.     sleep(1);
  120. }
  121.