bool dimOutHandler(void) { const auto from = toTicks(Light::dimIn + Light::lightOn); const auto len = toTicks(Light::dimOut); light_.fill( uint8_t{255}-curTickToFill(from, len) ); return false; }
bool dimInHandler(void) { const auto from = toTicks(0); const auto len = toTicks(Light::dimIn); light_.fill( curTickToFill(from, len) ); return false; }
/** @brief process next cycle. * @return true if tisk was the last tick of the cycle, false otherwise. */ bool nextTick(void) { // pre-condition check if( not isStarted() ) return false; // count ticks tick(); // cycle: dim-in, lights on, dim-out if( tick_ < toTicks(Light::dimIn) ) return dimInHandler(); if( tick_ < toTicks(Light::dimIn + Light::lightOn) ) return lightOnHandler(); if( tick_ < toTicks(Light::dimIn + Light::lightOn + Light::dimOut) ) return dimOutHandler(); // end of cycle return stop(); }
int64_t Util::currentTimeTicks(int64_t ticksPerSec) { int64_t result; struct timeval now; int ret = THRIFT_GETTIMEOFDAY(&now, NULL); assert(ret == 0); THRIFT_UNUSED_VARIABLE(ret); // squelching "unused variable" warning toTicks(result, now, ticksPerSec); return result; }
const int64_t Util::currentTimeTicks(int64_t ticksPerSec) { int64_t result; #if defined(HAVE_CLOCK_GETTIME) struct timespec now; int ret = clock_gettime(CLOCK_REALTIME, &now); assert(ret == 0); toTicks(result, now, ticksPerSec); #elif defined(HAVE_GETTIMEOFDAY) struct timeval now; int ret = gettimeofday(&now, nullptr); assert(ret == 0); toTicks(result, now, ticksPerSec); #else #error "No high-precision clock is available." #endif // defined(HAVE_CLOCK_GETTIME) return result; }
int64_t Util::currentTimeTicks(int64_t ticksPerSec) { int64_t result; #if defined(HAVE_CLOCK_GETTIME) struct timespec now; int ret = clock_gettime(CLOCK_REALTIME, &now); assert(ret == 0); ret = ret; //squelching "unused variable" warning toTicks(result, now, ticksPerSec); #elif defined(HAVE_GETTIMEOFDAY) struct timeval now; int ret = gettimeofday(&now, NULL); assert(ret == 0); toTicks(result, now, ticksPerSec); #else //#error "No high-precision clock is available." #endif // defined(HAVE_CLOCK_GETTIME) return result; }
const int64_t Util::monotonicTimeTicks(int64_t ticksPerSec) { #if defined(HAVE_CLOCK_GETTIME) static bool useRealtime; if (useRealtime) { return currentTimeTicks(ticksPerSec); } struct timespec now; int ret = clock_gettime(CLOCK_MONOTONIC, &now); if (ret != 0) { // CLOCK_MONOTONIC is probably not supported on this system assert(errno == EINVAL); useRealtime = true; return currentTimeTicks(ticksPerSec); } int64_t result; toTicks(result, now, ticksPerSec); return result; #else return currentTimeTicks(ticksPerSec); #endif // defined(HAVE_CLOCK_GETTIME) }