Ejemplo n.º 1
0
 private static string ButtonStatus(EndPointActionArguments misc, string[] items)
 {
     lock (LockObject)
     {
        return "Button status is " + _buttonPushed;
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Execute this endpoint. We'll call the action with the supplied arguments and
 /// return whatever string the action returns.
 /// </summary>
 /// <returns></returns>
 public String Execute(EndPointActionArguments misc)
 {
     if (Action != null)
     {
         return Action(misc, _arguments);
     }
     return "Unknown action";
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Execute this endpoint. We'll call the action with the supplied arguments and
 /// return whatever string the action returns.
 /// </summary>
 /// <returns></returns>
 public String Execute(EndPointActionArguments misc)
 {
     if (Action != null)
     {
         return(Action(misc, _arguments));
     }
     return("Unknown action");
 }
Ejemplo n.º 4
0
 private string TMP100(EndPointActionArguments misc, string[] items)
 {
     double tempC = TMP100Reader.Instance.GetTemperature();
     double tempF = tempC * 1.8 + 32;
     if (misc.ReturnType == HelperClass.ReturnType.HTML)
     {
         return HTMLUtils.BuildHTML("Temperature is: " + tempC + "C / " + tempF + "F at Desk.");
     }
     else if (misc.ReturnType == HelperClass.ReturnType.JSON)
     {
         return @"
     {""sensors"":[
     {""Location"":""Desk"", ""TempC"":""" + tempC + @""", ""TempF"":""" + tempF + @"""},
     {""Location"":""Dummy"", ""TempC"":"" " + tempC + @""", ""TempF"":""" + tempF + @"""}
     ]}";
     }
     throw new NotImplementedException("Invalid returntype: " + misc.ReturnType.ToString());
 }
Ejemplo n.º 5
0
        private string Echo(EndPointActionArguments misc, string[] items)
        {
            String text = "";
            if (items != null && items.Length > 0)
            {
                foreach (var item in items)
                {
                    text += item + " ";
                }
            }
            else
            {
                text = "No arguments!";
            }


            return "OK. Wrote out: " + (text.Length == 0 ? "n/a" : text);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// We'll get an endpoint invokcation from the web server
        /// so we can execute the endpoint action and response based on its supplied arguments
        /// in a seperate thread, hence the event. we'll set the event return string
        /// so the web server can know how to respond back to the ui in a seperate thread
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        private static void EndPointHandler(object source, EndPoinEventArgs e)
        {
            var misc = new EndPointActionArguments
            {
                Connection = e.Connection
            };

            e.ReturnString = e.Command.Execute(misc);

            // we can override the manual use of the socket if we returned a value other than null
            if (e.ReturnString != null && e.Command.UsesManualSocket)
            {
                e.ManualSent = false;
            }
            else
            {
                e.ManualSent = e.Command.UsesManualSocket;
            }
        }
Ejemplo n.º 7
0
        private string FadeColor(EndPointActionArguments misc, string[] items)
        {
            byte r, g, b = 0;

            if (items != null && items.Length > 0)
            {
                r = byte.Parse(GetArgByName(items, "r", 0));
                g = byte.Parse(GetArgByName(items, "g", 0));
                b = byte.Parse(GetArgByName(items, "b", 0));
            }
            else
            {
                return "Missing arguments. RGB values in range 0-255 needed!\n\r";
            }

            BlinkMHandler.Instance.FadeColor(r, g, b);

            return "Set color to RGB[" + r + "," + g + "," + b + "]\n\r";
        }
Ejemplo n.º 8
0
    /// <summary>
    /// We'll get an endpoint invokcation from the web server
    /// so we can execute the endpoint action and response based on its supplied arguments
    /// in a seperate thread, hence the event. we'll set the event return string
    /// so the web server can know how to respond back to the ui in a seperate thread
    /// </summary>
    /// <param name="source"></param>
    /// <param name="e"></param>
    private static void EndPointHandler(object source, EndPoinEventArgs e)
    {
        var misc = new EndPointActionArguments
                        {
                            Connection = e.Connection
                        };

        e.ReturnString = e.Command.Execute(misc);

        // we can override the manual use of the socket if we returned a value other than null
        if (e.ReturnString != null && e.Command.UsesManualSocket)
        {
            e.ManualSent = false;
        }
        else
        {
            e.ManualSent = e.Command.UsesManualSocket;
        }
    }
Ejemplo n.º 9
0
 private string TMP100log(EndPointActionArguments misc, string[] items)
 {
     if (misc.ReturnType == HelperClass.ReturnType.HTML)
     {
         return HTMLUtils.BuildHTML("bork bork bork");
     }
     else if (misc.ReturnType == HelperClass.ReturnType.JSON)
     {
         string s = @"{""Temperature History"":[";
         foreach(NetDuinoUtils.TMP100.TempData td in TMP100LoggerService.Instance.Temperatures)
         {
             string line = @"
     {""Timestamp"":"+ td.TimeStamp +@", ""TempC"":""" + td.Temperature + @"""},";
             s += line;
         }
         s += @"
     ]}";
         return s;
     }
     throw new NotImplementedException("Invalid returntype: " + misc.ReturnType.ToString());
 }
Ejemplo n.º 10
0
 private string StopScript(EndPointActionArguments misc, string[] items)
 {
     BlinkMHandler.Instance.StopScript();
     return "Script stopped.\n\r";
 }
Ejemplo n.º 11
0
        private string SetTimeAdjust(EndPointActionArguments misc, string[] items)
        {
            SByte speed = 0;

            if (items != null && items.Length == 1)
            {
                speed = SByte.Parse(GetArgByName(items, "speed", 0));
            }
            else
            {
                return "speed = -128 - 127 \n\r";
            }

            BlinkMHandler.Instance.SetTimeAdjust(speed);

            return "Setting time adjust to [" + speed + "]\n\r";
        }
Ejemplo n.º 12
0
        private string SetStartupParameters(EndPointActionArguments misc, string[] items)
        {
            //Byte run, Byte scriptid, Byte repeats, Byte fade, SByte time)
            byte run, scriptid, repeats,fade = 0;
            SByte time = 0;

            if (items != null && items.Length > 1)
            {
                run = byte.Parse(GetArgByName(items, "run", 15));
                scriptid = byte.Parse(GetArgByName(items, "scriptid", 0));
                repeats = byte.Parse(GetArgByName(items, "repeats", 0));
                fade = byte.Parse(GetArgByName(items, "fade", 15));
                time = SByte.Parse(GetArgByName(items, "time", 0));
            }
            else
            {
                return "run = 0/1\n\r" +
                       "scriptid = 0-18\n\r" +
                       "repeats = byte, 0 for autorepeat\n\r" +
                       "fade = 0-255 (default 15)\n\r" +
                       "time = -128-127 (default 0)";
            }

            BlinkMHandler.Instance.SetStartupParameters(run, scriptid, repeats, fade, time);

            return "Set start parameters to run[" + run + "] scriptid[" + scriptid + "] repeats[" + repeats + "] fade[" + fade + "] time[" + time + "]";
        }
Ejemplo n.º 13
0
        private string PlayScript(EndPointActionArguments misc, string[] items)
        {
            byte scriptid, repeats, startline = 0;

            if (items != null && items.Length > 1)
            {
                scriptid  = byte.Parse(GetArgByName(items, "scriptid" , 0));
                repeats   = byte.Parse(GetArgByName(items, "repeats"  , 1));
                startline = byte.Parse(GetArgByName(items, "startline", 0));
            }
            else
            {
                return "scriptid = 0-18\n\rrepeats = byte, 0 for autorepeat\n\rstartline = 0-xx (default 0)\n\r";
            }

            BlinkMHandler.Instance.PlayScript(scriptid, repeats, startline);

            return "Playing script ["+scriptid+"] repeating [" + repeats + "] starting at line [" + startline + "]\n\r";
        }
Ejemplo n.º 14
0
 private string GetColor(EndPointActionArguments misc, string[] items)
 {
     byte[] color = BlinkMHandler.Instance.GetColor();
     if (color.Length == 3)
     {
         return "RGB[" + color[0] + "," + color[1] + "," + color[2] + "]\n\r";
     }
     else
     {
         return "Invalid color data. Sadpanda!\n\r";
     }
 }