Subversion Repositories HomeAutomation

Rev

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

  1. GetModule("irReceive");
  2.  
  3. var irrecord_remote_name = null;
  4. var irrecord_remote_identification = null;
  5. var irrecord_remote_last = null;
  6.  
  7. function irrecord(alias, remote_name)
  8. {
  9.     if (!remote_name)
  10.     {
  11.         return "You must supply a name for the remote to record";
  12.     }
  13.    
  14.     irrecord_remote_name = "Remote_" + remote_name;
  15.     irrecord_remote_identification = resolvealias(alias);
  16.  
  17.     if (irrecord_remote_identification["is_group"])
  18.     {
  19.         return "Alias can not be an alias group";
  20.     }
  21.  
  22.     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");
  23. }
  24. RegisterConsoleCommand(irrecord, function(args) { return StandardAutocomplete(args, irReceive.instance_.GetAvailableNames()); });
  25.  
  26. function irrecord_handle_input(response)
  27. {
  28.     if (response == ".")
  29.     {
  30.         return "Finished!";
  31.     }
  32.    
  33.     if (!irrecord_remote_last)
  34.     {
  35.         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");
  36.     }
  37.    
  38.     Storage_SetParameter(irrecord_remote_name, response, JSON.stringify(irrecord_remote_last));
  39.    
  40.     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");
  41.    
  42.     irrecord_remote_last = null;
  43.    
  44.     return result;
  45. }
  46.  
  47. function irrecord_on_ir(event, id, channel, data, protocol)
  48. {
  49.     if (id == irrecord_remote_identification["module_id"] && channel == irrecord_remote_identification["extra"])
  50.     {
  51.         irrecord_remote_last = { "protocol" : protocol, "data" : data };
  52.     }
  53. }
  54.  
  55.  
  56. irReceive.instance_.Bind("onReleased", irrecord_on_ir);
  57.