Example #1
0
        void LedWebEventReceived(string path, HomeOSGadgeteer.Networking.WebServer.HttpMethod method, HomeOSGadgeteer.Networking.Responder responder)
        {
            byte r=0, g=0, b=0;
            int time = 0;

            try
            {
                string rstring = responder.GetParameterValueFromURL("r");
                string gstring = responder.GetParameterValueFromURL("g");
                string bstring = responder.GetParameterValueFromURL("b");
                string timestring = responder.GetParameterValueFromURL("t");

                if (rstring != null && rstring != "")
                {
                    try
                    {
                        int rint = int.Parse(rstring);
                        if (rint >= 0 && rint <= 255)
                        {
                            r = (byte)rint;
                        }
                    }
                    catch { }
                }

                if (gstring != null && gstring != "")
                {
                    try
                    {
                        int gint = int.Parse(gstring);
                        if (gint >= 0 && gint <= 255)
                        {
                            g = (byte)gint;
                        }
                    }
                    catch { }
                }

                if (bstring != null && bstring != "")
                {
                    try
                    {
                        int bint = int.Parse(bstring);
                        if (bint >= 0 && bint <= 255)
                        {
                            b = (byte)bint;
                        }
                    }
                    catch { }
                }

                if (timestring != null && timestring != "")
                {
                    try
                    {
                        time = int.Parse(timestring);
                        if (time < 0) time = 0;
                    }
                    catch { }
                }
            }
            catch { }

            TimeSpan duration = new TimeSpan(0, 0, time);
            RemoteControlLedEndTime = GT.Timer.GetMachineTime() + duration;
            GT.Timer rcEndTimer = new GT.Timer(duration);
            rcEndTimer.Behavior = GT.Timer.BehaviorType.RunOnce;
            rcEndTimer.Tick += (t) => hgd.SetLed();
            rcEndTimer.Start();

            multicolorLed.TurnColor(new GT.Color(r, g, b));

            responder.Respond("Setting LED to r=" + r + " g=" + g + " b=" + b + " for t=" + time + " secs");
        }