Ejemplo n.º 1
0
        public static void CheckControlRules(double LightPercent, bool Motion)
        {
            int  NrLeds  = (int)System.Math.Round((8 * LightPercent) / 100);
            int  LedMask = 0;
            int  i       = 1;
            bool Alarm;

            while (NrLeds > 0)
            {
                NrLeds--;
                LedMask |= i;
                i      <<= 1;
            }

            Alarm = LightPercent < 20 && Motion;

            if (LedMask != lastLedMask)
            {
                lastLedMask = LedMask;
                foreach (Actuator Actuator in Topology.Source.GetObjects(typeof(Actuator), User.AllPrivileges))
                {
                    Actuator.UpdateLeds(LedMask);
                }
            }

            if (!lastAlarm.HasValue || lastAlarm.Value != Alarm)
            {
                lastAlarm = Alarm;
                UpdateClients();

                foreach (Actuator Actuator in Topology.Source.GetObjects(typeof(Actuator), User.AllPrivileges))
                {
                    Actuator.UpdateAlarm(Alarm);
                }

                if (Alarm)
                {
                    Thread T = new Thread(SendAlarmMail);
                    T.Priority = ThreadPriority.BelowNormal;
                    T.Name     = "SendAlarmMail";
                    T.Start();
                }
            }
        }
        private object TestActuator(object[] P)
        {
            int i, j;

            foreach (Actuator Actuator in Topology.Source.GetObjects(typeof(Actuator), User.AllPrivileges))
            {
                Actuator.UpdateAlarm(true);

                i = 0;
                for (j = 0; j < 8; j++)
                {
                    i <<= 1;
                    i  |= 1;
                    Actuator.UpdateLeds(i);
                }

                Actuator.UpdateAlarm(false);

                for (j = 0; j < 8; j++)
                {
                    i <<= 1;
                    i  &= 255;
                    Actuator.UpdateLeds(i);
                }

                if (Controller.lastLedMask >= 0)
                {
                    Actuator.UpdateLeds(Controller.lastLedMask);
                }

                if (Controller.lastAlarm.HasValue)
                {
                    Actuator.UpdateAlarm(Controller.lastAlarm.Value);
                }
            }

            return(null);
        }