#pragma once

//#include "AccelStepper.h"
#include "BasicStepperDriver.h"

#define OFFSET 5

#define MOTOR_STEPS 360
#define RPM 120
#define MICROSTEPS 1

typedef enum
{
  MOTOR0,
  MOTOR1
} e_motor;

class c_motor
{
  const int _sclk;
  const int _dir;
  const int _en;
  const int _rst;

  long _currentpos;
  long _targetpos;

  //AccelStepper _stepper;
  BasicStepperDriver _stepper;

public:
  c_motor(int sclk, int dir, int en, int rst) : _sclk(sclk), _dir(dir), _en(en), _rst(rst),
                                                _stepper(MOTOR_STEPS, _sclk, _dir, _en)
  {
  }

  void init(bool setvref = false);
  void begin(void);

  void moveTo(long pos)
  {
    _stepper.startMove(pos);
    if((_targetpos += pos) > 360)
    {
      _targetpos -= 360;
    }
  }

  bool ready( void );
  void run(void)
  {
    _stepper.nextAction();

  }

  void increasePos(void);
  void decreasePos(void);

  BasicStepperDriver *getStepper(void)
  {
    return &_stepper;
  }
};

void handleMotors(void);
void initMotors(void);
void SetMotors(long pos0, long pos1);
void increaseMotor(e_motor motor);
void decreaseMotor(e_motor motor);
