Ejemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        for (int i = 0; i < HueColor.Count; ++i)
        {
            UICornerCut    ucc       = Instantiate(template, template.transform.parent);
            HueColor.Names enumColor = (HueColor.Names)i;

            //ucc.color = HueColor.HueColorValue (enumColor);
            ucc.color = enumColor.Color();
            ucc.GetComponentInChildren <Text> ().text = enumColor.ToString();

            ucc.gameObject.SetActive(true);
        }

        for (int i = 0; i < HueColor.Count; ++i)
        {
            UICornerCut    ucc       = Instantiate(template, template.transform.parent);
            HueColor.Names enumColor = (HueColor.Names)i;

            ucc.color = HueColor.HueColorValue(enumColor, 128);
            ucc.GetComponentInChildren <Text> ().text = enumColor.ToString() + " a=128";

            ucc.gameObject.SetActive(true);
        }
    }
 /// <summary>
 /// Set hue.
 /// </summary>
 /// <param name="color">
 /// The color.
 /// </param>
 internal void SetHue(string color)
 {
     if (Enum.TryParse(color, true, out HueColor tempHueColor))
     {
         this.hueColor = tempHueColor;
     }
     else
     {
         throw new ArgumentException($"invalid color ({color})", nameof(color));
     }
 }
Ejemplo n.º 3
0
 public void UpdateValues(Light light)
 {
     this.light                  = light;
     this.DeviceName.Text        = this.light.Name;
     this.OnToggle.Checked       = this.light.On;
     this.BrightnessSlider.Value = this.light.Brightness;
     if (this.light.Color != null)
     {
         var color = HueColor.ConvertXyToRgb(this.light.Color.X, this.light.Color.Y, 255f);
         this.LightColorIndicator.BackColor = color;
     }
 }
Ejemplo n.º 4
0
        public override void Render(IDrawingContextImpl context)
        {
            var canvas  = (context as ISkiaDrawingContextImpl)?.SkCanvas;
            var surface = (context as ISkiaDrawingContextImpl)?.SkSurface;

            if (canvas == null | surface == null)
            {
                context.Clear(Colors.White);
                context.DrawText(new SolidColorBrush(Colors.Black), new Point(), NoSkia);
            }
            else
            {
                Surface = surface;
                var width  = (int)Bounds.Width;
                var height = (int)Bounds.Height;

                var info = new SKImageInfo(width, height);

                using (SKPaint paint = new SKPaint())
                {
                    SKColor[] colors = { SKColors.White, HueColor.ToSKColor() };

                    SKPoint center = new SKPoint(info.Rect.MidX, info.Rect.MidY);

                    paint.Shader = SKShader.CreateLinearGradient(new SKPoint(0, 0), new SKPoint(width, 0), colors, SKShaderTileMode.Repeat);

                    var rect = SKRect.Create(width, height);
                    canvas.DrawRect(rect, paint);
                }

                // Creates the black gradient effect (transparent to black)
                using (SKPaint paint = new SKPaint())
                {
                    SKColor[] colors = { SKColors.Transparent, SKColors.Black };

                    paint.Shader = SKShader.CreateLinearGradient(new SKPoint(0, 0), new SKPoint(0, height), colors, SKShaderTileMode.Repeat);

                    var rect = SKRect.Create(width, height);

                    canvas.DrawRect(rect, paint);
                }

                using (SKPaint paint = new SKPaint())
                {
                    paint.Shader = SKShader.CreateColor(StrokeColor.ToSKColor());
                    var rect = SKRect.Create(width, height);
                    paint.Style       = SKPaintStyle.Stroke;
                    paint.StrokeWidth = StrokeWidth;
                    canvas.DrawRect(rect, paint);
                }
            }
        }
Ejemplo n.º 5
0
    private Item createItem(string name, string state, string shortName, string unit = null)
    {
        switch (name)
        {
        case Settings.AirPressure:
            return(new AirPressure(name, state, unit, shortName));

        case Settings.AmbientLight:
            return(new AmbientLight(name, state, unit, shortName));

        case Settings.AmbientTemp:
            return(new AmbientTemp(name, state, unit, shortName));

        case Settings.Dimmer1 + "_Sensor":
            return(new DimmerSensor(Settings.Dimmer1, state, null, shortName));

        case Settings.Dimmer1 + "_Actuator":
            return(new DimmerActuator(Settings.Dimmer1, state, shortName));

        case Settings.Dimmer2 + "_Sensor":
            return(new DimmerSensor(Settings.Dimmer2, state, null, shortName));

        case Settings.Dimmer2 + "_Actuator":
            return(new DimmerActuator(Settings.Dimmer2, state, shortName));

        case Settings.DoorLock:
            return(new DoorLock(name, state, shortName));

        case Settings.GongSound:
            return(new GongSound(name, state, shortName));

        case Settings.GongLight:
            return(new GongLight(name, state, shortName));

        case Settings.Humidity:
            return(new Humidity(name, state, unit, shortName));

        case Settings.AmbientLight2:
            return(new AmbientLight(name, state, unit, shortName));

        case Settings.LinearPoti:
            return(new Poti(name, state, unit, shortName));

        case Settings.NFCReader:
            return(new NfcReader(name, state, shortName));

        case Settings.CoffeeMachine:
            return(new CoffeeMachineActuator(name, state, shortName));

        case Settings.myoArmband:
            return(new MyoArmband(name, state, shortName));

        case Settings.colorSensor:
            return(new ColorSensor(name, state, shortName));

        case Settings.hueLamp1dimmer:
            return(new HueDimmer(name, state, shortName));

        case Settings.hueLamp2dimmer:
            return(new HueDimmer(name, state, shortName));

        //Associate HueColor with HueDimmer if HueDimmer already exists
        case Settings.hueLamp1color:
        {
            HueColor  hc1 = new HueColor(name, state, shortName);
            HueDimmer hd1 = (HueDimmer)ItemManager.getInstance().getItem(Settings.hueLamp1dimmer);
            if (hd1 != null)
            {
                hd1.hueColor = hc1;
            }
            return(hc1);
        }

        case Settings.hueLamp2color:
            HueColor  hc2 = new HueColor(name, state, shortName);
            HueDimmer hd2 = (HueDimmer)ItemManager.getInstance().getItem(Settings.hueLamp2dimmer);
            if (hd2 != null)
            {
                hd2.hueColor = hc2;
            }
            return(hc2);

        default:
            Debug.Log("invalid name: " + name);
            break;
        }

        return(null);
    }
Ejemplo n.º 6
0
    public IEnumerator performAction()
    {
        UnityWebRequest www;

        www = UnityWebRequest.Get(requestURL);

        yield return(www.Send());

        while (!www.isDone)
        {
            Debug.LogError(".");
            yield return(null);
        }

        if (www.isError)
        {
            Debug.Log(www.error);
        }
        else
        {
            string temp = www.downloadHandler.text;
#if WINDOWS_UWP
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(List <GETResponse>));

            MemoryStream ms     = new MemoryStream();
            StreamWriter writer = new StreamWriter(ms);
            writer.Write(temp);
            writer.Flush();
            ms.Position = 0;
            //get status from json answer
            getResponses = (List <GETResponse>)ser.ReadObject(ms);
#endif
            foreach (string fullItemName in Settings.Items)
            {
                GETResponse singleItemGetResponse = getResponses.Find(x => x.name.Equals(fullItemName));
                if (singleItemGetResponse != null)
                {
                    //gather all info needed to update or create the item in the ItemManager
                    //we need key, name, state, shortName, unit (optionally). We already have key, name, state.
                    //first read in the unit, if existent
                    string unit = "";

                    if (singleItemGetResponse.stateDescription != null && singleItemGetResponse.stateDescription.pattern != null)
                    {
                        string[] stateDesc = singleItemGetResponse.stateDescription.pattern.Split(' ');
                        if (stateDesc.Length > 1)
                        {
                            unit = stateDesc[1];
                            if (unit.EndsWith("%"))
                            {
                                unit = unit.Remove(unit.Length - 1);
                            }
                        }
                    }

                    //next, the shortName
                    string shortName;
                    switch (fullItemName)
                    {
                    case Settings.LinearPoti:
                        shortName = Settings.LinearPoti;
                        break;

                    case Settings.NFCReader:
                        shortName = Settings.NFCReader;
                        break;

                    case Settings.CoffeeMachine:
                        shortName = Settings.CoffeeMachine;
                        break;

                    case Settings.myoArmband:
                        shortName = Settings.myoArmband;
                        break;

                    case Settings.hueLamp1dimmer:
                        shortName = "huedimmer_1";
                        break;

                    case Settings.hueLamp2dimmer:
                        shortName = "huedimmer_2";
                        break;

                    default:
                        string[] tempName = fullItemName.Split('_');
                        shortName = tempName[tempName.Length - 2] + "" + tempName[tempName.Length - 1];
                        break;
                    }

                    //now we have all we need. Update the list!

                    //if the current item is the dimmer, update both sensor and actuator reference
                    if (fullItemName.Contains("homematic_dimmer"))
                    {
                        ItemManager.getInstance().updateItem(fullItemName + "_Sensor", fullItemName, singleItemGetResponse.state, shortName, unit);
                        ItemManager.getInstance().updateItem(fullItemName + "_Actuator", fullItemName, singleItemGetResponse.state, shortName, unit);
                    }
                    else
                    if (fullItemName.Contains("bulb210_color"))
                    {
                        ItemManager.getInstance().updateItem(fullItemName, fullItemName, singleItemGetResponse.state, shortName, unit);
                        HueColor i      = (HueColor)ItemManager.getInstance().getItem(fullItemName);
                        string[] colors = singleItemGetResponse.state.Split(',');
                        int.TryParse(colors[0], out i.h);
                        int.TryParse(colors[1], out i.s);
                        int.TryParse(colors[2], out i.v);
                    }
                    else

                    if (fullItemName.Equals(Settings.colorSensor))
                    {
                        ItemManager.getInstance().updateItem(fullItemName, fullItemName, singleItemGetResponse.state, shortName, unit);
                        ColorSensor c      = (ColorSensor)ItemManager.getInstance().getItem(fullItemName);
                        string[]    colors = singleItemGetResponse.state.Split(',');
                        int.TryParse(colors[0], out c.r);
                        int.TryParse(colors[1], out c.g);
                        int.TryParse(colors[2], out c.b);
                    }
                    else
                    {
                        ItemManager.getInstance().updateItem(fullItemName, fullItemName, singleItemGetResponse.state, shortName, unit);
                    }
                }
            }
            //default case
        }
    }
Ejemplo n.º 7
0
    // Update is called once per frame
    void Update()
    {
        updateCounter++;
        if (updateCounter >= Settings.statusUpdateNumber)
        {
            string status = "invalid";

            string   objectName;
            string[] nameSubstrings;

            objectName = gameObject.transform.parent.name;

            nameSubstrings = objectName.Split('_');

            int    pos         = objectName.IndexOf('_');
            string cleanedName = objectName.Substring(pos + 1);

            Item i = ItemManager.getInstance().getItem(cleanedName);
            if (i != null)
            {
                status = i.state;
                if (i.type.Equals("Sensor"))
                {
                    status += " " + ((Sensor)i).unit;

                    if (cleanedName.Contains("idscan"))
                    {
                        status = ((NfcReader)i).getName();
                    }
                }
                updateCounter = 0;
                this.transform.GetChild(0).GetChild(1).GetComponent <Text>().text = i.shortName;
                //if(objectName.Contains("dimmer"))
                //    Debug.Log("shortname of " + objectName + " is " + i.shortName + " with status " + status);
            }
            if (i is ColorSensor || i is HueDimmer || i is CoffeeMachineActuator)
            {
                if (i is ColorSensor || i is HueDimmer)
                {
                    byte r, g, b;

                    if (i is ColorSensor)
                    {
                        ColorSensor c = (ColorSensor)i;
                        r = Convert.ToByte(c.r);
                        g = Convert.ToByte(c.g);
                        b = Convert.ToByte(c.b);
                        this.transform.GetChild(0).GetChild(1).GetChild(0).GetComponent <Image>().color = new Color32(r, g, b, 255);
                    }
                    else
                    {
                        HueDimmer hd = (HueDimmer)i;
                        HueColor  c  = hd.hueColor;

                        float hf = (float)c.h / 360;
                        float sf = (float)c.s / 100;
                        float vf = (float)c.v / 100;

                        Color rgbColor = Color.HSVToRGB(hf, sf, vf, false);
                        this.transform.GetChild(0).GetChild(1).GetChild(0).GetComponent <Image>().color = rgbColor;

                        string RGBstring = rgbColor.ToString();

                        int Ri = (int)(rgbColor.r * 255);
                        int Bi = (int)(rgbColor.b * 255);
                        int Gi = (int)(rgbColor.g * 255);

                        string RGBstr = Ri.ToString() + "," + Gi.ToString() + "," + Bi.ToString();
                        Debug.Log(RGBstr);
                        this.transform.GetChild(0).GetChild(1).GetChild(1).GetComponent <Text>().text = RGBstr;
                    }

                    this.transform.GetChild(0).GetChild(2).GetComponent <Text>().text = status;
                }
                else
                {
                    CoffeeMachineActuator c = (CoffeeMachineActuator)i;
                    this.transform.GetChild(0).GetChild(3).GetChild(1).GetComponent <Text>().text = c.getWaterLevel();
                    this.transform.GetChild(0).GetChild(2).GetComponent <Text>().text             = status;
                }
            }
            else
            {
                this.transform.GetChild(0).GetChild(2).GetComponent <Text>().text = status;
            }
        }
    }
Ejemplo n.º 8
0
        private IEnumerator Cycle()
        {
            var lastStopTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

            for (var i = 0;; i++)
            {
                i %= ColorStops.Length;
                var colorStop = ColorStops[i];

                FrontColor = colorStop.FrontColor;
                BackColor  = colorStop.BackColor;

                if (colorStop.Length != 0)
                {
                    yield return(new WaitForSeconds(colorStop.Length));
                }

                if (colorStop.Transition != null)
                {
                    var nextColorStop = ColorStops[(i + 1) % ColorStops.Length];

                    var transitionTime = colorStop.Transition.Length * 1000;
                    var difference     = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - lastStopTime;

                    switch (colorStop.Transition.Type)
                    {
                    case TransitionTypes.RgbShift:
                    {
                        while (difference < transitionTime)
                        {
                            var progress = difference / transitionTime;
                            FrontColor = Color.Lerp(colorStop.FrontColor, nextColorStop.FrontColor, progress);
                            BackColor  = Color.Lerp(colorStop.BackColor, nextColorStop.BackColor, progress);

                            yield return(new WaitForEndOfFrame());

                            difference = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - lastStopTime;
                        }

                        break;
                    }

                    case TransitionTypes.HueShift:
                    {
                        var frontStartColor = colorStop.FrontColor.ToHueColor();
                        var frontEndColor   = nextColorStop.FrontColor.ToHueColor();
                        var backStartColor  = colorStop.BackColor.ToHueColor();
                        var backEndColor    = nextColorStop.BackColor.ToHueColor();

                        while (difference < transitionTime)
                        {
                            var progress = difference / transitionTime;
                            FrontColor = HueColor.Lerp(frontStartColor, frontEndColor, progress).ToRgbColor();
                            BackColor  = HueColor.Lerp(backStartColor, backEndColor, progress).ToRgbColor();

                            yield return(new WaitForEndOfFrame());

                            difference = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - lastStopTime;
                        }

                        break;
                    }
                    }
                }

                lastStopTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
            }
        }