Ejemplo n.º 1
0
        private static void ConfigRoutine()
        {
            lightAPIs = new Dictionary <string, LifxAPI>();
            List <Light> lights = LifxAPI.GetLightStatus().Results;

            Console.WriteLine(lights.Count + " light(s) found");
            Console.WriteLine("Assigning lights to gestures...");

            string[] configFileLines = new string[lights.Count];
            for (int i = 0; i < lights.Count; i++)
            {
                Console.Write("{0}\t to command: ", lights[i].Label);
                string assignedGesture = Console.ReadLine();
                while (!IsValidGestureName(assignedGesture))
                {
                    Console.Write("Invalid gesture assignment, please try again: ");
                    assignedGesture = Console.ReadLine();
                }
                configFileLines[i] = lights[i].Label + "\t" + assignedGesture;
            }
            Console.WriteLine(dir + configFileName);
            System.IO.File.WriteAllLines(dir + configFileName, configFileLines);
            Console.WriteLine("Configuration Complete!");
            LoadConfig();
        }
Ejemplo n.º 2
0
        private static void OnGestureDetected(object sender, GestureSegmentTriggeredEventArgs args, ConsoleColor foregroundColor)
        {
            LightListResponse response;

            string gesture = args.GestureSegment.Name;

            if (gesture == "RotateUp1")
            {
                response = lightAPIs["Onefinger"].BrightnessUp();
            }
            else if (gesture == "RotateDown1")
            {
                response = lightAPIs["Onefinger"].BrightnessDown();
            }
            else if (gesture == "RotateUp2")
            {
                response = lightAPIs["TwoFingers"].BrightnessUp();
            }
            else if (gesture == "RotateDown2")
            {
                response = lightAPIs["TwoFingers"].BrightnessDown();
            }
            else if (lightAPIs.ContainsKey(gesture))
            {
                response = lightAPIs[gesture].Toggle();
            }
            else if (gesture == "Open")
            {
                LifxAPI.TurnOnAll();
            }
            else if (gesture == "Close")
            {
                LifxAPI.TurnOffAll();
            }

            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write("Gesture detected! : ");
            Console.ForegroundColor = foregroundColor;
            Console.WriteLine(gesture);
            Console.ResetColor();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            if (!System.IO.File.Exists(dir + configFileName))
            {
                ConfigRoutine();
            }
            else
            {
                LoadConfig();
            }

            //Console.Title = "GesturesServiceStatus[Initializing]";
            //Console.WriteLine("Execute one of the following gestures: closedFist->oneFinger, twoFingers, threeFingers, fourFingers, fiveFingers\npress 'ctrl+c' to exit");
            PrintConfigInfo();
            // One can optionally pass the hostname/IP address where the gestures service is hosted
            gesturesServiceHostName = !args.Any() ? "localhost" : args[0];

            //
            // Main Program Loop
            //
            while (true)
            {
                Console.WriteLine("Gesture detection started...\nPress 'esc' to pause gesture detection and show menu");

                StartGestureDetection();

                ConsoleKeyInfo keyPressed;
                do
                {
                    keyPressed = Console.ReadKey(true);
                } while (keyPressed.Key != ConsoleKey.Escape);

                StopGestureDetection();

                //
                // Menu Loop
                //
                while (true)
                {
                    string userInput;
                    Console.Write("Enter a command - ");
                    userInput = Console.ReadLine();
                    string[] commandArray = userInput.Split(null);

                    if (userInput == "q")
                    {
                        Environment.Exit(0);
                    }
                    if (userInput == "config" || userInput == "c")
                    {
                        ConfigRoutine();
                    }
                    else if (userInput == "help" || userInput == "h")
                    {
                        PrintConfigInfo();
                    }
                    else if (userInput == "status")
                    {
                        LightListResponse response = LifxAPI.GetLightStatus();
                    }
                    else if (userInput == "start" || userInput == "s")
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Invalid input");
                    }
                }
            }
        }