Subversion Repositories HomeAutomation

Rev

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

  1.  
  2. function irReceive(type, name, id)
  3. {
  4.     this.CanService(type, name, id);
  5. }
  6.  
  7. extend(irReceive, CanService);
  8.  
  9. irReceive.prototype.myLastIRdata = null;
  10. irReceive.prototype.myLastProtocol = null;
  11. irReceive.prototype.myLastStatus = null;
  12. irReceive.prototype.myLastButton = null;
  13. irReceive.prototype.myLastRemote = null;
  14.  
  15. irReceive.prototype.canMessageHandler = function(canMessage)
  16. {
  17.     if (canMessage.getDirectionFlag() == "From_Owner")
  18.     {
  19.         switch (canMessage.getCommandName())
  20.         {
  21.         case "IR":
  22.         this.myLastIRdata = canMessage.getData("IRdata");
  23.         this.myLastProtocol = canMessage.getData("Protocol");
  24.         this.myLastStatus = canMessage.getData("Status");
  25.         this.lookupName(this.myLastProtocol, this.myLastIRdata);
  26.        
  27.         if (this.myLastButton == null)
  28.         {
  29.             log(this.myName + ":" + this.myId + "> New IR, protocol: " + this.myLastProtocol + ", data: " + this.myLastIRdata + ", button was " + this.myLastStatus + "\n");
  30.         }
  31.         else
  32.         {
  33.             log(this.myName + ":" + this.myId + "> New IR, remote: " + this.myLastRemote + ", button: " + this.myLastButton + ", button was " + this.myLastStatus + "\n");
  34.         }
  35.        
  36.         this.callEvent("newIRdata", null);
  37.         break;
  38.         }
  39.     }
  40.    
  41.     this.CanService.prototype.canMessageHandler.call(this, canMessage);
  42. }
  43.  
  44. irReceive.prototype.lookupName = function(protocol, data)
  45. {
  46.     var remotesStore = DataStore.getStore("IRRemotes");
  47.    
  48.     if (remotesStore)
  49.     {
  50.         for (var n = 0; n < remotesStore['remotes'].length; n++)
  51.         {
  52.             if (remotesStore['remotes'][n]['protocol'] == protocol)
  53.             {
  54.                 if (remotesStore['remotes'][n]['codes'][data])
  55.                 {
  56.                     this.myLastButton = remotesStore['remotes'][n]['codes'][data];
  57.                     this.myLastRemote = remotesStore['remotes'][n]['name'];
  58.                     return;
  59.                 }
  60.             }
  61.         }
  62.     }
  63.    
  64.     this.myLastButton = null;
  65.     this.myLastRemote = null;
  66. }
  67.  
  68. irReceive.prototype.getLastIRdata = function()
  69. {
  70.     return this.myLastIRdata;
  71. }
  72.  
  73. irReceive.prototype.getLastProtocol = function()
  74. {
  75.     return this.myLastProtocol;
  76. }
  77.  
  78. irReceive.prototype.getLastStatus = function()
  79. {
  80.     return this.myLastStatus;
  81. }
  82.  
  83. irReceive.prototype.getLastButton = function()
  84. {
  85.     return this.myLastButton;
  86. }
  87.  
  88. irReceive.prototype.getLastRemote = function()
  89. {
  90.     return this.myLastRemote;
  91. }
  92.