SimpleScheduler.cpp
// this is the function called in loop() which actually runs through the tasks and
// determines if it is time to run them again.
this is the function called in loop() which actually runs through the tasks and
determines if it is time to run them again.
this is the function called in loop () which actually runs through the tasks and determines if it is time to run them again .
void SimpleScheduler::checkQueue() {
  SimpleTask current = taskList, next = NULL ;
  unsigned long cMicros = micros() ;
  unsigned long cMillis = millis() ;
  if (cMicros > microsOfLastCheck) {
      currentGranularity = cMicros - microsOfLastCheck ;
  } else {
      currentGranularity = ((uint32_t)(-1l) - microsOfLastCheck) + cMicros ;
  }
  if (sampleSize == 0) {
      averageGranularity = currentGranularity ;
  } else {
      averageGranularity = (averageGranularity * (sampleSize - 1) + currentGranularity) / sampleSize ;
  }
  if (sampleSize != AVG_SAMPLE_SIZE) sampleSize++ ;
  while(current) {
    next = current->next ;
    if (!(current->taskFlags & _m_taskPaused)) {
      uint32_t delta ;
      if (current->taskFlags & _m_taskUseMicros)
          delta = (cMicros < current->lastRun) ?
              ((cMicros + current->period) - (current->lastRun + current->period)) :
              (cMicros - current->lastRun) ;
      else
          delta = (cMillis < current->lastRun) ?
              ((cMillis + current->period) - (current->lastRun + current->period)) :
              (cMillis - current->lastRun) ;
      if (delta > current->period) {
        if (current->loopMax != 0) {
          current->loopCount++ ;
          if (current->loopCount == current->loopMax) current->taskFlags |= _m_taskLastRun ;
        }
        if (current->taskFlags & _m_taskSendSelf) {
         ((void (*)(SimpleTask)) (current->theTask))(current) ;
        } else {
          (current->theTask)() ;
        }
        current->taskFlags &= ~_m_taskFirstRun ;
        current->lastRun = (current->taskFlags & _m_taskUseMicros) ? cMicros : cMillis ;
        if(current->taskFlags & _m_taskLastRun) removeTask(current) ;
      }
    }
    current = next ;
  }
  microsOfLastCheck = cMicros ;
}
void SimpleScheduler :: checkQueue ( ) { SimpleTask current = taskList , next = NULL ; unsigned long cMicros = micros ( ) ; unsigned long cMillis = millis ( ) ; if ( cMicros > microsOfLastCheck ) { currentGranularity = cMicros - microsOfLastCheck ; } else { currentGranularity = ( ( uint32_t ) ( -1l ) - microsOfLastCheck ) + cMicros ; } if ( sampleSize == 0 ) { averageGranularity = currentGranularity ; } else { averageGranularity = ( averageGranularity * ( sampleSize - 1 ) + currentGranularity ) / sampleSize ; } if ( sampleSize != AVG_SAMPLE_SIZE ) sampleSize ++ ; while ( current ) { next = current -> next ; if ( ! ( current -> taskFlags & _m_taskPaused ) ) { uint32_t delta ; if ( current -> taskFlags & _m_taskUseMicros ) delta = ( cMicros < current -> lastRun ) ? ( ( cMicros + current -> period ) - ( current -> lastRun + current -> period ) ) : ( cMicros - current -> lastRun ) ; else delta = ( cMillis < current -> lastRun ) ? ( ( cMillis + current -> period ) - ( current -> lastRun + current -> period ) ) : ( cMillis - current -> lastRun ) ; if ( delta > current -> period ) { if ( current -> loopMax != 0 ) { current -> loopCount ++ ; if ( current -> loopCount == current -> loopMax ) current -> taskFlags |= _m_taskLastRun ; } if ( current -> taskFlags & _m_taskSendSelf ) { ( ( void ( * ) ( SimpleTask ) ) ( current -> theTask ) ) ( current ) ; } else { ( current -> theTask ) ( ) ; } current -> taskFlags &= ~ _m_taskFirstRun ; current -> lastRun = ( current -> taskFlags & _m_taskUseMicros ) ? cMicros : cMillis ; if ( current -> taskFlags & _m_taskLastRun ) removeTask ( current ) ; } } current = next ; } microsOfLastCheck = cMicros ; }
this is the function called in loop() which actually runs through the tasks and
determines if it is time to run them again.
this is the function called in loop () which actually runs through the tasks and determines if it is time to run them again .
// average will be biased a bit at the wrap-around point, but it should be close enough for all but the // most picky... in which case, you're probably doing your own thing because you need more precision // than this is capable of.