Subversion Repositories DIN Is Noise

Rev

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

/*
* autopause.cc
* DIN Is Noise is copyright (c) 2006-2022 Jagannathan Sampath
* DIN Is Noise is released under GNU Public License 2.0
* For more information, please visit https://dinisnoise.org/
*/


#include "chrono.h"
#include "autopause.h"
#include "defvelaccel.h"
#include "autorotator.h"

autopauset::autopauset (defvelaccel& d) {
  yes = d.autos.pause.yes;
  every = d.autos.pause.every ();
  f0r = d.autos.pause.f0r ();
  alarmt &a0 = alm[0], &a1 = alm[1];
  a0.triggert = every;
  a1.triggert = f0r;
  t[0] = &every;
  t[1] = &f0r;
  vt[0] = &d.autos.pause.every;
  vt[1] = &d.autos.pause.f0r;
  a = 0;
}

void autopauset::operator() (autorotator& ar) {
  alarmt &aa = alm[a];
  if (aa(ui_clk())) {
    aa.stop ();
    a = !a;
    double& ta = *t[a];
    ta = (*vt[a])();
    if (a) ar.yes = 0; else ar.yes = 1;
    alarmt& nxt = alm[a];
    nxt.triggert = ta;
    nxt.start ();
  }
}

void autopauset::go () {
  a = 0;
  alm[a].start ();
}