Exemplo n.º 1
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);
    }
Exemplo n.º 2
0
    public void updateItem(string key, string name, string state, string shortName, string unit = null)
    {
        //Debug.LogFormat("updating key {0} name {1} state {2} shortName {3} unit{4}", key, name, state, shortName, unit);
        if (items.ContainsKey(key))
        {
            Item i = items[key];
            //if (i == null)
            //Debug.Log("item was null");
            //else
            //Debug.Log("item wasnt null");
            string gameObjectName = name;

            if (name.Equals(Settings.NFCReader))
            {
                ((NfcReader)i).update(name, state, shortName, unit);
                gameObjectName = "Sensor_" + gameObjectName;
            }
            else if (name.Equals(Settings.myoArmband))
            {
                ((MyoArmband)i).update(name, state, shortName, unit);
                gameObjectName = "Sensor_" + gameObjectName;
            }
            else if (i.type.Equals("Sensor"))
            {
                ((Sensor)i).update(name, state, shortName, unit);
                gameObjectName = "Sensor_" + gameObjectName;
            }
            else if (i.type.Equals("Actuator"))
            {
                ((Actuator)i).update(name, state, shortName, unit);
                gameObjectName = "Actuator_" + gameObjectName;
            }

            //Associate HueColor with HueDimmer if HueDimmer didn't exist at item creation time
            if (name.Equals(Settings.hueLamp1dimmer))
            {
                HueDimmer hd1 = (HueDimmer)ItemManager.getInstance().getItem(name);
                if (hd1.hueColor == null)
                {
                    hd1.hueColor = (HueColor)ItemManager.getInstance().getItem(Settings.hueLamp1color);
                }
            }

            if (name.Equals(Settings.hueLamp2dimmer))
            {
                HueDimmer hd2 = (HueDimmer)ItemManager.getInstance().getItem(name);
                if (hd2.hueColor == null)
                {
                    hd2.hueColor = (HueColor)ItemManager.getInstance().getItem(Settings.hueLamp2color);
                }
            }

            if (!gameObjectName.Contains("Sensor") && !gameObjectName.Contains("homematic_dimmer"))
            {
                GameObject g = GameObject.Find(gameObjectName);
                if (!gameObjects.ContainsKey(gameObjectName))
                {
                    if (g != null)
                    {
                        gameObjects.Add(gameObjectName, g);
                    }
                    else
                    {
                        Debug.Log("tried to add " + gameObjectName + " but could not find reference");
                    }
                }

                //(de-)activate prefab
                if (gameObjects.ContainsKey(gameObjectName))
                {
                    GameObject gameObject = gameObjects[gameObjectName];
                    //Debug.Log("gameobject " + gameObjectName + " found");
                    if (state.Equals("error") | state.Equals("NULL") | state.Equals("UNDEF"))
                    {
                        gameObject.SetActive(false);
                    }
                    else
                    {
                        gameObject.SetActive(true);
                    }
                }
                else
                {
                    Debug.Log("could not find " + gameObjectName);
                }
            }
        }
        else
        {
            if (Settings.Items.Contains(name))
            {
                items[key] = createItem(key, state, shortName, unit);
                Debug.Log("created item " + name + "with key " + key);
                if (GameObject.Find(items[key].type + "_" + name) == null)
                {
                    if (items[key].type.Equals("Sensor") && !name.Contains("homematic_dimmer"))
                    {
                        GameObject.Find("Managers").GetComponent <InstantiatePrefab>().InstantiateSensor(name);
                    }
                }
            }
        }
    }
Exemplo n.º 3
0
        void Update()
        {
            //if (isSelected || isFocused)
            //{
            //    cubeMeshRenderer.material = style.highlightMat;
            //}
            //else
            //{
            //    cubeMeshRenderer.material = cubeDefaultMat;
            //}

            if (this.c != null)
            {
                updateCounter++;
                colorUpdateCounter++;
                if (updateCounter >= Settings.requestUpdateNumber)
                {
                    if (c.connState.Equals(Connection.States.Active))
                    {
                        Item source = ItemManager.getInstance().getItem(SourceName);
                        Item target = ItemManager.getInstance().getItem(TargetName);
                        if (source is Poti && target is DimmerActuator)
                        {
                            Poti           sPoti   = (Poti)source;
                            DimmerActuator tDimmer = (DimmerActuator)target;

                            int stateDim  = int.Parse(tDimmer.state);
                            int statePoti = int.Parse(sPoti.state);
                            if (statePoti == 0)
                            {
                                StartCoroutine(tDimmer.sendOFF());
                            }
                            else if (statePoti == 100)
                            {
                                StartCoroutine(tDimmer.sendON());
                            }
                            else if (stateDim <= (statePoti - 10))
                            {
                                StartCoroutine(tDimmer.sendINCREASE());
                            }
                            else if (stateDim >= (statePoti + 10))
                            {
                                StartCoroutine(tDimmer.sendDECREASE());
                            }
                        }
                        else
                        {
                            if (source is Poti && target is HueDimmer)
                            {
                                Poti      sPoti   = (Poti)source;
                                HueDimmer hDimmer = (HueDimmer)target;
                                StartCoroutine(hDimmer.sendState(sPoti.state));
                            }
                            else
                            {
                                if (source is ColorSensor && target is HueDimmer)
                                {
                                    if (colorUpdateCounter >= 100)
                                    {
                                        byte        r, g, b;
                                        ColorSensor cs = (ColorSensor)source;
                                        r = Convert.ToByte(cs.r);
                                        g = Convert.ToByte(cs.g);
                                        b = Convert.ToByte(cs.b);

                                        float h, s, v;

                                        Color32 colRgb = new Color32(r, g, b, 255);
                                        Color.RGBToHSV(colRgb, out h, out s, out v);
                                        HueDimmer hDimmer = (HueDimmer)target;

                                        int hr = (int)(h * 360);
                                        int sr = (int)(s * 100);
                                        int vr = (int)(v * 100);

                                        StartCoroutine(hDimmer.sendColor(hr, sr, vr));
                                        colorUpdateCounter = 0;
                                    }
                                }
                            }
                        }
                    }
                    updateCounter = 0;
                }
            }
        }
Exemplo n.º 4
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;
            }
        }
    }
Exemplo n.º 5
0
 public ColorHueConnection(string id, ColorSensor source, HueDimmer target) : base(id, source, target)
 {
     this.id     = id;
     this.source = source;
     this.target = target;
 }
Exemplo n.º 6
0
 public PotiHueConnection(string id, Poti source, HueDimmer target) : base(id, source, target)
 {
     this.id     = id;
     this.source = source;
     this.target = target;
 }