Пример #1
0
        public async void InitBlasters()
        {
            WLog("Scanning blasters...");
            RmBlasters.Clear();
            var devices = await SharpBroadlink.Broadlink.Discover(5);

            WLog("Found: {0} online blasters", devices.Length.ToString());
            foreach (BlasterInfo bi in PluginSettings.Blasters)
            {
                bi.Online = false;
            }
            foreach (Rm Discovered in devices)
            {
                var Registered = GetBlasterByIP(Discovered.Host.Address.ToString());
                if (Registered != null)
                {
                    RmBlasters.Add(Registered.Name, Discovered);
                    WLog("Blaster '{0}' [{1}] online", Registered.Name, Registered.IP);
                }
                else
                {
                    WLog("Found new blaster [{0}]. Added to collection", Discovered.Host.Address.ToString());
                    BlasterInfo biNew = new BlasterInfo()
                    {
                        IP = Discovered.Host.Address.ToString(), Name = Discovered.Host.Address.ToString()
                    };
                    PluginSettings.Blasters.Add(biNew);
                    Registered = GetBlasterByIP(Discovered.Host.Address.ToString());
                    RmBlasters.Add(Registered.Name, Discovered);
                }
                Registered.Online = true;
            }
            // check for offline
            foreach (BlasterInfo bi in PluginSettings.Blasters)
            {
                if (!bi.Online)
                {
                    WLog("! Blaster '{0}' [{1}] offline", bi.Name, bi.IP);
                }
            }
        }
Пример #2
0
        private void SetupGrid()
        {
            foreach (IRCode irc in plugin.PluginSettings.IRCodes)
            {
                if (plugin.GetBlasterByName(irc.Blaster) == null)
                {
                    BlasterInfo newBI = new BlasterInfo()
                    {
                        IP = "", Name = irc.Blaster, Online = false
                    };
                    plugin.PluginSettings.Blasters.Add(newBI);
                }
            }

            dgvIRCodes.Columns.Clear();
            dgvIRCodes.AutoGenerateColumns = false;

            DataGridViewTextBoxColumn dgvc1 = new DataGridViewTextBoxColumn();

            dgvc1.Name             = "Name";
            dgvc1.DataPropertyName = "Name";
            dgvc1.Width            = 300;
            dgvIRCodes.Columns.Add(dgvc1);

            Dictionary <IRCodeType, string> dctCodeTypes = new Dictionary <IRCodeType, string>();

            dctCodeTypes.Add(IRCodeType.RAW, "RAW");
            dctCodeTypes.Add(IRCodeType.PRONTO, "Pronto");

            DataGridViewComboBoxColumn dgvc2 = new DataGridViewComboBoxColumn();

            dgvc2.Name             = "CodeType";
            dgvc2.DataPropertyName = "CodeType";
            dgvc2.ValueMember      = "key";
            dgvc2.DisplayMember    = "value";
            dgvc2.Width            = 100;
            dgvc2.DataSource       = new BindingSource()
            {
                DataSource = dctCodeTypes
            };

            dgvIRCodes.Columns.Add(dgvc2);

            DataGridViewTextBoxColumn dgvc3 = new DataGridViewTextBoxColumn();

            dgvc3.Name             = "Command";
            dgvc3.DataPropertyName = "Command";
            dgvc3.Width            = 400;
            dgvIRCodes.Columns.Add(dgvc3);

            //Dictionary<BlasterInfo, string> dctBlasters = new Dictionary<BlasterInfo, string>();
            comboBoxVia.Items.Clear();
            comboBoxVia.Items.Add("<join blaster>");
            comboBoxVia.SelectedIndex = 0;

            List <string> lib = new List <string>();

            foreach (BlasterInfo bi in plugin.PluginSettings.Blasters)
            {
                lib.Add(bi.ToString());
                comboBoxVia.Items.Add(bi.Name);
            }

            DataGridViewComboBoxColumn dgvc4 = new DataGridViewComboBoxColumn();

            dgvc4.Name             = "Blaster";
            dgvc4.DataPropertyName = "Blaster";
            dgvc4.Width            = 200;
            dgvc4.DataSource       = new BindingSource()
            {
                DataSource = lib
            };

            dgvIRCodes.Columns.Add(dgvc4);

            dgvIRCodes.DataSource = plugin.PluginSettings.IRCodes;

            dgvIRCodes.Invalidate();
        }