예제 #1
0
        /// <summary>
        /// Transforms a RGB into color into the corresponding hue, brightness and saturation
        /// parameters for the Hue light.
        /// </summary>
        /// <param name="color">Color.</param>
        /// <param name="hue">Hue.</param>
        /// <param name="saturation">Saturation.</param>
        /// <param name="brightness">Brightness.</param>
        public static void ColorValues(Color color, out int hue, out int saturation, out int brightness)
        {
            Vector3 hsv = HueLight.HueHSVfromRGB(color);

            hue        = Mathf.RoundToInt(hsv.x);
            saturation = Mathf.RoundToInt(hsv.y);
            brightness = Mathf.RoundToInt(hsv.z);
        }
예제 #2
0
        IEnumerator UpdateLightFromBridgeEnumerator(string id, HueLight lightToUpdate, Action <List <HueErrorInfo> > errorCallback = null)
        {
            string url = string.Format("{0}/lights/{1}", BaseURLWithUserName, id);

            var www = new WWWWrapper(url);

            yield return(www.waitToFinish());

            if (isValidJsonResponse(www, errorCallback))
            {
                ProcessLightUpdate(www.responseJSON, lightToUpdate);
            }
        }
예제 #3
0
        void ProcessLightUpdate(JSON json, HueLight lightToUpdate)
        {
            lightToUpdate.name            = json.getString(HueKeys.NAME, "");
            lightToUpdate.modelID         = json.getString(HueKeys.MODEL_ID, "");
            lightToUpdate.type            = json.getString(HueKeys.TYPE, "");
            lightToUpdate.softwareVersion = json.getString(HueKeys.SOFTWARE_VERSION, "");

            lightToUpdate.isColor    = (lightToUpdate.type == "Extended color light");
            lightToUpdate.isDimmable = (lightToUpdate.isColor || (lightToUpdate.type == "Dimmable light"));

            var stateJson = json.getJSON(HueKeys.STATE);

            lightToUpdate.state = GetStateFromJSON(stateJson);
        }
예제 #4
0
 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
 {
     EditorGUI.PropertyField(position, property, label, true);
     if (property.isExpanded)
     {
         if (GUI.Button(new Rect(position.xMin + 30f, position.yMax - 20f, position.width - 30f, 20f), "Set State"))
         {
             string id = property.FindPropertyRelative("id").stringValue;
             //pretty ugly but
             HueLight light = HueBridge.instance.Lights.Find(x => x.id == id);
             if (light != null)
             {
                 light.SetState();
             }
         }
     }
 }
예제 #5
0
        void ProcessLights(JSON response, Action <List <HueLight> > lightsCallback)
        {
            var list = new List <HueLight>();

            foreach (var id in response.getKeyList())
            {
                var lightJson = response.getJSON(id);

                Debug.LogFormat("Light {0}: {1}", id, lightJson);

                //var lightDict = kv.Value as Dictionary<string, object>;
                var light = new HueLight(id);
                ProcessLightUpdate(lightJson, light);
                list.Add(light);
            }
            lightsCallback(list);
        }
예제 #6
0
 public void CopyState(HueLight fromLight)
 {
     SetState(fromLight.StateToParameters());
 }
예제 #7
0
 // Gets a light's current data from the bridge and updates the client's data about it.
 public void UpdateLightFromBridge(string id, HueLight lightToUpdate, Action <List <HueErrorInfo> > errorCallback = null)
 {
     StartCoroutine(UpdateLightFromBridgeEnumerator(id, lightToUpdate, errorCallback));
 }