#include "Arduino.h"
#include <LiquidCrystal.h>
#include <BasicStepperDriver.h>

#include "Jogrunner.h"

Jogrunner::Jogrunner(LiquidCrystal *lcd, BasicStepperDriver *stepper, int stepper_rpm) {
  _lcd = lcd;
  _stepper = stepper;
  _stepper_rpm = stepper_rpm;
}

void Jogrunner::start() {
  _lcd->clear();
  _lcd->print("Jogging...");
  _lcd->setCursor(0, 1);
  _lcd->print("[sel] to return");
}

void Jogrunner::setSpeed(bool speed) {
  if (speed == LOW) {
    _stepper->setRPM(_stepper_rpm);
  } else {
    _stepper->setRPM(2 * _stepper_rpm);
  }
}

void Jogrunner::stop() {
  _stepper->stop();
  setSpeed(LOW);
}

void Jogrunner::forward() {
  _stepper->startMove(100 * 360);
}

void Jogrunner::backward() {
  _stepper->startMove(-100 * 360);
}
