Материал из Module developer
Перейти к: навигация, поиск
  // Creating the wiget 
  function CreateDimmer (md) {  
     // Refer to the popup you want to clone 
     var popup = IR.GetItem("Dimmer" + moduleID);
     // Assing the variable the channel name                
     var channelName = deviceName + ":" + "channel" + md.W + moduleID; 
     widget = md.subDevice.addWidget(popup.Clone("Dimmer" + md.index + moduleID));
     // Calling variables required for wiget creation 
     var dimmer = IR.GetItem("Dimmer" + md.index + moduleID);
     var dimmerLevel = dimmer.GetItem("Level");
     var dimmerButton = dimmer.GetItem("Button");
  
     // Adding channels selected by the user
     device.AddChannel(channelName, [subnetID, deviceID, HDLCodes.singleChannelLigtning, separator, parseInt(md.W, 16), 0x0, 0x0, 0x0, 0x01, 0x0, 0x0]);
     device.AddTag(channelName, [subnetID, deviceID, HDLCodes.singleChannelLigtning, separator, parseInt(md.W, 16), 0x0, 0x0]);

     // Calling the function for assigning the slider                
     var userSlider5 = new UserSlider(dimmerLevel, dimmer.GetItem("Slider")); 
                             
     // Sending the command from the level to the HDL dimmer channel 
     IR.AddListener (IR.EVENT_ITEM_RELEASE, dimmerLevel, function () {
        device.Set(channelName, this.Value);   
     }, dimmerLevel);
  
     // The button for switching on/off (0 or 100)               
     IR.AddListener (IR.EVENT_ITEM_PRESS, dimmerButton, function() {
        device.Set (channelName, dimmerButton.Value * 100);
     });