コード例 #1
0
ファイル: Programme.cpp プロジェクト: imclab/Thermduino
bool
Programme::isActive(Clock &clock)
{
	// Calculate the time limits in seconds
	unsigned long startTimeSec = ((unsigned long)startTime)
	                             * TIME_CONVERSION_RATIO;
	unsigned long endTimeSec = ((unsigned long)endTime)
	                            * TIME_CONVERSION_RATIO;
	
	if (isWeekday()) {
		// Weekday programme
		return ((getWeekdays() & (0x01 << clock.getDayOfWeek())) != 0)
		       && clock.getSecsToday() >= startTimeSec
		       && clock.getSecsToday() < endTimeSec;
	} else {
		// Non-Weekday programme
		uint8_t dayNumber = clock.getDayNumber();
		unsigned long secsToday = clock.getSecsToday();
		
		return (dayNumber == startDayNumber    && startDayNumber == endDayNumber
		        && secsToday >= startTimeSec && secsToday < endTimeSec)
		       || (dayNumber == startDayNumber && startDayNumber != endDayNumber
		           && secsToday >= startTimeSec)
		       || (dayNumber == endDayNumber   && startDayNumber != endDayNumber
		           && secsToday < startTimeSec)
		       || (dayNumber > startDayNumber  && startDayNumber != endDayNumber
		           && dayNumber < endDayNumber);
	}
}
コード例 #2
0
ファイル: Programme.cpp プロジェクト: imclab/Thermduino
bool
Programme::isExpired(Clock &clock)
{
	if (isWeekday()) {
		return false;
	} else {
		uint8_t dayNumber = clock.getDayNumber();
		return (dayNumber > endDayNumber)
		       || (dayNumber == endDayNumber
		           && !isActive(clock));
	}
}