Esempio n. 1
0
 public void Begin(LightZone activeZone)
 {
 }
Esempio n. 2
0
        public override void Begin(LightZone activeZone)
        {
            TimeSpan timeRemaining = TotalDuration - (new DateTime(1, 1, 1, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second) - EventStartTime);
            bool     turningOn = true;
            TimeSpan max, min;
            int      newbrightness;

            /*
             * So long as the there is enough time for the minimum 'on' period to elapse, it will cylce. The first cycle will be a turn-on,
             * and it will set the max and min to the maximum and minimum 'on' periods. Then, it ensures that the maximum will not
             * cause the event to exceed the maximum event duration. Then, it calculates a random number of seconds
             * between the maximum and minimum previously defined and sleeps for that amount of time. Finally, it reverses
             * the value of 'turningOn', so that it proceeds to set the max and min to the maximum and minimum 'off' times and
             * changes the value of 'newBrightness' to shut off the lights instead of turning them on.
             */
            while (timeRemaining > MinOnDuration || (StayOnEntireDuration && timeRemaining > new TimeSpan(0, 0, 10)))
            {
                if (turningOn)
                {
                    max           = MaxOnDuration;
                    min           = MinOnDuration;
                    newbrightness = OnBrightness;
                }
                else
                {
                    max           = MaxOffDuration;
                    min           = MinOffDuration;
                    newbrightness = 0;
                }
                TimeSpan realmax = max;
                if (timeRemaining < max)
                {
                    realmax = timeRemaining; // The maximum time must always be less than or equal to the time remaining (no OT)
                }
                int secondsToSleep;
                if (min < realmax)
                {
                    secondsToSleep = RandGenerator.Next((int)(min.TotalSeconds), (int)(realmax.TotalSeconds));
                }
                else if (min.TotalSeconds > 0)
                {
                    secondsToSleep = (int)min.TotalSeconds;
                }
                else
                {
                    break;
                }

                //Finds seconds to sleep as a random number between the minimum sleep time and the maximum sleep time.
                //It finds seconds (not milliseconds) so that the limit on integer size is not exceeded
                string onORoff;
                if (turningOn)
                {
                    onORoff = "on";
                }
                else
                {
                    onORoff = "off";
                }
                activeZone.Log.WriteLine(String.Format(
                                             "Turning {0} {1} lights",
                                             onORoff,
                                             activeZone.name
                                             ));
                activeZone.SetBrightness(newbrightness);
                Thread.Sleep(new TimeSpan(0, 0, secondsToSleep));
                turningOn     = !turningOn; //Switches TurningOn (if true, it is now false. if false, it is now true)
                timeRemaining = TotalDuration - (new DateTime(1, 1, 1, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second) - EventStartTime);
            }
            if (TurnOffAfter)
            {
                activeZone.SetBrightness(0);
            }
        }
Esempio n. 3
0
 public AutoController(LightZone editingZone, List <Event> events)
 {
     EditingZone     = editingZone;
     ScheduledEvents = events;
 }