Exemple #1
0
 void UpdateSmartLightUI(SmartLight sl)
 {
     if (sl.Name == gameObject.name)
     {
         Renderer rend = gameObject.GetComponent <Renderer>();
         //Debug.Log(sl.State.Hue);
         Vector4 ledColor = ColorService.GetColorByHue(sl.State.Hue);
         //Debug.Log(ledColor);
         rend.material.color = ledColor;
     }
 }
Exemple #2
0
        public LuxxusSmartLight(SmartLight light)
            : base(light)
        {
            if (light != null && light.State != null)
            {
                if (light.State.Intensity > 100)
                {
                    light.State.Intensity = 100;
                }

                double intensity = Math.Round(light.State.Intensity * 255.0 / 100.0, MidpointRounding.ToEven);

                this.State.Intensity = (ushort)intensity;
            }
        }
Exemple #3
0
    private void initBrightness(List <SmartLight> smartLights)
    {
        var idTag = holoLightContainer.tag;

        // Ignores HoloLightContainers that do not have a valid id assigned to tag
        if (int.TryParse(idTag, out arrayId))
        {
            currentLight = smartLights[arrayId];
        }

        // Calculates ranges for BrightnessIndicator public vars
        sizeRange       = maxSize - minSize;
        heightRange     = maxHeight - minHeight;
        brightnessRange = maxBrightness - minBrightness;
    }
 private void initSelector()
 {
     if (holoLightContainer.tag != "Untagged")
     {
         var idTag = holoLightContainer.tag;
         // Ignores HoloLightContainers that do not have a valid id assigned to tag
         if (int.TryParse(idTag, out arrayId))
         {
             currentLight = SmartLightManager.lights[arrayId];
         }
     }
     else
     {
         Debug.Log("No tag containing arrayId was found on this HoloLightContainer.");
     }
 }
    // Update is called once per frame
    void Update()
    {
        var focusObject = GestureManager.Instance.FocusedObject;

        if (focusObject != null)
        {
            //slm.UpdateLightState(focusObject.name, param, value);
            //SmartLightManager.light
            if (focusObject.tag != "Untagged")
            {
                var idTag = focusObject.tag;
                //// Ignores focusObject if it does not have a valid id assigned to tag
                if (int.TryParse(idTag, out arrayId))
                {
                    currentLight = SmartLightManager.lights[arrayId];
                }
            }
        }
    }
Exemple #6
0
        public SmartLight[] GetLights()
        {
            SmartLight[] result = null;

            lock (this.UpdatingDataLocker)
            {
                if (this.CurrentLampStates != null)
                {
                    result = new SmartLight[this.CurrentLampStates.Count];

                    for (int i = 0; i < this.CurrentLampStates.Count; i++)
                    {
                        SmartLightState state = new SmartLightState(this.CurrentLampStates[i].State);
                        state.Intensity = (ushort)Math.Round(state.Intensity * 100.0 / 255.0, MidpointRounding.ToEven);
                        result[i]       = new SmartLight(this.CurrentLampStates[i].Id, state);
                    }
                }
            }

            return(result);
        }
Exemple #7
0
    private IEnumerator updateLight(SmartLight sl)
    {
        string request = "http://" + bridgeValues.bridgeip + "/api/" + bridgeValues.username + "/lights/" + sl.ID.ToString() + "/state";
        //Debug.Log("Send triggered to " + request);

        string json = JsonUtility.ToJson(sl.State);

        UnityWebRequest www = UnityWebRequest.Put(request, json);

        yield return(www.Send());

        if (www.isError)
        {
            Debug.LogError("There was an error with your request: " + www.error);
        }
        else
        {
            // TODO - Perhaps this should be changed to be an event in the event mananger's listing
            hologramCollection.BroadcastMessage("UpdateSmartLightUI", sl);
        }
    }
    void buildUpdateCall(string param, int value)
    {
        var focusedObject = GestureManager.Instance.FocusedObject;

        //Debug.Log("here is focused object: " + focusObject);
        //if (focusObject != null)
        //{
        //    slm.UpdateLightState(focusObject.name, param, value);
        //    //SmartLightManager.light
        //}
        if (focusedObject != null)
        {
            // retrieves array index (arrayId) from the tag assigned in SmartLightManager
            if (focusedObject.tag != "Untagged")
            {
                var idTag = focusedObject.tag;
                //// Ignores focusedObject if it does not have a valid id assigned to tag
                if (int.TryParse(idTag, out arrayId))
                {
                    currentLight = SmartLightManager.lights[arrayId];
                    if (param == "On")
                    {
                        currentLight.State.On = true;
                    }
                    else if (param == "Off")
                    {
                        currentLight.State.On = false;
                    }
                    else if (param == "hue")
                    {
                        // auto sets saturation to full to show vibrant colors. Will replace when Saturation UI is added in another version
                        currentLight.State.Sat = 254;

                        currentLight.State.Hue = value;

                        if (voiceChangedColor != null)
                        {
                            // arrayID is adjusted to compensate for diff in Hue id
                            voiceChangedColor(arrayId + 1, ColorService.GetColorByHue(value));
                        }
                    }
                    else if (param == "bri")
                    {
                        currentLight.State.Bri = value;
                    }
                    else if (param == "alert")
                    {
                        if (value == 0)
                        {
                            currentLight.State.Alert = "none";
                        }
                        else
                        {
                            currentLight.State.Alert = "lselect";
                        }
                    }
                    // hueAPI.UpdateLight(currentLight);
                    SmartLightManager.UpdateLightState(arrayId);
                    currentLight.State.Alert = "none";
                }
                else
                {
                    Debug.Log("a tag with a valid array index (arrayId) could not be found on focusedObject");
                }
            }
            else
            {
                Debug.Log("No tag containing arrayId was found on this focusedObject.");
            }
        }
    }
    void buildUpdateCall(string param, int value)
    {
        var focusedObject = GestureManager.Instance.FocusedObject;

        //Debug.Log("here is focused object: " + focusObject);
        //if (focusObject != null)
        //{
        //    slm.UpdateLightState(focusObject.name, param, value);
        //    //SmartLightManager.light
        //}
        if (focusedObject != null)
        {
            // retrieves array index (arrayId) from the tag assigned in SmartLightManager
            if (focusedObject.tag != "Untagged")
            {
                var idTag = focusedObject.tag;
                //// Ignores focusedObject if it does not have a valid id assigned to tag
                if (int.TryParse(idTag, out arrayId))
                {
                    currentLight = SmartLightManager.lights[arrayId];
                    if (param == "On")
                    {
                        currentLight.State.On = true;
                    }
                    else if (param == "Off")
                    {
                        currentLight.State.On = false;
                    }
                    else if (param == "hue")
                    {
                        currentLight.State.Hue = value;
                        currentLight.State.Sat = 254;
                    }
                    else if (param == "bri")
                    {
                        currentLight.State.Bri = value;
                    }
                    else if (param == "alert")
                    {
                        if (value == 0)
                        {
                            currentLight.State.Alert = "none";
                        }
                        else
                        {
                            currentLight.State.Alert = "lselect";
                        }
                    }
                    // hueAPI.UpdateLight(currentLight);
                    SmartLightManager.UpdateLightState(arrayId);
                    currentLight.State.Alert = "none";
                }
                else
                {
                    Debug.Log("a tag with a valid array index (arrayId) could not be found on focusedObject");
                }
            }
            else
            {
                Debug.Log("No tag containing arrayId was found on this focusedObject.");
            }
        }
    }
Exemple #10
0
 public void UpdateLight(SmartLight sl)
 {
     StartCoroutine(updateLight(sl));
 }
Exemple #11
0
        public void Start()
        {
            Console.WriteLine("Starting smartobject...");

            Console.WriteLine("What is my Address?");

            Console.Write("-> ");
            string address = Console.ReadLine();

            IPAddress ipAddress;

            if (!string.IsNullOrEmpty(address) && IPAddress.TryParse(address, out ipAddress))
            {
                Console.WriteLine("What is my port?");

                Console.Write("-> ");
                string portStr = Console.ReadLine();

                int port = 0;

                if (!string.IsNullOrEmpty(portStr) && int.TryParse(portStr, out port))
                {
                    if (SmartManagerService.Register(address, port))
                    {
                        Console.WriteLine("Choose my type:");
                        Console.WriteLine("1 - TV");
                        Console.WriteLine("2 - Air Conditioner");
                        Console.WriteLine("3 - Light");
                        Console.WriteLine("4 - Water heater");
                        Console.WriteLine("5 - Lock");

                        Console.Write("->");
                        string type = Console.ReadLine();

                        SmartThing smartThing = null;

                        switch (type)
                        {
                        case "1":
                            smartThing = new SmartTV();

                            break;

                        case "2":
                            smartThing = new SmartAirConfitioner();

                            break;

                        case "3":
                            smartThing = new SmartLight();

                            break;

                        case "4":
                            smartThing = new SmartWaterHeater();

                            break;

                        case "5":
                            smartThing = new SmartLock();

                            break;

                        default:
                            Console.WriteLine("Invalid choice...");

                            break;
                        }

                        if (smartThing != null)
                        {
                            new Listener().Listen(ipAddress, port, smartThing);
                        }
                    }

                    else
                    {
                        Console.WriteLine("Sorry... Could not register myself to the manager...");
                    }
                }

                else
                {
                    Console.WriteLine("Port not valid...");
                }
            }

            else
            {
                Console.WriteLine("Invalid address...");
            }

            Console.WriteLine("Smart object shutting down...");
        }