/// <summary>
        /// Default ctor
        /// </summary>
        public LocoIOConnectorConfigurationControl()
        {
            InitializeComponent();

            labels = new[] { lbPin1, lbPin2, lbPin3, lbPin4, lbPin5, lbPin6, lbPin7, lbPin8 };
            addressControls = new[] { tbAddr1, tbAddr2, tbAddr3, tbAddr4, tbAddr5, tbAddr6, tbAddr7, tbAddr8 };
            addresses = new AddressList(8);

            for (int i = 0; i < 8; i++)
            {
                var tbAddr = addressControls[i];
                tbAddr.Value = addresses[i];
                var index = i;
                tbAddr.GotFocus += (s, x) => {
                    tbAddr.Select(0, tbAddr.Value.ToString().Length);
                    oldAddress = (int)tbAddr.Value;
                };
                tbAddr.ValueChanged += (s, x) => {
                    addresses[index] = (int) tbAddr.Value;
                    var newAddress = (int)tbAddr.Value;
                    var tbNextAddr = (index + 1 < 8) ? addressControls[index + 1] : null;
                    if ((tbNextAddr != null) && (tbNextAddr.Value == oldAddress +1))
                    {
                        // Adjust next address
                        oldAddress = (int)tbNextAddr.Value;
                        tbNextAddr.Value = newAddress + 1;
                    }
                };
            }

            Connector = Connector.First;
            lvModes.Items.AddRange(ConnectorMode.All.Select(x => new ListViewItem(x.Name) { Tag = x }).ToArray());
            UpdateUI(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Use this mode to create a configuration using the
        /// given addresses for the given connector.
        /// </summary>
        public ConnectorConfig CreateConfig(Connector connector, AddressList addresses, int subMode)
        {
            var pinConfigs = new PinConfig[PinCount];
            var pinOffset  = GetPinOffset(subMode);

            for (int i = 0; i < PinCount; i++)
            {
                var pin = i + 1 + pinOffset;
                if (connector == Connector.Second)
                {
                    pin += 8;
                }
                pinConfigs[i] = new PinConfig(pin);
            }
            var result = new ConnectorConfig(pinConfigs);

            Configure(result, addresses, subMode);
            return(result);
        }
 /// <summary>
 /// Create a configuration from the settings found in this control.
 /// </summary>
 public ConnectorConfig CreateConfig()
 {
     var mode = SelectedMode ?? ConnectorMode.None;
     var pinOffset = mode.GetPinOffset(SelectedSubMode);
     var usedAddresses = new AddressList(8 - pinOffset);
     for (var i = pinOffset; i < 8; i++)
     {
         usedAddresses[i - pinOffset] = addresses[i];
     }
     return mode.CreateConfig(connector, usedAddresses, SelectedSubMode);
 }
Esempio n. 4
0
 /// <summary>
 /// Use this mode to create a configuration using the
 /// given addresses for the given connector.
 /// </summary>
 public ConnectorConfig CreateConfig(Connector connector, AddressList addresses, int subMode)
 {
     var pinConfigs = new PinConfig[PinCount];
     var pinOffset = GetPinOffset(subMode);
     for (int i = 0; i < PinCount; i++)
     {
         var pin = i + 1 + pinOffset;
         if (connector == Connector.Second)
             pin += 8;
         pinConfigs[i] = new PinConfig(pin);
     }
     var result = new ConnectorConfig(pinConfigs);
     Configure(result, addresses, subMode);
     return result;
 }
Esempio n. 5
0
 /// <summary>
 /// Use this mode to configure the given target.
 /// </summary>
 protected abstract void Configure(ConnectorConfig target, AddressList addresses, int subMode);
Esempio n. 6
0
 /// <summary>
 /// Use this mode to configure the given target.
 /// </summary>
 protected abstract void Configure(ConnectorConfig target, AddressList addresses, int subMode);