Ejemplo n.º 1
0
        //safty functions
        public bool TestArgs(string value, LegoSensor_Args x)
        {
            switch (x)
            {
            case (LegoSensor_Args.command):
                if (CommandsSupported)
                {
                    string[] commands = Commands.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    for (int y = 0; y < commands.Length; y++)
                    {
                        if (commands[y] == value)
                        {
                            return(true);
                        }
                    }
                    return(false);
                }
                else
                {
                    return(false);
                }


            case (LegoSensor_Args.direct):
                return(false);

            case (LegoSensor_Args.mode):
                string[] modes = Modes.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                for (int y = 0; y < modes.Length; y++)
                {
                    if (modes[y] == value)
                    {
                        return(true);
                    }
                }
                return(false);

            case (LegoSensor_Args.poll_ms):
                int p;
                if (int.TryParse(value, out p))
                {
                    if (p > 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }

            default:
                throw new ArgumentNullException();
            }
        }
Ejemplo n.º 2
0
 //hands on for more advanced users
 public void SetArg(string Value, LegoSensor_Args x)
 {
     if (x == LegoSensor_Args.direct)
     {
         throw new InvalidOperationException("use the 'Stream' from 'GetDirectStream()' ");
     }
     else if (TestArgs(Value, x))
     {
         WriteVar(LegoSensor_Args_To_String(x), Value);
     }
     else
     {
         throw new ArgumentOutOfRangeException();
     }
 }
Ejemplo n.º 3
0
        //helpers
        public string LegoSensor_Args_To_String(LegoSensor_Args x)
        {
            switch (x)
            {
            case (LegoSensor_Args.command):
                return("command");

            case (LegoSensor_Args.direct):
                return("direct");

            case (LegoSensor_Args.mode):
                return("mode");

            case (LegoSensor_Args.poll_ms):
                return("poll_ms");

            default:
                return("INVALID");
            }
        }