Exemple #1
0
        /// <summary>
        /// Initializes the controller chains using the given configuration.
        /// </summary>
        /// <param name="config">Configuration structure.</param>
        public bool Init(T100kConfig config)
        {
            logger.Info($"Initializing china RGB LED controller");

            sender = new RateLimitedLoop(updateControllers, (int)(1000.0 / config.Framerate), "RGBLED");

            bool foundNetworkInterface = !config.StrictIPChecking;

            //if "StrictIPChecking" is set, set foundNetworkInterface to false

            logger.Debug($"Searching for network interfaces");
            foreach (var iface in NetworkInterface.GetAllNetworkInterfaces())
            {
                logger.Debug($"Scanning network interface {iface.Name}.");
                if (iface.OperationalStatus != OperationalStatus.Up)
                {
                    //skip lo, and unconnected network interfaces
                    logger.Info($"Skipping network interface {iface.Name}, status: {iface.OperationalStatus}");
                    continue;
                }
                bool hasUseableIP = false;
                foreach (var ip in iface.GetIPProperties().UnicastAddresses)
                {
                    // According to the manual of those LED controllers, the host has to use
                    // IPv4 using the address 192.168.60.178
                    if (ip.Address.AddressFamily == AddressFamily.InterNetwork &&
                        ip.Address.Equals(new IPAddress(new byte[] { 192, 168, 60, 178 })))
                    {
                        hasUseableIP = true;
                        break;
                    }
                }
                if (hasUseableIP)
                {
                    logger.Info($"Using interface {iface.Name}");
                    foundNetworkInterface = true;
                    break;
                }
                logger.Debug($"Skipping interface {iface.Name}, no valid address.");
            }

            if (!foundNetworkInterface)
            {
                logger.Warn("Failed to find usable network interface with the IP address 192.168.60.178");
                return(false);
            }

            logger.Info("Creating controllers.");
            for (byte i = 0; i < config.MaximumControllerID; i++)
            {
                var c = new Controller(i);
                c.RefreshController += controllerNeedsRefresh;
                controllers.Add(c);
            }
            udpSocket = new UdpClient();
            udpSocket.Client.ReceiveTimeout = 10;
            return(true);
        }
Exemple #2
0
        public static int Main(string[] args)
        {
            T100kConfig cfg = T100kConfig.Default;
            T100kNAL    nal = new T100kNAL();

            Console.CancelKeyPress += (sender, e) => run = false;
            setupLogging(args.Length >= 1 && args[0] == "-v");

            if (!nal.Init(cfg))
            {
                return(1);
            }

            try
            {
                nal.Start();
                Console.WriteLine("T100k Controller © Martin Koppehel 2016");
                Console.WriteLine("use -v to get more output");
                Console.WriteLine(USAGE);

                while (run)
                {
                    var s = Console.ReadLine();
                    if (string.IsNullOrWhiteSpace(s))
                    {
                        break; // exit on newline or whitespace
                    }
                    var x = s.Split(' ');

                    if (x.Length < 4)
                    {
                        Console.WriteLine(USAGE);
                        continue;
                    }

                    var cid  = byte.Parse(x[0]);
                    var uni  = byte.Parse(x[1]);
                    var chan = ushort.Parse(x[2]);
                    var c    = ColorTranslator.FromHtml(x[3]);
                    nal.UpdateData(new OutputItem
                    {
                        ControllerID = cid,
                        UniverseID   = uni,
                        Channel      = chan,
                        Color        = new RGBColor {
                            R = c.R, B = c.B, G = c.G
                        }
                    }.Enumerate());
                }
            }
            finally
            {
                nal.Stop();
                nal.Destroy();
            }
            return(0);
        }