Exemplo n.º 1
0
        static void Main(string[] args)
        {
            AlniTimeBoxDevice box = new AlniTimeBoxDevice();

            box.Connect();

            //box.SetView(TimeBoxDevice.ViewType.Clock);
            box.SetTimeColor(Color.Orange);
            box.SetTime(DateTime.Now);

            //TestDevice(box);

            while (true)
            {
                string[] _params = Console.ReadLine().Split(' ');
                string   command = _params[0];
                if (command == "write")
                {
                    _params = string.Join(" ", _params.Skip(1).ToArray()).Split(';');
                    string[]     text   = _params[0].Replace("|", "\n").Split(' ');
                    string[]     color  = _params[1].Split(' ');
                    List <Color> colors = new List <Color>();
                    foreach (string _color in color)
                    {
                        colors.Add(ColorTranslator.FromHtml(_color));
                    }

                    Color[][] message = CreateMessage(
                        text,
                        colors.ToArray()
                        );

                    Color[][] messageFilled = PixelTextHelper.FillDimensions(message);

                    box.ShowPixelArt(messageFilled);
                }
                else if (command == "view")
                {
                    TimeBoxDevice.ViewType defaultView = TimeBoxDevice.ViewType.Clock;
                    TimeBoxDevice.ViewType viewType    = defaultView;
                    if (_params.Length > 1)
                    {
                        string arg = _params[1];
                        try
                        {
                            Type enumType = typeof(TimeBoxDevice.ViewType);

                            viewType = (TimeBoxDevice.ViewType)Enum.Parse(enumType, arg);
                            if (Enum.IsDefined(enumType, viewType) == false)
                            {
                                viewType = defaultView;
                            }
                        }
                        catch (ArgumentException)
                        {
                            viewType = defaultView;
                        }
                    }
                    box.SetView(viewType);
                }
            }
            //Thread.Sleep(Int32.MaxValue);
        }