#ifndef Motor_h
#define Motor_h

#include "Arduino.h"
#include <TMC2130Stepper.h>
#include <TMC2130Stepper_REGDEFS.h>

class Motor_Controler
{
  private:
    TMC2130Stepper step_driver;
    TMC2130Stepper width_driver;
    double width_position = -1;
    volatile int hole_counter = 0;
    int hole_sensor_pin;
    int home_sensor_pin;
    int micsteps_s;
    int micsteps_w;
    int en_step_pin;
    int width_s_pin;
    int step_s_pin;
    int steps_per_move_tooth;
    double width_per_width_step;
    double initPosition;
    void _step(int step_pin, int move_speed, int num_of_steps, int ramp_steps, float ramp_amount);
    void _enableCounter();
    void _disableCounter();
    bool _checkTempFlag(TMC2130Stepper driver);
  
  public:
    Motor_Controler(int mosi, int miso, int sck,
                    int en_s, int dir_s, int step_s, int cs_s, int microsteps_s, int current_s, int schop_s, double full_step_angle_s, int teeth_count,
                    int en_w, int dir_w, int step_w, int cs_w, int microsteps_w, int current_w, int schop_w, double full_step_angle_w, double lead_per_rotate,
                    double RSense, double hcur_s, double hcur_w,
                    int hole_sensor, int home_sensor, double init_position);
    bool SwitchMotorSleep(void);
    bool HomeWidth(int move_speed);
    bool Step(bool forward, int move_speed, int pitch);
    bool RollOutTape(int pitch, int move_speed);
    bool WasHomed(void);
    bool SetWidth(double pos, int move_speed);
    void TrimStep(bool forward, int move_speed);
    void TrimWidth(bool add, int move_speed);
    void Counter_interrupt_handler(void);
    int GetHoleCount(void);
    void ShowParams(void);
    double GetPosition();
    bool Test_Con();
};
#endif
