Exemple #1
0
        public LedItem()
        {
            AllItems.Add(this);

            MainWindow.ActiveWindow.itemStackPanel.Children.Add(this);

            Name = $"Item{LedItem.AllItems.Count}";

            foreach (LedItem item in LedItem.AllItems)
            {
                if (item.ItemName == "LED")
                {
                    ItemName = $"LED{LedItem.AllItems.Count}";
                }
            }

            ID = MainWindow.IDCounter;

            LedItem.RefreshSyncableItems();

            //make item selected if its the first
            if (LedItem.AllItems.Count == 1)
            {
                MainWindow.ActiveWindow.SelectedLedItem = this;
            }

            MainWindow.IDCounter++;

            DataContext = this;

            InitializeComponent();
        }
Exemple #2
0
        public void Delete()
        {
            MainWindow.ActiveWindow.itemStackPanel.Children.Remove(this);

            AllItems.Remove(this);

            LedItem.RefreshSyncableItems();

            //display no led message if this was the last led
            if (LedItem.AllItems.Count != 0)
            {
                //select the next item if this item was selected
                if (MainWindow.ActiveWindow.SelectedLedItem == this)
                {
                    MainWindow.ActiveWindow.SelectedLedItem = AllItems[0];
                }

                bool foundport = false;

                foreach (LedItem item in LedItem.AllItems)
                {
                    if (item.ComPortName == ComPortName)
                    {
                        foundport = true;
                    }
                }

                if (!foundport)
                {
                    try
                    {
                        arduino.ActiveSerialPort.Close();
                    }
                    catch { }

                    Arduino.AllArduinos.Remove(arduino);
                }
            }
            else
            {
                MainWindow.ActiveWindow.SelectedLedItem = null;
            }

            //If this led was the syncparent of any other led, remove that sync
            foreach (LedItem item in LedItem.AllItems)
            {
                if (item.SyncedLedItem == this.ItemName)
                {
                    item.SyncedLedItem = "DONTSYNC";
                    item.CurrentMode   = "Static";

                    if (item == MainWindow.ActiveWindow.SelectedLedItem)
                    {
                        MainWindow.ActiveWindow.SelectedMode = "Static";
                    }
                }
            }
        }
        public LedItemProperties(string name, int type, string comPort, int ledCount, int dPin, int rPin, int gPin, int bPin, int bautRate, LedItem ledItem)
        {
            InitializeComponent();
            DataContext = this;
            RefreshPorts();
            comPortComboBox.ItemsSource = AvailablePorts;

            this.ledItem = ledItem;

            SelectedItemName = name;
            SelectedType     = type;
            SelectedComPort  = comPort;
            SelectedLedCount = ledCount;
            SelectedDPin     = dPin;
            SelectedRPin     = rPin;
            SelectedGPin     = gPin;
            SelectedBPin     = bPin;
            SelectedBaud     = bautRate;

            MainWindow.ActiveWindow.propertiesBackgroundGrid.MouseUp += CancelBtn_Click;
        }