Subversion Repositories DIN Is Noise

Rev

Rev 1370 | Rev 1713 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
* alarm.cc
* DIN Is Noise is copyright (c) 2006-2020 Jagannathan Sampath
* For more information, please visit https://dinisnoise.org/
*/


#include "alarm.h"
#include "chrono.h"

alarm_t::alarm_t (double tt) {
  triggert = tt;
  startt = nowt = 0;
  elapsed = 0;
  active = 0;
}

int alarm_t::operator() (double t) {
  nowt = t;
  elapsed = nowt - startt;
  if (elapsed < triggert)
    return 0;
  else {
    startt = nowt;
    return 1;
  }
}

double alarm_t::operator() () {
  return (elapsed * 1.0 / triggert);
}

void alarm_t::start () {
  startt = ui_clk ();
  elapsed = 0.0;
  active = 1;
}

void alarm_t::stop () {
  active = 0;
}