Subversion Repositories HomeAutomation

Rev

Rev 999 | Rev 1046 | Go to most recent revision | 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.getProtocolName(this.myLastProtocol), this.myLastIRdata);
  26.        
  27.         if (this.myLastButton == null)
  28.         {
  29.             log(this.myName + ":" + this.myId + "> New IR, protocol: " + this.getProtocolName(this.myLastProtocol) + ", data: " + this.myLastIRdata + ", button was " + this.getStatusName(this.myLastStatus).toLowerCase() + "\n");
  30.         }
  31.         else
  32.         {
  33.             log(this.myName + ":" + this.myId + "> New IR, remote: " + this.myLastRemote + ", button: " + this.myLastButton + ", button was " + this.getStatusName(this.myLastStatus).toLowerCase() + "\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.getStatusName = function(status)
  84. {
  85.     var returnData = "Released";
  86.     if (status == 1) {
  87.         returnData = "Pressed";
  88.     }
  89.     return returnData;
  90. }
  91. irReceive.prototype.getProtocolName = function(protocol)
  92. {
  93.     var returnData = "Unknown";
  94.     switch (protocol)
  95.     {
  96.     case 0:
  97.         returnData = "RC5";
  98.     break;
  99.     case 1:
  100.         returnData = "RC6";
  101.     break;
  102.     case 2:
  103.         returnData = "RCMM";
  104.     break;
  105.     case 3:
  106.         returnData = "SIRC";
  107.     break;
  108.     case 4:
  109.         returnData = "Sharp";
  110.     break;
  111.     case 5:
  112.         returnData = "NEC";
  113.     break;
  114.     case 6:
  115.         returnData = "Samsung";
  116.     break;
  117.     case 7:
  118.         returnData = "Marantz";
  119.     break;
  120.     case 255:
  121.         returnData = "Unknown";
  122.     break;
  123.     default:
  124.         returnData = "New protocol, irReceive.js must be updated";
  125.     break;
  126.     }
  127.     return returnData;
  128. }
  129.