Exemplo n.º 1
0
        private void NewSensorData(object Sender, SensorDataEventArgs e)
        {
            FieldNumeric Num;
            FieldBoolean Bool;
            double?      LightPercent = null;
            bool?        Motion       = null;

            if (e.HasRecentFields)
            {
                foreach (Field Field in e.RecentFields)
                {
                    switch (Field.FieldName)
                    {
                    case "Temperature":
                        if ((Num = Field as FieldNumeric) != null)
                        {
                            Num = Num.Convert("C");
                            if (Num.Unit == "C")
                            {
                                Controller.SetTemperature(Num.Value);
                            }
                        }
                        break;

                    case "Light":
                        if ((Num = Field as FieldNumeric) != null)
                        {
                            Num = Num.Convert("%");
                            if (Num.Unit == "%" && Num.Value >= 0 && Num.Value <= 100)
                            {
                                Controller.SetLight(Num.Value);
                                LightPercent = Num.Value;
                            }
                        }
                        break;

                    case "Motion":
                        if ((Bool = Field as FieldBoolean) != null)
                        {
                            Controller.SetMotion(Bool.Value);
                            Motion = Bool.Value;
                        }
                        break;
                    }
                }

                if (LightPercent.HasValue && Motion.HasValue)
                {
                    Controller.CheckControlRules(LightPercent.Value, Motion.Value);
                }
            }
        }