示例#1
0
        private void Button224_authtokengenerate_Click(object sender, EventArgs e)
        {
            string token = Nanoleaf.GenerateToken(textBox224_location.Text);

            if (token != null)
            {
                textBox221_authtoken.Text = token;
            }
            if (textBox224_location.Text.Length > 0 && textBox224_authtoken.Text.Length > 0 && !textBox224_authtoken.Text.StartsWith("---"))
            {
                devices[3] = new NanoleafDevice(textBox224_location.Text, textBox224_authtoken.Text);
                UpdateEffectList();
            }
        }
示例#2
0
        private void UpdateEffectList()
        {
            if (alerts == null || chatCmds == null || devices == null || alerts.Length == 0 || chatCmds.Length == 0 || devices.Length == 0)
            {
                return;
            }
            for (int i = 0; i < devices.Length; i++)
            {
                if (devices[i] == null)
                {
                    continue;
                }
                string[] el = Nanoleaf.GetEffectList(devices[i]);
                if (el != null)
                {
                    devices[i].SetEffectList(el);
                }
            }

            ArrayList els = new ArrayList();

            for (int i = 0; i < devices.Length; i++)
            {
                if (devices[i] == null)
                {
                    continue;
                }
                string[] el = devices[i].GetEffectList();
                //els.Add("--- Device #" + i + " ---");
                for (int j = 0; j < el.Length; j++)
                {
                    els.Add(el[j]);
                }
            }

            ComboBox[] effects = { comboBox231_default, comboBox232_follow, comboBox233_sub, comboBox234_donation, comboBox235_cheer, comboBox236_host, comboBox237_raid, comboBox241_effect, comboBox242_effect, comboBox243_effect, comboBox244_effect, comboBox245_effect, comboBox246_effect, comboBox247_effect, comboBox248_effect, comboBox249_effect, comboBox2410_effect };
            for (int i = 0; i < effects.Length; i++)
            {
                if (effects[i].Items.Count == 0)
                {
                    if (i == 0)
                    {
                        effects[i].Items.Add(EffectChange.CurrentEffect);
                    }
                    else
                    {
                        effects[i].Items.Add("");
                    }
                }
                foreach (string en in els)
                {
                    effects[i].Items.Add(en);
                }
                if (i < 7 && alerts[i] != null)
                {
                    effects[i].SelectedIndex = effects[i].FindStringExact(alerts[i].GetEffectName());
                    effects[i].SelectedText  = alerts[i].GetEffectName();
                }
                else if (i >= 7 && chatCmds[i - 6] != null)
                {
                    effects[i].SelectedIndex = effects[i].FindStringExact(chatCmds[i - 6].GetEffectName());
                    effects[i].SelectedText  = chatCmds[i - 6].GetEffectName();
                }
            }
        }
示例#3
0
        private void QueueHandler()
        {
            JSONSLCBEvent SLCBEvent;
            string        eventname;
            EffectChange  ec;

            Boolean[] devs;
            int[]     currentBrightness;
            string[]  currentEffect;
            Boolean   useCurrentEffect;
            string    newLightEffect;
            int       duration;
            int       newBrightness;
            Boolean   IsActiveCmdBrightness;

            while (true)
            {
                if (eventQueue.Count > 0)
                {
                    SLCBEvent             = (JSONSLCBEvent)eventQueue.Dequeue();
                    eventname             = [email protected]([email protected]("_") + 1);
                    ec                    = null;
                    duration              = 0;
                    newBrightness         = 50;
                    IsActiveCmdBrightness = false;

                    try {
                        /* (1) check paramter */
                        if (eventname.Equals("CHATCMD"))
                        {
                            /* identify chat commnand */
                            try {
                                ec = chatCmds[(int)((EffectChange.ChatCmd)Enum.Parse(typeof(EffectChange.ChatCmd), SLCBEvent.EventData.command))];
                            } catch { /* no actions */ }
                        }
                        else
                        {
                            /* identify alert */
                            try {
                                ec = alerts[(int)((EffectChange.Type)Enum.Parse(typeof(EffectChange.Type), eventname))];
                            } catch { /* no actions */ }
                        }
                        if (ec == null && ec.GetEffectName().Length == 0)
                        {
                            continue;
                        }
                        duration      = ec.GetDuration();
                        newBrightness = ec.GetBrightness();
                        if (eventname.Equals("CHATCMD") && SLCBEvent.EventData.brightness != -1)
                        {
                            newBrightness         = SLCBEvent.EventData.brightness;
                            IsActiveCmdBrightness = true;
                        }
                        newLightEffect = ec.GetEffectName();
                        if (eventname.Equals("CHATCMD") && SLCBEvent.EventData.command.Equals("MASTER"))
                        {
                            string clf = SLCBEvent.EventData.effectName;
                            foreach (NanoleafDevice nd in devices)
                            {
                                foreach (string lf in nd.GetEffectList())
                                {
                                    if (lf.ToLower().Equals(clf.ToLower()))
                                    {
                                        newLightEffect = lf;
                                        goto go;
                                    }
                                }
                            }
                            go : /* continue */;
                        }
                        if (newLightEffect.Length == 0)
                        {
                            continue;
                        }

                        devs = ec.GetDevices();
                        currentBrightness = new int[devs.Length];
                        currentEffect     = new string[devs.Length];

                        /* (2) change effect and brightness */
                        for (int i = 0; i < devs.Length; i++)
                        {
                            if (!devs[i] || devices[i] == null || devices[i].GetLocation().Length == 0 || devices[i].GetAuthToken().Length == 0)
                            {
                                continue;
                            }

                            /* set useCurrentEffect */
                            if (devices[i].GetDefaultEffect() == null)
                            {
                                useCurrentEffect = true;
                            }
                            else
                            {
                                useCurrentEffect = devices[i].GetDefaultEffect().Equals(EffectChange.CurrentEffect);
                            }

                            /* set currentEffect */
                            if (useCurrentEffect)
                            {
                                currentEffect[i] = Nanoleaf.GetCurrentEffect(devices[i]).Replace("\"", "");
                            }
                            else
                            {
                                currentEffect[i] = alerts[(int)EffectChange.Type.DEFAULT].GetEffectName();
                            }

                            /* change effect */
                            Nanoleaf.ChangeEffect(devices[i], newLightEffect);
                            mainForm.AddListViewEventsItem(DateTime.Now, "", "Device #" + (i + 1) + ", change effect to " + newLightEffect + " for " + duration + "s");

                            /* change brightness */
                            if (ec.IsActiveBrightness() || IsActiveCmdBrightness)
                            {
                                if (alerts[(int)EffectChange.Type.DEFAULT].IsActiveBrightness())
                                {
                                    currentBrightness[i] = alerts[(int)EffectChange.Type.DEFAULT].GetBrightness();
                                }
                                else
                                {
                                    dynamic data = JsonConvert.DeserializeObject <JSONNanoleafGetBrightness>(Nanoleaf.GetCurrentBrightness(devices[i]));
                                    currentBrightness[i] = ((JSONNanoleafGetBrightness)data).value;
                                }
                                Nanoleaf.ChangeBrightness(devices[i], newBrightness, duration);
                                mainForm.AddListViewEventsItem(DateTime.Now, "", "Device #" + (i + 1) + ", change brightness to " + newBrightness + "%" + " for " + duration + "s");
                            }
                        }

                        if (duration <= 0)
                        {
                            continue;
                        }

                        /* (3) wait */
                        Thread.Sleep(duration * 1000);

                        /* (4) change back effect and brightness */
                        for (int i = 0; i < devs.Length; i++)
                        {
                            if (!devs[i] || devices[i] == null || devices[i].GetLocation().Length == 0 || devices[i].GetAuthToken().Length == 0)
                            {
                                continue;
                            }

                            /* change effect */
                            Nanoleaf.ChangeEffect(devices[i], currentEffect[i]);
                            mainForm.AddListViewEventsItem(DateTime.Now, "", "Device #" + (i + 1) + ", change effect to " + currentEffect[i]);

                            /* change brightness */
                            if (ec.IsActiveBrightness() || IsActiveCmdBrightness)
                            {
                                Nanoleaf.ChangeBrightness(devices[i], currentBrightness[i]);
                                mainForm.AddListViewEventsItem(DateTime.Now, "", "Device #" + (i + 1) + ", change brightness to " + currentBrightness[i] + "%");
                            }
                        }
                    } catch (Exception e) {
                        mainForm.AddListViewEventsItem(DateTime.Now, eventname, e.ToString());
                    }
                }
                else
                {
                    /* pause thread */
                    _event.Reset();
                    _event.WaitOne();
                }
            }
        }