예제 #1
0
        public override void Render(PixelColor[,] colorMap)
        {
            if (currentStep < skipStep)
            {
                currentStep++;
                return;
            }
            else
            {
                currentStep = 0;
            }

            if (preMap == null)
            {
                preMap = PixelColor.GetSingleColorMap(Program.TableWidth, Program.TableHeight, PixelColor.BLACK);
            }

            bool   madeChange = false;
            string outString  = string.Empty;

            for (int x = 0; x < 4; x++)
            {
                for (int y = 0; y < 2; y++)
                {
                    if (!preMap[x, y].Same(colorMap[x, y]))
                    {
                        string hexColor = System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color
                                                                                .FromArgb(colorMap[x, y].r, colorMap[x, y].g, colorMap[x, y].b));
                        outString += string.Format("{0}{1}.", new object[]
                                                   { (x + (y * 4)), hexColor }); //TODO Hardcoded Table Width !!!!

                        madeChange   = true;
                        preMap[x, y] = colorMap[x, y];
                    }
                }
            }

            if (madeChange)
            {
                //Send changes over the ethernet
                server.Send(outString);
            }
        }
        public override void Render(PixelColor[,] colorMap)
        {
            if (preMap == null)
            {
                preMap = PixelColor.GetSingleColorMap(Program.TableWidth, Program.TableHeight, PixelColor.BLACK);
            }

            bool   madeChange = false;
            string outString  = string.Empty;

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    if (!preMap[x, y].Same(colorMap[x, y]))
                    {
                        preMap[x, y] = colorMap[x, y];
                        if (Mathf.IsOdd(y))
                        {
                            y = height - y;
                        }

                        outString += string.Format("{0};{1}_{2}:{3}:{4}|", new object[]
                        {
                            x,
                            y,
                            colorMap[x, y].r,
                            colorMap[x, y].g,
                            colorMap[x, y].b
                        });
                        madeChange   = true;
                        preMap[x, y] = colorMap[x, y];
                    }
                }
            }
            outString = outString.TrimEnd('|').Trim();

            if (madeChange)
            {
                server.Send(outString);
            }
        }
예제 #3
0
        static bool DoConsoleCommand(string command)
        {
            if (command == "exit")
            {
                Environment.Exit(0);
                return(false);
            }
            else if (command == "shutdown")
            {
                Console.WriteLine("Shutting down the system...");
                try
                {
                    Process.Start(new ProcessStartInfo()
                    {
                        FileName = "sudo", Arguments = "shutdown -P now"
                    });
                }
                catch (Exception e) { }
                try
                {
                    var psi = new ProcessStartInfo("shutdown", "/s /t 0");
                    psi.CreateNoWindow  = true;
                    psi.UseShellExecute = false;
                    Process.Start(psi);
                }
                catch (Exception e) { }
                return(false);
            }
            else if (command.StartsWith("exec"))
            {
                if (communicationServer != null)
                {
                    communicationServer.ExecuteCommand(command.Replace("exec", "").Trim());
                }
                else
                {
                    Console.WriteLine("The Communication Server is offline. Sorry.");
                }
            }
            else if (command.StartsWith("clear"))
            {
                Console.Clear();
            }
            else if (command.StartsWith("echo"))
            {
                Console.WriteLine(command.Replace("echo", "").Trim());
            }
            else if (command.StartsWith("log"))
            {
                string userName = WindowsIdentity.GetCurrent().Name;
                LogFullLength(userName, command.Replace("log", "").Trim());
            }
            else if (command.StartsWith("whoami"))
            {
                Console.WriteLine(Environment.UserName);
            }
            else if (command.StartsWith("uptime"))
            {
                Console.WriteLine(Environment.TickCount + " ticks");
            }
            else if (command.StartsWith("tcp"))
            {
                communicationServer.Send(command.Replace("tcp", "").Trim());
            }
            else if (command.StartsWith("ws"))
            {
                webSocketServer.Broadcast(command.Replace("ws", "").Trim());
            }
            else if (command.StartsWith("beep"))
            {
                Console.Beep();
            }
            else if (command.StartsWith("play"))
            {
                string path = command.Replace("play", "").Trim();
            }
            else if (command.StartsWith("."))
            {
                if (lastCommand.Length > 0)
                {
                    Console.WriteLine("led-table: rep>" + lastCommand);
                    DoConsoleCommand(lastCommand);
                }
                return(true);
            }
            else if (command.StartsWith("status"))
            {
                Console.WriteLine("### SYSTEM STATUS ###");
                Console.WriteLine("Renderer: " + tableRenderer.GetType().ToString());
                Console.WriteLine("App: " + tableAppManager.GetCurrentApp().GetName());
            }
            else if (command == "help" || command == "?")
            {
                Console.WriteLine("## HELP ##");
                Console.WriteLine("- help/?");
                Console.WriteLine("- exec [command]");
                Console.WriteLine("- log [msg]");
                Console.WriteLine("- whoami");
                Console.WriteLine("- uptime");
                Console.WriteLine("- tcp [msg]");
                Console.WriteLine("- ws [msg]");
                Console.WriteLine("- echo [msg]");
                Console.WriteLine("- clear");
                Console.WriteLine("- beep");
                Console.WriteLine("- status");
                Console.WriteLine("- exit");
                Console.WriteLine("##########");
            }

            lastCommand = command;
            return(true);
        }