Subversion Repositories HomeAutomation

Rev

Rev 1622 | Blame | Last modification | View Log | SVN | RSS feed

  1.  
  2. RequireModule("irReceive");
  3.  
  4. var irrecord_remote_name = null;
  5. var irrecord_remote_identification = null;
  6. var irrecord_remote_last = null;
  7.  
  8. function irrecord_autocomplete(args)
  9. {
  10.     // args[0] == command name
  11.     var arg_index = args.length - 2;
  12.    
  13.     if (arg_index == 0)
  14.     {
  15.         return irReceive.instance_.GetAvailableNames();
  16.     }
  17.     else if (arg_index == 1)
  18.     {
  19.         var remotes = Storage_GetParameters("RemoteList");
  20.        
  21.         var result = new Array();
  22.        
  23.         for (var name in remotes)
  24.         {
  25.             result.push(name);
  26.         }
  27.        
  28.         return result;
  29.     }
  30.    
  31.     return new Array();
  32. }
  33.  
  34. function irrecord(alias, remote_name)
  35. {
  36.     if (!remote_name)
  37.     {
  38.         return "You must supply a name for the remote to record";
  39.     }
  40.    
  41.     irrecord_remote_name = remote_name;
  42.     irrecord_remote_identification = resolvealias(alias);
  43.  
  44.     if (irrecord_remote_identification["is_group"])
  45.     {
  46.         return "Alias can not be an alias group";
  47.     }
  48.  
  49.     return prompt("What is the name of the button you just pressed?", irrecord_handle_input, "Press a key on you remote and then name it.\n");
  50. }
  51. RegisterConsoleCommand(irrecord, irrecord_autocomplete);
  52.  
  53. function irrecord_handle_input(response)
  54. {
  55.     if (response == ".")
  56.     {
  57.         return "Finished!";
  58.     }
  59.    
  60.     if (!irrecord_remote_last)
  61.     {
  62.         return prompt("What is the name of the button you just pressed?", irrecord_handle_input, "You did not press anything on you remote, try again!\nPress a key on you remote and then name it.\n");
  63.     }
  64.    
  65.     Storage_SetParameter("Remote_" + irrecord_remote_name, response, JSON.stringify(irrecord_remote_last));
  66.     Storage_SetParameter("RemoteList", irrecord_remote_name, "Remote_" + irrecord_remote_name);
  67.    
  68.     var result = prompt("What is the name of the button you just pressed?", irrecord_handle_input, "Saved " + response + " with protocol " + irrecord_remote_last["protocol"] + " and data " + irrecord_remote_last["data"] + "\nPress a key on you remote and then name it.\n");
  69.    
  70.     irrecord_remote_last = null;
  71.    
  72.     return result;
  73. }
  74.  
  75. function irrecord_on_ir(event, id, channel, data, protocol)
  76. {
  77.     if (id == irrecord_remote_identification["module_id"] && channel == irrecord_remote_identification["extra"])
  78.     {
  79.         irrecord_remote_last = { "protocol" : protocol, "data" : data };
  80.     }
  81. }
  82.  
  83.  
  84. irReceive.instance_.Bind("onReleased", irrecord_on_ir);
  85.