Subversion Repositories HomeAutomation

Rev

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

  1.  
  2.  
  3. function IrManager(ir_receiver, xbmc_host, xbmc_port)
  4. {
  5.   var self = this;
  6.  
  7.   this.xbmc_host_             = xbmc_host;
  8.   this.xbmc_port_             = xbmc_port;
  9.   this.xbmc_reconnect_timer_  = null;
  10.  
  11.   Xbmc_SubscribeToConnectionStatus(function(event, connection_id, method, params)
  12.   {
  13.     if (event == "connected")
  14.     {
  15.       Timer_Cancel(timer_id);
  16.       self.xbmc_reconnect_timer_ = null;
  17.     }
  18.     else if (event == "disconnected")
  19.     {
  20.       self._SetXbmcReconnect();
  21.     }
  22.     else if (event == "notification")
  23.     {
  24.       Log("method:" + method + ", params: " + JSON.stringify(params));
  25.     }
  26.     else if (event == "command_success")
  27.     {
  28.      
  29.     }
  30.     else if (event == "command_error")
  31.     {
  32.       Log("Command failed: " + JSON.stringify(params));
  33.     }
  34.   });
  35.  
  36.   Module_RegisterToOnMessage(ir_receiver, function(alias_name, command, variables)
  37.   {
  38.     var button = IRIn_CodeToName(variables["IRdata"], variables["Protocol"], "LG_MKJ42519615");
  39.    
  40.     if (variables["Status"] == "Pressed")
  41.     {
  42.       switch (button)
  43.       {
  44.         case "RETURN":
  45.         {
  46.           Xbmc_Back();
  47.           break;
  48.         }
  49.         case "OK":
  50.         {
  51.           Xbmc_Select();
  52.           break;
  53.         }
  54.         case "UP":
  55.         {
  56.           Xbmc_Up();
  57.           break;
  58.         }
  59.         case "LEFT":
  60.         {
  61.           Xbmc_Left();
  62.           break;
  63.         }
  64.         case "DOWN":
  65.         {
  66.           Xbmc_Down();
  67.           break;
  68.         }
  69.         case "RIGHT":
  70.         {
  71.           Xbmc_Right();
  72.           break;
  73.         }
  74.         case "PLAY":
  75.         case "PAUSE":
  76.         {
  77.           Xbmc_PlayPause();
  78.           break;
  79.         }
  80.         case "STOP":
  81.         {
  82.           Xbmc_Stop();
  83.           break;
  84.         }
  85.       }
  86.     }
  87.   });
  88.  
  89.   this._SetXbmcReconnect = function()
  90.   {
  91.     self.xbmc_reconnect_timer_ = Timer_SetTimer(function(timer_id)
  92.     {
  93.       if (!Xbmc_IsConnected())
  94.       {
  95.         if (Xbmc_Connect(self.xbmc_host_, self.xbmc_port_))
  96.         {
  97.           Timer_Cancel(timer_id);
  98.           self.xbmc_reconnect_timer_ = null;
  99.         }
  100.       }
  101.      
  102.     }, 5000, true);
  103.   }
  104.  
  105.   if (!Xbmc_Connect(self.xbmc_host_, self.xbmc_port_))
  106.   {
  107.     self._SetXbmcReconnect();
  108.   }
  109. }
  110.