Subversion Repositories HomeAutomation

Rev

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