Animatroller.Simulator.SimulatorForm.AddAnalogInput C# (CSharp) Method

AddAnalogInput() public method

public AddAnalogInput ( AnalogInput3 logicalDevice ) : Animatroller.Framework.PhysicalDevice.AnalogInput
logicalDevice AnalogInput3
return Animatroller.Framework.PhysicalDevice.AnalogInput
        public Animatroller.Framework.PhysicalDevice.AnalogInput AddAnalogInput(AnalogInput3 logicalDevice)
        {
            var moduleControl = new Control.ModuleControl();
            moduleControl.Text = logicalDevice.Name;
            moduleControl.Size = new System.Drawing.Size(80, 80);

            var control = new Control.TrackBarAdv();
            moduleControl.ChildControl = control;
            control.Size = new System.Drawing.Size(80, 80);
            control.Maximum = 255;
            control.TickFrequency = 26;

            flowLayoutPanelLights.Controls.Add(moduleControl);

            var device = new Animatroller.Framework.PhysicalDevice.AnalogInput();

            control.ValueChanged += (sender, e) =>
            {
                device.Trigger((sender as TrackBar).Value / 255.0);
            };

            device.Connect(logicalDevice);

            control.Value = logicalDevice.Value.GetByteScale();

            logicalDevice.Output
                .ObserveOn(SynchronizationContext.Current)
                .Subscribe(x =>
                {
                    control.SuspendChangedEvents = true;
                    try
                    {
                        control.Value = x.GetByteScale();
                    }
                    finally
                    {
                        control.SuspendChangedEvents = false;
                    }
                });

            return device;
        }