Ejemplo n.º 1
0
        public void Start()
        {
            // Start the ledController
            try
            {
                _ledController = new LedController(_ledStrip);
            }
            catch (Exception e)
            {
                Console.Out.WriteLine("Failed to start the ledController (Are you running with sudo rights?)");
                throw;
            }

            // Start the StellaServer connection
            try
            {
                IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Parse(_configuration.Ip), _configuration.Port);
                _stellaServer.RenderFrameReceived += (sender, frame) => _ledController.RenderFrame(frame);
                _stellaServer.Start(remoteEndPoint, _configuration.UdpPort, _configuration.Id);
            }
            catch (Exception e)
            {
                Console.Out.WriteLine("Failed to start opening a connection with the server.");
                throw;
            }
        }
Ejemplo n.º 2
0
        private static void CreateStellaClientInstance(int id)
        {
            // Light
            int      ledCount = 300;
            Settings settings = Settings.CreateDefaultSettings();

            settings.Channels[0] = new Channel(ledCount, 18, 255, false, StripType.WS2812_STRIP);
            WS281x        ledstrip      = new WS281x(settings);
            LedController ledController = new LedController(ledstrip);

            // Server
            IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Parse(Program.SERVER_IP), 20055);

            StellaClientLib.Network.StellaServer stellaServer = new StellaClientLib.Network.StellaServer();
            stellaServer.RenderFrameReceived += (sender, frame) => ledController.RenderFrame(frame);
            stellaServer.Start(localEndPoint, 20056, id);

            string input;

            Console.Out.WriteLine($"Running StellaClient instance with id {id}");
            while ((input = Console.ReadLine()) != "q")
            {
                Console.Out.WriteLine("q - quit");

                switch (input)
                {
                default:
                    Console.Out.WriteLine("Unknown command.");
                    break;
                }
            }
            stellaServer.Dispose();
        }
Ejemplo n.º 3
0
        public void Render__LedStripRenderGetsCalled()
        {
            FrameWithoutDelta frame = new FrameWithoutDelta(0, 100, 1);

            frame[0] = new PixelInstruction(10, 20, 30);
            var mock = new Mock <ILEDStrip>();

            mock.Setup(x => x.Render());

            LedController controller = new LedController(mock.Object);

            controller.RenderFrame(frame);

            mock.Verify(x => x.Render(), Times.Once);
        }
Ejemplo n.º 4
0
        public void PrepareFrame_Frame_FrameGetsDrawnToStrip()
        {
            FrameWithoutDelta frame = new FrameWithoutDelta(0, 100, 1);

            frame[0] = new PixelInstruction(10, 20, 30);

            var mock = new Mock <ILEDStrip>();

            int   index = -1;
            Color color = new Color();

            mock.Setup(x => x.SetLEDColor(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <Color>())).Callback <int, int, Color>((i, j, c) =>
            {
                index = j;
                color = c;
            });

            LedController controller = new LedController(mock.Object);

            controller.RenderFrame(frame);
            Assert.AreEqual(0, index);
            Assert.AreEqual(Color.FromArgb(10, 20, 30), color);
        }