示例#1
0
        public void Init(ScreenScanner scanner)
        {
            if (scanner == null)
            {
                throw new Exception();
            }
            this.scanner = scanner;

            WinHueSettings whs = new WinHueSettings();

            if (string.IsNullOrEmpty(whs.settings.DefaultBridge) || string.IsNullOrWhiteSpace(whs.settings.DefaultBridge))
            {
                throw new Exception("Bridge not configured. Use WinHue to pair the bridge");
            }

            if (!whs.settings.BridgeInfo.ContainsKey(whs.settings.DefaultBridge))
            {
                throw new Exception("Bridge not configured. Use WinHue to pair the bridge");
            }


            IPAddress ip = IPAddress.Parse(whs.settings.BridgeInfo[whs.settings.DefaultBridge].ip);

            bridge = new Bridge(ip, whs.settings.DefaultBridge, whs.settings.BridgeInfo[whs.settings.DefaultBridge].apiversion, whs.settings.BridgeInfo[whs.settings.DefaultBridge].swversion, whs.settings.BridgeInfo[whs.settings.DefaultBridge].apikey);

            /*Test if lights are available*/
            foreach (int lid in Settings.lights)
            {
                Light l = (bridge.GetLight(lid.ToString()));
                if (null == l)
                {
                    throw new Exception("Light " + lid + " was not found in the bridge. Use WinHue to check your setup");
                }
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            /*Global exception handler dumps exception to textfile*/
            Application.ThreadException += Application_ThreadException;

            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.UnhandledException += CurrentDomain_UnhandledException;
            try
            {
                options.Parse(args);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error parsing arguments: " + ex.Message);
                options.WriteOptionDescriptions(Console.Out);
                return;
            }
            if (showHelp)
            {
                options.WriteOptionDescriptions(Console.Out);
                return;
            }
            if (Settings.lights.Count == 0 && Settings.groups.Count == 0)
            {
                Console.WriteLine("Chosing lights is mandatory. Specify at least one light or group to use");
                options.WriteOptionDescriptions(Console.Out);
                return;
            }

            ScreenScanner scanner = new ScreenScanner();
            LightSetter   ls      = new LightSetter();

            try
            {
                ls.Init(scanner);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }


            scanner.Start();
            ls.Start();

            do
            {
                Thread.Sleep(100);
                Console.Clear();
                Console.WriteLine("Lighting process running");
                Console.WriteLine("Average color" + scanner.AvarageColor.ToString());
                Console.WriteLine("AvarageSaturatedColor" + scanner.AvarageSaturatedColor.ToString());
                Console.WriteLine("AvarageLuminuosity = " + scanner.AvarageLuma);
                Console.WriteLine("");
                Console.WriteLine("Updates sent to bridge = " + ls.LightUpdatesSent);
                Console.WriteLine("");
                Console.WriteLine("Press any key to terminate");
            }while (!Console.KeyAvailable);

            ls.Stop();
            scanner.Stop();
        }