Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AComConfigDialog"/> class.
        /// </summary>
        /// <param name="pins">Pins.</param>
        /// <param name="signal">Signal.</param>
        /// <param name="pin">Pin.</param>
        /// <param name="parent">Parent.</param>
        /// <param name="units">Units.</param>
        public AComConfigDialog(APin[] pins, MeasurementCombination signal = null, APin pin = null, Gtk.Window parent = null, List<string> units = null)
            : base("Analog Inputs Combinations - Dialog", parent, Gtk.DialogFlags.Modal, new object[0])
        {
            this.Build ();

            sbMeanValuesCount.Adjustment.Upper = int.MaxValue;
            sbMeanValuesCount.Adjustment.Lower = 1;

            APins = pins;

            cbColor.Color = GUIHelper.ColorHelper.GetRandomGdkColor ();

            if (signal == null) {
                Combination_ = new MeasurementCombination ();
                Combination_.Color = cbColor.Color;
            } else {
                Combination = signal;
                if (!string.IsNullOrEmpty (Combination.OperationString)) {
                    CompileOperation ();
                } else {
                    SetWarning ();
                }
                buttonOk.Label = "Apply";
            }

            if (pin != null) {
                Combination_.AddPin (pin);
                Combination_.Unit = Combination_.Pins [0].Unit;
            }

            SetupNodeView ();
            DrawNodeView ();
            UpdateCBPins ();
            SetApplyButton ();

            entryOperation.Activated += (sender, e) => {
                if (!CompileTimer.Enabled) {
                    CompileTimer.Start ();
                }
            };
            entryOperation.FocusInEvent += (sender, e) => {
                if (!CompileTimer.Enabled) {
                    CompileTimer.Start ();
                }
            };

            CompileTimer.Elapsed += CompileTimerElapsed;

            Units = units;
            ListStore store = new ListStore (typeof(string));
            Units.ForEach (o => store.AppendValues (new object[]{ o }));
            cbeUnit.Model = store;
            if (!string.IsNullOrEmpty (Combination_.Unit)) {
                if (Units.Contains (Combination_.Unit)) {
                    cbeUnit.Active = Array.IndexOf (Units.ToArray (), Combination_.Unit);
                } else {
                    store.AppendValues (new string[]{ Combination_.Unit });
                    cbeUnit.Active = Units.Count;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Gets the unused digital pins.
        /// </summary>
        /// <returns>The unused digital pins.</returns>
        private DPin[] GetUnusedDigitalPins()
        {
            var unusedpins = new List<DPin> ();
            var numpins = Board.NumberOfDigitalPins;
            for (uint i = 0; i < numpins; i++)
            {
                unusedpins.Add (new DPin () {
                    Number = i,
                    AnalogNumber = ((Array.IndexOf (Board.HardwareAnalogPins, i) > -1) ? Array.IndexOf (Board.HardwareAnalogPins, i) : -1),
                    RX = (Board.RX [0] == i),
                    TX = (Board.TX [0] == i),
                    SDA = (Board.SDA [0] == i),
                    SCL = (Board.SCL [0] == i)
                });
            }

            foreach (IPin pin in Pins)
            {
                if (pin is DPin)
                {
                    unusedpins.RemoveAll (o => o.Number == pin.Number);
                } else if (pin is APin)
                {
                    unusedpins.RemoveAll (o => o.Number == (pin as APin).DigitalNumber);
                }
            }
            return unusedpins.ToArray<DPin> ();
        }