feat: gestion GRBL STEPPER

This commit is contained in:
2023-11-23 12:55:08 +01:00
parent 0a43f65ce2
commit caa5b0ceb7
5 changed files with 92 additions and 29 deletions

22
lib/GRBL/include/GRBL.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef GRBL_H
#define GRBL_H
#include <Arduino.h>
#include "Module_GRBL_13.2.h"
class iGRBL{
public:
virtual void init(int speed, double pas, int accel, String mode = "distance") = 0;
virtual void mouveForward(int mm = 5) = 0;
};
class GRBL : public iGRBL{
public:
GRBL(int grblAddr);
void init(int speed, double pas, int accel, String mode = "distance") override;
void mouveForward(int mm = 5) override;
private:
Module_GRBL* grbl;
};
#endif

34
lib/GRBL/src/GRBL.cpp Normal file
View File

@ -0,0 +1,34 @@
#include "../include/GRBL.h"
GRBL::GRBL(int grblAddr){
this->grbl = new Module_GRBL(grblAddr);
}
void GRBL::init(int speed, double pas, int accel, String mode){
char s[1024];
this->grbl->Init(&Wire);
this->grbl->setMode(mode);
sprintf(s,"$0=%f", pas); // step/mm
this->grbl->sendGcode(s);
Serial.println(s);
sprintf(s,"$4=%d", speed); // speed
this->grbl->sendGcode(s);
Serial.println(s);
sprintf(s,"$8=%d", accel); // acceleration, mm/sec^2
this->grbl->sendGcode(s);
Serial.println(s);
sprintf(s,"$3=%d", 500); // puse/µsec
this->grbl->sendGcode(s);
Serial.println(s);
}
void GRBL::mouveForward(int mm = 5){
char s[1024];
sprintf(s, "G1 X%d", mm);
this->grbl->sendGcode(s);
}