//
// A1526Timer.h                 
//
#ifndef A1526TIMER_H
#define A1526TIMER_H

#include <QtGui>
#include <time.h>
#include <A1526Control.h>

using namespace std;

class A1526Control;
class A1526TimerEvent;
class enviro;

/**************************
 * A1526TimerWindow class *
 **************************/
class A1526TimerWindow : public QWidget
{
  Q_OBJECT
	    
public slots:
  void start() {
    QString dummy;
    start( dummy );
  }
  void start( QString );
  void runevent( int );
  void next();

public:
  A1526TimerWindow( A1526Control *parent = 0, 
		    unsigned short j = 0, unsigned short i = 0 );
  A1526Control* getA1526Control(){ return myA1526Control; }
  unsigned short getSlot(){ return slot; }
  unsigned short getChannel(){ return channel; }
  void stop();
  bool isRunning(){ return running; }

private:
  void printc(const char*, ...);
  void print(const char*, ...);

private:
  QFuture<void> *future;
  QFutureWatcher<void> *futurewatcher;
  A1526Control *myA1526Control;
  enviro *myenviro;
  const char* name;
  unsigned short slot, channel;
  vector<A1526TimerEvent*> A1526TimerEvents;
  bool running;
  unsigned int currentstep;
  QString measurementtype;
  time_t startTime, now;
  char timetag[20];

signals:
  void consolewrite(const QString);
};


// Class of the object which changes Vset/Veff/Iset at a given time 
class A1526TimerEvent
{

public:
  A1526TimerEvent( int time_ = 0, bool on_ = true, 
		   unsigned long voltage_ = 0, float current_ = 0. ) {
    voltage = voltage_;
    current = current_;
    on = on_;
    time = time_;
  }
  ~A1526TimerEvent() {}
  int getTime() { return time; }
  float getCurrent() { return current; }
  int getVoltage() { return (int) voltage; }
  bool getOn() { return on; }

private:
  bool on;
  unsigned long voltage;
  float current;
  int time;
};

#endif
