126 lines
2.7 KiB
C++
126 lines
2.7 KiB
C++
#ifndef VHFMILL_H
|
|
#define VHFMILL_H
|
|
|
|
#include <QObject>
|
|
#include <QIODevice>
|
|
#include <QThread>
|
|
#include <QString>
|
|
#include <vector>
|
|
#include <stdint.h>
|
|
#include <QTimer>
|
|
|
|
class VhfMill : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
enum {
|
|
AXIS_NONE = 0,
|
|
AXIS_X = 1,
|
|
AXIS_Y = 1<<1,
|
|
AXIS_Z = 1<<2,
|
|
AXIS_A = 1<<3,
|
|
AXIS_B = 1<<4,
|
|
AXIS_ALL = AXIS_X | AXIS_Y | AXIS_Z | AXIS_A | AXIS_B,
|
|
};
|
|
typedef int Axis;
|
|
|
|
private:
|
|
|
|
typedef enum {
|
|
MODE_PREINIT,
|
|
MODE_HOME,
|
|
MODE_NORMAL,
|
|
MODE_TOOLCHANGE,
|
|
MODE_JOG,
|
|
} Mode;
|
|
|
|
std::vector<int> limits_;
|
|
|
|
QIODevice* serial_;
|
|
uint8_t nAxis_;
|
|
|
|
uint8_t outputs_ = 0;
|
|
int spindleSpeed_ = 0;
|
|
uint16_t sensors_;
|
|
std::vector<int> lastKnownPos_;
|
|
std::vector<int> touchoffPos_;
|
|
Mode mode_ = MODE_PREINIT;
|
|
Axis axisHomed_ = AXIS_NONE;
|
|
Axis homeAxis_ = AXIS_NONE;
|
|
|
|
Axis jogAxis_ = AXIS_NONE;
|
|
int jogStep_ = -1;
|
|
int jogDirection_ = 0;
|
|
|
|
QTimer positionTimer;
|
|
QTimer stateTimer;
|
|
QTimer initTimer;
|
|
|
|
QByteArray lineBuffer_;
|
|
|
|
void processIncomeingLine();
|
|
static int axisToMashineNumber(Axis axis);
|
|
QByteArray generateCmdForOffset(QByteArray command);
|
|
|
|
private slots:
|
|
void serialReadyRead();
|
|
void initTimerFn();
|
|
void stateTimerFn();
|
|
void reinit();
|
|
|
|
public:
|
|
explicit VhfMill(QIODevice* serial, uint8_t nAxis = 4, QObject *parent = nullptr);
|
|
std::vector<int> getLastKnownPosition() const;
|
|
Axis homed() const;
|
|
bool allHomed() const;
|
|
uint8_t axisCount() const;
|
|
uint16_t getLastKnownSensors() const;
|
|
bool presureReady() const;
|
|
bool isInitDone() const;
|
|
int getLastSpindleSpeed() const;
|
|
std::vector<int> getLastTouchoffPosition() const;
|
|
const std::vector<int>& getLimits() const;
|
|
|
|
static const QString textForErrno(int errorNumber);
|
|
static size_t axisToIndex(Axis axis);
|
|
|
|
public slots:
|
|
void setSpindleSpeed(int speed);
|
|
void send(const QByteArray& cmd);
|
|
void stop();
|
|
void home(VhfMill::Axis axis);
|
|
void jog(VhfMill::Axis axis, int jogDirection);
|
|
void setOutput(int output, bool state);
|
|
void setTool(int tool);
|
|
void reqTool();
|
|
void reqOutputs();
|
|
void reqPosition();
|
|
void reqSensors();
|
|
void reqSpindleSpeed();
|
|
void enablePosUpdates(bool enable);
|
|
void enableStateUpdates(bool enable);
|
|
void touchOff(VhfMill::Axis axis, int offset);
|
|
void touchOffAbsolute(std::vector<int> touchoffPos);
|
|
void setjogStep(int step);
|
|
void init();
|
|
|
|
signals:
|
|
void raiseError(int errorNumber);
|
|
void positionUpdate(std::vector<int> position);
|
|
void isHomed(VhfMill::Axis axis);
|
|
void gotLine(QByteArray string);
|
|
void gotToolNum(int tool);
|
|
void gotOutputs(uint8_t outputs);
|
|
void gotSindleSpeed(int speed);
|
|
void gotProbeState(bool state);
|
|
void gotPressureState(bool state);
|
|
void touchOffChanged();
|
|
void initDone();
|
|
void toolChangeDone();
|
|
void touchoffChanged(std::vector<int> touchoffPos);
|
|
void jogStepChanged(int step);
|
|
};
|
|
|
|
#endif // VHFMILL_H
|