Beispiel #1
0
void AlarmClass::updateNextTrigger()
{
  if( (value != 0) && Mode.isEnabled )
  {
    time_t time = now();
    if(Mode.isAlarm && nextTrigger <= time )   // update alarm if next trigger is not yet in the future
    {
	  if ((repeatvalue&0x00ffffff)==0  || ((nextTrigger+(repeatvalue&0x00ffffff))>=(value + previousMidnight(time)) && nextTrigger<(value + previousMidnight(time))) )
      {
		if( value + previousMidnight(time) <= time) 
		{
		  nextTrigger = value + nextMidnight(time); // if time has passed then set for tomorrow
		}
		else
		{
		  nextTrigger = value + previousMidnight(time);  // set the date to today and add the time given in value	
		}
	  }
	  else
	  {
		if (repeatcount==0)
		{
			repeatcount=(repeatvalue&0xff000000)>>24;
			nextTrigger=0;
		}
		if (repeatcount>0) repeatcount-=1;

		if (nextTrigger==0)
		{
		  if( value + previousMidnight(time) <= time) 
		  {
		    nextTrigger = value + nextMidnight(time); // if time has passed then set for tomorrow 
		  }
		  else
		  {
		    nextTrigger = value + previousMidnight(time);  // set the date to today and add the time given in value	
		  }
		}
		else
		{
		  nextTrigger = nextTrigger + (repeatvalue&0x00ffffff);
		}
	  }
	  //Serial.print("nextTrigger[");
	  //Serial.print(relayid, DEC);
	  //Serial.print("] - ");
	  //Serial.print(month(nextTrigger));
	  //Serial.print("/");
	  //Serial.print(day(nextTrigger));
	  //Serial.print("/");
	  //Serial.print(year(nextTrigger));
	  //Serial.print(" ");
	  //Serial.print(hour(nextTrigger));
	  //Serial.print(":");
	  //Serial.print(minute(nextTrigger));
	  //Serial.print(":");
	  //Serial.println(second(nextTrigger));
    }
void Alarm::check(){
    if(_next > 0){
	  if((RTC.now().unixtime() >= _next)){
		if(_repeat){
    	  _next = nextMidnight(RTC.now().unixtime()) + _hour * SECS_PER_HOUR + _minute * SECS_PER_MIN + _second;
	    }else{
		  _next = 0;
	    }
        (*_callback)();
	  }
   }
}
void Alarm::set(byte hour, byte minute, byte second, AlarmCallback_t callback, boolean repeat){
	_hour = hour;
	_minute = minute;
	_second = second;
	_callback = callback;
	// set the event for today
	_next = previousMidnight(RTC.now().unixtime()) + _hour * SECS_PER_HOUR + _minute * SECS_PER_MIN + _second;
	// did the event already pass for today? if so, set it for tomorrow
	if(RTC.now().unixtime() >= _next){
		_next = nextMidnight(RTC.now().unixtime()) + _hour * SECS_PER_HOUR + _minute * SECS_PER_MIN + _second;
	}
	_repeat = repeat;
}
Beispiel #4
0
void AlarmNode::updateNextTrigger() {  
  if ((value != 0) && isEnabled) {
    time_t time = now();
    if (nextTrigger <= time) {  // update alarm if next trigger is not yet in the future     
      if (value + previousMidnight(time) <= time) {
        nextTrigger = value + nextMidnight(time); // if time has passed then set for tomorrow
      } else {
        nextTrigger = value + previousMidnight(time);  // set the date to today and add the time given in value   
      }
    }
  } else {
    isEnabled = 0;  // Disable if the value is 0
  }
}
Beispiel #5
0
void AlarmClass::updateNextTrigger()
{  
  if( (value != 0) && Mode.isEnabled )
  {
    time_t time = now();
    if( dtIsAlarm(Mode.alarmType) && nextTrigger <= time )   // update alarm if next trigger is not yet in the future
    {      
      if(Mode.alarmType == dtExplicitAlarm ) // is the value a specific date and time in the future
      {
        nextTrigger = value;  // yes, trigger on this value   
      }
      else if(Mode.alarmType == dtDailyAlarm)  //if this is a daily alarm
      {
        if( value + previousMidnight(now()) <= time)
        {
          nextTrigger = value + nextMidnight(time); // if time has passed then set for tomorrow
        }
        else
        {
          nextTrigger = value + previousMidnight(time);  // set the date to today and add the time given in value   
        }
      }
      else if(Mode.alarmType == dtWeeklyAlarm)  // if this is a weekly alarm
      {
        if( (value + previousSunday(now())) <= time)
        {
          nextTrigger = value + nextSunday(time); // if day has passed then set for the next week.
        }
        else
        {
          nextTrigger = value + previousSunday(time);  // set the date to this week today and add the time given in value 
        } 
      }
      else  // its not a recognized alarm type - this should not happen 
      {
        Mode.isEnabled = 0;  // Disable the alarm
      }	  
    }
    if( Mode.alarmType == dtTimer)
    {
      // its a timer
      nextTrigger = time + value;  // add the value to previous time (this ensures delay always at least Value seconds)
    }
  }
  else
  {
    Mode.isEnabled = 0;  // Disable if the value is 0
  }
}
Beispiel #6
0
void AlarmClass::updateNextTrigger()
{
  if( (value != 0) && Mode.isEnabled )
  {
    time_t time = now();
    if(Mode.isAlarm && nextTrigger <= time )   // update alarm if next trigger is not yet in the future
    {
      if( value > SECS_PER_WEEK ) { // is the value a specific data and time in the future 
        nextTrigger = value;  // yes, trigger on this value	
      }
      else if ( value <= SECS_PER_DAY) {
        if( value + previousMidnight(now()) <= time) 
		{
          nextTrigger = value + nextMidnight(time); // if time has passed then set for tomorrow 
		}
		else
		{
          nextTrigger = value + previousMidnight(time);  // set the date to today and add the time given in value	
		}
      }
      else if ( value <= SECS_PER_WEEK) {
        nextTrigger = value + previousMidnight(time); // set the date to today and add the time given in value
      }
      else {
        Mode.isEnabled = 0; // values more than a year but less than today have expired so the alarm is disabled 
      }
    }
    if(Mode.isAlarm == false){
      // its a timer
      nextTrigger = time + value;  // add the value to previous time (this ensures delay always at least Value seconds)
    }
  }
  else {
    Mode.isEnabled = 0;  // Disable if the value is 0
  }
}